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

Commit 1231f55

Browse files
authored
[Front] v1.1.0 - [Front] Comprehensive Console Logging (#83)
* Refactor SignalR class and remove INet interface * Update version numbers and improve logging * Update version numbers and add logging in ProductGet class * Update OrderGet class with logging improvements * Update version numbers and add logging in AdminProductGet * Update version and add logging in AdminOrderGet * Update Carousel and ObjectStorage classes * Add error handling to useRequest hooks in GuidImage and ProductCarousel components * Update useToast and GuidImage Update MakeCoverCol and AdminProduct Update Confirm and AdminProductGet * Refactor ShopCart Columns component * Update OrderDetail component with Logger and add MakeCoverCol to columns * Refactor history columns and add logger to order detail * Add logger to handle errors in useRequest * Add error logging to useRequest calls * Update RadioGroup component to use useEffect and useState * Update ShopCart and Product with Logger * Add logging to Combo API calls * Update useRequest calls with log parameter * Update OrderAppend component to include ParentLog * Update OrderAction and OrderAppend components * Update AdminOrderDetail and Shipment components * Fix logger import and add logging to useErrorToast * Update Admin User components * Fix error handling in AdminProduct and AdminProductComboDelete * Update AdminProductPhotoEdit component and usePhoto function * Refactor code for AdminOrderDetail and AdminProductVariantDelete components * Refactor component imports and remove unused code * Add Logger to AdminProductAddButton and AdminProductPhotoEdit * Add logging to AdminProductDelete and AdminProductTypeDelete * Fix order and user components * Update @fluentui/react-components to version 9.43.2
1 parent ad054eb commit 1231f55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1147
-881
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@azure/msal-browser": "^3.6.0",
1919
"@azure/msal-common": "^14.5.0",
2020
"@azure/msal-react": "^2.0.8",
21-
"@fluentui/react-components": "^9.43.0",
21+
"@fluentui/react-components": "^9.43.2",
2222
"@fluentui/react-hooks": "^8.6.34",
2323
"@fluentui/react-icons": "^2.0.224",
2424
"@griffel/react": "^1.5.19",

pnpm-lock.yaml

Lines changed: 567 additions & 547 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/OrderInfo.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Field, Label, makeStyles, tokens } from "@fluentui/react-components";
22
import { useRequest } from "ahooks";
3+
import { Logger } from "~/Helpers/Logger";
34
import { ColFlex, Flex } from "~/Helpers/Styles";
45
import { Hub } from "~/ShopNet";
56
import { AdminHub } from "~/ShopNet/Admin";
@@ -29,6 +30,8 @@ interface IOrderInfo {
2930
Admin?: true;
3031
}
3132

33+
const log = new Logger("Order", "Info");
34+
3235
/**
3336
* @author Aloento
3437
* @since 0.5.0
@@ -38,10 +41,11 @@ export function OrderInfo({ OrderId, Order, Admin }: IOrderInfo) {
3841
const style = useStyles();
3942

4043
const { data: admin } = useRequest(() => AdminHub.User.Get.OrderUser(OrderId), {
41-
manual: !Admin
44+
manual: !Admin,
45+
onError: log.error
4246
});
4347

44-
const { data: me } = Hub.User.Get.useMe({
48+
const { data: me } = Hub.User.Get.useMe(log, {
4549
manual: Admin
4650
});
4751

src/Components/Setting.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useMsal } from "@azure/msal-react";
22
import { Button, Dialog, DialogActions, DialogBody, DialogContent, DialogSurface, DialogTitle, DialogTrigger, Field, Input, Label, Toast, ToastBody, ToastTitle, makeStyles, tokens } from "@fluentui/react-components";
33
import { useState } from "react";
4+
import { Logger } from "~/Helpers/Logger";
45
import { ColFlex, Flex } from "~/Helpers/Styles";
56
import { useErrorToast } from "~/Helpers/useToast";
67
import { Hub } from "~/ShopNet";
@@ -33,10 +34,12 @@ const useStyles = makeStyles({
3334
},
3435
});
3536

37+
const log = new Logger("Setting");
38+
3639
/**
3740
* @author Aloento
3841
* @since 0.1.0
39-
* @version 0.4.0
42+
* @version 0.4.1
4043
*/
4144
export function Setting({ Open, Toggle, New }: ISetting) {
4245
const style = useStyles();
@@ -46,7 +49,7 @@ export function Setting({ Open, Toggle, New }: ISetting) {
4649
const [phone, setPhone] = useState<string>();
4750
const [address, setAddress] = useState<string>();
4851

49-
Hub.User.Get.useMe({
52+
Hub.User.Get.useMe(log, {
5053
manual: New,
5154
onSuccess(data) {
5255
if (!data) return;
@@ -58,7 +61,7 @@ export function Setting({ Open, Toggle, New }: ISetting) {
5861
}
5962
});
6063

61-
const { dispatch, dispatchToast } = useErrorToast();
64+
const { dispatch, dispatchToast } = useErrorToast(log);
6265

6366
const { run } = Hub.User.Post.useUpdate({
6467
manual: true,

src/Components/ShopCart/Columns.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Body1Strong, Button, Caption1, DataGridCell, Link, SpinButton, TableColumnDefinition, createTableColumn, makeStyles } from "@fluentui/react-components";
22
import { DeleteRegular } from "@fluentui/react-icons";
33
import { MakeCoverCol } from "~/Helpers/CoverCol";
4+
import { Logger } from "~/Helpers/Logger";
45
import { ColFlex } from "~/Helpers/Styles";
56
import { useLimit } from "~/Helpers/useLimit";
67
import { ICartItem } from ".";
@@ -27,13 +28,7 @@ const useStyles = makeStyles({
2728
},
2829
});
2930

30-
/**
31-
* @author Aloento
32-
* @since 0.1.0
33-
* @version 0.3.1
34-
*/
35-
export const CartColumns: TableColumnDefinition<ICartItem>[] = [
36-
MakeCoverCol(44),
31+
const columns: TableColumnDefinition<ICartItem>[] = [
3732
createTableColumn<ICartItem>({
3833
columnId: "Product",
3934
renderCell(item) {
@@ -81,11 +76,21 @@ export const CartColumns: TableColumnDefinition<ICartItem>[] = [
8176
<Button
8277
appearance="subtle"
8378
icon={<DeleteRegular />}
84-
onClick={() => {
85-
Update(List.filter(x => x.Id !== item.Id));
86-
}} />
79+
onClick={() => Update(List.filter(x => x.Id !== item.Id))} />
8780
</DataGridCell>
8881
);
8982
},
9083
})
9184
];
85+
86+
/**
87+
* @author Aloento
88+
* @since 0.1.0
89+
* @version 0.3.1
90+
*/
91+
export function CartColumns(log: Logger): TableColumnDefinition<ICartItem>[] {
92+
return [
93+
MakeCoverCol(44, log),
94+
...columns
95+
];
96+
}

src/Components/ShopCart/Confirm.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Button, Field, Textarea, Toast, ToastBody, ToastTitle, makeStyles, tokens } from "@fluentui/react-components";
22
import { Drawer, DrawerBody, DrawerHeader, DrawerHeaderTitle } from "@fluentui/react-components/unstable";
3+
import { useConst } from "@fluentui/react-hooks";
34
import { DismissRegular } from "@fluentui/react-icons";
45
import { useBoolean } from "ahooks";
56
import { useState } from "react";
7+
import { Logger } from "~/Helpers/Logger";
68
import { ColFlex } from "~/Helpers/Styles";
79
import { useErrorToast } from "~/Helpers/useToast";
810
import { Hub } from "~/ShopNet";
@@ -28,10 +30,12 @@ const useStyles = makeStyles({
2830
}
2931
});
3032

33+
const log = new Logger("TopNavBar", "ShopCart", "Confirm");
34+
3135
/**
3236
* @author Aloento
3337
* @since 0.1.0
34-
* @version 0.4.1
38+
* @version 0.4.2
3539
*/
3640
export function Confirm() {
3741
const [cmt, setCmt] = useState<string>();
@@ -41,7 +45,7 @@ export function Confirm() {
4145
const { Nav } = useRouter();
4246
const style = useStyles();
4347

44-
const { dispatch, dispatchToast } = useErrorToast();
48+
const { dispatch, dispatchToast } = useErrorToast(log);
4549

4650
const { run } = Hub.Order.Post.useNew({
4751
manual: true,
@@ -93,9 +97,9 @@ export function Confirm() {
9397

9498
<DrawerBody>
9599
<div className={style.body}>
96-
<PersonaInfo />
100+
<PersonaInfo Log={log} />
97101

98-
<DelegateDataGrid Items={List} Columns={CartColumns} NoHeader />
102+
<DelegateDataGrid Items={List} Columns={useConst(() => CartColumns(log))} NoHeader />
99103

100104
<Field label="Comment" size="large">
101105
<Textarea value={cmt} onChange={(_, v) => setCmt(v.value)} maxLength={1000} />

src/Components/ShopCart/Context.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useRequest } from "ahooks";
22
import { ReactNode, createContext, useContext, useState } from "react";
3+
import { Logger } from "~/Helpers/Logger";
34
import { Hub } from "~/ShopNet";
45
import { CartTable } from "~/ShopNet/Database";
56
import { ICartItem } from ".";
@@ -31,10 +32,12 @@ export function useShopCart() {
3132
return useContext(ShopCart);
3233
}
3334

35+
const log = new Logger("ShopCart", "Context");
36+
3437
/**
3538
* @author Aloento
3639
* @since 0.5.0
37-
* @version 0.3.0
40+
* @version 0.3.1
3841
*/
3942
export function ShopCartContext({ children }: { children: ReactNode }) {
4043
const [list, setList] = useState<ICartItem[]>([]);
@@ -44,14 +47,16 @@ export function ShopCartContext({ children }: { children: ReactNode }) {
4447
const res: ICartItem[] = [];
4548

4649
for (const i of arr) {
47-
const b = await Hub.Product.Get.Basic(i.ProdId);
50+
const b = await Hub.Product.Get.Basic(i.ProdId, log);
4851
res.push({
4952
...i,
5053
...b
5154
});
5255
}
5356

5457
setList(res);
58+
}, {
59+
onError: log.error,
5560
});
5661

5762
async function Update(val: ICartItem[]) {
@@ -70,7 +75,7 @@ export function ShopCartContext({ children }: { children: ReactNode }) {
7075
}
7176

7277
async function Add(prodId: number, type: Record<string, string>, quantity: number) {
73-
const res = await Hub.Product.Get.Basic(prodId);
78+
const res = await Hub.Product.Get.Basic(prodId, log);
7479
list.push({
7580
...res,
7681
Id: list.length,

src/Components/ShopCart/Persona.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Field, Label, makeStyles, tokens } from "@fluentui/react-components";
2+
import { useConst } from "@fluentui/react-hooks";
3+
import type { Logger } from "~/Helpers/Logger";
24
import { ColFlex, Flex } from "~/Helpers/Styles";
35
import { Hub } from "~/ShopNet";
46

@@ -31,11 +33,12 @@ export interface IPersona {
3133
/**
3234
* @author Aloento
3335
* @since 0.5.0
34-
* @version 0.2.0
36+
* @version 0.2.1
3537
*/
36-
export function PersonaInfo() {
38+
export function PersonaInfo({ Log }: { Log: Logger }) {
3739
const style = useStyles();
38-
const { data } = Hub.User.Get.useMe();
40+
const log = useConst(() => Log.With("PersonaInfo"));
41+
const { data } = Hub.User.Get.useMe(log);
3942

4043
return <>
4144
<div className={style.person}>

src/Components/ShopCart/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Body1, Popover, PopoverSurface, PopoverTrigger, ToggleButton, Tooltip, makeStyles, shorthands, tokens } from "@fluentui/react-components";
2+
import { useConst } from "@fluentui/react-hooks";
23
import { CartRegular } from "@fluentui/react-icons";
34
import { useBoolean, useUpdateEffect } from "ahooks";
5+
import { Logger } from "~/Helpers/Logger";
46
import { Flex } from "~/Helpers/Styles";
57
import { DelegateDataGrid } from "../DataGrid/Delegate";
68
import { CartColumns } from "./Columns";
@@ -42,6 +44,8 @@ export interface ICartItem {
4244
Quantity: number;
4345
}
4446

47+
const log = new Logger("TopNavBar", "ShopCart");
48+
4549
/**
4650
* @author Aloento
4751
* @since 0.1.0
@@ -80,10 +84,12 @@ export function ShopCart() {
8084
</PopoverTrigger>
8185

8286
<PopoverSurface>
83-
<DelegateDataGrid Items={List} Columns={CartColumns} NoHeader />
87+
<DelegateDataGrid Items={List} Columns={useConst(() => CartColumns(log))} NoHeader />
8488

8589
<div className={style.conf}>
86-
<Body1>{List.map(x => x.Quantity).reduce((prev, curr) => prev + curr, 0)} items in shopping cart</Body1>
90+
<Body1>
91+
{List.map(x => x.Quantity).reduce((prev, curr) => prev + curr, 0)} items in shopping cart
92+
</Body1>
8793

8894
<Confirm />
8995
</div>

src/Helpers/CoverCol.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DataGridCell, DataGridHeaderCell, createTableColumn, makeStyles, tokens } from "@fluentui/react-components";
22
import { GuidImage } from "./GuidImage";
3+
import type { Logger } from "./Logger";
34
import { Cover } from "./Styles";
45

56
/**
@@ -25,12 +26,10 @@ const useStyle = makeStyles({
2526
* @since 0.5.0
2627
* @version 0.2.0
2728
*/
28-
export function MakeCoverCol(Size: number) {
29-
const w = { width: `${Size}px` };
29+
export function MakeCoverCol(size: number, log: Logger) {
30+
const w = { width: `${size}px` };
3031

31-
return createTableColumn<{
32-
Cover: string;
33-
}>({
32+
return createTableColumn<{ Cover: string; }>({
3433
columnId: "Cover",
3534
renderHeaderCell: () => {
3635
const style = useStyle();
@@ -50,16 +49,10 @@ export function MakeCoverCol(Size: number) {
5049
className={style.img}
5150
style={w}
5251
Guid={item.Cover}
52+
Log={log}
5353
/>
5454
</DataGridCell>
5555
)
5656
},
5757
})
5858
}
59-
60-
/**
61-
* @author Aloento
62-
* @since 0.1.0
63-
* @version 0.2.0
64-
*/
65-
export const CoverCol = MakeCoverCol(50);

0 commit comments

Comments
 (0)