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 { data: cartData } = useGetCartItems(isSuccess);
|
||||
|
||||
const walletAmount = userWallet?.data?.wallet ?? 0;
|
||||
const walletAmount = userWallet?.data?.balance ?? 0;
|
||||
const totalAmount = cartData?.data?.total ?? 0;
|
||||
const isWalletInsufficient = walletAmount < totalAmount;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { ef } from '@/lib/helpers/utfNumbers'
|
||||
import { Cup, Star1, MoneyRecive } from 'iconsax-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 { useGetAbout } from '../../../about/hooks/useAboutData';
|
||||
import { toast } from '@/components/Toast';
|
||||
@@ -11,10 +11,11 @@ import { extractErrorMessage } from '@/lib/func';
|
||||
function TransactionsIndex() {
|
||||
|
||||
const { data: userWallet } = useGetUserWallet();
|
||||
const { data: userPointsBalance } = useGetUserPointsBalance();
|
||||
const { data: aboutData } = useGetAbout();
|
||||
const { mutate: convertScoreToWallet, isPending: isConverting } = useConvertScoreToWallet();
|
||||
const userPoints = userWallet?.data?.points ?? 0;
|
||||
const userWalletAmount = userWallet?.data?.wallet ?? 0;
|
||||
const userPoints = userPointsBalance?.data?.balance ?? 0;
|
||||
const userWalletAmount = userWallet?.data?.balance ?? 0;
|
||||
const conversionRate = Number(aboutData?.data?.score?.purchaseScore ?? 1000);
|
||||
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>
|
||||
</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>
|
||||
|
||||
|
||||
@@ -11,7 +11,14 @@ export const useGetMyCoupons = () => {
|
||||
export const useGetUserWallet = () => {
|
||||
return useQuery({
|
||||
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 {
|
||||
CouponsResponse,
|
||||
WalletResponse,
|
||||
WalletBalanceResponse,
|
||||
TransactionsResponse,
|
||||
} from "../types/Types";
|
||||
|
||||
@@ -10,8 +10,20 @@ export const getMyCoupons = async (): Promise<CouponsResponse> => {
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getUserWallet = async (): Promise<WalletResponse> => {
|
||||
const { data } = await api.get<WalletResponse>("/public/user/wallet");
|
||||
export const getUserWalletBalance = async (): Promise<
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -39,6 +39,12 @@ export interface Wallet {
|
||||
|
||||
export type WalletResponse = BaseResponse<Wallet>;
|
||||
|
||||
export interface WalletBalance {
|
||||
balance: number;
|
||||
}
|
||||
|
||||
export type WalletBalanceResponse = BaseResponse<WalletBalance>;
|
||||
|
||||
export interface PaymentMethod {
|
||||
id: string;
|
||||
createdAt: string;
|
||||
|
||||
Reference in New Issue
Block a user