Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

[Front] SpinBorderCheck #105

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading