Skip to content

Commit

Permalink
update to stop the payoffRequest from being submitted after the form …
Browse files Browse the repository at this point in the history
…is submitted
  • Loading branch information
crisner1978 committed Aug 29, 2023
1 parent fc56306 commit 84a2820
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export default function Form({ vdp }: Props) {
}
})}
<Vehicle errors={errors} watchJoint={watchJoint} />
<TradeInfo errors={errors} />
<TradeInfo errors={errors} isSubmitting={isSubmitting} />
<Agreement isError={isError} onClick={() => setError(false)} />
<div className='mt-8 grid grid-cols-1 px-5 pt-10 md:ml-3 md:grid-cols-3'>
<button
Expand Down
4 changes: 3 additions & 1 deletion src/components/sections/TradeInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import { FieldErrors, useFormContext } from 'react-hook-form'

type TradeInfoProps = {
errors: FieldErrors
isSubmitting: boolean
}

const TradeInfo = ({ errors }: TradeInfoProps) => {
const TradeInfo = ({ errors, isSubmitting }: TradeInfoProps) => {
const [payload, setPayload] = useState<any>({})
const { lenders, lenderCats, isTrade, setTrade } = usePayoffLenders()
const { watchTradeInVin } = useTradeQuery(setPayload)
Expand All @@ -23,6 +24,7 @@ const TradeInfo = ({ errors }: TradeInfoProps) => {
lenders,
payload,
setPayload,
isSubmitting,
})
const customer = useCustomer((s) => s.customer)
const methods = useFormContext()
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/usePayoffQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ const usePayoffQuery = ({
lenders,
payload,
setPayload,
isSubmitting,
}: {
watchTradeInVin: string
lenders: Record<string, any>[]
payload: any
setPayload: Dispatch<any>
isSubmitting: boolean
}) => {
const [customer, setCustomer] = useCustomer((s) => [s.customer, s.setCustomer])
const { setValue, setFocus, watch } = useFormContext()
Expand Down Expand Up @@ -56,6 +58,12 @@ const usePayoffQuery = ({
}
}, [isLienOther, lenders, setFocus, setPayload, ssn, watchLienName, watchTradeInVin])

useEffect(() => {
if(isSubmitting) {
setReady(false)
}
},[isReady, isSubmitting, setReady])

useEffect(() => {
if (isReady && isTrade && Object.keys(payload)?.length > 0) {
const getPayoff = async () => {
Expand Down

1 comment on commit 84a2820

@vercel
Copy link

@vercel vercel bot commented on 84a2820 Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

credit-app – ./

credit-app.dev.driv.ly
credit-app-git-main.dev.driv.ly
credit.driv.ly

Please sign in to comment.