import { ComboBox } from "../common/combo-box" import { FC, useEffect, useState } from "react" import { useUserStore } from "../../store/user" import { ButtonComponent } from "../common/button" import { Controller, SubmitHandler, useForm } from "react-hook-form" import { CardBank, SendWithdraw } from "../../types" import { ErrorComponent } from "../common/error" import { useMutation } from "@tanstack/react-query" import { sendwithdraw } from "../../services/api/wallet" import toast from "react-hot-toast" import { handleError } from "../../utility/error-handle" import { Input } from "../common/input" type Props = { pending: boolean } export const WalletAddress: FC = ({ pending }) => { const [selectedCard, setSelectedCard] = useState(null) const { mutate, isPending } = useMutation({ mutationFn: sendwithdraw, mutationKey: ["withdraw"] }) const { handleSubmit, formState: { errors }, control, watch } = useForm({ }) const cardDetail: any = watch("card") const [userBanks, setUserBanks] = useState([]) const { user } = useUserStore() useEffect(() => { const tempUserBanks: any = [...userBanks] user?.cardBank?.map((cards: any) => tempUserBanks.push({ id: cards?.IBAN, name: cards?.PAN, })) setUserBanks(tempUserBanks) }, [user]) useEffect(() => { const selectedCard: CardBank | CardBank[] | [] = user?.cardBank?.filter((cardBanks: any) => cardBanks?.IBAN === cardDetail?.id && cardBanks?.PAN === cardDetail?.name) setSelectedCard(selectedCard?.[0]) }, [cardDetail]) const handleSendWithdraw: SubmitHandler = async () => { await mutate({ card: { holderName: selectedCard?.holderName, PAN: selectedCard?.PAN, IBAN: selectedCard?.IBAN } }, { onSuccess: (res: any) => { toast.success("درخواست شما با موفقیت ثبت شد") }, onError: (err: any) => handleError(err) }) } return (
wallet

ثبت درخواست برداشت از حساب

{!pending && ( <> {/* */} )} />}
{!pending &&

برای درخواست برداشت از حساب، حساب بانکی مورد نظر خود را انتخاب کنید. پس از انتخاب حساب بانکی، مبلغ مورد نظر خود را وارد کرده و درخواست خود را ثبت کنید.

} {pending &&

{`همکار گرامی طبق درخواست قبلی، عملیات واریز به حساب شما در حال اجراست. متاسفانه پیش از تکمیل درخواست، امکان شروع عملیات جدید برای شما وجود ندارد.`}

}
) }