loan repay API added

This commit is contained in:
victorAnumudu
2025-03-04 19:12:19 +01:00
parent 0064f5e4c3
commit eab8745468
5 changed files with 54 additions and 53 deletions
@@ -2,10 +2,12 @@ import React, { useState } from 'react'
import { useMutation } from '@tanstack/react-query'
import Label from '../../Label'
import InputText from '../../InputText'
import { verifyLoan } from '../../../services/siteServices'
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('')
@@ -19,17 +21,15 @@ export default function PinRepayment({step, handleStep, screens}) {
const proceed = useMutation({
mutationFn: () => {
let fields = {pin, bvn:step.activeUser.bvn, loan_application_id:step.details.loan_application_id}
let fields = {pin, loan_id:step.details.selected_loan_id, customerID:step.activeUser.customerid}
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)
return repayLoan(fields)
},
onError: (error) => {
setError(error.message)
@@ -41,14 +41,6 @@ export default function PinRepayment({step, handleStep, screens}) {
}
})
const handleClick = (selectedAmount) => { // remove later
if(!pin){
return setError('Enter Pin')
}
setIsSuccess(true)
// handleStep({selectedAmount}, screens.finished)
}
return (
<>
{!isSuccess ?
@@ -57,8 +49,7 @@ export default function PinRepayment({step, handleStep, screens}) {
<p className='text-center text-base md:text-xl'>{`Your loan amount due is ${step.details.selectedAmount}`}</p>
<Label name='Enter your 4 Digit pin' htmlfor='pin' />
<InputText id='pin' name='pin' type='text' value={pin} handleChange={handlePinChange} />
{/* <button onClick={()=>{proceed.mutate()}} disabled={proceed.isPending} className='p-3 bg-purple-800 text-base sm:text-xl text-white font-bold rounded'>{proceed.isPending ? 'loading...' : 'Continue'}</button> */}
<button onClick={()=>handleClick()} className='p-3 bg-purple-800 text-base sm:text-xl text-white font-bold rounded'>{'Continue'}</button>
<button onClick={()=>{proceed.mutate()}} disabled={proceed.isPending} className='p-3 bg-purple-800 text-base sm:text-xl text-white font-bold rounded'>{proceed.isPending ? 'loading...' : 'Continue'}</button>
</div>
</div>
:
@@ -17,27 +17,23 @@ export default function RepayLoanList({step, handleStep, screens}) {
const loanInfoList = data?.data // LOAN INFO LIST
const selectedLoan = useMutation({
mutationFn: (details) => {
let fields = {bvn:step.activeUser.bvn, loan: details.loan}
// if(!fields.bvn){
// throw new Error('*')
// }
setSelectedAmount(details.amount)
return loanSelect(fields)
},
onError: (error) => {
// setError('*')
},
onSuccess: (res) => {
const selectedOffer = res.data.loan
handleStep({selectedAmount, selectedOffer, ...res.data}, screens.repay_pin)
}
})
// const selectedLoan = useMutation({
// mutationFn: (details) => {
// let fields = {bvn:step.activeUser.bvn, loan: details.loan}
// setSelectedAmount(details.amount)
// return loanSelect(fields)
// },
// onError: (error) => {
// },
// onSuccess: (res) => {
// const selectedOffer = res.data.loan
// handleStep({selectedAmount, selectedOffer, ...res.data}, screens.repay_pin)
// }
// })
const handleClick = (selectedAmount) => { // remove later
handleStep({selectedAmount}, screens.repay_pin)
}
const handleClick = (selected_loan_id, selectedAmount) => {
handleStep({selected_loan_id, selectedAmount}, screens.repay_pin)
}
return (
<div className='mt-3 flex flex-col gap-4'>
@@ -64,7 +60,7 @@ export default function RepayLoanList({step, handleStep, screens}) {
disabled={isDisabled || selectedLoan.isPending}
// value={item.loan}
// onClick={()=>selectedLoan.mutate(item)}
onClick={()=>handleClick(amount)}
onClick={()=>handleClick(item.loan_id, amount)}
className={`w-full flex gap-2 justify-between items-center p-2 bg-purple-800 ${selectedLoan.isPending && 'bg-purple-800/50'} text-base sm:text-xl text-white font-bold rounded ${isDisabled && 'opacity-50'}`}
>
{item?.description}