Skip to content

Commit

Permalink
[Back] Export divider | StockChange | IsArchived | Split ProductGetCo…
Browse files Browse the repository at this point in the history
…mboList - [Front] stale-while-revalidate
  • Loading branch information
Aloento committed Feb 19, 2024
1 parent a704915 commit 9a3bd0e
Show file tree
Hide file tree
Showing 20 changed files with 730 additions and 704 deletions.
8 changes: 5 additions & 3 deletions TSystems.LoveOTC/AdminHub/Order/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ await this.Db.Comments.AddAsync(new() {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 1.2.0
* @version 1.3.0
* </remarks>
*/
public async Task<bool> OrderPostClose(uint orderId, string reason) {
public async Task<string> OrderPostClose(uint orderId, string reason) {
var valid = typeof(Comment)
.GetProperty(nameof(Comment.Content))!
.GetCustomAttribute<StringLengthAttribute>()!;
Expand Down Expand Up @@ -72,7 +72,9 @@ await this.Db.Comments.AddAsync(new() {
Order = order,
});

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

return order.Status.ToString();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion TSystems.LoveOTC/Hub/Order/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal partial class ShopHub {
* </remarks>
*/
[Authorize]
public async Task<bool> OrderDeleteCancel(uint orderId) {
public async Task<bool> OrderDeleteCancelled(uint orderId) {
var row = await this.Db.Orders
.Where(x => x.UserId == this.UserId)
.Where(x => x.OrderId == orderId)
Expand Down
4 changes: 2 additions & 2 deletions TSystems.LoveOTC/Hub/Order/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ await this.Db.Orders
[Authorize]
public async Task<dynamic> OrderGetItems(uint orderId) =>
await this.Db.OrderCombos
.Where(x => x.Order.UserId == this.UserId)
.Where(x => x.OrderId == orderId)
.Where(x => x.Order.UserId == this.UserId)
.Select(x => new {
x.Quantity,
Types = x.Combo.Types.Select(t => t.TypeId).ToArray()
Expand All @@ -50,8 +50,8 @@ await this.Db.OrderCombos
[Authorize]
public Task<uint[]> OrderGetCmts(uint orderId) =>
this.Db.Comments
.Where(x => x.Order.UserId == this.UserId)
.Where(x => x.OrderId == orderId)
.Where(x => x.Order.UserId == this.UserId)
.Select(x => x.CommentId)
.ToArrayAsync();
}
10 changes: 6 additions & 4 deletions TSystems.LoveOTC/Hub/Order/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ await this.Db.Comments.AddAsync(new() {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 1.2.0
* @version 1.3.0
* </remarks>
*/
[Authorize]
public async Task<bool> OrderPostCancel(uint orderId, string reason) {
public async Task<string> OrderPostCancel(uint orderId, string reason) {
var valid = typeof(Comment)
.GetProperty(nameof(Comment.Content))!
.GetCustomAttribute<StringLengthAttribute>()!;
Expand All @@ -118,8 +118,8 @@ public async Task<bool> OrderPostCancel(uint orderId, string reason) {
throw new HubException(valid.FormatErrorMessage("Reason"));

var order = await this.Db.Orders
.Where(x => x.UserId == this.UserId)
.Where(x => x.OrderId == orderId)
.Where(x => x.UserId == this.UserId)
.Where(x => x.Status != OrderStatus.Cancelled)
.Where(x => x.Status != OrderStatus.Finished)
.Include(x => x.OrderCombos)
Expand All @@ -139,7 +139,9 @@ await this.Db.Comments.AddAsync(new() {
Order = order
});

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

return order.Status.ToString();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@fluentui/react-components": "^9.46.4",
"@fluentui/react-hooks": "^8.6.36",
"@fluentui/react-icons": "^2.0.226",
"@fluentui/react-icons": "^2.0.227",
"@griffel/react": "^1.5.20",
"@lexical/clipboard": "0.10.0",
"@lexical/code": "0.10.0",
Expand Down Expand Up @@ -52,10 +52,10 @@
},
"devDependencies": {
"@types/lodash-es": "^4.17.12",
"@types/react": "^18.2.55",
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react-swc": "^3.6.0",
"typescript": "^5.3.3",
"vite": "^5.1.0"
"vite": "^5.1.3"
}
}
1,131 changes: 569 additions & 562 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

44 changes: 23 additions & 21 deletions src/Components/Order/Append.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { Button, Field, Textarea, Toast, ToastTitle, makeStyles } from "@fluentu
import { useConst } from "@fluentui/react-hooks";
import { useState } from "react";
import { Flex } from "~/Helpers/Styles";
import { useSWR } from "~/Helpers/useSWR";
import { useErrorToast } from "~/Helpers/useToast";
import { Hub } from "~/ShopNet";
import { AdminHub } from "~/ShopNet/Admin";
import { SignalR } from "~/ShopNet/SignalR";
import { IOrderRef } from ".";
import { IOrderComp } from ".";
import { useOrder } from "./useOrder";

/**
* @author Aloento
Expand All @@ -24,19 +23,17 @@ const useStyles = makeStyles({
/**
* @author Aloento
* @since 0.5.0
* @version 1.2.0
* @version 1.3.0
*/
export function CommentAppend({ OrderId, Refresh, Admin, ParentLog }: IOrderRef) {
export function CommentAppend({ OrderId, Refresh, Admin, ParentLog }: IOrderComp & { Refresh: () => void }) {
const log = useConst(() => ParentLog.With("Append"));

const style = useStyles();
const [cmt, setCmt] = useState<string>();

const { dispatch, dispatchToast } = useErrorToast(log);

const hub = (Admin ? AdminHub : Hub).Order.Post as typeof AdminHub.Order.Post & typeof Hub.Order.Post;

const { run: append } = hub.useAppend({
const { run: append, loading } = (Admin ? AdminHub : Hub).Order.Post.useAppend({
manual: true,
onError(e, req) {
dispatch({
Expand All @@ -54,10 +51,13 @@ export function CommentAppend({ OrderId, Refresh, Admin, ParentLog }: IOrderRef)
);

Refresh();
setCmt("");
}
});

const { run: cancel } = (Admin ? hub.useClose : hub.useCancel)({
const { data: order, mutate } = useOrder(OrderId, Admin);

const { run: cancel, loading: submit } = (Admin ? AdminHub : Hub).Order.Post.useCancel({
manual: true,
onError(e, params) {
dispatch({
Expand All @@ -66,26 +66,21 @@ export function CommentAppend({ OrderId, Refresh, Admin, ParentLog }: IOrderRef)
Error: e
});
},
onSuccess() {
onSuccess(data) {
dispatchToast(
<Toast>
<ToastTitle>Order {Admin ? "Closed" : "Cancelled"}</ToastTitle>
</Toast>,
{ intent: "success" }
);

Refresh();
mutate((old) => ({
...old!,
Status: data
}));
}
});

const index = useConst(() => SignalR.Index(OrderId, Hub.Order.Get.order));

const { data: order } = useSWR(
index,
() => (Admin ? AdminHub : Hub).Order.Get.Order(OrderId),
{ useMemory: true }
);

switch (order?.Status) {
case "Cancelled":
case "Finished":
Expand All @@ -100,7 +95,10 @@ export function CommentAppend({ OrderId, Refresh, Admin, ParentLog }: IOrderRef)
<div className={style.body}>
{
!(order?.Status === "Finished" || order?.Status === "Returning") &&
<Button onClick={() => cancel(OrderId, cmt!)}>
<Button
onClick={() => cancel(OrderId, cmt!)}
disabled={submit}
>
{
Admin
? "Force Close"
Expand All @@ -109,7 +107,11 @@ export function CommentAppend({ OrderId, Refresh, Admin, ParentLog }: IOrderRef)
</Button>
}

<Button appearance="primary" onClick={() => append(OrderId, cmt!)}>
<Button
appearance="primary"
onClick={() => append(OrderId, cmt!)}
disabled={loading}
>
Add Comment
</Button>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Order/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface IComment {
*/
export function OrderComment({ OrderId, Admin, ParentLog }: IOrderComp) {
const log = useConst(() => ParentLog.With("Comment"));
const { data, run } = Hub.Order.Get.useCmts(OrderId, log, Admin);
const { data, refresh } = Hub.Order.Get.useCmts(OrderId, log, Admin);

return <>
<Field label="Comment" size="large">
Expand All @@ -38,6 +38,6 @@ export function OrderComment({ OrderId, Admin, ParentLog }: IOrderComp) {
)}
</Field>

<CommentAppend OrderId={OrderId} Refresh={run} ParentLog={log} Admin={Admin} />
<CommentAppend OrderId={OrderId} Refresh={refresh} ParentLog={log} Admin={Admin} />
</>;
}
34 changes: 7 additions & 27 deletions src/Components/Order/Drawer.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import { Body1Strong, Caption1, DataGridCell, DataGridHeaderCell, Link, TableColumnDefinition, createTableColumn, makeStyles, tokens } from "@fluentui/react-components";
import { useConst } from "@fluentui/react-hooks";
import { DelegateDataGrid } from "~/Components/DataGrid";
import { OrderComment } from "~/Components/Order/Comment";
import { OrderInfo } from "~/Components/Order/Info";
import { ICartItem } from "~/Components/ShopCart";
import { MakeCoverCol } from "~/Helpers/CoverCol";
import { ColFlex } from "~/Helpers/Styles";
import { useSWR } from "~/Helpers/useSWR";
import { AdminOrderAction } from "~/Pages/Admin/Order/Action";
import { AdminOrderList } from "~/Pages/Admin/Order/List";
import { Shipment } from "~/Pages/Admin/Order/Ship";
import { Hub } from "~/ShopNet";
import { AdminHub } from "~/ShopNet/Admin";
import { SignalR } from "~/ShopNet/SignalR";
import { IOrderComp } from ".";
import { OrderAction } from "../../Pages/History/Action";
import { useRouter } from "../Router";

/**
* @author Aloento
Expand All @@ -25,7 +20,8 @@ import { useRouter } from "../Router";
const useStyles = makeStyles({
body: {
...ColFlex,
rowGap: tokens.spacingVerticalL
rowGap: tokens.spacingVerticalL,
paddingBottom: tokens.spacingVerticalXXL
},
prod: {
...ColFlex,
Expand Down Expand Up @@ -82,38 +78,22 @@ const columns: TableColumnDefinition<ICartItem>[] = [
/**
* @author Aloento
* @since 1.3.5
* @version 1.3.0
* @version 1.4.0
*/
export function OrderDetailDrawer({ OrderId, Admin, ParentLog }: IOrderComp) {
const style = useStyles();

const { Nav } = useRouter();
const index = useConst(() => SignalR.Index(OrderId, Hub.Order.Get.order));

const { data: order, run } = useSWR(
index,
() => (Admin ? AdminHub : Hub).Order.Get.Order(OrderId),
{
onError(e) {
Nav("History");
ParentLog.error(e);
},
useMemory: true
}
);

const { data: cart } = Hub.Order.Get.useItems(OrderId, ParentLog, Admin);

return (
<div className={style.body}>
<OrderInfo OrderId={OrderId} Order={order} Admin={Admin} ParentLog={ParentLog} />
<OrderInfo OrderId={OrderId} Admin={Admin} ParentLog={ParentLog} />

{
Admin
?
<>
<AdminOrderList Items={cart} />
<Shipment OrderId={OrderId} TrackingNumber={order?.TrackingNumber} Refresh={run} />
<Shipment OrderId={OrderId} />
</>
:
<DelegateDataGrid
Expand All @@ -127,9 +107,9 @@ export function OrderDetailDrawer({ OrderId, Admin, ParentLog }: IOrderComp) {
{
Admin
?
<AdminOrderAction OrderId={OrderId} Status={order?.Status} Refresh={run} ParentLog={ParentLog} />
<AdminOrderAction OrderId={OrderId} />
:
<OrderAction OrderId={OrderId} Status={order?.Status} Refresh={run} ParentLog={ParentLog} />
<OrderAction OrderId={OrderId} />
}
</div>
);
Expand Down
25 changes: 15 additions & 10 deletions src/Components/Order/Info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { useRequest } from "ahooks";
import { ColFlex, Flex } from "~/Helpers/Styles";
import { Hub } from "~/ShopNet";
import { AdminHub } from "~/ShopNet/Admin";
import type { OrderEntity } from "~/ShopNet/Order/Entity";
import type { IOrderComp } from ".";
import { useRouter } from "../Router";
import { useOrder } from "./useOrder";

/**
* @author Aloento
Expand All @@ -21,19 +22,23 @@ const useStyles = makeStyles({
},
});

interface IOrderInfo extends IOrderComp {
Order?: OrderEntity.Order;
}

/**
* @author Aloento
* @since 0.5.0
* @version 1.0.0
* @version 1.1.0
*/
export function OrderInfo({ OrderId, Order, Admin, ParentLog }: IOrderInfo) {
export function OrderInfo({ OrderId, Admin, ParentLog }: IOrderComp) {
const log = useConst(() => ParentLog.With("Info"));
const style = useStyles();

const { Nav } = useRouter();
const { data: order } = useOrder(OrderId, Admin, {
onError(e) {
Nav(Admin ? "Admin/Order" : "History");
ParentLog.error(e);
}
});

const { data: admin } = useRequest(() => AdminHub.User.Get.OrderUser(OrderId), {
manual: !Admin,
onError: log.error
Expand Down Expand Up @@ -61,13 +66,13 @@ export function OrderInfo({ OrderId, Order, Admin, ParentLog }: IOrderInfo) {
<div className={style.flex}>
<div className={style.box}>
<Field label="Order Date" size="large">
<Label>{Order?.CreateAt.toLocaleDateString()}</Label>
<Label>{order?.CreateAt.toLocaleDateString()}</Label>
</Field>
</div>

<div className={style.box}>
<Field label="Status" size="large">
<Label>{Order?.Status}</Label>
<Label>{order?.Status}</Label>
</Field>
</div>
</div>
Expand All @@ -83,7 +88,7 @@ export function OrderInfo({ OrderId, Order, Admin, ParentLog }: IOrderInfo) {
!Admin &&
<div className={style.box}>
<Field label="Tracking Number" size="large">
<Label>{Order?.TrackingNumber}</Label>
<Label>{order?.TrackingNumber}</Label>
</Field>
</div>
}
Expand Down
Loading

0 comments on commit 9a3bd0e

Please sign in to comment.