From 51bd49e6d8f538057b5563e9db810b9e0b53252b Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Wed, 6 Dec 2023 22:40:42 +0100 Subject: [PATCH] [Front | Hub] Standardise Request (#72) * Fix API call in Persona.tsx * Add SixLabors.ImageSharp and update version in Setting component * Update SQL connection string and API requests * Update useLimit function to use the new useRequest syntax * Update version number in Combo Delete and Combo Detail components * Refactor code to use arrow function syntax for Refresh prop * Refactor API calls in Persona and AdminOrderDetail components * Update useRequest in Confirm component * Fix OrderAppend Refresh function signature * Update dependencies and fix code issues * Update admin user grant functionality * Refactor Admin User components * Refactor API calls in Admin Product components * Refactor delete functions in Admin Product pages * Update Exceptions and Patch functions * Fix API request in AdminProductNewCombo and AdminProductType components * Update order append and ship functionality * Update dependencies in package.json * Fix cancel order error handling --- SoarCraft.AwaiShop/AdminHub/AdminHub.cs | 1 + SoarCraft.AwaiShop/Program.cs | 4 +- package.json | 34 +- pnpm-lock.yaml | 364 +++++++++--------- src/Components/NewUser.tsx | 9 +- src/Components/Persona.tsx | 9 +- src/Components/Setting.tsx | 21 +- src/Components/ShopCart/Confirm.tsx | 26 +- src/Components/ShopCart/Persona.tsx | 5 +- src/Helpers/Exceptions.ts | 11 + src/Helpers/useLimit.ts | 26 +- src/Pages/Admin/Order/Append.tsx | 49 ++- src/Pages/Admin/Order/Detail.tsx | 6 +- src/Pages/Admin/Order/Ship.tsx | 29 +- src/Pages/Admin/Order/index.tsx | 2 +- src/Pages/Admin/Product/Add.tsx | 23 +- src/Pages/Admin/Product/Category.tsx | 27 +- src/Pages/Admin/Product/Combo/Delete.tsx | 21 +- src/Pages/Admin/Product/Combo/Detail.tsx | 30 +- src/Pages/Admin/Product/Combo/New.tsx | 27 +- src/Pages/Admin/Product/Combo/index.tsx | 6 +- src/Pages/Admin/Product/Delete.tsx | 23 +- src/Pages/Admin/Product/Name.tsx | 25 +- src/Pages/Admin/Product/Photo/Edit.tsx | 63 ++- src/Pages/Admin/Product/Photo/index.tsx | 49 ++- src/Pages/Admin/Product/Variant/Delete.tsx | 23 +- .../Admin/Product/Variant/Edit/Delete.tsx | 23 +- src/Pages/Admin/Product/Variant/Edit/Name.tsx | 24 +- src/Pages/Admin/Product/Variant/Edit/Type.tsx | 29 +- src/Pages/Admin/Product/Variant/New.tsx | 28 +- src/Pages/Admin/Product/Variant/index.tsx | 7 +- src/Pages/Admin/Product/index.tsx | 2 +- src/Pages/Admin/User/Admin.tsx | 43 +-- src/Pages/Admin/User/Delete.tsx | 23 +- src/Pages/Admin/User/index.tsx | 3 +- src/Pages/Gallery.tsx | 16 +- src/Pages/History/Append.tsx | 47 ++- src/Pages/History/Detail.tsx | 6 +- src/Pages/History/index.tsx | 2 +- src/Pages/Product/Carousel.tsx | 7 +- src/Pages/Product/Lexical.tsx | 4 +- src/Pages/Product/RadioGroup.tsx | 4 +- src/Pages/Product/index.tsx | 5 +- src/ShopNet/Admin/Order/Get.ts | 2 +- src/ShopNet/Admin/Order/Post.ts | 25 +- src/ShopNet/Admin/Product/Delete.ts | 39 +- src/ShopNet/Admin/Product/Get.ts | 2 +- src/ShopNet/Admin/Product/Patch.ts | 102 ++--- src/ShopNet/Admin/Product/Post.ts | 61 ++- src/ShopNet/Admin/User/Delete.ts | 18 +- src/ShopNet/Admin/User/Get.ts | 2 +- src/ShopNet/Admin/User/Post.ts | 11 +- src/ShopNet/Gallery/Get.ts | 2 +- src/ShopNet/Order/Get.ts | 2 +- src/ShopNet/Order/Post.ts | 51 +-- src/ShopNet/Product/Get.ts | 7 +- src/ShopNet/SignalR.ts | 8 +- src/ShopNet/User/Get.tsx | 2 +- src/ShopNet/User/Post.ts | 15 +- 59 files changed, 758 insertions(+), 777 deletions(-) diff --git a/SoarCraft.AwaiShop/AdminHub/AdminHub.cs b/SoarCraft.AwaiShop/AdminHub/AdminHub.cs index d359950e..4319545e 100644 --- a/SoarCraft.AwaiShop/AdminHub/AdminHub.cs +++ b/SoarCraft.AwaiShop/AdminHub/AdminHub.cs @@ -6,6 +6,7 @@ namespace SoarCraft.AwaiShop.AdminHub; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; +using SixLabors.ImageSharp; /** * diff --git a/SoarCraft.AwaiShop/Program.cs b/SoarCraft.AwaiShop/Program.cs index e9ba0025..9dc02d83 100644 --- a/SoarCraft.AwaiShop/Program.cs +++ b/SoarCraft.AwaiShop/Program.cs @@ -30,9 +30,9 @@ if (Shared.Dev) { x.EnableSensitiveDataLogging(); x.EnableDetailedErrors(); - x.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")); + x.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"), opt => opt.EnableRetryOnFailure()); } else - x.UseSqlServer(Environment.GetEnvironmentVariable("SQLAZURECONNSTR_Zero")); + x.UseSqlServer(Environment.GetEnvironmentVariable("SQLAZURECONNSTR_Zero"), opt => opt.EnableRetryOnFailure()); }); if (Shared.Dev) diff --git a/package.json b/package.json index 068a7cd9..1bdf8e36 100644 --- a/package.json +++ b/package.json @@ -22,26 +22,26 @@ "@fluentui/react-hooks": "^8.6.33", "@fluentui/react-icons": "^2.0.223", "@griffel/react": "^1.5.19", - "@lexical/clipboard": "^0.12.4", - "@lexical/code": "^0.12.4", - "@lexical/file": "^0.12.4", - "@lexical/html": "^0.12.4", - "@lexical/link": "^0.12.4", - "@lexical/list": "^0.12.4", - "@lexical/mark": "^0.12.4", - "@lexical/markdown": "^0.12.4", - "@lexical/overflow": "^0.12.4", - "@lexical/react": "^0.12.4", - "@lexical/rich-text": "^0.12.4", - "@lexical/selection": "^0.12.4", - "@lexical/table": "^0.12.4", - "@lexical/utils": "^0.12.4", + "@lexical/clipboard": "^0.12.5", + "@lexical/code": "^0.12.5", + "@lexical/file": "^0.12.5", + "@lexical/html": "^0.12.5", + "@lexical/link": "^0.12.5", + "@lexical/list": "^0.12.5", + "@lexical/mark": "^0.12.5", + "@lexical/markdown": "^0.12.5", + "@lexical/overflow": "^0.12.5", + "@lexical/react": "^0.12.5", + "@lexical/rich-text": "^0.12.5", + "@lexical/selection": "^0.12.5", + "@lexical/table": "^0.12.5", + "@lexical/utils": "^0.12.5", "@microsoft/signalr": "^8.0.0", "@microsoft/signalr-protocol-msgpack": "^8.0.0", "ahooks": "^3.7.8", "dayjs": "^1.11.10", "dexie": "^3.2.4", - "lexical": "^0.12.4", + "lexical": "^0.12.5", "lodash-es": "^4.17.21", "react": "^18.2.0", "react-dom": "^18.2.0", @@ -54,7 +54,7 @@ "@types/react": "^18.2.42", "@types/react-dom": "^18.2.17", "@vitejs/plugin-react-swc": "^3.5.0", - "typescript": "^5.3.2", - "vite": "^5.0.5" + "typescript": "^5.3.3", + "vite": "^5.0.6" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1a3cbb30..8be64339 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,47 +27,47 @@ dependencies: specifier: ^1.5.19 version: 1.5.19(react@18.2.0) '@lexical/clipboard': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5) '@lexical/code': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5) '@lexical/file': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5) '@lexical/html': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5) '@lexical/link': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5) '@lexical/list': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5) '@lexical/mark': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5) '@lexical/markdown': - specifier: ^0.12.4 - version: 0.12.4(@lexical/clipboard@0.12.4)(@lexical/selection@0.12.4)(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(@lexical/clipboard@0.12.5)(@lexical/selection@0.12.5)(lexical@0.12.5) '@lexical/overflow': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5) '@lexical/react': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4)(react-dom@18.2.0)(react@18.2.0)(yjs@13.6.10) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5)(react-dom@18.2.0)(react@18.2.0)(yjs@13.6.10) '@lexical/rich-text': - specifier: ^0.12.4 - version: 0.12.4(@lexical/clipboard@0.12.4)(@lexical/selection@0.12.4)(@lexical/utils@0.12.4)(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(@lexical/clipboard@0.12.5)(@lexical/selection@0.12.5)(@lexical/utils@0.12.5)(lexical@0.12.5) '@lexical/selection': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5) '@lexical/table': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5) '@lexical/utils': - specifier: ^0.12.4 - version: 0.12.4(lexical@0.12.4) + specifier: ^0.12.5 + version: 0.12.5(lexical@0.12.5) '@microsoft/signalr': specifier: ^8.0.0 version: 8.0.0 @@ -84,8 +84,8 @@ dependencies: specifier: ^3.2.4 version: 3.2.4 lexical: - specifier: ^0.12.4 - version: 0.12.4 + specifier: ^0.12.5 + version: 0.12.5 lodash-es: specifier: ^4.17.21 version: 4.17.21 @@ -117,13 +117,13 @@ devDependencies: version: 18.2.17 '@vitejs/plugin-react-swc': specifier: ^3.5.0 - version: 3.5.0(vite@5.0.5) + version: 3.5.0(vite@5.0.6) typescript: - specifier: ^5.3.2 - version: 5.3.2 + specifier: ^5.3.3 + version: 5.3.3 vite: - specifier: ^5.0.5 - version: 5.0.5 + specifier: ^5.0.6 + version: 5.0.6 packages: @@ -359,8 +359,8 @@ packages: dev: true optional: true - /@floating-ui/core@1.5.1: - resolution: {integrity: sha512-QgcKYwzcc8vvZ4n/5uklchy8KVdjJwcOeI+HnnTNclJjs2nYsy23DOCf+sSV1kBwD9yDAoVKCkv/gEPzgQU3Pw==} + /@floating-ui/core@1.5.2: + resolution: {integrity: sha512-Ii3MrfY/GAIN3OhXNzpCKaLxHQfJF9qvwq/kEJYdqDxeIHa01K8sldugal6TmeeXl+WMvhv9cnVzUTaFFJF09A==} dependencies: '@floating-ui/utils': 0.1.6 dev: false @@ -368,7 +368,7 @@ packages: /@floating-ui/dom@1.5.3: resolution: {integrity: sha512-ClAbQnEqJAKCJOEbbLo5IUlZHkNszqhuxS4fHAVxRPXPya6Ysf2G8KypnYcOTpx6I8xcgF9bbHb6g/2KpbV8qA==} dependencies: - '@floating-ui/core': 1.5.1 + '@floating-ui/core': 1.5.2 '@floating-ui/utils': 0.1.6 dev: false @@ -1769,171 +1769,171 @@ packages: csstype: 3.1.2 dev: false - /@lexical/clipboard@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-kFR+UdhtLCMTQgZCyDmYzp2yjPFMNpUZ4TaRjuRBpCRFYwKMlgie4p1J4VJm6sT23kkAFZtVjOfp+gDEYnPHRQ==} + /@lexical/clipboard@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-A0k0g5mCHDgROLF33TwiKdjMWEfajyPcIF64lsHapZ19ZTi1iabGkXvpHnyHaMq79py1Se/e6tOcmFe9nOJkrQ==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - '@lexical/html': 0.12.4(lexical@0.12.4) - '@lexical/list': 0.12.4(lexical@0.12.4) - '@lexical/selection': 0.12.4(lexical@0.12.4) - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/html': 0.12.5(lexical@0.12.5) + '@lexical/list': 0.12.5(lexical@0.12.5) + '@lexical/selection': 0.12.5(lexical@0.12.5) + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 dev: false - /@lexical/code@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-pX7rJCjbjCl6VdOPl2hl/UkjP3iPPyCQgH2VQ+WlXapDd+0uZ54nPL1MKCCaFUZocHPmOmSRKKGUp6K2CNiqzg==} + /@lexical/code@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-YV879sO2C0efWXgj4ZUzpowPWxbid8T5I0vysQIzuWPiaQG0fjilz1maYV+X95hD2VXW8yhyOnEdScfeKk62Zg==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 prismjs: 1.29.0 dev: false - /@lexical/dragon@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-7DaXdQ/5GJ8HRpPYr2+SjaUi912tG9L6ukg9IglG1t51lWGxqLx2chW17tp50XDTtY05w9VnoMaxtgsuCN5Pmg==} + /@lexical/dragon@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-RFU6wIIUS0/ab5JtLp2rKaUi7nltDT96+GdmvNVHpAfa7TZuepYsoi7PtZB9aF/Outye4U7dQU2tNwesDBf8kg==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - lexical: 0.12.4 + lexical: 0.12.5 dev: false - /@lexical/file@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-QE25zTs95bZpJTLzvfMDUv12XwJ3QzZzO4Pk73ri2kkp3Mav9R+9E7LEyUdBNwZJiHquU5NZspOgD+7vzBGXAg==} + /@lexical/file@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-/+SI+8x4x2if1Jm7290YQ/MREiP4adYRiEZykQyJWXo101ZdpKl+hs9MyOKcU35aJpPGEGZnqXNzgeu4bBBTEA==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - lexical: 0.12.4 + lexical: 0.12.5 dev: false - /@lexical/hashtag@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-iCxQRBZmgwAV6kypmxtWg7HVhBC7PKclmqLNaLDLoKBm+keEXpKnGB5iEtgK/tCMiwkzrg+wGcrw5qi+YjvM9Q==} + /@lexical/hashtag@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-nlPFScTiuZgUtuBSnRkHK9AuRDV35zZug4JLG1Hkky+Fh1PJ+0MK+/K8mhoatp13zm7GqN2fMOrrUGufqEingw==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 dev: false - /@lexical/history@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-XLbSSr9FueAxuKHo4LBi+lZNVAEReNNDCt4MM2Ol8UZhWPlpNskSB/sECYEEQ6/ItlzgtnKyKWjfDFBHRWvC2g==} + /@lexical/history@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-nF5TurEE4qRbuNP/i5pDtVfWHQXb4ONof+MvKmHNfLRJbxSj7Ee33MVG9x851PjAzXoXuGJvw6FMBCasGXQx7A==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 dev: false - /@lexical/html@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-RD/n9n1eCuTZtLaTEI3wuUDlJjCn6j+/0c9GvzqLKhNz9f+E5zMVExhzTT4cZQh5WXbzGFNlwC/cuOtaM3wODg==} + /@lexical/html@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-OzsWKVcr9wUGvAbgyUdG+32/cI2RclI4I4JmIyfLbiYMBYdafu+j160cjohNWu9gQFjVFszIjG4CBxfwRM+Sag==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - '@lexical/selection': 0.12.4(lexical@0.12.4) - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/selection': 0.12.5(lexical@0.12.5) + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 dev: false - /@lexical/link@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-gmEs0GJGDhgwV1x0IrO7Br2GCALijZLIayGWoLAgYiXZee4WZpvjbngZuC6yghYBhrme6muPRMG2sLMwV2cWiQ==} + /@lexical/link@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-h7p5G+XXKqNrb4lk55mJL23Us5pz2szbzZevccADJ9Om6o3i4aNyjv1MeC29WXjmgS0YKHDlYcnKEgyAPKvVMw==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 dev: false - /@lexical/list@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-qxwRIz+4Aj2u2fzyGPo86vX+1ebwCnamppr/c5ZWuqpRTWtYDWjq5LQKIwAvZBxCzPdtP5jzwyZ6VYWQXYW4Kg==} + /@lexical/list@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-KNJ262krlpcDZ2U1LC8xp86uw2nqt88iEQgpF+khv3SAqqLbhT8tMpyZ6+eWbW3mHPhQIxFutJGazMAqMW3uUA==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 dev: false - /@lexical/mark@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-NFFk/3AFFJARjsth8wd5HdeW8XhcaECoQ8wwnJ4fRZzgN0lu3ZSiq+CuVm0NRN5xA5KoUT6sfIQqGOzIPfvdsw==} + /@lexical/mark@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-61ctAYrxTGl4uMDTnE5fRH4yrs8sqnRyivuNWyOmQR6W/G3s0gHwkUZC7akOSnPLYhfnXRl3C4haY8pH93sWQg==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 dev: false - /@lexical/markdown@0.12.4(@lexical/clipboard@0.12.4)(@lexical/selection@0.12.4)(lexical@0.12.4): - resolution: {integrity: sha512-cOk0dkafyvQI4DMwwMfkP329bRVfyhXcVF3dcRiydl6ZIgqOrj/EMi+C0qxQkcqg0MO26Rky6LLJ4vQi6AgJDg==} + /@lexical/markdown@0.12.5(@lexical/clipboard@0.12.5)(@lexical/selection@0.12.5)(lexical@0.12.5): + resolution: {integrity: sha512-F3cBcuhoGWxxCqERUXF4fYfJhceK7gFYQPRsXir5mYriSNZIQIMhJoeAt8Pjer0UjFyQvNfQ+AzzXHu5xYNLLA==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - '@lexical/code': 0.12.4(lexical@0.12.4) - '@lexical/link': 0.12.4(lexical@0.12.4) - '@lexical/list': 0.12.4(lexical@0.12.4) - '@lexical/rich-text': 0.12.4(@lexical/clipboard@0.12.4)(@lexical/selection@0.12.4)(@lexical/utils@0.12.4)(lexical@0.12.4) - '@lexical/text': 0.12.4(lexical@0.12.4) - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/code': 0.12.5(lexical@0.12.5) + '@lexical/link': 0.12.5(lexical@0.12.5) + '@lexical/list': 0.12.5(lexical@0.12.5) + '@lexical/rich-text': 0.12.5(@lexical/clipboard@0.12.5)(@lexical/selection@0.12.5)(@lexical/utils@0.12.5)(lexical@0.12.5) + '@lexical/text': 0.12.5(lexical@0.12.5) + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 transitivePeerDependencies: - '@lexical/clipboard' - '@lexical/selection' dev: false - /@lexical/offset@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-6fjXCx+YD1TMl6GFL4wowhBgbIg+UX3j2OOXh3F7WEp3SDvzoJsJ6F7xRctrHQbluCITM3oDwOyHa1J0m5lrFg==} + /@lexical/offset@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-K+Mt4tOmwKarsJ1esdqNgN9Ep/JaeFa9ZQ7DKx8KIOkXL35nPb9NXuBvYyJjh1crP/iwsuP15kymgDjxj9ciMw==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - lexical: 0.12.4 + lexical: 0.12.5 dev: false - /@lexical/overflow@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-mEWgVukoOgcyDruHvzk1amy9jgGDVXFYiPn20ykxgrVQz6XEpq+lfyic/BUnN4toNR8p6jc/Yxi2lF1ELCU0Kg==} + /@lexical/overflow@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-boP1oTgBbNmbo8+1tgpDAs1P/lbTk4oWZ6x88E9VNVBJSkG2ZrmQKQoJzKzHwpjXbm+Cechf77JxfgTOabzYxw==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - lexical: 0.12.4 + lexical: 0.12.5 dev: false - /@lexical/plain-text@0.12.4(@lexical/clipboard@0.12.4)(@lexical/selection@0.12.4)(@lexical/utils@0.12.4)(lexical@0.12.4): - resolution: {integrity: sha512-osbqOyt19oFG0kTbV71jxxCdgnUqNYW6QXIIaS1SwcCN/N1CdFZ0sNpjPkHIFx9AdZ/Tmi4u9SNFUo16DjvThA==} + /@lexical/plain-text@0.12.5(@lexical/clipboard@0.12.5)(@lexical/selection@0.12.5)(@lexical/utils@0.12.5)(lexical@0.12.5): + resolution: {integrity: sha512-n24aQvTIy4AN+LaoQce6BIuSY4pUshiTp4OpiRh48o5c9NU0DmzEa0l9fBS1GfvjZL9bN5luiINFYn/bMB49nA==} peerDependencies: - '@lexical/clipboard': 0.12.4 - '@lexical/selection': 0.12.4 - '@lexical/utils': 0.12.4 - lexical: 0.12.4 + '@lexical/clipboard': 0.12.5 + '@lexical/selection': 0.12.5 + '@lexical/utils': 0.12.5 + lexical: 0.12.5 dependencies: - '@lexical/clipboard': 0.12.4(lexical@0.12.4) - '@lexical/selection': 0.12.4(lexical@0.12.4) - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/clipboard': 0.12.5(lexical@0.12.5) + '@lexical/selection': 0.12.5(lexical@0.12.5) + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 dev: false - /@lexical/react@0.12.4(lexical@0.12.4)(react-dom@18.2.0)(react@18.2.0)(yjs@13.6.10): - resolution: {integrity: sha512-tz4ebqJ++YP/Y6FCjk5aU3bvgrps8+i9abqvaaNCSzSQavI0qHtdS7EGy4S9qyO6qKuthXcOGIQxGTweRTkDsA==} + /@lexical/react@0.12.5(lexical@0.12.5)(react-dom@18.2.0)(react@18.2.0)(yjs@13.6.10): + resolution: {integrity: sha512-pAbJQksin223Yp1p1VsPKxkRtSppVij+HcLTzP89q2QuSA0z0p/T+f5jZjs8eV6tecMtmrjizhdLTbk0jkej1w==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 react: '>=17.x' react-dom: '>=17.x' dependencies: - '@lexical/clipboard': 0.12.4(lexical@0.12.4) - '@lexical/code': 0.12.4(lexical@0.12.4) - '@lexical/dragon': 0.12.4(lexical@0.12.4) - '@lexical/hashtag': 0.12.4(lexical@0.12.4) - '@lexical/history': 0.12.4(lexical@0.12.4) - '@lexical/link': 0.12.4(lexical@0.12.4) - '@lexical/list': 0.12.4(lexical@0.12.4) - '@lexical/mark': 0.12.4(lexical@0.12.4) - '@lexical/markdown': 0.12.4(@lexical/clipboard@0.12.4)(@lexical/selection@0.12.4)(lexical@0.12.4) - '@lexical/overflow': 0.12.4(lexical@0.12.4) - '@lexical/plain-text': 0.12.4(@lexical/clipboard@0.12.4)(@lexical/selection@0.12.4)(@lexical/utils@0.12.4)(lexical@0.12.4) - '@lexical/rich-text': 0.12.4(@lexical/clipboard@0.12.4)(@lexical/selection@0.12.4)(@lexical/utils@0.12.4)(lexical@0.12.4) - '@lexical/selection': 0.12.4(lexical@0.12.4) - '@lexical/table': 0.12.4(lexical@0.12.4) - '@lexical/text': 0.12.4(lexical@0.12.4) - '@lexical/utils': 0.12.4(lexical@0.12.4) - '@lexical/yjs': 0.12.4(lexical@0.12.4)(yjs@13.6.10) - lexical: 0.12.4 + '@lexical/clipboard': 0.12.5(lexical@0.12.5) + '@lexical/code': 0.12.5(lexical@0.12.5) + '@lexical/dragon': 0.12.5(lexical@0.12.5) + '@lexical/hashtag': 0.12.5(lexical@0.12.5) + '@lexical/history': 0.12.5(lexical@0.12.5) + '@lexical/link': 0.12.5(lexical@0.12.5) + '@lexical/list': 0.12.5(lexical@0.12.5) + '@lexical/mark': 0.12.5(lexical@0.12.5) + '@lexical/markdown': 0.12.5(@lexical/clipboard@0.12.5)(@lexical/selection@0.12.5)(lexical@0.12.5) + '@lexical/overflow': 0.12.5(lexical@0.12.5) + '@lexical/plain-text': 0.12.5(@lexical/clipboard@0.12.5)(@lexical/selection@0.12.5)(@lexical/utils@0.12.5)(lexical@0.12.5) + '@lexical/rich-text': 0.12.5(@lexical/clipboard@0.12.5)(@lexical/selection@0.12.5)(@lexical/utils@0.12.5)(lexical@0.12.5) + '@lexical/selection': 0.12.5(lexical@0.12.5) + '@lexical/table': 0.12.5(lexical@0.12.5) + '@lexical/text': 0.12.5(lexical@0.12.5) + '@lexical/utils': 0.12.5(lexical@0.12.5) + '@lexical/yjs': 0.12.5(lexical@0.12.5)(yjs@13.6.10) + lexical: 0.12.5 react: 18.2.0 react-dom: 18.2.0(react@18.2.0) react-error-boundary: 3.1.4(react@18.2.0) @@ -1941,64 +1941,64 @@ packages: - yjs dev: false - /@lexical/rich-text@0.12.4(@lexical/clipboard@0.12.4)(@lexical/selection@0.12.4)(@lexical/utils@0.12.4)(lexical@0.12.4): - resolution: {integrity: sha512-gWMDmdRRFPk00JfQv52650qcpjTN6oBrrYwBydYvEG8WTC8o1k8qEOZaOFja6GElPt0520dpyvcWHTlIL0jv3Q==} + /@lexical/rich-text@0.12.5(@lexical/clipboard@0.12.5)(@lexical/selection@0.12.5)(@lexical/utils@0.12.5)(lexical@0.12.5): + resolution: {integrity: sha512-33R8ODRI5kKGbF70A/FWdISbbSPk+q4hKtiEJaV67zYPBuzrz0YHcni+tgKiykS05LgCksI/e43sfEkiykjrVQ==} peerDependencies: - '@lexical/clipboard': 0.12.4 - '@lexical/selection': 0.12.4 - '@lexical/utils': 0.12.4 - lexical: 0.12.4 + '@lexical/clipboard': 0.12.5 + '@lexical/selection': 0.12.5 + '@lexical/utils': 0.12.5 + lexical: 0.12.5 dependencies: - '@lexical/clipboard': 0.12.4(lexical@0.12.4) - '@lexical/selection': 0.12.4(lexical@0.12.4) - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/clipboard': 0.12.5(lexical@0.12.5) + '@lexical/selection': 0.12.5(lexical@0.12.5) + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 dev: false - /@lexical/selection@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-9lJt9PBJW7lWYiPDo/PGl2nZ6NrdYaDBidEoMNhyusPjeBEr35z4Hm0qWUhDrPDQPhK2i1oBw6nZa94bxuS9Lw==} + /@lexical/selection@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-oWJ87T4j6plf2yQzElOeudUyv7kdwTkuhzTZbcCTBNH/cSMdp55/Kv2doBynxhfHYEceuBKE7f8rci//T9DUPQ==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - lexical: 0.12.4 + lexical: 0.12.5 dev: false - /@lexical/table@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-Lyy6y1HOQqzU8O2cH5Zhzek46B0UU7NceM2fJKM7qiBSuxY/nE0BzkFq0xDk3x5W+vhXob6Z32sJSNFImtuqKw==} + /@lexical/table@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-vgSTsjvGw+TrYYBmf3FR0kYJ+j1oOlBmrO1sqvuIrGPXKWmvYL+RbKIkm2xhtApVHVYgqfFvxNiZrPL5Wf9dXg==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - '@lexical/utils': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/utils': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 dev: false - /@lexical/text@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-r/7402eCf6C/7BqUNR7ZLZQQjsE62wjeuf0rFeW1ulOpwiti/dFn1o+EsCb0hvNeHPzfGgRC+FuDT9KSEKu7Ig==} + /@lexical/text@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-PU1ntXQCqon3HTjrEPl/HdKB/boyW36vKgiPvojoaAhBhkEnuiN+Pq9hrexORBcZPyLFp6wYoWXjKSO4fJVYeA==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - lexical: 0.12.4 + lexical: 0.12.5 dev: false - /@lexical/utils@0.12.4(lexical@0.12.4): - resolution: {integrity: sha512-ColV11ANBY6deT7CdGwP4lzv3pb5caFfFLcVKdGDMMJSUYFQ5l69aZvDP2qWWnNqzGLb+AJSunMd142wWc5LGg==} + /@lexical/utils@0.12.5(lexical@0.12.5): + resolution: {integrity: sha512-wPVyvi1Cvtf7aHwVKlG/9RlgHxSUzpGvXm87t889Rg7uZfOteyvXHJStjpSCZ3pvZ60y5ETin4OoetaVZciPfw==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 dependencies: - '@lexical/list': 0.12.4(lexical@0.12.4) - '@lexical/selection': 0.12.4(lexical@0.12.4) - '@lexical/table': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/list': 0.12.5(lexical@0.12.5) + '@lexical/selection': 0.12.5(lexical@0.12.5) + '@lexical/table': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 dev: false - /@lexical/yjs@0.12.4(lexical@0.12.4)(yjs@13.6.10): - resolution: {integrity: sha512-qtCiABugE1CiZ7K5iFfQnB1KqfWtLyiRK0nxAaSxuZzQTO4+Kh3WDh7ULppPa53Sf3pKpw8Sq2XB4AXP6csbkg==} + /@lexical/yjs@0.12.5(lexical@0.12.5)(yjs@13.6.10): + resolution: {integrity: sha512-GNiRND/8ePdTWuSDFloPo/1355V0ce6OtH/25qxCq5D9MLNiIkAcwqQfnWFUdOtVMuNJOVc4OfCE9ARCGuEjyQ==} peerDependencies: - lexical: 0.12.4 + lexical: 0.12.5 yjs: '>=13.5.22' dependencies: - '@lexical/offset': 0.12.4(lexical@0.12.4) - lexical: 0.12.4 + '@lexical/offset': 0.12.5(lexical@0.12.5) + lexical: 0.12.5 yjs: 13.6.10 dev: false @@ -2279,13 +2279,13 @@ packages: /@types/scheduler@0.16.8: resolution: {integrity: sha512-WZLiwShhwLRmeV6zH+GkbOFT6Z6VklCItrDioxUnv+u4Ll+8vKeFySoFyK/0ctcRpOmwAicELfmys1sDc/Rw+A==} - /@vitejs/plugin-react-swc@3.5.0(vite@5.0.5): + /@vitejs/plugin-react-swc@3.5.0(vite@5.0.6): resolution: {integrity: sha512-1PrOvAaDpqlCV+Up8RkAh9qaiUjoDUcjtttyhXDKw53XA6Ve16SOp6cCOpRs8Dj8DqUQs6eTW5YkLcLJjrXAig==} peerDependencies: vite: ^4 || ^5 dependencies: '@swc/core': 1.3.100 - vite: 5.0.5 + vite: 5.0.6 transitivePeerDependencies: - '@swc/helpers' dev: true @@ -2426,8 +2426,8 @@ packages: resolution: {integrity: sha512-yQa1dz+FilQ+w3JM6GH2V/wnFeQhfbkK9stvs3UiraW3GOEO7zrOBBh0ZuHsrzeN1xx6v7P5EpA2JtOUUnfN/w==} dev: false - /lexical@0.12.4: - resolution: {integrity: sha512-giNrnp45H6P4IHFhkKaHEPTF+bKLBWdEIDL/FGjRZf+to7l7TORIBk/23Zdchzt/VGgKGWu950EOvGh53gkVMQ==} + /lexical@0.12.5: + resolution: {integrity: sha512-ZMqisIxNe+JBqaUa1Qmz7ghpvnmARHxgYz+F0rcXRtSPZtgEL8OT2c9xk8CJ4ccVpf+qRQlONzCEIZfQQHd/RA==} dev: false /lib0@0.2.88: @@ -2703,8 +2703,8 @@ packages: resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} dev: false - /typescript@5.3.2: - resolution: {integrity: sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==} + /typescript@5.3.3: + resolution: {integrity: sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==} engines: {node: '>=14.17'} hasBin: true dev: true @@ -2735,8 +2735,8 @@ packages: react-dom: 18.2.0(react@18.2.0) dev: false - /vite@5.0.5: - resolution: {integrity: sha512-OekeWqR9Ls56f3zd4CaxzbbS11gqYkEiBtnWFFgYR2WV8oPJRRKq0mpskYy/XaoCL3L7VINDhqqOMNDiYdGvGg==} + /vite@5.0.6: + resolution: {integrity: sha512-MD3joyAEBtV7QZPl2JVVUai6zHms3YOmLR+BpMzLlX2Yzjfcc4gTgNi09d/Rua3F4EtC8zdwPU8eQYyib4vVMQ==} engines: {node: ^18.0.0 || >=20.0.0} hasBin: true peerDependencies: diff --git a/src/Components/NewUser.tsx b/src/Components/NewUser.tsx index c4a1f8b9..60d9a352 100644 --- a/src/Components/NewUser.tsx +++ b/src/Components/NewUser.tsx @@ -1,6 +1,5 @@ import { AuthenticatedTemplate } from "@azure/msal-react"; -import { useBoolean } from "ahooks"; -import { useEffect } from "react"; +import { useBoolean, useMount } from "ahooks"; import { Subject } from "rxjs"; import { Setting } from "./Setting"; @@ -14,14 +13,14 @@ export const OnNewUserSubject = new Subject(); /** * @author Aloento * @since 1.0.0 - * @version 0.1.1 + * @version 0.1.2 */ export function NewUser() { const [open, { toggle }] = useBoolean(); - useEffect(() => { + useMount(() => { OnNewUserSubject.subscribe(x => x && toggle()); - }, []); + }); return ( diff --git a/src/Components/Persona.tsx b/src/Components/Persona.tsx index 9ec75974..35349276 100644 --- a/src/Components/Persona.tsx +++ b/src/Components/Persona.tsx @@ -26,18 +26,15 @@ const useStyles = makeStyles({ export function OrderPersona({ OrderId, Admin }: { OrderId: number; Admin?: true }) { const style = useStyles(); - const { data: admin } = useRequest(AdminHub.User.Get.OrderUser.bind(AdminHub.User.Get), { - defaultParams: [OrderId], + const { data: admin } = useRequest(() => AdminHub.User.Get.OrderUser(OrderId), { manual: !Admin }) - const { data: me } = useRequest(Hub.User.Get.useMe.bind(Hub.User.Get), { + const { data: me } = Hub.User.Get.useMe({ manual: Admin }); - const { data: order } = useRequest(Hub.Order.Get.Order.bind(Hub.Order.Get), { - defaultParams: [OrderId] - }); + const { data: order } = useRequest(() => Hub.Order.Get.Order(OrderId)); const data = Admin ? admin : me; diff --git a/src/Components/Setting.tsx b/src/Components/Setting.tsx index 8f30849c..174b0231 100644 --- a/src/Components/Setting.tsx +++ b/src/Components/Setting.tsx @@ -1,6 +1,5 @@ import { useMsal } from "@azure/msal-react"; import { Button, Dialog, DialogActions, DialogBody, DialogContent, DialogSurface, DialogTitle, DialogTrigger, Field, Input, Label, Toast, ToastBody, ToastTitle, makeStyles, tokens } from "@fluentui/react-components"; -import { useRequest } from "ahooks"; import { useState } from "react"; import { ColFlex, Flex } from "~/Helpers/Styles"; import { useErrorToast } from "~/Helpers/useToast"; @@ -37,7 +36,7 @@ const useStyles = makeStyles({ /** * @author Aloento * @since 0.1.0 - * @version 0.3.3 + * @version 0.4.0 */ export function Setting({ Open, Toggle, New }: ISetting) { const style = useStyles(); @@ -61,16 +60,16 @@ export function Setting({ Open, Toggle, New }: ISetting) { const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(Hub.User.Post.Update.bind(Hub.User.Post), { + const { run } = Hub.User.Post.useUpdate({ manual: true, - onFinally([req], _, e) { - if (e) - return dispatch({ - Message: `Failed ${New ? "Create" : "Update"} Info`, - Error: e, - Request: req - }); - + onError(e, [req]) { + dispatch({ + Message: `Failed ${New ? "Create" : "Update"} Info`, + Error: e, + Request: req + }); + }, + onSuccess(_, [req]) { dispatchToast( Info {New ? "Created" : "Updated"} diff --git a/src/Components/ShopCart/Confirm.tsx b/src/Components/ShopCart/Confirm.tsx index 830a3cc5..b66b3d07 100644 --- a/src/Components/ShopCart/Confirm.tsx +++ b/src/Components/ShopCart/Confirm.tsx @@ -1,7 +1,7 @@ import { Button, Field, Textarea, Toast, ToastBody, ToastTitle, makeStyles, tokens } from "@fluentui/react-components"; import { Drawer, DrawerBody, DrawerHeader, DrawerHeaderTitle } from "@fluentui/react-components/unstable"; import { DismissRegular } from "@fluentui/react-icons"; -import { useBoolean, useRequest } from "ahooks"; +import { useBoolean } from "ahooks"; import { useState } from "react"; import { ColFlex } from "~/Helpers/Styles"; import { useErrorToast } from "~/Helpers/useToast"; @@ -31,7 +31,7 @@ const useStyles = makeStyles({ /** * @author Aloento * @since 0.1.0 - * @version 0.4.0 + * @version 0.4.1 */ export function Confirm() { const [cmt, setCmt] = useState(); @@ -43,15 +43,16 @@ export function Confirm() { const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(Hub.Order.Post.New.bind(Hub.Order.Post), { - onFinally([req], data, e) { - if (e) - return dispatch({ - Message: "Failed Create Order", - Request: req, - Error: e - }); - + const { run } = Hub.Order.Post.useNew({ + manual: true, + onError(e, req) { + dispatch({ + Message: "Failed Create Order", + Request: req, + Error: e + }); + }, + onSuccess(data) { dispatchToast( Order Placed @@ -64,8 +65,7 @@ export function Confirm() { toggle(); Nav("History", data); }, - manual: true, - }) + }); return <> diff --git a/src/Components/ShopCart/Persona.tsx b/src/Components/ShopCart/Persona.tsx index c3a68257..41b5f2d1 100644 --- a/src/Components/ShopCart/Persona.tsx +++ b/src/Components/ShopCart/Persona.tsx @@ -1,5 +1,4 @@ import { Field, Label, makeStyles, tokens } from "@fluentui/react-components"; -import { useRequest } from "ahooks"; import { ColFlex, Flex } from "~/Helpers/Styles"; import { Hub } from "~/ShopNet"; @@ -32,11 +31,11 @@ export interface IPersona { /** * @author Aloento * @since 0.5.0 - * @version 0.1.0 + * @version 0.2.0 */ export function PersonaInfo() { const style = useStyles(); - const { data } = useRequest(Hub.User.Get.useMe.bind(Hub.User.Get)); + const { data } = Hub.User.Get.useMe(); return <>
diff --git a/src/Helpers/Exceptions.ts b/src/Helpers/Exceptions.ts index dba90eb4..ff3631f0 100644 --- a/src/Helpers/Exceptions.ts +++ b/src/Helpers/Exceptions.ts @@ -8,3 +8,14 @@ export class NotLoginError extends Error { super("Please Login First"); } } + +/** + * @author Aloento + * @since 1.0.0 + * @version 0.1.0 + */ +export class NotTrueError extends Error { + public constructor() { + super("Server Returned False"); + } +} diff --git a/src/Helpers/useLimit.ts b/src/Helpers/useLimit.ts index 88615d4b..ad11bc23 100644 --- a/src/Helpers/useLimit.ts +++ b/src/Helpers/useLimit.ts @@ -1,32 +1,26 @@ import { useRequest } from "ahooks"; -import { useMemo } from "react"; import { useShopCart } from "~/Components/ShopCart/Context"; import { Hub } from "~/ShopNet"; /** * @author Aloento * @since 0.5.0 - * @version 0.1.0 + * @version 0.2.0 */ export function useLimit(prodId: number): [boolean, number] { const { List } = useShopCart(); - const { data } = useRequest(Hub.Product.Get.Limit.bind(Hub.Product.Get), { - defaultParams: [prodId] - }) + const { data } = useRequest(() => Hub.Product.Get.Limit(prodId)); const limit = data || 3; + let count = 0; - return useMemo(() => { - let count = 0; + for (const i of List) { + if (i.ProdId === prodId) + count += i.Quantity; - for (const i of List) { - if (i.ProdId === prodId) - count += i.Quantity; + if (count >= limit) + return [true, limit]; + } - if (count >= limit) - return [true, limit]; - } - - return [false, limit]; - }, [List]); + return [false, limit]; } diff --git a/src/Pages/Admin/Order/Append.tsx b/src/Pages/Admin/Order/Append.tsx index 3689157f..78db9a6b 100644 --- a/src/Pages/Admin/Order/Append.tsx +++ b/src/Pages/Admin/Order/Append.tsx @@ -1,5 +1,4 @@ import { Button, Field, Textarea, Toast, ToastTitle, makeStyles } from "@fluentui/react-components"; -import { useRequest } from "ahooks"; import { useState } from "react"; import { Flex } from "~/Helpers/Styles"; import { useErrorToast } from "~/Helpers/useToast"; @@ -20,24 +19,24 @@ const useStyles = makeStyles({ /** * @author Aloento * @since 0.5.0 - * @version 0.2.0 + * @version 0.2.1 */ -export function AdminOrderAppend({ OrderId, Refresh }: { OrderId: number; Refresh: (id: number) => void }) { +export function AdminOrderAppend({ OrderId, Refresh }: { OrderId: number; Refresh: () => void }) { const style = useStyles(); const [cmt, setCmt] = useState(); const { dispatch, dispatchToast } = useErrorToast(); - const { run: append } = useRequest(AdminHub.Order.Post.Append.bind(AdminHub.Order.Post), { + const { run: append } = AdminHub.Order.Post.useAppend({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Append Comment", - Request: req, - Error: e - }); - + onError(e, params) { + dispatch({ + Message: "Failed Append Comment", + Request: params, + Error: e + }); + }, + onSuccess() { dispatchToast( Comment Appended @@ -45,20 +44,20 @@ export function AdminOrderAppend({ OrderId, Refresh }: { OrderId: number; Refres { intent: "success" } ); - Refresh(OrderId); - }, + Refresh(); + } }); - const { run: close } = useRequest(AdminHub.Order.Post.Close.bind(AdminHub.Order.Post), { + const { run: close } = AdminHub.Order.Post.useClose({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Close", - Request: req, - Error: e - }); - + onError(e, params) { + dispatch({ + Message: "Failed Close Order", + Request: params, + Error: e + }); + }, + onSuccess() { dispatchToast( Order Closed @@ -66,8 +65,8 @@ export function AdminOrderAppend({ OrderId, Refresh }: { OrderId: number; Refres { intent: "success" } ); - Refresh(OrderId); - }, + Refresh(); + } }); return <> diff --git a/src/Pages/Admin/Order/Detail.tsx b/src/Pages/Admin/Order/Detail.tsx index d7e0ebf2..88e9ec9e 100644 --- a/src/Pages/Admin/Order/Detail.tsx +++ b/src/Pages/Admin/Order/Detail.tsx @@ -33,7 +33,7 @@ export function AdminOrderDetail({ OrderId }: { OrderId: number; }) { const [open, { toggle, setTrue }] = useBoolean(); const { Nav, Paths } = useRouter(); - const { data, run } = useRequest(Hub.Order.Get.Detail.bind(Hub.Order.Get), { + const { data, run } = useRequest(() => Hub.Order.Get.Detail(OrderId), { onError(e) { Nav("Admin", "Order"); console.error(e); @@ -43,7 +43,7 @@ export function AdminOrderDetail({ OrderId }: { OrderId: number; }) { useMount(() => { if (parseInt(Paths.at(2)!) === OrderId) { - run(OrderId); + run(); setTrue(); } }); @@ -54,7 +54,7 @@ export function AdminOrderDetail({ OrderId }: { OrderId: number; }) { icon={} onClick={() => { Nav("Admin", "Order", OrderId); - run(OrderId); + run(); setTrue(); }} /> diff --git a/src/Pages/Admin/Order/Ship.tsx b/src/Pages/Admin/Order/Ship.tsx index da018f8c..852cb451 100644 --- a/src/Pages/Admin/Order/Ship.tsx +++ b/src/Pages/Admin/Order/Ship.tsx @@ -9,31 +9,30 @@ import { AdminHub } from "~/ShopNet/Admin"; /** * @author Aloento * @since 0.5.0 - * @version 0.2.1 + * @version 0.2.2 */ -export function Shipment({ OrderId, Refresh }: { OrderId: number; Refresh: (id: number) => void }) { +export function Shipment({ OrderId, Refresh }: { OrderId: number; Refresh: () => void }) { const [edit, { setTrue, setFalse }] = useBoolean(); const [track, setTrack] = useState(""); const { dispatch, dispatchToast } = useErrorToast(); - useRequest(Hub.Order.Get.Order.bind(Hub.Order.Get), { - defaultParams: [OrderId], + useRequest(() => Hub.Order.Get.Order(OrderId), { onSuccess(data) { setTrack(data?.TrackingNumber!); } }); - const { run } = useRequest(AdminHub.Order.Post.Ship.bind(AdminHub.Order.Post), { + const { run } = AdminHub.Order.Post.useShip({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Update Tracking Number", - Request: req, - Error: e - }); - + onError(e, params) { + dispatch({ + Message: "Failed Update Tracking Number", + Request: params, + Error: e + }); + }, + onSuccess() { dispatchToast( Tracking Number Updated @@ -42,8 +41,8 @@ export function Shipment({ OrderId, Refresh }: { OrderId: number; Refresh: (id: ); setFalse(); - Refresh(OrderId); - }, + Refresh(); + } }); return ( diff --git a/src/Pages/Admin/Order/index.tsx b/src/Pages/Admin/Order/index.tsx index 6a7f6653..f583d30e 100644 --- a/src/Pages/Admin/Order/index.tsx +++ b/src/Pages/Admin/Order/index.tsx @@ -85,7 +85,7 @@ const columns: TableColumnDefinition[] = [ * @version 0.2.0 */ export function AdminOrder() { - const { data } = useRequest(AdminHub.Order.Get.List.bind(AdminHub.Order.Get)); + const { data } = useRequest(() => AdminHub.Order.Get.List()); return ( diff --git a/src/Pages/Admin/Product/Add.tsx b/src/Pages/Admin/Product/Add.tsx index 705e3f42..95ac762f 100644 --- a/src/Pages/Admin/Product/Add.tsx +++ b/src/Pages/Admin/Product/Add.tsx @@ -1,6 +1,5 @@ import { Button, Dialog, DialogActions, DialogBody, DialogContent, DialogSurface, DialogTrigger, Input, Subtitle2, Toast, ToastBody, ToastTitle, makeStyles } from "@fluentui/react-components"; import { AddRegular } from "@fluentui/react-icons"; -import { useRequest } from "ahooks"; import { useState } from "react"; import { useRouter } from "~/Components/Router"; import { ColFlex } from "~/Helpers/Styles"; @@ -19,7 +18,7 @@ const useStyles = makeStyles({ /** * @author Aloento * @since 0.1.0 - * @version 0.3.1 + * @version 0.3.2 */ export function AdminProductAddButton() { const { Nav, Paths } = useRouter(); @@ -31,16 +30,16 @@ export function AdminProductAddButton() { const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Post.Create.bind(AdminHub.Product.Post), { + const { run } = AdminHub.Product.Post.useCreate({ manual: true, - onFinally(req, data, e) { - if (e) - return dispatch({ - Message: `Failed Create ${name}`, - Request: req, - Error: e - }); - + onError(e, params) { + dispatch({ + Message: `Failed Create ${name}`, + Request: params, + Error: e + }); + }, + onSuccess(data) { dispatchToast( New Product Created @@ -50,7 +49,7 @@ export function AdminProductAddButton() { ); Nav("Admin", data); - }, + } }); return ( diff --git a/src/Pages/Admin/Product/Category.tsx b/src/Pages/Admin/Product/Category.tsx index 8ed32da5..bba865cd 100644 --- a/src/Pages/Admin/Product/Category.tsx +++ b/src/Pages/Admin/Product/Category.tsx @@ -25,14 +25,13 @@ const useStyles = makeStyles({ /** * @author Aloento * @since 0.5.0 - * @version 0.3.0 + * @version 0.3.1 */ export function AdminProductCategory({ ProdId }: { ProdId: number; }) { const [cate, setCate] = useState(""); const [edit, { setTrue, setFalse }] = useBoolean(); - useRequest(AdminHub.Product.Get.Category.bind(AdminHub.Product.Get), { - defaultParams: [ProdId], + useRequest(() => AdminHub.Product.Get.Category(ProdId), { onSuccess(data) { data && setCate(data); } @@ -40,16 +39,16 @@ export function AdminProductCategory({ ProdId }: { ProdId: number; }) { const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Patch.Category.bind(AdminHub.Product.Patch), { + const { run } = AdminHub.Product.Patch.useCategory({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Update Category", - Request: req, - Error: e - }); - + onError(e, params) { + dispatch({ + Message: "Failed Update Category", + Request: params, + Error: e + }); + }, + onSuccess() { dispatchToast( Category Updated @@ -58,10 +57,10 @@ export function AdminProductCategory({ ProdId }: { ProdId: number; }) { ); setFalse(); - }, + } }); - const { data: cates } = useRequest(Hub.Gallery.Get.Categories.bind(Hub.Gallery.Get), { + const { data: cates } = useRequest(() => Hub.Gallery.Get.Categories(), { onSuccess(data) { setMatchCate(data); } diff --git a/src/Pages/Admin/Product/Combo/Delete.tsx b/src/Pages/Admin/Product/Combo/Delete.tsx index 94818c84..e161e3a4 100644 --- a/src/Pages/Admin/Product/Combo/Delete.tsx +++ b/src/Pages/Admin/Product/Combo/Delete.tsx @@ -1,27 +1,26 @@ import { Button, Toast, ToastTitle } from "@fluentui/react-components"; import { DeleteRegular } from "@fluentui/react-icons"; -import { useRequest } from "ahooks"; import { useErrorToast } from "~/Helpers/useToast"; import { AdminHub } from "~/ShopNet/Admin"; /** * @author Aloento * @since 0.5.0 - * @version 0.2.0 + * @version 0.2.1 */ export function AdminProductComboDelete({ ComboId, Refresh }: { ComboId: number; Refresh: () => void }) { const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Delete.Combo.bind(AdminHub.Product.Delete), { + const { run } = AdminHub.Product.Delete.useCombo({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Delete Combo", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Delete Combo", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Combo Deleted diff --git a/src/Pages/Admin/Product/Combo/Detail.tsx b/src/Pages/Admin/Product/Combo/Detail.tsx index dd065938..f0a509be 100644 --- a/src/Pages/Admin/Product/Combo/Detail.tsx +++ b/src/Pages/Admin/Product/Combo/Detail.tsx @@ -80,35 +80,33 @@ const useStyles = makeStyles({ */ export interface IDetailComboItem extends IComboItem { ProdId: number; - Refresh: (prodId: number) => void; + Refresh: () => void; } /** * @author Aloento * @since 0.5.0 - * @version 0.2.0 + * @version 0.2.1 */ export function AdminProductComboDetail({ Id, ProdId, Combo, Stock, Refresh }: IDetailComboItem) { const [open, { toggle }] = useBoolean(); const [combo, setCombo] = useState(Combo); const [stock, setStock] = useState(Stock); - const { data: varis } = useRequest(AdminHub.Product.Get.Variants.bind(AdminHub.Product.Get), { - defaultParams: [ProdId] - }); + const { data: varis } = useRequest(() => AdminHub.Product.Get.Variants(ProdId)); const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Patch.Combo.bind(AdminHub.Product.Patch), { + const { run } = AdminHub.Product.Patch.useCombo({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Update Combo", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Update Combo", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Combo Updated @@ -116,9 +114,9 @@ export function AdminProductComboDetail({ Id, ProdId, Combo, Stock, Refresh }: I { intent: "success" } ); - Refresh(ProdId); + Refresh(); toggle(); - }, + } }); return ( diff --git a/src/Pages/Admin/Product/Combo/New.tsx b/src/Pages/Admin/Product/Combo/New.tsx index 9a833f94..fa6ad8c3 100644 --- a/src/Pages/Admin/Product/Combo/New.tsx +++ b/src/Pages/Admin/Product/Combo/New.tsx @@ -70,15 +70,14 @@ const useStyles = makeStyles({ /** * @author Aloento * @since 0.5.0 - * @version 0.2.0 + * @version 0.2.1 */ -export function AdminProductNewCombo({ ProdId, Refresh }: { ProdId: number; Refresh: (prodId: number) => void }) { +export function AdminProductNewCombo({ ProdId, Refresh }: { ProdId: number; Refresh: () => void }) { const [open, { toggle }] = useBoolean(); const [combo, setCombo] = useState>({}); const [stock, setStock] = useState(1); - const { data: varis } = useRequest(AdminHub.Product.Get.Variants.bind(AdminHub.Product.Get), { - defaultParams: [ProdId], + const { data: varis } = useRequest(() => AdminHub.Product.Get.Variants(ProdId), { onSuccess(data) { for (const i of data) combo[i.Name] = ""; @@ -89,16 +88,16 @@ export function AdminProductNewCombo({ ProdId, Refresh }: { ProdId: number; Refr const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Post.Combo.bind(AdminHub.Product.Post), { + const { run } = AdminHub.Product.Post.useCombo({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Create Combo", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Create Combo", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Combo Created @@ -106,7 +105,7 @@ export function AdminProductNewCombo({ ProdId, Refresh }: { ProdId: number; Refr { intent: "success" } ); - Refresh(ProdId); + Refresh(); toggle(); }, }); diff --git a/src/Pages/Admin/Product/Combo/index.tsx b/src/Pages/Admin/Product/Combo/index.tsx index 801b2fa5..8f574057 100644 --- a/src/Pages/Admin/Product/Combo/index.tsx +++ b/src/Pages/Admin/Product/Combo/index.tsx @@ -105,7 +105,7 @@ const columns: TableColumnDefinition[] = [ - item.Refresh(item.ProdId)} /> + ) } @@ -118,9 +118,7 @@ const columns: TableColumnDefinition[] = [ * @version 0.2.0 */ export function AdminProductCombo({ ProdId }: { ProdId: number }) { - const { data, run } = useRequest(Hub.Product.Get.Combo.bind(Hub.Product.Get), { - defaultParams: [ProdId] - }); + const { data, run } = useRequest(() => Hub.Product.Get.Combo(ProdId)); return <>
diff --git a/src/Pages/Admin/Product/Delete.tsx b/src/Pages/Admin/Product/Delete.tsx index 32bc1f80..902c6b04 100644 --- a/src/Pages/Admin/Product/Delete.tsx +++ b/src/Pages/Admin/Product/Delete.tsx @@ -1,5 +1,4 @@ import { Button, Toast, ToastTitle } from "@fluentui/react-components"; -import { useRequest } from "ahooks"; import { useRouter } from "~/Components/Router"; import { useErrorToast } from "~/Helpers/useToast"; import { AdminHub } from "~/ShopNet/Admin"; @@ -7,22 +6,22 @@ import { AdminHub } from "~/ShopNet/Admin"; /** * @author Aloento * @since 1.0.0 - * @version 0.1.0 + * @version 0.1.1 */ export function AdminProductDelete({ ProdId }: { ProdId: number }) { const { Nav } = useRouter(); const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Delete.Product.bind(AdminHub.Product.Delete), { + const { run } = AdminHub.Product.Delete.useProduct({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Delete Product", - Request: req, - Error: e - }); - + onError(e, params) { + dispatch({ + Message: "Failed Delete Product", + Request: params, + Error: e + }); + }, + onSuccess() { dispatchToast( Product Deleted @@ -32,7 +31,7 @@ export function AdminProductDelete({ ProdId }: { ProdId: number }) { Nav("/Admin"); location.reload(); - }, + } }); return ( diff --git a/src/Pages/Admin/Product/Name.tsx b/src/Pages/Admin/Product/Name.tsx index ccf8d975..64453fd0 100644 --- a/src/Pages/Admin/Product/Name.tsx +++ b/src/Pages/Admin/Product/Name.tsx @@ -9,15 +9,14 @@ import { AdminHub } from "~/ShopNet/Admin"; /** * @author Aloento * @since 0.5.0 - * @version 0.1.0 + * @version 0.1.1 */ export function AdminProductName({ ProdId }: { ProdId: number; }) { const [name, setName] = useState(""); const [edit, { setTrue, setFalse }] = useBoolean(); const { Nav } = useRouter(); - useRequest(AdminHub.Product.Get.Name.bind(AdminHub.Product.Get), { - defaultParams: [ProdId], + useRequest(() => AdminHub.Product.Get.Name(ProdId), { onSuccess(data) { setName(data); }, @@ -29,16 +28,16 @@ export function AdminProductName({ ProdId }: { ProdId: number; }) { const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Patch.Name.bind(AdminHub.Product.Patch), { + const { run } = AdminHub.Product.Patch.useName({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Update Name", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Update Name", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Name Updated @@ -47,7 +46,7 @@ export function AdminProductName({ ProdId }: { ProdId: number; }) { ); setFalse(); - }, + } }); return ( diff --git a/src/Pages/Admin/Product/Photo/Edit.tsx b/src/Pages/Admin/Product/Photo/Edit.tsx index 7b7e3959..26bdf473 100644 --- a/src/Pages/Admin/Product/Photo/Edit.tsx +++ b/src/Pages/Admin/Product/Photo/Edit.tsx @@ -1,6 +1,5 @@ import { Button, Dialog, DialogBody, DialogContent, DialogSurface, DialogTitle, DialogTrigger, Field, Image, Input, Toast, ToastTitle, makeStyles, tokens } from "@fluentui/react-components"; import { DismissRegular, EditRegular } from "@fluentui/react-icons"; -import { useRequest } from "ahooks"; import { useState } from "react"; import { ColFlex, Cover, Flex } from "~/Helpers/Styles"; import { useErrorToast } from "~/Helpers/useToast"; @@ -32,7 +31,7 @@ const useStyles = makeStyles({ /** * @author Aloento * @since 0.5.0 - * @version 0.3.0 + * @version 0.3.1 */ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption }, Refresh }: { Photo: IPhotoItem; Refresh: () => void; }) { const style = useStyles(); @@ -40,16 +39,16 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption }, Refresh } const { dispatch, dispatchToast } = useErrorToast(); - const { run: updateCaption } = useRequest(AdminHub.Product.Patch.Caption.bind(AdminHub.Product.Patch), { + const { run: updateCaption } = AdminHub.Product.Patch.useCaption({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Update Caption", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Update Caption", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Caption Updated @@ -58,19 +57,19 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption }, Refresh } ); Refresh(); - }, + } }); - const { run: updateFile } = useRequest(AdminHub.Product.Patch.Photo.bind(AdminHub.Product.Patch), { + const { run: updateFile } = AdminHub.Product.Patch.usePhoto({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Update Photo", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Update Photo", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Photo Updated @@ -79,19 +78,19 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption }, Refresh } ); Refresh(); - }, + } }); - const { run: deletePhoto } = useRequest(AdminHub.Product.Delete.Photo.bind(AdminHub.Product.Delete), { + const { run: deletePhoto } = AdminHub.Product.Delete.usePhoto({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Delete Photo", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Delete Photo", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Photo Deleted @@ -100,7 +99,7 @@ export function AdminProductPhotoEdit({ Photo: { Id, Cover, Caption }, Refresh } ); Refresh(); - }, + } }); return ( diff --git a/src/Pages/Admin/Product/Photo/index.tsx b/src/Pages/Admin/Product/Photo/index.tsx index 36e6a19e..e93fec40 100644 --- a/src/Pages/Admin/Product/Photo/index.tsx +++ b/src/Pages/Admin/Product/Photo/index.tsx @@ -40,7 +40,7 @@ export interface IPhotoItem { /** * @author Aloento * @since 0.5.0 - * @version 0.1.0 + * @version 0.1.1 */ const columns: TableColumnDefinition[] = [ MakeCoverCol(70), @@ -65,18 +65,16 @@ const columns: TableColumnDefinition[] = [ renderCell(item) { const { dispatch } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Post.MovePhoto.bind(AdminHub.Product.Post), { + const { run } = AdminHub.Product.Post.useMovePhoto({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Update Order", - Request: req, - Error: e - }); - - refreshCarousel(); + onError(e, params) { + dispatch({ + Message: "Failed Update Order", + Request: params, + Error: e + }); }, + onSuccess: refreshCarousel }); return ( @@ -110,27 +108,24 @@ let refreshCarousel: () => void; /** * @author Aloento * @since 0.5.0 - * @version 0.3.0 + * @version 0.3.1 */ export function AdminProductPhoto({ ProdId }: { ProdId: number }) { - const { data, run } = useRequest(Hub.Product.Get.Carousel.bind(Hub.Product.Get), { - defaultParams: [ProdId] - }); - - refreshCarousel = () => run(ProdId); + const { data, run } = useRequest(() => Hub.Product.Get.Carousel(ProdId)); + refreshCarousel = run; const { dispatch, dispatchToast } = useErrorToast(); - const { run: newPhoto } = useRequest(AdminHub.Product.Post.Photo.bind(AdminHub.Product.Post), { + const { run: newPhoto } = AdminHub.Product.Post.usePhoto({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Upload Photo", - Request: req, - Error: e - }); - + onError(e, params) { + dispatch({ + Message: "Failed Upload Photo", + Request: params, + Error: e + }); + }, + onSuccess() { dispatchToast( Photo Uploaded @@ -139,7 +134,7 @@ export function AdminProductPhoto({ ProdId }: { ProdId: number }) { ); refreshCarousel(); - }, + } }); return <> diff --git a/src/Pages/Admin/Product/Variant/Delete.tsx b/src/Pages/Admin/Product/Variant/Delete.tsx index 4d162e0c..a3be46ea 100644 --- a/src/Pages/Admin/Product/Variant/Delete.tsx +++ b/src/Pages/Admin/Product/Variant/Delete.tsx @@ -1,27 +1,26 @@ import { Button, Toast, ToastTitle } from "@fluentui/react-components"; import { DeleteRegular } from "@fluentui/react-icons"; -import { useRequest } from "ahooks"; import { useErrorToast } from "~/Helpers/useToast"; import { AdminHub } from "~/ShopNet/Admin"; /** * @author Aloento * @since 0.5.0 - * @version 0.1.0 + * @version 0.1.1 */ export function AdminProductVariantDelete({ VariantId, Refresh }: { VariantId: number; Refresh: () => void }) { const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Delete.Variant.bind(AdminHub.Product.Delete), { + const { run } = AdminHub.Product.Delete.useVariant({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Delete Variant", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Delete Variant", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Variant Deleted @@ -30,7 +29,7 @@ export function AdminProductVariantDelete({ VariantId, Refresh }: { VariantId: n ); Refresh(); - }, + } }); return ( diff --git a/src/Pages/Admin/Product/Variant/Edit/Delete.tsx b/src/Pages/Admin/Product/Variant/Edit/Delete.tsx index 4b3721c7..34722ee9 100644 --- a/src/Pages/Admin/Product/Variant/Edit/Delete.tsx +++ b/src/Pages/Admin/Product/Variant/Edit/Delete.tsx @@ -1,27 +1,26 @@ import { Button, Toast, ToastTitle } from "@fluentui/react-components"; import { DeleteRegular } from "@fluentui/react-icons"; -import { useRequest } from "ahooks"; import { useErrorToast } from "~/Helpers/useToast"; import { AdminHub } from "~/ShopNet/Admin"; /** * @author Aloento * @since 0.5.0 - * @version 0.1.0 + * @version 0.1.1 */ export function AdminProductTypeDelete({ VariantId, Type, Refresh }: { VariantId: number; Type: string; Refresh: () => void }) { const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Delete.Type.bind(AdminHub.Product.Delete), { + const { run } = AdminHub.Product.Delete.useType({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Delete Type", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Delete Type", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Type Deleted @@ -30,7 +29,7 @@ export function AdminProductTypeDelete({ VariantId, Type, Refresh }: { VariantId ); Refresh(); - }, + } }); return ( diff --git a/src/Pages/Admin/Product/Variant/Edit/Name.tsx b/src/Pages/Admin/Product/Variant/Edit/Name.tsx index 6595904c..0eaa880c 100644 --- a/src/Pages/Admin/Product/Variant/Edit/Name.tsx +++ b/src/Pages/Admin/Product/Variant/Edit/Name.tsx @@ -1,6 +1,6 @@ import { Button, Input, Subtitle2, Toast, ToastTitle } from "@fluentui/react-components"; import { EditRegular, SendRegular } from "@fluentui/react-icons"; -import { useBoolean, useRequest } from "ahooks"; +import { useBoolean } from "ahooks"; import { useState } from "react"; import { useErrorToast } from "~/Helpers/useToast"; import { AdminHub } from "~/ShopNet/Admin"; @@ -8,23 +8,23 @@ import { AdminHub } from "~/ShopNet/Admin"; /** * @author Aloento * @since 0.5.0 - * @version 0.1.0 + * @version 0.1.1 */ export function AdminProductVariantName({ Id, Name }: { Id: number; Name: string; }) { const [name, setName] = useState(Name); const [edit, { setTrue, setFalse }] = useBoolean(); const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Patch.VariantName.bind(AdminHub.Product.Patch), { + const { run } = AdminHub.Product.Patch.useVariantName({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Update Variant Name", - Request: req, - Error: e - }); - + onError(e, params) { + dispatch({ + Message: "Failed Update Variant Name", + Request: params[0], + Error: e + }); + }, + onSuccess() { dispatchToast( Variant Name Updated @@ -33,7 +33,7 @@ export function AdminProductVariantName({ Id, Name }: { Id: number; Name: string ); setFalse(); - }, + } }); return ( diff --git a/src/Pages/Admin/Product/Variant/Edit/Type.tsx b/src/Pages/Admin/Product/Variant/Edit/Type.tsx index 7cb6654d..546cbd63 100644 --- a/src/Pages/Admin/Product/Variant/Edit/Type.tsx +++ b/src/Pages/Admin/Product/Variant/Edit/Type.tsx @@ -1,6 +1,7 @@ import { Button, Field, Input, Popover, PopoverSurface, PopoverTrigger, Toast, ToastBody, ToastTitle, makeStyles, tokens } from "@fluentui/react-components"; import { AddRegular, EditRegular } from "@fluentui/react-icons"; -import { useBoolean, useRequest } from "ahooks"; +import { useBoolean } from "ahooks"; +import { Options } from "ahooks/lib/useRequest/src/types"; import { useState } from "react"; import { ColFlex } from "~/Helpers/Styles"; import { useErrorToast } from "~/Helpers/useToast"; @@ -21,7 +22,7 @@ const useStyles = makeStyles({ /** * @author Aloento * @since 0.5.0 - * @version 0.2.0 + * @version 0.2.1 */ export function AdminProductType({ VariantId, Type, Refresh, New }: { VariantId: number; Type?: string; Refresh: () => void; New?: true }) { const style = useStyles(); @@ -30,20 +31,20 @@ export function AdminProductType({ VariantId, Type, Refresh, New }: { VariantId: const { dispatch, dispatchToast } = useErrorToast(); - const options = { + const options: Options = { manual: true, - onFinally(req: any[], res?: number | boolean, e?: Error) { - if (e) - return dispatch({ - Message: `Failed ${New ? "Create" : "Update"} Type ${res} ${name}`, - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: `Failed ${New ? "Create" : "Update"} Type ${name}`, + Request: req, + Error: e + }); + }, + onSuccess(data) { dispatchToast( Type {New ? "Created" : "Updated"} - {res} {name} + {data} {name} , { intent: "success" } ); @@ -54,9 +55,9 @@ export function AdminProductType({ VariantId, Type, Refresh, New }: { VariantId: } } - const { run: post } = useRequest(AdminHub.Product.Post.Type.bind(AdminHub.Product.Post), options); + const { run: post } = AdminHub.Product.Post.useType(options); - const { run: patch } = useRequest(AdminHub.Product.Patch.Type.bind(AdminHub.Product.Patch), options); + const { run: patch } = AdminHub.Product.Patch.useType(options); return ( diff --git a/src/Pages/Admin/Product/Variant/New.tsx b/src/Pages/Admin/Product/Variant/New.tsx index dd5b60d3..3152dfd4 100644 --- a/src/Pages/Admin/Product/Variant/New.tsx +++ b/src/Pages/Admin/Product/Variant/New.tsx @@ -1,6 +1,6 @@ import { Button, Field, Input, Popover, PopoverSurface, PopoverTrigger, Toast, ToastTitle, makeStyles, tokens } from "@fluentui/react-components"; import { AddRegular } from "@fluentui/react-icons"; -import { useBoolean, useRequest } from "ahooks"; +import { useBoolean } from "ahooks"; import { useState } from "react"; import { ColFlex } from "~/Helpers/Styles"; import { useErrorToast } from "~/Helpers/useToast"; @@ -21,25 +21,25 @@ const useStyles = makeStyles({ /** * @author Aloento * @since 0.5.0 - * @version 0.1.1 + * @version 0.1.2 */ -export function AdminProductNewVariant({ ProdId, Refresh }: { ProdId: number; Refresh: (prodId: number) => void }) { +export function AdminProductNewVariant({ ProdId, Refresh }: { ProdId: number; Refresh: () => void }) { const style = useStyles(); const [open, { toggle }] = useBoolean(); const [name, setName] = useState(""); const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.Product.Post.Variant.bind(AdminHub.Product.Post), { + const { run } = AdminHub.Product.Post.useVariant({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Create Variant", - Request: req, - Error: e - }); - + onError(e, params) { + dispatch({ + Message: "Failed Create Variant", + Request: params, + Error: e + }); + }, + onSuccess() { dispatchToast( Variant Created @@ -47,10 +47,10 @@ export function AdminProductNewVariant({ ProdId, Refresh }: { ProdId: number; Re { intent: "success" } ); - Refresh(ProdId); + Refresh(); setName(""); toggle(); - }, + } }); return ( diff --git a/src/Pages/Admin/Product/Variant/index.tsx b/src/Pages/Admin/Product/Variant/index.tsx index 15b57d09..e6ddd0b6 100644 --- a/src/Pages/Admin/Product/Variant/index.tsx +++ b/src/Pages/Admin/Product/Variant/index.tsx @@ -135,11 +135,8 @@ let refreshVariant: () => void; export function AdminProductVariant({ ProdId }: { ProdId: number }) { const style = useStyles(); - const { data, run } = useRequest(AdminHub.Product.Get.Variants.bind(AdminHub.Product.Get), { - defaultParams: [ProdId] - }); - - refreshVariant = () => run(ProdId); + const { data, run } = useRequest(() => AdminHub.Product.Get.Variants(ProdId)); + refreshVariant = run; return <>
diff --git a/src/Pages/Admin/Product/index.tsx b/src/Pages/Admin/Product/index.tsx index a6e4eab2..7ce7f2ac 100644 --- a/src/Pages/Admin/Product/index.tsx +++ b/src/Pages/Admin/Product/index.tsx @@ -122,7 +122,7 @@ const columns: TableColumnDefinition[] = [ * @version 0.1.1 */ export function AdminProduct() { - const { data } = useRequest(AdminHub.Product.Get.List.bind(AdminHub.Product.Get)); + const { data } = useRequest(() => AdminHub.Product.Get.List()); return ( diff --git a/src/Pages/Admin/User/Admin.tsx b/src/Pages/Admin/User/Admin.tsx index 67099b6e..5377985f 100644 --- a/src/Pages/Admin/User/Admin.tsx +++ b/src/Pages/Admin/User/Admin.tsx @@ -1,26 +1,25 @@ import { Checkbox, Toast, ToastTitle } from "@fluentui/react-components"; -import { useRequest } from "ahooks"; import { useErrorToast } from "~/Helpers/useToast"; import { AdminHub } from "~/ShopNet/Admin"; /** * @author Aloento * @since 0.5.0 - * @version 0.1.0 + * @version 0.1.1 */ export function AdminUserAdmin({ UserId, Admin, Refresh }: { UserId: string; Admin?: boolean; Refresh: () => void }) { const { dispatch, dispatchToast } = useErrorToast(); - const { run: grant } = useRequest(AdminHub.User.Post.Admin.bind(AdminHub.User.Post), { + const { run: grant } = AdminHub.User.Post.useAdmin({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Grant Admin", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Grant Admin", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Admin Granted @@ -29,19 +28,19 @@ export function AdminUserAdmin({ UserId, Admin, Refresh }: { UserId: string; Adm ); Refresh(); - }, + } }); - const { run: revoke } = useRequest(AdminHub.User.Delete.Admin.bind(AdminHub.User.Delete), { + const { run: revoke } = AdminHub.User.Delete.useAdmin({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Revoke Admin", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Revoke Admin", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Admin Revoked @@ -50,7 +49,7 @@ export function AdminUserAdmin({ UserId, Admin, Refresh }: { UserId: string; Adm ); Refresh(); - }, + } }); return ( diff --git a/src/Pages/Admin/User/Delete.tsx b/src/Pages/Admin/User/Delete.tsx index 8c3119c3..a9db3c0c 100644 --- a/src/Pages/Admin/User/Delete.tsx +++ b/src/Pages/Admin/User/Delete.tsx @@ -1,27 +1,26 @@ import { Button, Toast, ToastTitle } from "@fluentui/react-components"; import { DeleteRegular } from "@fluentui/react-icons"; -import { useRequest } from "ahooks"; import { useErrorToast } from "~/Helpers/useToast"; import { AdminHub } from "~/ShopNet/Admin"; /** * @author Aloento * @since 0.5.0 - * @version 0.1.0 + * @version 0.1.1 */ export function AdminUserDelete({ UserId, Refresh }: { UserId: string; Refresh: () => void }) { const { dispatch, dispatchToast } = useErrorToast(); - const { run } = useRequest(AdminHub.User.Delete.User.bind(AdminHub.User.Delete), { + const { run } = AdminHub.User.Delete.useUser({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Delete User", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Delete User", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( User Deleted @@ -30,7 +29,7 @@ export function AdminUserDelete({ UserId, Refresh }: { UserId: string; Refresh: ); Refresh(); - }, + } }); return ( diff --git a/src/Pages/Admin/User/index.tsx b/src/Pages/Admin/User/index.tsx index 260c9be0..905ae92e 100644 --- a/src/Pages/Admin/User/index.tsx +++ b/src/Pages/Admin/User/index.tsx @@ -83,8 +83,7 @@ let refreshUser: () => void; * @version 0.2.0 */ export function AdminUser() { - const { data, run } = useRequest(AdminHub.User.Get.List.bind(AdminHub.User.Get)); - + const { data, run } = useRequest(() => AdminHub.User.Get.List()); refreshUser = run; return ( diff --git a/src/Pages/Gallery.tsx b/src/Pages/Gallery.tsx index f3019136..c5191bc2 100644 --- a/src/Pages/Gallery.tsx +++ b/src/Pages/Gallery.tsx @@ -47,11 +47,11 @@ export interface IProductInfo { /** * @author Aloento * @since 0.1.0 - * @version 0.1.1 + * @version 0.1.2 */ export function Gallery() { const style = useStyles(); - const { data } = useRequest(Hub.Gallery.Get.Categories.bind(Hub.Gallery.Get)); + const { data } = useRequest(() => Hub.Gallery.Get.Categories()); return (
@@ -65,13 +65,11 @@ export function Gallery() { /** * @author Aloento * @since 0.5.0 - * @version 0.1.1 + * @version 0.1.2 */ function GalleryCategory({ Category }: { Category: string }) { const style = useStyles(); - const { data } = useRequest(Hub.Gallery.Get.Products.bind(Hub.Gallery.Get), { - defaultParams: [Category] - }); + const { data } = useRequest(() => Hub.Gallery.Get.Products(Category)); const list = data || [[], 0]; return <> @@ -92,13 +90,11 @@ function GalleryCategory({ Category }: { Category: string }) { /** * @author Aloento * @since 0.5.0 - * @version 0.1.1 + * @version 0.1.2 */ function GalleryCard({ Id }: { Id: number }) { const style = useStyles(); - const { data } = useRequest(Hub.Product.Get.Basic.bind(Hub.Product.Get), { - defaultParams: [Id] - }) + const { data } = useRequest(() => Hub.Product.Get.Basic(Id)); return ( diff --git a/src/Pages/History/Append.tsx b/src/Pages/History/Append.tsx index c2761f8b..a5bc21b4 100644 --- a/src/Pages/History/Append.tsx +++ b/src/Pages/History/Append.tsx @@ -1,5 +1,4 @@ import { Button, Field, Textarea, Toast, ToastTitle, makeStyles } from "@fluentui/react-components"; -import { useRequest } from "ahooks"; import { useState } from "react"; import { Flex } from "~/Helpers/Styles"; import { useErrorToast } from "~/Helpers/useToast"; @@ -22,22 +21,22 @@ const useStyles = makeStyles({ * @since 0.5.0 * @version 0.2.1 */ -export function OrderAppend({ OrderId, Refresh }: { OrderId: number; Refresh: (id: number) => void }) { +export function OrderAppend({ OrderId, Refresh }: { OrderId: number; Refresh: () => void }) { const style = useStyles(); const [cmt, setCmt] = useState(); const { dispatch, dispatchToast } = useErrorToast(); - const { run: append } = useRequest(Hub.Order.Post.Append.bind(Hub.Order.Post), { + const { run: append } = Hub.Order.Post.useAppend({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Append Comment", - Request: req, - Error: e - }); - + onError(e, req) { + dispatch({ + Message: "Failed Append Comment", + Request: req, + Error: e + }); + }, + onSuccess() { dispatchToast( Comment Appended @@ -45,20 +44,20 @@ export function OrderAppend({ OrderId, Refresh }: { OrderId: number; Refresh: (i { intent: "success" } ); - Refresh(OrderId); - }, + Refresh(); + } }); - const { run: cancel } = useRequest(Hub.Order.Post.Cancel.bind(Hub.Order.Post), { + const { run: cancel } = Hub.Order.Post.useCancel({ manual: true, - onFinally(req, _, e) { - if (e) - return dispatch({ - Message: "Failed Cancel", - Request: req, - Error: e - }); - + onError(e, params) { + dispatch({ + Message: "Failed Cancel Order", + Request: params, + Error: e + }); + }, + onSuccess() { dispatchToast( Order Canceled @@ -66,8 +65,8 @@ export function OrderAppend({ OrderId, Refresh }: { OrderId: number; Refresh: (i { intent: "success" } ); - Refresh(OrderId); - }, + Refresh(); + } }); return <> diff --git a/src/Pages/History/Detail.tsx b/src/Pages/History/Detail.tsx index 6a1cd368..ff4d1fb7 100644 --- a/src/Pages/History/Detail.tsx +++ b/src/Pages/History/Detail.tsx @@ -93,7 +93,7 @@ export function OrderDetail({ OrderId }: { OrderId: number }) { const { Nav, Paths } = useRouter(); const [open, { toggle, setTrue }] = useBoolean(); - const { data, run } = useRequest(Hub.Order.Get.Detail.bind(Hub.Order.Get), { + const { data, run } = useRequest(() => Hub.Order.Get.Detail(OrderId), { onError(e) { Nav("History"); console.error(e); @@ -103,7 +103,7 @@ export function OrderDetail({ OrderId }: { OrderId: number }) { useMount(() => { if (parseInt(Paths.at(1)!) === OrderId) { - run(OrderId); + run(); setTrue(); } }); @@ -111,7 +111,7 @@ export function OrderDetail({ OrderId }: { OrderId: number }) { return <>