diff --git a/src/app/api/auth/login/route.ts b/src/app/api/auth/login/route.ts index a51a83c..7dbe591 100644 --- a/src/app/api/auth/login/route.ts +++ b/src/app/api/auth/login/route.ts @@ -23,7 +23,7 @@ const routeHandler = async (req: NextRequest) => { }, }); - const { token } = JSON.parse(oriyoResponse.data); + const { token, card_id } = JSON.parse(oriyoResponse.data); if (!token) { return NextResponse.json({ error: 'Credentials error' }, { status: 401 }); @@ -31,10 +31,14 @@ const routeHandler = async (req: NextRequest) => { const response = NextResponse.json({ success: true }); - response.cookies.set(`${validatedBody.type}__token`, token, { - path: '/', - maxAge: 2 * 60 * 60, - }); + response.cookies.set( + `${validatedBody.type}__token`, + JSON.stringify({ token, card_id }), + { + path: '/', + maxAge: 2 * 60 * 60, + }, + ); return response; } catch (error) { diff --git a/src/app/api/bonus/info/route.ts b/src/app/api/bonus/info/route.ts new file mode 100644 index 0000000..efb8011 --- /dev/null +++ b/src/app/api/bonus/info/route.ts @@ -0,0 +1,31 @@ +import { NextRequest, NextResponse } from 'next/server'; + +import oriyoClient from '@/app/api-utlities/utilities/oriyo.client'; + +import { validationErrorHandler } from '../../middlewares/error-handler.middleware'; + +export const routeHandler = async (req: NextRequest) => { + const bonusTokenData = req.cookies.get('bonus__token'); + + if (!bonusTokenData) { + return NextResponse.json( + { error: 'User does not have access' }, + { status: 401 }, + ); + } + + const { card_id, token } = JSON.parse(bonusTokenData.value); + + const oriyoResponse = await oriyoClient.get('/client/info', { + params: { + card_id, + token, + }, + }); + + return new Response(oriyoResponse.data, { + headers: { 'Content-Type': 'application/json' }, + }); +}; + +export const GET = validationErrorHandler(routeHandler); diff --git a/src/entities/bonus/api/bonus.api.ts b/src/entities/bonus/api/bonus.api.ts new file mode 100644 index 0000000..b8d31bf --- /dev/null +++ b/src/entities/bonus/api/bonus.api.ts @@ -0,0 +1,17 @@ +import { baseAPI } from '@/shared/api/base-api'; + +import { ClientInfo } from '../model/types/bonus-client-info.type'; + +export const bonusApi = baseAPI.injectEndpoints({ + endpoints: (builder) => ({ + fetchMyBonusInfo: builder.query({ + query: () => { + return { + url: '/bonus/info', + }; + }, + }), + }), +}); + +export const { useFetchMyBonusInfoQuery } = bonusApi; diff --git a/src/entities/bonus/model/types/bonus-client-info.type.ts b/src/entities/bonus/model/types/bonus-client-info.type.ts new file mode 100644 index 0000000..dd7138f --- /dev/null +++ b/src/entities/bonus/model/types/bonus-client-info.type.ts @@ -0,0 +1,8 @@ +export interface ClientInfo { + card_id: number; + fullname: string; + cardno: string; + reg_date: string; + end_date: string; + bonuses: string; +} diff --git a/src/pages-templates/(dashboard)/customer-dashboard/index.tsx b/src/pages-templates/(dashboard)/customer-dashboard/index.tsx index d4181a1..2e0a319 100644 --- a/src/pages-templates/(dashboard)/customer-dashboard/index.tsx +++ b/src/pages-templates/(dashboard)/customer-dashboard/index.tsx @@ -2,6 +2,8 @@ import { ArrowUpRight, Clock, CreditCard, LogOut, User } from 'lucide-react'; +import { useFetchMyBonusInfoQuery } from '@/entities/bonus/api/bonus.api'; + import { useTextController } from '@/shared/language/hooks/use-text-controller'; import { Button } from '@/shared/shadcn-ui/button'; import { @@ -14,20 +16,11 @@ import { import { TransactionsTable } from '@/widgets/transactions-table'; -// Sample customer data -const customerData = { - firstName: 'Алишер', - lastName: 'Рахмонов', - passportNumber: 'A12345678', - bonusPoints: 1250, - cardNumber: '5678-9012-3456-7890', - expiryDate: '12/2025', - registrationDate: '15.06.2020', -}; - export function CustomerDashboard() { const { t } = useTextController(); + const { data, isLoading } = useFetchMyBonusInfoQuery({}); + return (
@@ -41,35 +34,44 @@ export function CustomerDashboard() {
- {/* Bonus Card */} - - - - {t('customer.bonusCard.title')} - - - {t('customer.bonusCard.description')} - - - -
-

- {customerData.bonusPoints} -

-

- {t('customer.bonusCard.points')} -

-
-
-
- - {t('customer.bonusCard.validUntil')} -
- -
-
+ {!data || isLoading ? ( + // TODO: Bunyod please add loader here + <>Loader here + ) : ( + <> + + + + {t('customer.bonusCard.title')} + + + {t('customer.bonusCard.description')} + + + +
+

{data.bonuses}

+

+ {t('customer.bonusCard.points')} +

+
+
+
+ + + {t('customer.bonusCard.validUntil')}{' '} + {new Date(data.end_date).toLocaleDateString('en-GB')} + +
+ +
+
+ + )}
+ + {/* Bonus Card */} {/* Customer Card */} @@ -79,40 +81,37 @@ export function CustomerDashboard() { -
-
-
-

- {t('customer.infoCard.regDateLabel')} -

-

- {customerData.firstName} {customerData.lastName} -

+ {!data || isLoading ? ( + // TODO: Bunyod please add loader here + <>Loader here + ) : ( +
+
+
+

+ {t('customer.infoCard.regDateLabel')} +

+

{data.fullname}

+
+
+

+ {t('customer.infoCard.regDateLabel')} +

+

+ {new Date(data.reg_date).toLocaleDateString('en-GB')} +

+
-
-

- {t('customer.infoCard.regDateLabel')} -

-

- {customerData.registrationDate} -

+
+
+

+ {t('customer.infoCard.cardNumberLabel')} +

+

{data.cardno}

+
-
-
-

- {t('customer.infoCard.cardNumberLabel')} -

-

{customerData.cardNumber}

-
-
-

- {t('customer.infoCard.expiryDateLabel')} -

-

{customerData.expiryDate}

-
-
-
+ )}