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

Commit

Permalink
The most significant changes involve the addition of the Admin para…
Browse files Browse the repository at this point in the history
…meter to various functions and components, the importation of `AdminOrderAction` and `Shipment` components into `Drawer.tsx`, and the replacement of the `AdminOrderDetail` component with the `OrderDetail` component in `index.tsx`.

1. The `Admin` parameter was added to the `OrderComment` function in `Comment.tsx` and passed to the `useCmts` and `CommentAppend` functions. This change allows the system to differentiate between admin and non-admin users.
2. The `AdminOrderAction` and `Shipment` components were imported into `Drawer.tsx`. This change allows these components to be used within the `Drawer.tsx` file.
3. The `OrderDetailDrawer` function in `Drawer.tsx` was updated to use a ternary operator to decide whether to use `AdminHub` or `Hub` based on the `Admin` parameter. This change allows the function to dynamically choose between the two options based on the user's admin status.
4. The `OrderDetail` function in `index.tsx` was updated to include the `Admin` parameter in the `OrderDetailDrawer` component. This change allows the `OrderDetailDrawer` component to access the `Admin` parameter.
5. The `AdminOrderAction` function in `Action.tsx` was updated twice to include the `ParentLog` parameter and to use the `useConst` hook to create a new `log` constant. This change allows the function to access the `ParentLog` parameter and use it to create a new constant.
6. The `AdminOrderDetail` function and related imports were removed from `Detail.tsx`. This change simplifies the code by removing unnecessary elements.
7. The `OrderDetail` component was imported into `index.tsx` and used in place of the `AdminOrderDetail` component. This change simplifies the code by using a single component for both admin and non-admin users.
  • Loading branch information
Aloento committed Feb 15, 2024
1 parent d4eea88 commit 5efe204
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 147 deletions.
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);
const { data, run } = 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} />
<CommentAppend OrderId={OrderId} Refresh={run} ParentLog={log} Admin={Admin} />
</>;
}
42 changes: 26 additions & 16 deletions src/Components/Order/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -80,26 +82,25 @@ const columns: TableColumnDefinition<ICartItem>[] = [
/**
* @author Aloento
* @since 1.3.5
* @version 1.2.0
* @version 1.3.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, 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);

Expand All @@ -110,17 +111,26 @@ export function OrderDetailDrawer({ OrderId, Admin, ParentLog }: IOrderComp) {
{
Admin
?
<AdminOrderList Items={cart} />
<>
<AdminOrderList Items={cart} />
<Shipment OrderId={OrderId} TrackingNumber={order?.TrackingNumber} Refresh={run} />
</>
:
<DelegateDataGrid
Items={cart}
Columns={[MakeCoverCol(44, ParentLog), ...columns]}
/>
}

<OrderComment OrderId={OrderId} ParentLog={ParentLog} />
<OrderComment OrderId={OrderId} ParentLog={ParentLog} Admin={Admin} />

<OrderAction OrderId={OrderId} Status={order?.Status} Refresh={run} ParentLog={ParentLog} />
{
Admin
?
<AdminOrderAction OrderId={OrderId} Status={order?.Status} Refresh={run} ParentLog={ParentLog} />
:
<OrderAction OrderId={OrderId} Status={order?.Status} Refresh={run} ParentLog={ParentLog} />
}
</div>
);
}
2 changes: 1 addition & 1 deletion src/Components/Order/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function OrderDetail({ OrderId, Admin, ParentLog }: IOrderComp) {
</DrawerHeader>

<DrawerBody ref={ref}>
{inViewport && <OrderDetailDrawer OrderId={OrderId} ParentLog={log} />}
{inViewport && <OrderDetailDrawer OrderId={OrderId} ParentLog={log} Admin={Admin} />}
</DrawerBody>
</Drawer>
</>
Expand Down
20 changes: 5 additions & 15 deletions src/Pages/Admin/Order/Action.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);

Expand Down
111 changes: 0 additions & 111 deletions src/Pages/Admin/Order/Detail.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/Pages/Admin/Order/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { DataGridCell, DataGridHeaderCell, Label, SpinButton, TableColumnDefinition, createTableColumn, makeStyles, tokens } from "@fluentui/react-components";
import { useRequest } from "ahooks";
import { DelegateDataGrid } from "~/Components/DataGrid";
import { OrderDetail } from "~/Components/Order";
import { Logger } from "~/Helpers/Logger";
import { Flex } from "~/Helpers/Styles";
import { IOrderItem } from "~/Pages/History";
import { HistoryColumns } from "~/Pages/History/Columns";
import { AdminHub } from "~/ShopNet/Admin";
import { AdminOrderDetail } from "./Detail";

/**
* @author Aloento
Expand Down Expand Up @@ -86,7 +86,7 @@ const columns: TableColumnDefinition<IAdminOrderItem>[] = [
renderCell(item) {
return (
<DataGridCell className={useStyles().twoc}>
<AdminOrderDetail OrderId={item.Id} />
<OrderDetail OrderId={item.Id} ParentLog={log} Admin />
</DataGridCell>
)
},
Expand Down

0 comments on commit 5efe204

Please sign in to comment.