customer club + convert score to wallet
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
@@ -5,8 +5,22 @@ export interface ServiceArea {
|
||||
coordinates: number[][][];
|
||||
}
|
||||
|
||||
export interface Score {
|
||||
scoreAmount: string;
|
||||
scoreCredit: string;
|
||||
birthdayScore: string;
|
||||
purchaseScore: string;
|
||||
referrerScore: string;
|
||||
registerScore: string;
|
||||
purchaseAmount: string;
|
||||
marriageDateScore: string;
|
||||
}
|
||||
|
||||
export interface Restaurant {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
deletedAt: string | null;
|
||||
name: string;
|
||||
slug: string;
|
||||
logo: string | null;
|
||||
@@ -15,6 +29,7 @@ export interface Restaurant {
|
||||
latitude: number | null;
|
||||
longitude: number | null;
|
||||
serviceArea: ServiceArea;
|
||||
isActive: boolean;
|
||||
establishedYear: number | null;
|
||||
phoneNumber: string | null;
|
||||
phone: string;
|
||||
@@ -27,6 +42,8 @@ export interface Restaurant {
|
||||
tagNames: string[] | null;
|
||||
images: string[] | null;
|
||||
vat: number;
|
||||
domain: string;
|
||||
score: Score;
|
||||
}
|
||||
|
||||
export interface ReviewFood {
|
||||
|
||||
@@ -1,19 +1,41 @@
|
||||
'use client';
|
||||
import { ef } from '@/lib/helpers/utfNumbers'
|
||||
import { Cup, Star1 } from 'iconsax-react'
|
||||
import { Cup, Star1, MoneyRecive } from 'iconsax-react'
|
||||
import React from 'react'
|
||||
import { useGetUserWallet } from '../../hooks/useTransactionData';
|
||||
import { useConvertScoreToWallet, useGetUserWallet } from '../../hooks/useTransactionData';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useGetAbout } from '../../../about/hooks/useAboutData';
|
||||
import { toast } from '@/components/Toast';
|
||||
import { extractErrorMessage } from '@/lib/func';
|
||||
|
||||
function TransactionsIndex() {
|
||||
|
||||
const { data: userWallet } = useGetUserWallet();
|
||||
const { data: aboutData } = useGetAbout();
|
||||
const { mutate: convertScoreToWallet, isPending: isConverting } = useConvertScoreToWallet();
|
||||
const userPoints = userWallet?.data?.points ?? 0;
|
||||
const userWalletAmount = userWallet?.data?.wallet ?? 0;
|
||||
const conversionRate = Number(aboutData?.data?.score?.purchaseScore ?? 1000);
|
||||
const calculatedAmount = Math.floor(userPoints / conversionRate) * Number(aboutData?.data?.score?.purchaseAmount ?? 1);
|
||||
|
||||
const handleConvert = async () => {
|
||||
convertScoreToWallet(undefined, {
|
||||
onSuccess: () => {
|
||||
toast('تبدیل امتیاز به اعتبار با موفقیت انجام شد', 'success');
|
||||
window.location.reload();
|
||||
},
|
||||
onError: (error) => {
|
||||
toast(extractErrorMessage(error), 'error');
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<section className='pt-6'>
|
||||
<h1 className='font-medium'>کدهای تخفیف</h1>
|
||||
<h1 className='font-medium'>باشگاه مشتریان</h1>
|
||||
|
||||
<section
|
||||
aria-label="درباره کدهای تخفیف"
|
||||
aria-label="درباره باشگاه مشتریان"
|
||||
className='mt-3 bg-container rounded-normal grid grid-cols-4 items-center'
|
||||
>
|
||||
<div className='col-span-3 py-5 pe-7 ps-5 relative h-36.5'>
|
||||
@@ -57,6 +79,52 @@ function TransactionsIndex() {
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* بخش نمایش اعتبار کاربر */}
|
||||
<section className='mt-6 bg-container rounded-normal p-5'>
|
||||
<div className='flex items-center gap-2 mb-4'>
|
||||
<MoneyRecive color='currentColor' size={24} className='text-primary' variant='Bold' />
|
||||
<h2 className='font-bold text-base'>اعتبار شما</h2>
|
||||
</div>
|
||||
<div className='bg-linear-to-l from-primary/10 to-primary/5 rounded-md p-4'>
|
||||
<div className='flex justify-between items-center'>
|
||||
<span className='text-sm text-muted-foreground'>موجودی کیف پول:</span>
|
||||
<span className='font-bold text-lg text-primary'>{ef(userWalletAmount.toLocaleString())} تومان</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* بخش تبدیل امتیاز به اعتبار */}
|
||||
<section className='mt-6 bg-container rounded-normal p-5'>
|
||||
<div className='flex items-center gap-2 mb-4'>
|
||||
<MoneyRecive color='currentColor' size={24} className='text-primary' variant='Bold' />
|
||||
<h2 className='font-bold text-base'>تبدیل امتیاز به اعتبار</h2>
|
||||
</div>
|
||||
|
||||
<p className='text-sm text-muted-foreground mb-4'>
|
||||
هر {ef(aboutData?.data?.score?.purchaseScore?.toString() ?? '0')} امتیاز معادل {ef(aboutData?.data?.score?.purchaseAmount?.toString() ?? '0')} تومان اعتبار است
|
||||
</p>
|
||||
|
||||
<div className='space-y-4'>
|
||||
<div className='bg-accent/50 rounded-md p-4 space-y-2'>
|
||||
<div className='flex justify-between items-center'>
|
||||
<span className='text-sm text-muted-foreground'>امتیاز شما:</span>
|
||||
<span className='font-bold text-lg'>{ef(userPoints.toString())}</span>
|
||||
</div>
|
||||
<div className='flex justify-between items-center'>
|
||||
<span className='text-sm text-muted-foreground'>دریافت میکنید:</span>
|
||||
<span className='font-bold text-lg text-primary'>{ef(calculatedAmount.toString())} تومان</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
onClick={handleConvert}
|
||||
disabled={userPoints <= 0 || isConverting}
|
||||
className='w-full'
|
||||
>
|
||||
{isConverting ? 'در حال تبدیل...' : 'تبدیل تمام امتیازات'}
|
||||
</Button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import * as api from "../service/TransactionService";
|
||||
|
||||
export const useGetMyCoupons = () => {
|
||||
@@ -14,3 +14,9 @@ export const useGetUserWallet = () => {
|
||||
queryFn: api.getUserWallet,
|
||||
});
|
||||
};
|
||||
|
||||
export const useConvertScoreToWallet = () => {
|
||||
return useMutation({
|
||||
mutationFn: api.convertScoreToWallet,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -10,3 +10,8 @@ export const getUserWallet = async (): Promise<WalletResponse> => {
|
||||
const { data } = await api.get<WalletResponse>("/public/user/wallet");
|
||||
return data;
|
||||
};
|
||||
|
||||
export const convertScoreToWallet = async () => {
|
||||
const { data } = await api.post("/public/user/convert-score-to-wallet");
|
||||
return data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user