From 189a5450841e01983aacfceb1c084ec78f8043b4 Mon Sep 17 00:00:00 2001 From: wayanrivan Date: Tue, 20 May 2025 13:53:52 +0700 Subject: [PATCH] update page dashboard conditional for cards bank and transaction detail --- src/auth/_models.ts | 1 + src/auth/providers/JWTProvider.tsx | 59 +++-- .../dashboards/home/DashboardHomePage.tsx | 2 +- .../blocks/DetailTransaction.tsx | 210 ++++++++++-------- 4 files changed, 152 insertions(+), 120 deletions(-) diff --git a/src/auth/_models.ts b/src/auth/_models.ts index a580966..8bf87ed 100644 --- a/src/auth/_models.ts +++ b/src/auth/_models.ts @@ -9,6 +9,7 @@ export interface AuthModel { company: any; user: any; // api_token: string; + statusbalance: string; } export interface UserModel { diff --git a/src/auth/providers/JWTProvider.tsx b/src/auth/providers/JWTProvider.tsx index 934d228..ec33b0d 100644 --- a/src/auth/providers/JWTProvider.tsx +++ b/src/auth/providers/JWTProvider.tsx @@ -43,24 +43,6 @@ const AuthProvider = ({ children }: PropsWithChildren) => { const [auth, setAuth] = useState(authHelper.getAuth()); const [currentUser, setCurrentUser] = useState(); - const verify = async () => { - if (auth) { - try { - const { data: user } = await getUser(); - const createCacheUser = { - name: user.name, - email: user.email, - username: user.username, - role_name: auth.role_name - }; - localStorage.setItem('user', JSON.stringify(createCacheUser)); - } catch { - saveAuth(undefined); - setCurrentUser(undefined); - } - } - }; - const saveAuth = (auth: AuthModel | undefined) => { setAuth(auth); if (auth) { @@ -73,11 +55,20 @@ const AuthProvider = ({ children }: PropsWithChildren) => { const login = async (username: string, password: string) => { try { const { data: auth } = await axios - .post(LOGIN_URL, { username, password }) // , { headers: { 'Access-Control-Allow-Origin': "*" }} + .post(LOGIN_URL, { username, password }) .then((response) => response.data); - saveAuth({ ...auth.token, id: auth.user.id, role_name: auth.role_name, user: auth.user }); + const enhancedAuth: AuthModel = { + ...auth.token, + id: auth.user.id, + role_name: auth.role_name, + user: auth.user, + statusbalance: auth.role.status_balance + }; + + saveAuth(enhancedAuth); setCurrentUser(auth.user); + const createActivity = { module: 'Login', description: `Login`, @@ -108,6 +99,33 @@ const AuthProvider = ({ children }: PropsWithChildren) => { return { data: _axios }; }; + const verify = async () => { + if (auth) { + try { + const { data: user } = await getUser(); + + // Perbarui auth yang sekarang dengan statusbalance + saveAuth({ + ...auth, + statusbalance: user.role.status_balance + }); + + const createCacheUser = { + name: user.name, + email: user.email, + username: user.username, + role_name: auth.role_name, + statusbalance: user.role.status_balance + }; + + localStorage.setItem('user', JSON.stringify(createCacheUser)); + } catch { + saveAuth(undefined); + setCurrentUser(undefined); + } + } + }; + const logout = async () => { const createActivity = { module: 'Logout', @@ -130,7 +148,6 @@ const AuthProvider = ({ children }: PropsWithChildren) => { currentUser, setCurrentUser, login, - // register, requestPasswordResetLink, changePassword, getUser, diff --git a/src/pages/dashboards/home/DashboardHomePage.tsx b/src/pages/dashboards/home/DashboardHomePage.tsx index 0353ee8..a42faee 100644 --- a/src/pages/dashboards/home/DashboardHomePage.tsx +++ b/src/pages/dashboards/home/DashboardHomePage.tsx @@ -268,7 +268,7 @@ const DashboardHomePage = () => { ) : null}
- {bankaccount?.data && bankaccount?.data.length > 0 ? ( + {bankaccount?.data && bankaccount?.data.length > 0 && getAuth()?.statusbalance=='Y' ? ( bankaccount?.data.map((bankaccountdatas: { amount: string, creditlimit: string, monthlylimit: string; wallet: string; }, index: number) => ( { {/* )} */} + {transactionDetails?.kind == 'P' && ( + + )} + + {transactionDetails?.kind == 'P' && ( + + )} +
- {/* Tab Content */} + {activeTab === 'purchase' && ( + <> +

+ Purchase +

+
+
+

Amount

+

+ {new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format( + transactionDetails?.purchase?.amount ?? transactionDetails?.transfer?.amount ?? 0 + )} +

+
+
+

Cashback

+

+ {new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format( + transactionDetails?.purchase?.cashback ?? transactionDetails?.transfer?.cashback ?? 0 + )} +

+
+
+

Cashback Point

+

+ {transactionDetails?.purchase?.cashback_point ?? transactionDetails?.transfer?.cashback_point ?? 0} +

+
+
+

Fee Amount

+

+ {new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format( + transactionDetails?.purchase?.fee_amount ?? transactionDetails?.transfer?.fee_amount ?? 0 + )} +

+
+
+ + )} + + {activeTab === 'productdetail' && ( + <> +
+

+ Product Information +

+
+
+

Product Name

+

+ {transactionDetails?.purchase?.product?.name ?? "-"} +

+
+
+

Price Cash

+

+ {transactionDetails?.purchase?.product?.price_cash != null + ? new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(transactionDetails.purchase.product.price_cash) + : "-"} +

+
+
+

Price Point

+

+ {transactionDetails?.purchase?.product?.price_point ?? "-"} +

+
+
+

Product Type

+

+ {transactionDetails?.purchase?.product?.type ?? "-"} +

+
+
+

Provider Name

+

+ {transactionDetails?.purchase?.product?.provider?.description ?? "-"} +

+
+
+

Provider Type

+

+ {transactionDetails?.purchase?.product?.provider?.type === "h2h" + ? "HOST TO HOST" + : transactionDetails?.purchase?.product?.provider?.type === "agent" + ? "AGENT" + : "-"} +

+
+
+
+ + )} +
{activeTab === 'detail' && transactionDetails?.kind === 'P' && (

Transaction Information - - Info -

@@ -363,100 +471,6 @@ const DetailTransaction = () => {
-

- Purchase - - Purchase - -

-
-
-

Amount

-

- {new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format( - transactionDetails?.purchase?.amount ?? transactionDetails?.transfer?.amount ?? 0 - )} -

-
-
-

Cashback

-

- {new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format( - transactionDetails?.purchase?.cashback ?? transactionDetails?.transfer?.cashback ?? 0 - )} -

-
-
-

Cashback Point

-

- {transactionDetails?.purchase?.cashback_point ?? transactionDetails?.transfer?.cashback_point ?? 0} -

-
-
-

Fee Amount

-

- {new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format( - transactionDetails?.purchase?.fee_amount ?? transactionDetails?.transfer?.fee_amount ?? 0 - )} -

-
-
-
- )} - - - {activeTab === 'detail' && transactionDetails?.kind == 'P' && transactionDetails?.kind == 'P' && ( -
-

- Product Information - - Product Info - -

-
-
-

Product Name

-

- {transactionDetails?.purchase?.product?.name ?? "-"} -

-
-
-

Price Cash

-

- {transactionDetails?.purchase?.product?.price_cash != null - ? new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }).format(transactionDetails.purchase.product.price_cash) - : "-"} -

-
-
-

Price Point

-

- {transactionDetails?.purchase?.product?.price_point ?? "-"} -

-
-
-

Product Type

-

- {transactionDetails?.purchase?.product?.type ?? "-"} -

-
-
-

Provider Name

-

- {transactionDetails?.purchase?.product?.provider?.description ?? "-"} -

-
-
-

Provider Type

-

- {transactionDetails?.purchase?.product?.provider?.type === "h2h" - ? "HOST TO HOST" - : transactionDetails?.purchase?.product?.provider?.type === "agent" - ? "AGENT" - : "-"} -

-
-
)}