Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/components/AddWithdraw/AddWithdrawCountriesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@ import { useParams, useRouter } from 'next/navigation'
import EmptyState from '../Global/EmptyStates/EmptyState'
import { useAuth } from '@/context/authContext'
import { useEffect, useMemo, useRef, useState } from 'react'
import { DynamicBankAccountForm, IBankAccountDetails } from './DynamicBankAccountForm'
import { addBankAccount, updateUserById } from '@/app/actions/users'
import { BridgeKycStatus } from '@/utils/bridge-accounts.utils'
import { AddBankAccountPayload } from '@/app/actions/types/users.types'
import { useWebSocket } from '@/hooks/useWebSocket'
import { useWithdrawFlow } from '@/context/WithdrawFlowContext'
import { Account } from '@/interfaces'
import PeanutLoading from '../Global/PeanutLoading'
import { getCountryCodeForWithdraw } from '@/utils/withdraw.utils'
import { isMantecaCountry } from '@/constants/manteca.consts'
import { DeviceType, useDeviceType } from '@/hooks/useGetDeviceType'
import CryptoMethodDrawer from '../AddMoney/components/CryptoMethodDrawer'
import { useAppDispatch } from '@/redux/hooks'
import { bankFormActions } from '@/redux/slices/bank-form-slice'
import { InitiateBridgeKYCModal } from '../Kyc/InitiateBridgeKYCModal'
import { MultiStepBankAccountForm, IBankAccountDetails } from '../MultiStepBankAccountForm'

interface AddWithdrawCountriesListProps {
flow: 'add' | 'withdraw'
Expand Down Expand Up @@ -234,7 +232,8 @@ const AddWithdrawCountriesList = ({ flow }: AddWithdrawCountriesListProps) => {
setView('list')
}}
/>
<DynamicBankAccountForm

<MultiStepBankAccountForm
ref={formRef}
country={getCountryCodeForWithdraw(currentCountry.id)}
onSuccess={handleFormSubmit}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Claim/Link/views/BankFlowManager.view.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use client'

import { IClaimScreenProps } from '../../Claim.consts'
import { DynamicBankAccountForm, IBankAccountDetails } from '@/components/AddWithdraw/DynamicBankAccountForm'
import { ClaimBankFlowStep, useClaimBankFlow } from '@/context/ClaimBankFlowContext'
import { useCallback, useContext, useState, useRef, useEffect } from 'react'
import { loadingStateContext } from '@/context'
Expand Down Expand Up @@ -31,6 +30,7 @@ import { useAppDispatch } from '@/redux/hooks'
import { bankFormActions } from '@/redux/slices/bank-form-slice'
import { sendLinksApi } from '@/services/sendLinks'
import { InitiateBridgeKYCModal } from '@/components/Kyc/InitiateBridgeKYCModal'
import { MultiStepBankAccountForm, IBankAccountDetails } from '@/components/MultiStepBankAccountForm'

type BankAccountWithId = IBankAccountDetails &
(
Expand Down Expand Up @@ -465,7 +465,7 @@ export const BankFlowManager = (props: IClaimScreenProps) => {
}}
/>
</div>
<DynamicBankAccountForm
<MultiStepBankAccountForm
ref={formRef}
key={selectedCountry?.id}
country={getCountryCodeForWithdraw(selectedCountry?.id ?? '')}
Expand Down
62 changes: 62 additions & 0 deletions src/components/MultiStepBankAccountForm/FormInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react'
import { Control, Controller, FieldErrors, ControllerRenderProps, RegisterOptions } from 'react-hook-form'
import BaseInput from '@/components/0_Bruddle/BaseInput'
import ErrorAlert from '@/components/Global/ErrorAlert'
import { IBankAccountDetails } from './types'

interface FormInputProps {
name: keyof IBankAccountDetails
placeholder: string
rules: RegisterOptions<IBankAccountDetails, keyof IBankAccountDetails>
control: Control<IBankAccountDetails>
errors: FieldErrors<IBankAccountDetails>
touchedFields: Partial<Record<keyof IBankAccountDetails, boolean>>
type?: string
onBlur?: (field: ControllerRenderProps<IBankAccountDetails, keyof IBankAccountDetails>) => Promise<void> | void
}

const FormInput: React.FC<FormInputProps> = ({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

praise: i like this component

nit: lets add comments and not use any

name,
placeholder,
rules,
control,
errors,
touchedFields,
type = 'text',
onBlur,
}) => {
return (
<div className="w-full">
<div className="relative">
<Controller
name={name}
control={control}
rules={rules}
render={({ field }) => (
<BaseInput
{...field}
type={type}
placeholder={placeholder}
className="h-12 w-full rounded-sm border border-n-1 bg-white px-4 text-sm"
onBlur={async (e) => {
// Trim whitespace on blur
if (typeof field.value === 'string') {
field.onChange(field.value.trim())
}
field.onBlur()
if (onBlur) {
await onBlur(field)
}
}}
/>
)}
/>
</div>
<div className="mt-2 w-fit text-start">
{errors[name] && touchedFields[name] && <ErrorAlert description={errors[name]?.message ?? ''} />}
</div>
</div>
)
}

export default FormInput
Loading
Loading