Skip to content

Commit

Permalink
[Front] ShopCount | Setting Tips - [Back] Stock Change
Browse files Browse the repository at this point in the history
  • Loading branch information
Aloento committed Feb 7, 2024
1 parent cac538e commit fa9d2e9
Show file tree
Hide file tree
Showing 9 changed files with 584 additions and 540 deletions.
9 changes: 5 additions & 4 deletions TSystems.LoveOTC/AdminHub/Order/Export.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal partial class AdminHub {
* <remarks>
* @author Aloento
* @since 1.2.0
* @version 0.2.0
* @version 1.0.0
* </remarks>
*/
public async IAsyncEnumerable<byte[]> ExportOrder() {
Expand Down Expand Up @@ -224,16 +224,17 @@ public async IAsyncEnumerable<byte[]> ExportOrder() {

int shared(string text) {
var i = 0;
var table = sharedStringTablePart.SharedStringTable;

foreach (var item in sharedStringTablePart!.SharedStringTable.Elements<SharedStringItem>()) {
foreach (var item in table.Elements<SharedStringItem>()) {
if (item.InnerText == text)
return i;

i++;
}

sharedStringTablePart.SharedStringTable.AppendChild(new SharedStringItem(new Text(text)));
sharedStringTablePart.SharedStringTable.Save();
table.AppendChild(new SharedStringItem(new Text(text)));
table.Save();

return i;
}
Expand Down
24 changes: 17 additions & 7 deletions TSystems.LoveOTC/Hub/Order/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal partial class ShopHub {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 1.1.0
* @version 1.2.0
* </remarks>
*/
[Authorize]
Expand All @@ -39,19 +39,24 @@ await this.Db.Comments.AddAsync(new() {
});

foreach (var item in cart) {
if (item.Quantity > 3)
throw new HubException("No more than 3 of each type.");
if (item.Quantity is > Limit or < 1)
throw new HubException($"No more than {Limit} OR less 1 of each type.");

var combo = await this.Db.Combos
.Where(x => x.IsArchived != true)
.Where(x => x.ProductId == item.ProdId)
.Where(x => x.IsArchived != true)
.Where(x => item.Type.All(
i => x.Types
.Select(t => t.Name)
.Contains(i))
)
.Contains(i)
))
.SingleAsync();

if (combo.Stock < item.Quantity)
throw new HubException("Insufficient Stock");

combo.Stock -= item.Quantity;

await this.Db.OrderCombos.AddAsync(new() {
Order = order,
Combo = combo,
Expand Down Expand Up @@ -100,7 +105,7 @@ await this.Db.Comments.AddAsync(new() {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 1.1.0
* @version 1.2.0
* </remarks>
*/
[Authorize]
Expand All @@ -117,6 +122,8 @@ public async Task<bool> OrderPostCancel(uint orderId, string reason) {
.Where(x => x.OrderId == orderId)
.Where(x => x.Status != OrderStatus.Cancelled)
.Where(x => x.Status != OrderStatus.Finished)
.Include(x => x.OrderCombos)
.ThenInclude(x => x.Combo)
.SingleAsync();

order.Status = order.Status == OrderStatus.Shipping
Expand All @@ -129,6 +136,9 @@ await this.Db.Comments.AddAsync(new() {
Order = order
});

foreach (var oc in order.OrderCombos)
oc.Combo.Stock += oc.Quantity;

return await this.Db.SaveChangesAsync() > 0;
}

Expand Down
4 changes: 3 additions & 1 deletion TSystems.LoveOTC/Hub/Product/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ namespace TSystems.LoveOTC.Hub;
using Microsoft.EntityFrameworkCore;

internal partial class ShopHub {
protected const byte Limit = 3;

/**
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.2.0
* </remarks>
*/
public Task<byte> ProdGetLimit(uint _) => Task.FromResult<byte>(3);
public Task<byte> ProdGetLimit(uint _) => Task.FromResult(Limit);

/**
* <remarks>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"update": "npx npm-check-updates -u"
},
"dependencies": {
"@fluentui/react-components": "^9.46.3",
"@fluentui/react-components": "^9.46.4",
"@fluentui/react-hooks": "^8.6.36",
"@fluentui/react-icons": "^2.0.226",
"@griffel/react": "^1.5.20",
Expand Down Expand Up @@ -52,8 +52,8 @@
},
"devDependencies": {
"@types/lodash-es": "^4.17.12",
"@types/react": "^18.2.54",
"@types/react-dom": "^18.2.18",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react-swc": "^3.6.0",
"typescript": "^5.3.3",
"vite": "^5.0.12"
Expand Down
1,015 changes: 508 additions & 507 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

42 changes: 30 additions & 12 deletions src/Components/Setting.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Dialog, DialogActions, DialogBody, DialogContent, DialogSurface, DialogTitle, DialogTrigger, Field, Input, Label, Toast, ToastBody, ToastTitle, makeStyles, tokens } from "@fluentui/react-components";
import { Button, Dialog, DialogActions, DialogBody, DialogContent, DialogSurface, DialogTitle, DialogTrigger, Field, Input, Label, Toast, ToastBody, ToastTitle, Tooltip, makeStyles, tokens } from "@fluentui/react-components";
import { useEffect, useState } from "react";
import { useAuth } from "react-oidc-context";
import { Logger } from "~/Helpers/Logger";
Expand Down Expand Up @@ -39,7 +39,7 @@ const log = new Logger("Setting");
/**
* @author Aloento
* @since 0.1.0
* @version 0.5.0
* @version 0.7.0
*/
export function Setting({ Open, Toggle, New }: ISetting) {
const style = useStyles();
Expand Down Expand Up @@ -105,22 +105,40 @@ export function Setting({ Open, Toggle, New }: ISetting) {

<DialogContent className={style.box}>
<div className={style.one}>
<Field label="Name" size="large" required>
<Input size="medium" value={name} maxLength={20} onChange={(_, v) => setName(v.value)} />
</Field>

<Field label="Phone" size="large" required>
<Input size="medium" value={phone} maxLength={20} onChange={(_, v) => setPhone(v.value)} />
</Field>
<Tooltip
content="Full first and family names, will be used to the shipping label."
relationship="description"
withArrow
>
<Field label="Name" size="large" required>
<Input size="medium" value={name} maxLength={20} onChange={(_, v) => setName(v.value)} />
</Field>
</Tooltip>

<Tooltip
content="Up to 20 digits, starting with an internation access code."
relationship="description"
withArrow
>
<Field label="Phone" size="large" required>
<Input size="medium" value={phone} maxLength={20} onChange={(_, v) => setPhone(v.value)} />
</Field>
</Tooltip>
</div>

<Field label="E-Mail" size="large">
<Label>{auth.user?.profile.email}</Label>
</Field>

<Field label="Address" size="large" required>
<Input size="medium" value={address} maxLength={100} minLength={20} onChange={(_, v) => setAddress(v.value)} />
</Field>
<Tooltip
content="Your full shipping address including street, number, ZIP, town and country. Separate lines by commas."
relationship="description"
withArrow
>
<Field label="Address" size="large" required>
<Input size="medium" value={address} maxLength={100} minLength={20} onChange={(_, v) => setAddress(v.value)} />
</Field>
</Tooltip>
</DialogContent>

<DialogActions>
Expand Down
11 changes: 8 additions & 3 deletions src/Components/ShopCart/Columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ const columns: TableColumnDefinition<ICartItem>[] = [
max={max}
value={item.Quantity}
onChange={(_, v) => {
if (dis && v.value! >= item.Quantity)
if (dis)
return;

item.Quantity = v.value!;
const val = v.value || parseInt(v.displayValue!);

if ((!v.value && isNaN(val)) || val < 1 || val > max || val === item.Quantity)
return;

item.Quantity = val;
Update(List);
}} />
</DataGridCell>
Expand All @@ -86,7 +91,7 @@ const columns: TableColumnDefinition<ICartItem>[] = [
/**
* @author Aloento
* @since 0.1.0
* @version 0.3.1
* @version 0.4.0
*/
export function CartColumns(log: Logger): TableColumnDefinition<ICartItem>[] {
return [
Expand Down
11 changes: 9 additions & 2 deletions src/Pages/Product/Quantity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const useStyles = makeStyles({
/**
* @author Aloento
* @since 1.2.0
* @version 0.2.0
* @version 0.3.0
*/
export function ProductQuantity({ Id }: { Id: number; }) {
const style = useStyles();
Expand Down Expand Up @@ -61,7 +61,14 @@ export function ProductQuantity({ Id }: { Id: number; }) {
min={1}
max={max}
disabled={!Combo?.Stock}
onChange={(_, val) => setQuantity(val.value!)}
onChange={(_, v) => {
const val = v.value || parseInt(v.displayValue!);

if ((!v.value && isNaN(val)) || val < 1 || val > max || val === quantity)
return;

setQuantity(val);
}}
/>

<ProductAddCart
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ theme.fontFamilyMonospace = `TeleNeoWeb, ${theme.fontFamilyMonospace}`;
theme.fontFamilyNumeric = `TeleNeoWeb, ${theme.fontFamilyNumeric}`;

const log = new Logger("LoveOTC");
log.info("Version: 1.3.5 2024/02/05");
log.info("Version: 1.3.5 2024/02/07");
log.debug("T-Systems, EcoSystem Squad, Aloento");

/**
Expand Down

0 comments on commit fa9d2e9

Please sign in to comment.