();
- useRequest(Hub.User.Get.Me.bind(Hub.User.Get), {
+ Hub.User.Get.useMe({
manual: New,
onSuccess(data) {
if (!data) return;
@@ -59,13 +59,13 @@ export function Setting({ Open, Toggle, New }: ISetting) {
}
});
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(Hub.User.Post.Update.bind(Hub.User.Post), {
manual: true,
onFinally([req], _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: `Failed ${New ? "Create" : "Update"} Info`,
Error: e,
Request: req
diff --git a/src/Components/ShopCart/Confirm.tsx b/src/Components/ShopCart/Confirm.tsx
index acb09861..830a3cc5 100644
--- a/src/Components/ShopCart/Confirm.tsx
+++ b/src/Components/ShopCart/Confirm.tsx
@@ -4,7 +4,7 @@ import { DismissRegular } from "@fluentui/react-icons";
import { useBoolean, useRequest } from "ahooks";
import { useState } from "react";
import { ColFlex } from "~/Helpers/Styles";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { Hub } from "~/ShopNet";
import { DelegateDataGrid } from "../DataGrid/Delegate";
import { useRouter } from "../Router";
@@ -41,12 +41,12 @@ export function Confirm() {
const { Nav } = useRouter();
const style = useStyles();
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(Hub.Order.Post.New.bind(Hub.Order.Post), {
onFinally([req], data, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Create Order",
Request: req,
Error: e
diff --git a/src/Components/ShopCart/Persona.tsx b/src/Components/ShopCart/Persona.tsx
index d90eccbf..c3a68257 100644
--- a/src/Components/ShopCart/Persona.tsx
+++ b/src/Components/ShopCart/Persona.tsx
@@ -36,7 +36,7 @@ export interface IPersona {
*/
export function PersonaInfo() {
const style = useStyles();
- const { data } = useRequest(Hub.User.Get.Me.bind(Hub.User.Get));
+ const { data } = useRequest(Hub.User.Get.useMe.bind(Hub.User.Get));
return <>
diff --git a/src/Helpers/Exceptions.ts b/src/Helpers/Exceptions.ts
new file mode 100644
index 00000000..dba90eb4
--- /dev/null
+++ b/src/Helpers/Exceptions.ts
@@ -0,0 +1,10 @@
+/**
+ * @author Aloento
+ * @since 1.0.0
+ * @version 0.1.0
+ */
+export class NotLoginError extends Error {
+ public constructor() {
+ super("Please Login First");
+ }
+}
diff --git a/src/Helpers/useToast.tsx b/src/Helpers/useToast.tsx
index dd25bf5c..d80542fd 100644
--- a/src/Helpers/useToast.tsx
+++ b/src/Helpers/useToast.tsx
@@ -24,14 +24,14 @@ interface Cause {
/**
* @author Aloento
* @since 0.5.0
- * @version 0.2.0
+ * @version 0.2.1
*/
-export function use500Toast() {
+export function useErrorToast() {
const style = useStyles();
const { dispatchToast } = useToastController();
return {
- dispatchError: (e: Cause) => {
+ dispatch: (e: Cause) => {
dispatchToast(
Internal Error
diff --git a/src/Pages/Admin/Order/Append.tsx b/src/Pages/Admin/Order/Append.tsx
index 5f6bc942..3689157f 100644
--- a/src/Pages/Admin/Order/Append.tsx
+++ b/src/Pages/Admin/Order/Append.tsx
@@ -2,7 +2,7 @@ import { Button, Field, Textarea, Toast, ToastTitle, makeStyles } from "@fluentu
import { useRequest } from "ahooks";
import { useState } from "react";
import { Flex } from "~/Helpers/Styles";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -26,13 +26,13 @@ export function AdminOrderAppend({ OrderId, Refresh }: { OrderId: number; Refres
const style = useStyles();
const [cmt, setCmt] = useState();
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run: append } = useRequest(AdminHub.Order.Post.Append.bind(AdminHub.Order.Post), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Append Comment",
Request: req,
Error: e
@@ -53,7 +53,7 @@ export function AdminOrderAppend({ OrderId, Refresh }: { OrderId: number; Refres
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Close",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Order/Ship.tsx b/src/Pages/Admin/Order/Ship.tsx
index 63daee26..da018f8c 100644
--- a/src/Pages/Admin/Order/Ship.tsx
+++ b/src/Pages/Admin/Order/Ship.tsx
@@ -2,7 +2,7 @@ import { Button, Field, Input, Toast, ToastTitle } from "@fluentui/react-compone
import { EditRegular, SendRegular } from "@fluentui/react-icons";
import { useBoolean, useRequest } from "ahooks";
import { useState } from "react";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { Hub } from "~/ShopNet";
import { AdminHub } from "~/ShopNet/Admin";
@@ -15,7 +15,7 @@ export function Shipment({ OrderId, Refresh }: { OrderId: number; Refresh: (id:
const [edit, { setTrue, setFalse }] = useBoolean();
const [track, setTrack] = useState("");
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
useRequest(Hub.Order.Get.Order.bind(Hub.Order.Get), {
defaultParams: [OrderId],
@@ -28,7 +28,7 @@ export function Shipment({ OrderId, Refresh }: { OrderId: number; Refresh: (id:
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Update Tracking Number",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Add.tsx b/src/Pages/Admin/Product/Add.tsx
index f797c08a..705e3f42 100644
--- a/src/Pages/Admin/Product/Add.tsx
+++ b/src/Pages/Admin/Product/Add.tsx
@@ -4,7 +4,7 @@ import { useRequest } from "ahooks";
import { useState } from "react";
import { useRouter } from "~/Components/Router";
import { ColFlex } from "~/Helpers/Styles";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -29,13 +29,13 @@ export function AdminProductAddButton() {
const style = useStyles();
const [name, setName] = useState("");
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Post.Create.bind(AdminHub.Product.Post), {
manual: true,
onFinally(req, data, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: `Failed Create ${name}`,
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Category.tsx b/src/Pages/Admin/Product/Category.tsx
index dca9bbcc..8ed32da5 100644
--- a/src/Pages/Admin/Product/Category.tsx
+++ b/src/Pages/Admin/Product/Category.tsx
@@ -3,7 +3,7 @@ import { EditRegular, SendRegular } from "@fluentui/react-icons";
import { useBoolean, useRequest } from "ahooks";
import { useState } from "react";
import { Flex } from "~/Helpers/Styles";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { Hub } from "~/ShopNet";
import { AdminHub } from "~/ShopNet/Admin";
@@ -38,13 +38,13 @@ export function AdminProductCategory({ ProdId }: { ProdId: number; }) {
}
});
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Patch.Category.bind(AdminHub.Product.Patch), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Update Category",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Combo/Delete.tsx b/src/Pages/Admin/Product/Combo/Delete.tsx
index 0c9cb3c7..94818c84 100644
--- a/src/Pages/Admin/Product/Combo/Delete.tsx
+++ b/src/Pages/Admin/Product/Combo/Delete.tsx
@@ -1,7 +1,7 @@
import { Button, Toast, ToastTitle } from "@fluentui/react-components";
import { DeleteRegular } from "@fluentui/react-icons";
import { useRequest } from "ahooks";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -10,13 +10,13 @@ import { AdminHub } from "~/ShopNet/Admin";
* @version 0.2.0
*/
export function AdminProductComboDelete({ ComboId, Refresh }: { ComboId: number; Refresh: () => void }) {
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Delete.Combo.bind(AdminHub.Product.Delete), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Delete Combo",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Combo/Detail.tsx b/src/Pages/Admin/Product/Combo/Detail.tsx
index f53cc627..dd065938 100644
--- a/src/Pages/Admin/Product/Combo/Detail.tsx
+++ b/src/Pages/Admin/Product/Combo/Detail.tsx
@@ -5,7 +5,7 @@ import { isInteger } from "lodash-es";
import { useState } from "react";
import { DelegateDataGrid } from "~/Components/DataGrid/Delegate";
import { Flex } from "~/Helpers/Styles";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
import { IComboItem } from ".";
import { IVariantItem } from "../Variant";
@@ -97,13 +97,13 @@ export function AdminProductComboDetail({ Id, ProdId, Combo, Stock, Refresh }: I
defaultParams: [ProdId]
});
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Patch.Combo.bind(AdminHub.Product.Patch), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Update Combo",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Combo/New.tsx b/src/Pages/Admin/Product/Combo/New.tsx
index b6cc7bf2..9a833f94 100644
--- a/src/Pages/Admin/Product/Combo/New.tsx
+++ b/src/Pages/Admin/Product/Combo/New.tsx
@@ -5,7 +5,7 @@ import { isInteger } from "lodash-es";
import { useState } from "react";
import { DelegateDataGrid } from "~/Components/DataGrid/Delegate";
import { Flex } from "~/Helpers/Styles";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
import { IVariantItem } from "../Variant";
@@ -87,13 +87,13 @@ export function AdminProductNewCombo({ ProdId, Refresh }: { ProdId: number; Refr
},
});
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Post.Combo.bind(AdminHub.Product.Post), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Create Combo",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Delete.tsx b/src/Pages/Admin/Product/Delete.tsx
index 661c655d..32bc1f80 100644
--- a/src/Pages/Admin/Product/Delete.tsx
+++ b/src/Pages/Admin/Product/Delete.tsx
@@ -1,7 +1,7 @@
import { Button, Toast, ToastTitle } from "@fluentui/react-components";
import { useRequest } from "ahooks";
import { useRouter } from "~/Components/Router";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -11,13 +11,13 @@ import { AdminHub } from "~/ShopNet/Admin";
*/
export function AdminProductDelete({ ProdId }: { ProdId: number }) {
const { Nav } = useRouter();
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Delete.Product.bind(AdminHub.Product.Delete), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Delete Product",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Name.tsx b/src/Pages/Admin/Product/Name.tsx
index aadfcef7..ccf8d975 100644
--- a/src/Pages/Admin/Product/Name.tsx
+++ b/src/Pages/Admin/Product/Name.tsx
@@ -3,7 +3,7 @@ import { EditRegular, SendRegular } from "@fluentui/react-icons";
import { useBoolean, useRequest } from "ahooks";
import { useState } from "react";
import { useRouter } from "~/Components/Router";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -27,13 +27,13 @@ export function AdminProductName({ ProdId }: { ProdId: number; }) {
},
});
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Patch.Name.bind(AdminHub.Product.Patch), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Update Name",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Photo/Edit.tsx b/src/Pages/Admin/Product/Photo/Edit.tsx
index 5e173115..7b7e3959 100644
--- a/src/Pages/Admin/Product/Photo/Edit.tsx
+++ b/src/Pages/Admin/Product/Photo/Edit.tsx
@@ -3,7 +3,7 @@ import { DismissRegular, EditRegular } from "@fluentui/react-icons";
import { useRequest } from "ahooks";
import { useState } from "react";
import { ColFlex, Cover, Flex } from "~/Helpers/Styles";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
import { IPhotoItem } from ".";
@@ -38,13 +38,13 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption }, Refresh }
const style = useStyles();
const [cap, setCap] = useState(Caption || "");
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run: updateCaption } = useRequest(AdminHub.Product.Patch.Caption.bind(AdminHub.Product.Patch), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Update Caption",
Request: req,
Error: e
@@ -65,7 +65,7 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption }, Refresh }
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Update Photo",
Request: req,
Error: e
@@ -86,7 +86,7 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption }, Refresh }
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Delete Photo",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Photo/index.tsx b/src/Pages/Admin/Product/Photo/index.tsx
index d5f909d7..36e6a19e 100644
--- a/src/Pages/Admin/Product/Photo/index.tsx
+++ b/src/Pages/Admin/Product/Photo/index.tsx
@@ -4,7 +4,7 @@ import { useRequest } from "ahooks";
import { DelegateDataGrid } from "~/Components/DataGrid/Delegate";
import { MakeCoverCol } from "~/Helpers/CoverCol";
import { Flex } from "~/Helpers/Styles";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { Hub } from "~/ShopNet";
import { AdminHub } from "~/ShopNet/Admin";
import { AdminProductPhotoEdit } from "./Edit";
@@ -63,13 +63,13 @@ const columns: TableColumnDefinition[] = [
)
},
renderCell(item) {
- const { dispatchError } = use500Toast();
+ const { dispatch } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Post.MovePhoto.bind(AdminHub.Product.Post), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Update Order",
Request: req,
Error: e
@@ -119,13 +119,13 @@ export function AdminProductPhoto({ ProdId }: { ProdId: number }) {
refreshCarousel = () => run(ProdId);
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run: newPhoto } = useRequest(AdminHub.Product.Post.Photo.bind(AdminHub.Product.Post), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Upload Photo",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Variant/Delete.tsx b/src/Pages/Admin/Product/Variant/Delete.tsx
index 61a7e9ed..4d162e0c 100644
--- a/src/Pages/Admin/Product/Variant/Delete.tsx
+++ b/src/Pages/Admin/Product/Variant/Delete.tsx
@@ -1,7 +1,7 @@
import { Button, Toast, ToastTitle } from "@fluentui/react-components";
import { DeleteRegular } from "@fluentui/react-icons";
import { useRequest } from "ahooks";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -10,13 +10,13 @@ import { AdminHub } from "~/ShopNet/Admin";
* @version 0.1.0
*/
export function AdminProductVariantDelete({ VariantId, Refresh }: { VariantId: number; Refresh: () => void }) {
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Delete.Variant.bind(AdminHub.Product.Delete), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Delete Variant",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Variant/Edit/Delete.tsx b/src/Pages/Admin/Product/Variant/Edit/Delete.tsx
index 111a43fd..4b3721c7 100644
--- a/src/Pages/Admin/Product/Variant/Edit/Delete.tsx
+++ b/src/Pages/Admin/Product/Variant/Edit/Delete.tsx
@@ -1,7 +1,7 @@
import { Button, Toast, ToastTitle } from "@fluentui/react-components";
import { DeleteRegular } from "@fluentui/react-icons";
import { useRequest } from "ahooks";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -10,13 +10,13 @@ import { AdminHub } from "~/ShopNet/Admin";
* @version 0.1.0
*/
export function AdminProductTypeDelete({ VariantId, Type, Refresh }: { VariantId: number; Type: string; Refresh: () => void }) {
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Delete.Type.bind(AdminHub.Product.Delete), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Delete Type",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Variant/Edit/Name.tsx b/src/Pages/Admin/Product/Variant/Edit/Name.tsx
index ffac4d28..6595904c 100644
--- a/src/Pages/Admin/Product/Variant/Edit/Name.tsx
+++ b/src/Pages/Admin/Product/Variant/Edit/Name.tsx
@@ -2,7 +2,7 @@ import { Button, Input, Subtitle2, Toast, ToastTitle } from "@fluentui/react-com
import { EditRegular, SendRegular } from "@fluentui/react-icons";
import { useBoolean, useRequest } from "ahooks";
import { useState } from "react";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -13,13 +13,13 @@ import { AdminHub } from "~/ShopNet/Admin";
export function AdminProductVariantName({ Id, Name }: { Id: number; Name: string; }) {
const [name, setName] = useState(Name);
const [edit, { setTrue, setFalse }] = useBoolean();
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Patch.VariantName.bind(AdminHub.Product.Patch), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Update Variant Name",
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Variant/Edit/Type.tsx b/src/Pages/Admin/Product/Variant/Edit/Type.tsx
index 8d08e7f3..7cb6654d 100644
--- a/src/Pages/Admin/Product/Variant/Edit/Type.tsx
+++ b/src/Pages/Admin/Product/Variant/Edit/Type.tsx
@@ -3,7 +3,7 @@ import { AddRegular, EditRegular } from "@fluentui/react-icons";
import { useBoolean, useRequest } from "ahooks";
import { useState } from "react";
import { ColFlex } from "~/Helpers/Styles";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -28,13 +28,13 @@ export function AdminProductType({ VariantId, Type, Refresh, New }: { VariantId:
const [open, { toggle }] = useBoolean();
const [name, setName] = useState(Type || "");
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const options = {
manual: true,
onFinally(req: any[], res?: number | boolean, e?: Error) {
if (e)
- return dispatchError({
+ return dispatch({
Message: `Failed ${New ? "Create" : "Update"} Type ${res} ${name}`,
Request: req,
Error: e
diff --git a/src/Pages/Admin/Product/Variant/New.tsx b/src/Pages/Admin/Product/Variant/New.tsx
index 3b721480..dd5b60d3 100644
--- a/src/Pages/Admin/Product/Variant/New.tsx
+++ b/src/Pages/Admin/Product/Variant/New.tsx
@@ -3,7 +3,7 @@ import { AddRegular } from "@fluentui/react-icons";
import { useBoolean, useRequest } from "ahooks";
import { useState } from "react";
import { ColFlex } from "~/Helpers/Styles";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -28,13 +28,13 @@ export function AdminProductNewVariant({ ProdId, Refresh }: { ProdId: number; Re
const [open, { toggle }] = useBoolean();
const [name, setName] = useState("");
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.Product.Post.Variant.bind(AdminHub.Product.Post), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Create Variant",
Request: req,
Error: e
diff --git a/src/Pages/Admin/User/Admin.tsx b/src/Pages/Admin/User/Admin.tsx
index 6712eb6c..67099b6e 100644
--- a/src/Pages/Admin/User/Admin.tsx
+++ b/src/Pages/Admin/User/Admin.tsx
@@ -1,6 +1,6 @@
import { Checkbox, Toast, ToastTitle } from "@fluentui/react-components";
import { useRequest } from "ahooks";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -9,13 +9,13 @@ import { AdminHub } from "~/ShopNet/Admin";
* @version 0.1.0
*/
export function AdminUserAdmin({ UserId, Admin, Refresh }: { UserId: string; Admin?: boolean; Refresh: () => void }) {
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run: grant } = useRequest(AdminHub.User.Post.Admin.bind(AdminHub.User.Post), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Grant Admin",
Request: req,
Error: e
@@ -36,7 +36,7 @@ export function AdminUserAdmin({ UserId, Admin, Refresh }: { UserId: string; Adm
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Revoke Admin",
Request: req,
Error: e
diff --git a/src/Pages/Admin/User/Delete.tsx b/src/Pages/Admin/User/Delete.tsx
index c13c8f09..8c3119c3 100644
--- a/src/Pages/Admin/User/Delete.tsx
+++ b/src/Pages/Admin/User/Delete.tsx
@@ -1,7 +1,7 @@
import { Button, Toast, ToastTitle } from "@fluentui/react-components";
import { DeleteRegular } from "@fluentui/react-icons";
import { useRequest } from "ahooks";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { AdminHub } from "~/ShopNet/Admin";
/**
@@ -10,13 +10,13 @@ import { AdminHub } from "~/ShopNet/Admin";
* @version 0.1.0
*/
export function AdminUserDelete({ UserId, Refresh }: { UserId: string; Refresh: () => void }) {
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run } = useRequest(AdminHub.User.Delete.User.bind(AdminHub.User.Delete), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Delete User",
Request: req,
Error: e
diff --git a/src/Pages/History/Append.tsx b/src/Pages/History/Append.tsx
index 4eeb968a..c2761f8b 100644
--- a/src/Pages/History/Append.tsx
+++ b/src/Pages/History/Append.tsx
@@ -2,7 +2,7 @@ import { Button, Field, Textarea, Toast, ToastTitle, makeStyles } from "@fluentu
import { useRequest } from "ahooks";
import { useState } from "react";
import { Flex } from "~/Helpers/Styles";
-import { use500Toast } from "~/Helpers/useToast";
+import { useErrorToast } from "~/Helpers/useToast";
import { Hub } from "~/ShopNet";
/**
@@ -26,13 +26,13 @@ export function OrderAppend({ OrderId, Refresh }: { OrderId: number; Refresh: (i
const style = useStyles();
const [cmt, setCmt] = useState();
- const { dispatchError, dispatchToast } = use500Toast();
+ const { dispatch, dispatchToast } = useErrorToast();
const { run: append } = useRequest(Hub.Order.Post.Append.bind(Hub.Order.Post), {
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Append Comment",
Request: req,
Error: e
@@ -53,7 +53,7 @@ export function OrderAppend({ OrderId, Refresh }: { OrderId: number; Refresh: (i
manual: true,
onFinally(req, _, e) {
if (e)
- return dispatchError({
+ return dispatch({
Message: "Failed Cancel",
Request: req,
Error: e
diff --git a/src/ShopNet/Database.ts b/src/ShopNet/Database.ts
index 78ed8b84..ab6c132c 100644
--- a/src/ShopNet/Database.ts
+++ b/src/ShopNet/Database.ts
@@ -85,11 +85,6 @@ export const MSAL = new PublicClientApplication({
* @version 0.1.0
*/
export async function AccessToken(): Promise {
- const auth = MSAL.getActiveAccount();
-
- if (auth)
- return auth.idToken;
-
try {
const token = await MSAL.acquireTokenSilent({ scopes: [] });
return token.idToken;
diff --git a/src/ShopNet/SignalR.ts b/src/ShopNet/SignalR.ts
index d7d9ce5e..070e69e8 100644
--- a/src/ShopNet/SignalR.ts
+++ b/src/ShopNet/SignalR.ts
@@ -1,6 +1,7 @@
import { HubConnectionState } from "@microsoft/signalr";
import dayjs, { Dayjs } from "dayjs";
import { Subject } from "rxjs";
+import { NotLoginError } from "~/Helpers/Exceptions";
import { AdminNet } from "./Admin/AdminNet";
import { IConcurrency, MSAL, Shared } from "./Database";
import { ShopNet } from "./ShopNet";
@@ -54,11 +55,11 @@ export abstract class SignalR {
/**
* @author Aloento
* @since 1.0.0
- * @version 0.2.0
+ * @version 0.2.1
*/
protected static EnsureLogin() {
- if (!MSAL.getActiveAccount()?.idToken)
- throw new Error("Please Login First");
+ if (!MSAL.getActiveAccount())
+ throw new NotLoginError();
}
/**
diff --git a/src/ShopNet/User/Get.ts b/src/ShopNet/User/Get.ts
deleted file mode 100644
index 78a87a69..00000000
--- a/src/ShopNet/User/Get.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { IConcurrency } from "../Database";
-import { ShopNet } from "../ShopNet";
-
-/**
- * @author Aloento
- * @since 0.5.0
- * @version 0.1.0
- */
-export class UserGet extends ShopNet {
- /**
- * @author Aloento
- * @since 1.0.0
- * @version 0.1.0
- */
- public static Me(): Promise<({
- Name: string;
- EMail: string;
- Phone: string;
- Address: string;
- } & IConcurrency) | void> {
- this.EnsureLogin();
- return this.WithVersionCache(0, "UserGetMe");
- }
-}
diff --git a/src/ShopNet/User/Get.tsx b/src/ShopNet/User/Get.tsx
new file mode 100644
index 00000000..f5b27bbd
--- /dev/null
+++ b/src/ShopNet/User/Get.tsx
@@ -0,0 +1,55 @@
+import { Toast, ToastTitle } from "@fluentui/react-components";
+import { useRequest } from "ahooks";
+import type { Options } from "ahooks/lib/useRequest/src/types";
+import { NotLoginError } from "~/Helpers/Exceptions";
+import { useErrorToast } from "~/Helpers/useToast";
+import { IConcurrency } from "../Database";
+import { ShopNet } from "../ShopNet";
+
+interface IuseMe extends IConcurrency {
+ Name: string;
+ EMail: string;
+ Phone: string;
+ Address: string;
+}
+
+/**
+ * @author Aloento
+ * @since 0.5.0
+ * @version 0.1.0
+ */
+export class UserGet extends ShopNet {
+ /**
+ * @author Aloento
+ * @since 1.0.0
+ * @version 0.2.0
+ */
+ public static useMe(options?: Options, suppress: boolean = true) {
+ const { dispatch, dispatchToast } = useErrorToast();
+
+ return useRequest(() => {
+ this.EnsureLogin();
+ return this.WithVersionCache(0, "UserGetMe");
+ }, {
+ ...options,
+ onError: (e, req) => {
+ if (e instanceof NotLoginError) {
+ if (suppress)
+ console.debug(e);
+ else
+ dispatchToast(
+
+ {e.message}
+ ,
+ { intent: "warning", timeout: 5000 }
+ );
+ } else
+ dispatch({
+ Message: "Failed to Get Your Info",
+ Error: e,
+ Request: req
+ })
+ }
+ });
+ }
+}