import { Fragment, FC, useState } from 'react' import Button from '../../../components/Button' import { TickCircle } from 'iconsax-react' import { useTranslation } from 'react-i18next' import { useApproveInvoice, useRequestApprove } from '../hooks/useReceiptData' import { ErrorType } from '../../../helpers/types' import { toast } from '../../../components/Toast' import { clx } from '../../../helpers/utils' import { useGetProfile } from '../../profile/hooks/useProfileData' import { RequestApproveInvoiceType } from '../types/ReceiptTypes' import DefaulModal from '../../../components/DefaulModal' import OTPInput from 'react-otp-input' import { useCountDown } from '../../../hooks/useCountDown' type Props = { id: string, refetch: () => void, status: string } const ApproveInvoice: FC = ({ id, refetch, status }) => { const approveInvoce = useApproveInvoice() const requestApprove = useRequestApprove() const getProfile = useGetProfile() const { value, reset } = useCountDown(2, true) const [showModal, setShowModal] = useState(false) const { t } = useTranslation('global') const [code, setCode] = useState('') const handleConfrim = () => { approveInvoce.mutate({ code: code, id: id, phone: getProfile.data?.data?.user?.phone }, { onSuccess: () => { toast('فاکتور با موفقیت تایید شد', 'success') refetch() setShowModal(false) }, onError: (error: ErrorType) => { toast(error?.response?.data?.message || 'خطا در تایید فاکتور', 'error') } }) } const handleShowModal = () => { const params: RequestApproveInvoiceType = { id: id, phone: getProfile.data?.data?.user?.phone } requestApprove.mutate(params, { onSuccess: () => { setShowModal(true) reset() }, onError: (error: ErrorType) => { toast(error?.response?.data?.message || 'خطا در تایید فاکتور', 'error') } }) } if (status === 'PENDING' || status === 'WAIT_PAYMENT' && getProfile.isSuccess) return ( setShowModal(false)} isHeader title_header={t('profile.confrim')} >
کد تایید به شماره {getProfile.data?.data?.user?.phone} ارسال شده است.برای تایید کد مربوطه را وارد کنید.
کد تایید
} />
{ value !== '00:00' ?
{value}
{t('auth.counter_otp')}
:
{t('auth.try_again')}
}
) else return null } export default ApproveInvoice