import React, { useState } from 'react' import { useMutation } from '@tanstack/react-query' import Label from '../../Label' import InputText from '../../InputText' import { verifyLoan } from '../../../services/siteServices' export default function PinRepayment({step, handleStep, screens}) { const [isSuccess, setIsSuccess] = useState(false) const [error, setError] = useState('') const [pin, setPin] = useState('') const handlePinChange = ({target:{value}}) => { setError('') setPin(value) } const proceed = useMutation({ mutationFn: () => { let fields = {pin, bvn:step.activeUser.bvn, loan_application_id:step.details.loan_application_id} if(!fields.pin){ throw ({message:'Please enter pin'}) } // if(isNaN(fields.pin)){ // throw ({message:'Amount must be a valid figure'}) // } if(fields.pin.length != 4){ throw ({message:'Pin must be 4 digits'}) } return verifyLoan(fields) }, onError: (error) => { setError(error.message) setTimeout(()=>{setError('')},3000) }, onSuccess: (res) => { setIsSuccess(true) handleStep({...step}, screens.finished) } }) const handleClick = (selectedAmount) => { // remove later if(!pin){ return setError('Enter Pin') } setIsSuccess(true) // handleStep({selectedAmount}, screens.finished) } return ( <> {!isSuccess ?
{`Your loan amount due is ₦${step.details.selectedAmount}`}
Your loan repayment is being processed. You will receive a confirmation SMS shortly.
{error}