change end point wallet and score
This commit is contained in:
@@ -40,7 +40,7 @@ export const PaymentSection = ({ paymentType, onPaymentTypeChange }: PaymentSect
|
|||||||
const { isSuccess } = useGetProfile();
|
const { isSuccess } = useGetProfile();
|
||||||
const { data: cartData } = useGetCartItems(isSuccess);
|
const { data: cartData } = useGetCartItems(isSuccess);
|
||||||
|
|
||||||
const walletAmount = userWallet?.data?.wallet ?? 0;
|
const walletAmount = userWallet?.data?.balance ?? 0;
|
||||||
const totalAmount = cartData?.data?.total ?? 0;
|
const totalAmount = cartData?.data?.total ?? 0;
|
||||||
const isWalletInsufficient = walletAmount < totalAmount;
|
const isWalletInsufficient = walletAmount < totalAmount;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import { ef } from '@/lib/helpers/utfNumbers'
|
import { ef } from '@/lib/helpers/utfNumbers'
|
||||||
import { Cup, Star1, MoneyRecive } from 'iconsax-react'
|
import { Cup, Star1, MoneyRecive } from 'iconsax-react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useConvertScoreToWallet, useGetUserWallet } from '../../hooks/useTransactionData';
|
import { useConvertScoreToWallet, useGetUserPointsBalance, useGetUserWallet } from '../../hooks/useTransactionData';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { useGetAbout } from '../../../about/hooks/useAboutData';
|
import { useGetAbout } from '../../../about/hooks/useAboutData';
|
||||||
import { toast } from '@/components/Toast';
|
import { toast } from '@/components/Toast';
|
||||||
@@ -11,10 +11,11 @@ import { extractErrorMessage } from '@/lib/func';
|
|||||||
function TransactionsIndex() {
|
function TransactionsIndex() {
|
||||||
|
|
||||||
const { data: userWallet } = useGetUserWallet();
|
const { data: userWallet } = useGetUserWallet();
|
||||||
|
const { data: userPointsBalance } = useGetUserPointsBalance();
|
||||||
const { data: aboutData } = useGetAbout();
|
const { data: aboutData } = useGetAbout();
|
||||||
const { mutate: convertScoreToWallet, isPending: isConverting } = useConvertScoreToWallet();
|
const { mutate: convertScoreToWallet, isPending: isConverting } = useConvertScoreToWallet();
|
||||||
const userPoints = userWallet?.data?.points ?? 0;
|
const userPoints = userPointsBalance?.data?.balance ?? 0;
|
||||||
const userWalletAmount = userWallet?.data?.wallet ?? 0;
|
const userWalletAmount = userWallet?.data?.balance ?? 0;
|
||||||
const conversionRate = Number(aboutData?.data?.score?.purchaseScore ?? 1000);
|
const conversionRate = Number(aboutData?.data?.score?.purchaseScore ?? 1000);
|
||||||
const calculatedAmount = Math.floor(userPoints / conversionRate) * Number(aboutData?.data?.score?.purchaseAmount ?? 1);
|
const calculatedAmount = Math.floor(userPoints / conversionRate) * Number(aboutData?.data?.score?.purchaseAmount ?? 1);
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ function TransactionsIndex() {
|
|||||||
<p className='text-xs mt-[7px] dark:text-disabled-text'>با امتیازی که داری سفارش بده!</p>
|
<p className='text-xs mt-[7px] dark:text-disabled-text'>با امتیازی که داری سفارش بده!</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className='text-xs font-medium dark:text-foreground'>مجموع امتیازات شما: {ef(userWallet?.data?.points?.toString() ?? '0')}</p>
|
<p className='text-xs font-medium dark:text-foreground'>مجموع امتیازات شما: {ef(userPointsBalance?.data?.balance?.toString() ?? '0')}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,14 @@ export const useGetMyCoupons = () => {
|
|||||||
export const useGetUserWallet = () => {
|
export const useGetUserWallet = () => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["user-wallet"],
|
queryKey: ["user-wallet"],
|
||||||
queryFn: api.getUserWallet,
|
queryFn: api.getUserWalletBalance,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useGetUserPointsBalance = () => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["user-points-balance"],
|
||||||
|
queryFn: api.getUserPointsBalance,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { api } from "@/config/axios";
|
import { api } from "@/config/axios";
|
||||||
import {
|
import {
|
||||||
CouponsResponse,
|
CouponsResponse,
|
||||||
WalletResponse,
|
WalletBalanceResponse,
|
||||||
TransactionsResponse,
|
TransactionsResponse,
|
||||||
} from "../types/Types";
|
} from "../types/Types";
|
||||||
|
|
||||||
@@ -10,8 +10,20 @@ export const getMyCoupons = async (): Promise<CouponsResponse> => {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getUserWallet = async (): Promise<WalletResponse> => {
|
export const getUserWalletBalance = async (): Promise<
|
||||||
const { data } = await api.get<WalletResponse>("/public/user/wallet");
|
WalletBalanceResponse
|
||||||
|
> => {
|
||||||
|
const { data } = await api.get<WalletBalanceResponse>(
|
||||||
|
"/public/user/wallet/balance"
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
export const getUserPointsBalance = async (): Promise<
|
||||||
|
WalletBalanceResponse
|
||||||
|
> => {
|
||||||
|
const { data } = await api.get<WalletBalanceResponse>(
|
||||||
|
"/public/user/points/balance"
|
||||||
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,12 @@ export interface Wallet {
|
|||||||
|
|
||||||
export type WalletResponse = BaseResponse<Wallet>;
|
export type WalletResponse = BaseResponse<Wallet>;
|
||||||
|
|
||||||
|
export interface WalletBalance {
|
||||||
|
balance: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type WalletBalanceResponse = BaseResponse<WalletBalance>;
|
||||||
|
|
||||||
export interface PaymentMethod {
|
export interface PaymentMethod {
|
||||||
id: string;
|
id: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user