diff --git a/src/Components/Order/Comment.tsx b/src/Components/Order/Comment.tsx index f21d0aa..9e3aa5f 100644 --- a/src/Components/Order/Comment.tsx +++ b/src/Components/Order/Comment.tsx @@ -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); + const { data, run } = Hub.Order.Get.useCmts(OrderId, log, Admin); return <> @@ -38,6 +38,6 @@ export function OrderComment({ OrderId, Admin, ParentLog }: IOrderComp) { )} - + ; } diff --git a/src/Components/Order/Drawer.tsx b/src/Components/Order/Drawer.tsx index f685792..7b0dce0 100644 --- a/src/Components/Order/Drawer.tsx +++ b/src/Components/Order/Drawer.tsx @@ -7,7 +7,9 @@ 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"; @@ -80,7 +82,7 @@ const columns: TableColumnDefinition[] = [ /** * @author Aloento * @since 1.3.5 - * @version 1.2.0 + * @version 1.3.0 */ export function OrderDetailDrawer({ OrderId, Admin, ParentLog }: IOrderComp) { const style = useStyles(); @@ -88,18 +90,17 @@ export function OrderDetailDrawer({ OrderId, Admin, ParentLog }: IOrderComp) { const { Nav } = useRouter(); const index = useConst(() => SignalR.Index(OrderId, Hub.Order.Get.order)); - const { data: order, run } = useSWR(index, async () => { - if (Admin) - return AdminHub.Order.Get.Order(OrderId); - - return Hub.Order.Get.Order(OrderId); - }, { - onError(e) { - Nav("History"); - ParentLog.error(e); - }, - useMemory: true - }); + 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); @@ -110,7 +111,10 @@ export function OrderDetailDrawer({ OrderId, Admin, ParentLog }: IOrderComp) { { Admin ? - + <> + + + : } - + - + { + Admin + ? + + : + + } ); } diff --git a/src/Components/Order/index.tsx b/src/Components/Order/index.tsx index 11a1bab..7d3290f 100644 --- a/src/Components/Order/index.tsx +++ b/src/Components/Order/index.tsx @@ -66,7 +66,7 @@ export function OrderDetail({ OrderId, Admin, ParentLog }: IOrderComp) { - {inViewport && } + {inViewport && } diff --git a/src/Pages/Admin/Order/Action.tsx b/src/Pages/Admin/Order/Action.tsx index 2bd8fb4..181bf62 100644 --- a/src/Pages/Admin/Order/Action.tsx +++ b/src/Pages/Admin/Order/Action.tsx @@ -1,5 +1,6 @@ import { Button, Field, Toast, ToastTitle, makeStyles } from "@fluentui/react-components"; -import { Logger } from "~/Helpers/Logger"; +import { useConst } from "@fluentui/react-hooks"; +import { IOrderRef } from "~/Components/Order"; import { ColFlex } from "~/Helpers/Styles"; import { useErrorToast } from "~/Helpers/useToast"; import { AdminHub } from "~/ShopNet/Admin"; @@ -19,22 +20,11 @@ const useStyles = makeStyles({ /** * @author Aloento * @since 1.0.0 - * @version 0.1.1 + * @version 0.2.0 */ -interface IAdminOrderAction { - OrderId: number; - Status?: string; - Refresh: () => void; -} - -const log = new Logger("Admin", "Order", "Detail", "Action"); +export function AdminOrderAction({ OrderId, Status, Refresh, ParentLog }: IOrderRef & { Status?: string; }) { + const log = useConst(() => ParentLog.With("Action")); -/** - * @author Aloento - * @since 1.0.0 - * @version 0.1.2 - */ -export function AdminOrderAction({ OrderId, Status, Refresh }: IAdminOrderAction) { const style = useStyles(); const { dispatch, dispatchToast } = useErrorToast(log); diff --git a/src/Pages/Admin/Order/Detail.tsx b/src/Pages/Admin/Order/Detail.tsx deleted file mode 100644 index d44f21a..0000000 --- a/src/Pages/Admin/Order/Detail.tsx +++ /dev/null @@ -1,111 +0,0 @@ -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"; -import { useEffect } from "react"; -import { CommentAppend } from "~/Components/Order/Append"; -import { OrderComment } from "~/Components/Order/Comment"; -import { OrderInfo } from "~/Components/Order/Info"; -import { useRouter } from "~/Components/Router"; -import { Logger } from "~/Helpers/Logger"; -import { ColFlex } from "~/Helpers/Styles"; -import { AdminHub } from "~/ShopNet/Admin"; -import { AdminOrderAction } from "./Action"; -import { AdminOrderList } from "./List"; -import { Shipment } from "./Ship"; - -/** - * @author Aloento - * @since 0.5.0 - * @version 0.1.0 - */ -const useStyles = makeStyles({ - body: { - ...ColFlex, - rowGap: tokens.spacingVerticalXL - } -}); - -const log = new Logger("Admin", "Order", "Detail"); - -/** - * @author Aloento - * @since 0.5.0 - * @version 0.4.0 - */ -export function AdminOrderDetail({ OrderId }: { OrderId: number; }) { - const style = useStyles(); - const [open, { setTrue, setFalse }] = useBoolean(); - - const { Nav, Paths } = useRouter(); - const curr = parseInt(Paths.at(2)!); - - const { data, run: runDetail } = useRequest(() => AdminHub.Order.Get.Detail(OrderId, log), { - manual: true, - onError: log.error - }); - - const { data: order, run: runOrder } = useRequest(() => AdminHub.Order.Get.Order(OrderId), { - onError(e) { - Nav("Admin", "Order"); - log.error(e); - }, - manual: true - }); - - function run() { - runOrder(); - runDetail(); - } - - useEffect(() => { - if (curr === OrderId) { - run(); - setTrue(); - } else - setFalse(); - }, [curr]); - - return <> -