Skip to content

Commit

Permalink
[Front] SpinBorderCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Aloento committed Feb 7, 2024
1 parent fa9d2e9 commit 544be09
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 36 deletions.
2 changes: 1 addition & 1 deletion TSystems.LoveOTC/Hub/Product/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace TSystems.LoveOTC.Hub;
using Microsoft.EntityFrameworkCore;

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

/**
* <remarks>
Expand Down
7 changes: 2 additions & 5 deletions src/Components/ShopCart/Columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,9 @@ const columns: TableColumnDefinition<ICartItem>[] = [
max={max}
value={item.Quantity}
onChange={(_, v) => {
if (dis)
return;

const val = v.value || parseInt(v.displayValue!);
const val = parseInt(v.value || v.displayValue as any);

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

item.Quantity = val;
Expand Down
8 changes: 4 additions & 4 deletions src/Helpers/useLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { Hub } from "~/ShopNet";
/**
* @author Aloento
* @since 0.5.0
* @version 0.2.0
* @version 0.3.0
*/
export function useLimit(prodId: number): [boolean, number] {
export function useLimit(prodId: number): [boolean, number, number] {
const { List } = useShopCart();
const { data } = useRequest(() => Hub.Product.Get.Limit(prodId));

Expand All @@ -19,8 +19,8 @@ export function useLimit(prodId: number): [boolean, number] {
count += i.Quantity;

if (count >= limit)
return [true, limit];
return [true, limit, count];
}

return [false, limit];
return [false, limit, count];
}
2 changes: 1 addition & 1 deletion src/Pages/Admin/Order/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function AdminOrder() {
onChange={(_, data) => {
const value = parseInt(data.value || data.displayValue as any);

if (!Number.isNaN(value) && value && value <= page)
if (!isNaN(value) && value && value <= page)
run(value);
}}
/>
Expand Down
18 changes: 8 additions & 10 deletions src/Pages/Admin/Product/Combo/Detail.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Button, Combobox, DataGridCell, DataGridHeaderCell, Dialog, DialogBody, DialogContent, DialogSurface, DialogTitle, DialogTrigger, Label, Option, SpinButton, TableColumnDefinition, Toast, ToastTitle, createTableColumn, makeStyles, tokens } from "@fluentui/react-components";
import { DismissRegular, EditRegular } from "@fluentui/react-icons";
import { useBoolean, useRequest } from "ahooks";
import { isInteger } from "lodash-es";
import { useState } from "react";
import { DelegateDataGrid } from "~/Components/DataGrid";
import { Logger } from "~/Helpers/Logger";
Expand Down Expand Up @@ -89,7 +88,7 @@ const log = new Logger("Admin", "Product", "Detail", "Combo", "Detail");
/**
* @author Aloento
* @since 0.5.0
* @version 0.2.2
* @version 0.2.3
*/
export function AdminProductComboDetail({ Id, ProdId, Combo, Stock, Refresh }: IDetailComboItem) {
const [open, { toggle }] = useBoolean();
Expand Down Expand Up @@ -159,14 +158,13 @@ export function AdminProductComboDetail({ Id, ProdId, Combo, Stock, Refresh }: I
<div className={useStyles().body}>
<Label>Stock</Label>

<SpinButton value={stock} min={0} onChange={(_, x) => {
if (x.value)
setStock(x.value);
else if (x.displayValue) {
const i = parseInt(x.displayValue);
if (isInteger(i))
setStock(i);
}
<SpinButton value={stock} min={0} onChange={(_, v) => {
const val = parseInt(v.value || v.displayValue as any);

if (isNaN(val) || val < 0)
return;

setStock(val);
}} />

<Button appearance="primary" onClick={() => run(Id, combo, stock)}>Submit</Button>
Expand Down
18 changes: 8 additions & 10 deletions src/Pages/Admin/Product/Combo/New.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Button, Combobox, DataGridCell, DataGridHeaderCell, Dialog, DialogBody, DialogContent, DialogSurface, DialogTitle, DialogTrigger, Label, Option, SpinButton, TableColumnDefinition, Toast, ToastTitle, createTableColumn, makeStyles, tokens } from "@fluentui/react-components";
import { AddRegular, DismissRegular } from "@fluentui/react-icons";
import { useBoolean, useRequest } from "ahooks";
import { isInteger } from "lodash-es";
import { useState } from "react";
import { DelegateDataGrid } from "~/Components/DataGrid";
import { Logger } from "~/Helpers/Logger";
Expand Down Expand Up @@ -73,7 +72,7 @@ const log = new Logger("Admin", "Product", "Detail", "Combo", "NewCombo");
/**
* @author Aloento
* @since 0.5.0
* @version 0.2.2
* @version 0.2.3
*/
export function AdminProductNewCombo({ ProdId, Refresh }: { ProdId: number; Refresh: () => void }) {
const [open, { toggle }] = useBoolean();
Expand Down Expand Up @@ -147,14 +146,13 @@ export function AdminProductNewCombo({ ProdId, Refresh }: { ProdId: number; Refr
<div className={useStyles().body}>
<Label>Stock</Label>

<SpinButton value={stock} min={0} onChange={(_, x) => {
if (x.value)
setStock(x.value);
else if (x.displayValue) {
const i = parseInt(x.displayValue);
if (isInteger(i))
setStock(i);
}
<SpinButton value={stock} min={0} onChange={(_, v) => {
const val = parseInt(v.value || v.displayValue as any);

if (isNaN(val) || val < 0)
return;

setStock(val);
}} />

<Button appearance="primary" onClick={() => run(ProdId, combo, stock)}>Create</Button>
Expand Down
10 changes: 5 additions & 5 deletions src/Pages/Product/Quantity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ const useStyles = makeStyles({
/**
* @author Aloento
* @since 1.2.0
* @version 0.3.0
* @version 0.4.0
*/
export function ProductQuantity({ Id }: { Id: number; }) {
const style = useStyles();
const { Combo } = useRadioGroup();

const [_, max] = useLimit(Id);
const [_, max, count] = useLimit(Id);
const [quantity, setQuantity] = useState(1);

return (
Expand All @@ -59,12 +59,12 @@ export function ProductQuantity({ Id }: { Id: number; }) {
appearance="underline"
value={quantity}
min={1}
max={max}
max={max - count}
disabled={!Combo?.Stock}
onChange={(_, v) => {
const val = v.value || parseInt(v.displayValue!);
const val = parseInt(v.value || v.displayValue as any);

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

setQuantity(val);
Expand Down

0 comments on commit 544be09

Please sign in to comment.