import React, { useState } from 'react' import { useMutation } from '@tanstack/react-query' import Label from '../../Label' import InputText from '../../InputText' import { repayLoan } from '../../../services/siteServices' export default function PinRepayment({step, handleStep, screens}) { console.log('step', step.activeUser, step.details) 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, loan_id:step.details.selected_loan_id, customerID:step.activeUser.customerid} if(!fields.pin){ throw ({message:'Please enter pin'}) } if(fields.pin.length != 4){ throw ({message:'Pin must be 4 digits'}) } return repayLoan(fields) }, onError: (error) => { setError(error.message) setTimeout(()=>{setError('')},3000) }, onSuccess: (res) => { setIsSuccess(true) handleStep({...step}, 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 && <>

{error}

} ) }