-
+
-
+ {
+ Admin
+ ?
+
+ :
+
+ }
diff --git a/src/Components/Order/index.tsx b/src/Components/Order/index.tsx
index 946f1cb..11a1bab 100644
--- a/src/Components/Order/index.tsx
+++ b/src/Components/Order/index.tsx
@@ -32,7 +32,7 @@ export function OrderDetail({ OrderId, Admin, ParentLog }: IOrderComp) {
const [open, { set }] = useBoolean();
const { Nav, Paths } = useRouter();
- const curr = parseInt(Paths.at(1)!);
+ const curr = parseInt(Paths.at(Admin ? 2 : 1)!);
useEffect(() => set(curr === OrderId), [curr]);
const ref = useRef(null);
diff --git a/src/Pages/Admin/Order/Detail.tsx b/src/Pages/Admin/Order/Detail.tsx
index 91537c4..d44f21a 100644
--- a/src/Pages/Admin/Order/Detail.tsx
+++ b/src/Pages/Admin/Order/Detail.tsx
@@ -1,4 +1,4 @@
-import { Button, Field, makeStyles, tokens } from "@fluentui/react-components";
+import { Button, makeStyles, tokens } from "@fluentui/react-components";
import { Drawer, DrawerBody, DrawerHeader, DrawerHeaderTitle } from "@fluentui/react-components/unstable";
import { DismissRegular, OpenRegular } from "@fluentui/react-icons";
import { useBoolean, useRequest } from "ahooks";
@@ -96,9 +96,7 @@ export function AdminOrderDetail({ OrderId }: { OrderId: number; }) {
-
-
-
+
diff --git a/src/Pages/Admin/Order/List.tsx b/src/Pages/Admin/Order/List.tsx
index 17f6303..31ced90 100644
--- a/src/Pages/Admin/Order/List.tsx
+++ b/src/Pages/Admin/Order/List.tsx
@@ -1,4 +1,4 @@
-import { DataGridCell, DataGridHeaderCell, TableColumnDefinition, createTableColumn, makeStyles } from "@fluentui/react-components";
+import { DataGridCell, DataGridHeaderCell, Field, TableColumnDefinition, createTableColumn, makeStyles } from "@fluentui/react-components";
import { DelegateDataGrid } from "~/Components/DataGrid";
import { ICartItem } from "~/Components/ShopCart";
@@ -64,6 +64,8 @@ const columns: TableColumnDefinition[] = [
*/
export function AdminOrderList({ Items }: { Items?: ICartItem[] }) {
return (
-
+
+
+
)
}
diff --git a/src/ShopNet/Admin/Order/Get.ts b/src/ShopNet/Admin/Order/Get.ts
index 80fc46f..7dfca6e 100644
--- a/src/ShopNet/Admin/Order/Get.ts
+++ b/src/ShopNet/Admin/Order/Get.ts
@@ -1,10 +1,6 @@
-import { IOrderComp } from "~/Components/Order";
-import { ICartItem } from "~/Components/ShopCart";
import { Logger } from "~/Helpers/Logger";
import { IAdminOrderItem } from "~/Pages/Admin/Order";
-import { IComment } from "~/Pages/History/Comment";
import { ProductData } from "~/ShopNet/Product/Data";
-import { ProductGet } from "~/ShopNet/Product/Get";
import { AdminNet } from "../AdminNet";
import { AdminUserEntity } from "../User/Entity";
import { AdminOrderEntity } from "./Entity";
@@ -90,107 +86,6 @@ export abstract class AdminOrderGet extends AdminNet {
return items;
}
- /**
- * @author Aloento
- * @since 1.0.0
- * @version 0.1.1
- */
- public static async Detail(orderId: number, pLog: Logger): Promise {
- this.EnsureLogin();
- const log = pLog.With(...this.Log, "Detail");
-
- const meta = await this.GetTimeCache<
- {
- Items: {
- Types: number[];
- Quantity: number;
- }[],
- Comments: number[];
- }
- >(orderId, "OrderGetDetail", (x) => x.add(1, "m"), orderId);
-
- const items: ICartItem[] = [];
- let index = 0;
-
- for (const combo of meta.Items) {
- const variType: Record = {};
- let prodId = 0;
-
- for (const typeId of combo.Types) {
- const type = await ProductData.Type(typeId);
-
- if (!type) {
- log.warn(`[Mismatch] Type ${typeId} not found. Order : ${orderId}`);
- continue;
- }
-
- const vari = await ProductData.Variant(type.VariantId);
-
- if (!vari) {
- log.warn(`[Mismatch] Variant ${type.VariantId} not found. Type : ${typeId}, Order : ${orderId}`);
- continue;
- }
-
- variType[vari.Name] = type.Name;
- prodId = vari.ProductId;
- }
-
- const prod = await ProductData.Product(prodId);
-
- if (!prod) {
- log.warn(`[Mismatch] Product ${prodId} not found. Order : ${orderId}`);
- continue;
- }
-
- const [_, cover] = await ProductGet.PhotoList(prodId, log);
-
- if (!cover)
- log.warn(`Product ${prodId} has no photo`);
-
- items.push({
- Id: index++,
- ProdId: prodId,
- Cover: cover || "",
- Name: prod.Name,
- Type: variType,
- Quantity: combo.Quantity,
- });
- }
-
- const comments: IComment[] = [];
-
- for (const cmtId of meta.Comments) {
- const cmt = await AdminOrderEntity.Comment(cmtId);
-
- if (!cmt) {
- log.warn(`[Mismatch] Comment ${cmtId} not found. Order : ${orderId}`);
- continue;
- }
-
- let name = "Client";
-
- if (cmt.UserId) {
- const user = await AdminUserEntity.User(cmt.UserId);
-
- if (user)
- name = user.Name;
- else
- log.warn(`[Mismatch] User ${cmt.UserId} not found. Order : ${orderId}`);
- }
-
- comments.push({
- Content: cmt.Content,
- Time: cmt.CreateAt,
- User: name
- });
- }
-
- return {
- ShopCart: items,
- Comments: comments.sort((a, b) => a.Time.getTime() - b.Time.getTime())
- };
- }
-
public static Order = AdminOrderEntity.Order;
public static Export = AdminOrderExport.Export;
}
diff --git a/src/ShopNet/Order/Get.ts b/src/ShopNet/Order/Get.ts
index d7b9445..a0c26aa 100644
--- a/src/ShopNet/Order/Get.ts
+++ b/src/ShopNet/Order/Get.ts
@@ -1,10 +1,13 @@
import { useConst } from "@fluentui/react-hooks";
import { useAsyncEffect } from "ahooks";
import { useState } from "react";
-import { IComment } from "~/Components/Order/Comment";
-import { ICartItem } from "~/Components/ShopCart";
+import type { IComment } from "~/Components/Order/Comment";
+import type { ICartItem } from "~/Components/ShopCart";
import { Logger } from "~/Helpers/Logger";
-import { IOrderItem } from "~/Pages/History";
+import type { IOrderItem } from "~/Pages/History";
+import { AdminNet } from "../Admin/AdminNet";
+import { AdminOrderEntity } from "../Admin/Order/Entity";
+import { AdminUserEntity } from "../Admin/User/Entity";
import { ProductData } from "../Product/Data";
import { ProductGet } from "../Product/Get";
import { OrderEntity } from "./Entity";
@@ -75,13 +78,13 @@ export abstract class OrderGet extends OrderEntity {
/**
* @author Aloento
* @since 0.5.0
- * @version 2.0.0
+ * @version 2.1.0
*/
- public static useItems(orderId: number, pLog: Logger) {
+ public static useItems(orderId: number, pLog: Logger, admin?: true) {
const log = useConst(() => pLog.With(...this.Log, "Items"));
const [res, setRes] = useState();
- const req = this.useTimeCache<
+ const req = (admin ? AdminNet : this).useTimeCache<
{
Types: number[];
Quantity: number;
@@ -160,13 +163,13 @@ export abstract class OrderGet extends OrderEntity {
/**
* @author Aloento
* @since 1.3.5
- * @version 0.1.0
+ * @version 1.0.0
*/
- public static useCmts(orderId: number, pLog: Logger) {
+ public static useCmts(orderId: number, pLog: Logger, admin?: true) {
const log = useConst(() => pLog.With(...this.Log, "Cmts"));
const [res, setRes] = useState();
- const req = this.useTimeCache(
+ const req = (admin ? AdminNet : this).useTimeCache(
orderId,
"OrderGetCmts",
{
@@ -182,20 +185,47 @@ export abstract class OrderGet extends OrderEntity {
const comments: IComment[] = [];
- for (const cmtId of cmts) {
- const cmt = await this.Comment(cmtId);
+ if (admin)
+ for (const cmtId of cmts) {
+ const cmt = await AdminOrderEntity.Comment(cmtId);
- if (!cmt) {
- log.warn(`[Mismatch] Comment ${cmtId} not found. Order : ${orderId}`);
- continue;
+ if (!cmt) {
+ log.warn(`[Mismatch] Comment ${cmtId} not found. Order : ${orderId}`);
+ continue;
+ }
+
+ let name = "Client";
+
+ if (cmt.UserId) {
+ const user = await AdminUserEntity.User(cmt.UserId);
+
+ if (user)
+ name = user.Name;
+ else
+ log.warn(`[Mismatch] User ${cmt.UserId} not found. Order : ${orderId}`);
+ }
+
+ comments.push({
+ Content: cmt.Content,
+ Time: cmt.CreateAt,
+ User: name
+ });
}
+ else
+ for (const cmtId of cmts) {
+ const cmt = await this.Comment(cmtId);
- comments.push({
- Content: cmt.Content,
- Time: cmt.CreateAt,
- User: cmt.Name || "You"
- });
- }
+ if (!cmt) {
+ log.warn(`[Mismatch] Comment ${cmtId} not found. Order : ${orderId}`);
+ continue;
+ }
+
+ comments.push({
+ Content: cmt.Content,
+ Time: cmt.CreateAt,
+ User: cmt.Name || "You"
+ });
+ }
setRes(comments.sort((a, b) => a.Time.getTime() - b.Time.getTime()));
}, [req.data]);
diff --git a/src/ShopNet/SignalR.ts b/src/ShopNet/SignalR.ts
index af17a0e..7f42bca 100644
--- a/src/ShopNet/SignalR.ts
+++ b/src/ShopNet/SignalR.ts
@@ -11,12 +11,9 @@ import type { AdminNet } from "./Admin/AdminNet";
import { MSAL, Shared, type IConcurrency } from "./Database";
import type { ShopNet } from "./ShopNet";
-/**
- * @author Aloento
- * @since 1.0.0
- * @version 0.1.0
- */
-type INet = typeof ShopNet | typeof AdminNet;
+export namespace SignalR {
+ export type INet = typeof ShopNet | typeof AdminNet;
+}
/**
* @author Aloento
@@ -29,7 +26,7 @@ export abstract class SignalR {
* @since 1.0.0
* @version 0.1.1
*/
- protected static async EnsureConnected(this: INet): Promise {
+ protected static async EnsureConnected(this: SignalR.INet): Promise {
if (this.Hub.state === HubConnectionState.Connected)
return Promise.resolve();
@@ -52,7 +49,7 @@ export abstract class SignalR {
* @since 1.0.0
* @version 0.1.0
*/
- protected static async Invoke(this: INet, methodName: string, ...args: any[]): Promise {
+ protected static async Invoke(this: SignalR.INet, methodName: string, ...args: any[]): Promise {
await this.EnsureConnected();
return this.Hub.invoke(methodName, ...args);
}
@@ -62,7 +59,7 @@ export abstract class SignalR {
* @since 1.0.0
* @version 0.2.1
*/
- protected static EnsureLogin(this: INet) {
+ protected static EnsureLogin(this: SignalR.INet) {
if (!MSAL.getActiveAccount())
throw new NotLoginError();
}
@@ -72,7 +69,7 @@ export abstract class SignalR {
* @since 1.0.0
* @version 0.1.0
*/
- protected static EnsureTrue(this: INet, res: boolean | null | undefined): asserts res is true {
+ protected static EnsureTrue(this: SignalR.INet, res: boolean | null | undefined): asserts res is true {
if (!res)
throw new NotTrueError();
}
@@ -82,7 +79,7 @@ export abstract class SignalR {
* @since 1.0.0
* @version 0.1.2
*/
- protected static async HandleFileStream(this: INet, file: File, subject: Subject, pLog: Logger) {
+ protected static async HandleFileStream(this: SignalR.INet, file: File, subject: Subject, pLog: Logger) {
const chunkSize = 30 * 1024;
const chunks = Math.ceil(file.size / chunkSize);
let index = 0;
@@ -152,7 +149,7 @@ export abstract class SignalR {
* @liveSafe
*/
protected static async GetVersionCache(
- this: INet, key: string | number, methodName: string
+ this: SignalR.INet, key: string | number, methodName: string
): Promise {
const index = this.Index(key, methodName);
await this.getLocker(index);
@@ -208,7 +205,7 @@ export abstract class SignalR {
* @deprecated Use {@link useTimeCache} if possible.
*/
protected static async GetTimeCache(
- this: INet, key: string | number, methodName: string, exp: (now: Dayjs) => Dayjs, ...args: any[]
+ this: SignalR.INet, key: string | number, methodName: string, exp: (now: Dayjs) => Dayjs, ...args: any[]
): Promise {
const index = this.Index(key, methodName);
await this.getLocker(index);
@@ -233,7 +230,7 @@ export abstract class SignalR {
* @version 0.1.0
*/
protected static useTimeCache(
- this: INet, key: string | number, methodName: string, options: Options
+ this: SignalR.INet, key: string | number, methodName: string, options: Options
) {
const index = useConst(() => this.Index(key, methodName));
@@ -253,7 +250,7 @@ export abstract class SignalR {
* @deprecated
*/
protected static async UpdateCache(
- this: INet, action: (raw: T) => T, key: string | number, methodName: string, exp?: Dayjs
+ this: SignalR.INet, action: (raw: T) => T, key: string | number, methodName: string, exp?: Dayjs
) {
const index = this.Index(key, methodName);
const find = await Shared.Get(index);