Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | 19x 19x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x | import { palette } from "@palette";
// @mui
import Grid from "@mui/material/Grid";
// components
import { Text } from "@common/Text";
import { RHFInput } from "@common/Input";
import { RHFSelect } from "@common/Select";
import OnboardingBankStatement from "./OnboardingBankStatement";
import { Stack } from "@mui/material";
import { useFormContext } from "react-hook-form";
import { BankProviderText } from "@components/BankAccounts";
import {
TBankFormInputsNew,
TBankFormInputsOld,
} from "@hooks/onboarding/useAddOnboardingBankAccounts";
import { useAccessControl } from "features/Permissions/AccessControl";
import RESOURCE_BASE, {
CREATE_DENY_MESSAGE,
EDIT_DENY_MESSAGE,
OPERATIONS,
} from "@constants/permissions";
import { gridItemsRenderer } from "@utils/rendering/nodesRenderers";
import { BANK_ACCOUNT_NOTES_MAX_LENGTH } from "@constants/constants";
import { BA_DOCUMENTS } from "@constants/constants";
const options = [
{
value: "checking",
label: "Checking",
},
{
value: "savings",
label: "Savings",
},
];
const CreateOnboardingBankAccount = ({
firstAccount,
...rest
}: {
firstAccount?: any;
bankFiles?: any;
bankFilesLoading?: boolean;
}) => {
const { watch } = useFormContext<TBankFormInputsNew | TBankFormInputsOld>();
const values = watch();
const isApproved = firstAccount?.status === "approved";
const isLinked = firstAccount?.isLinked;
const isAddAllowed = useAccessControl({
resource: RESOURCE_BASE.BANK_ACCOUNT,
operation: OPERATIONS.CREATE,
withPortal: true,
});
const isEditAllowed = useAccessControl({
resource: RESOURCE_BASE.BANK_ACCOUNT,
operation: OPERATIONS.UPDATE,
withPortal: true,
});
const cantAdd = !firstAccount?.id && !isAddAllowed;
const cantEdit = (firstAccount?.id && !isEditAllowed) || isLinked;
const isInputDisabled = cantAdd || cantEdit || isApproved;
const inputs = [
{
node: (
<RHFSelect
name="accountType"
placeholder="Select an account"
label="Account type"
disabled={isInputDisabled}
options={options}
/>
),
sm: 4,
},
{
node: (
<RHFInput
name="name"
fullWidth
placeholder={BA_DOCUMENTS.name_input}
type="text"
label={BA_DOCUMENTS.name_input}
disabled={isInputDisabled}
/>
),
sm: 8,
},
{
node: (
<>
<RHFInput
name="routingNumber"
fullWidth
placeholder="Enter Routing Number"
type="text"
label="Routing number"
inputProps={{ maxLength: 9 }}
disabled={cantAdd || cantEdit}
/>
<BankProviderText routingNumber={values.routingNumber} />
</>
),
sm: 4,
},
{
node: (
<RHFInput
name="accountNumber"
fullWidth
placeholder="Enter Account Number"
disabled={isInputDisabled}
type="text"
label="Account number"
/>
),
sm: 8,
},
{
node: <OnboardingBankStatement firstAccount={firstAccount} {...rest} />,
sm: 12,
hidden: isInputDisabled,
},
{
node: (
<RHFInput
name="notes"
fullWidth
placeholder="Enter notes about account..."
type="text"
label="Notes (optional)"
multiline
rows={7}
disabled={cantAdd || cantEdit}
inputProps={{
maxLength: `${BANK_ACCOUNT_NOTES_MAX_LENGTH}`,
}}
helperText={`${
BANK_ACCOUNT_NOTES_MAX_LENGTH - values.notes.length
} Characters remaining`}
/>
),
sm: 12,
},
];
return (
<Stack direction="column" alignItems="stretch" gap="16px">
<Text
fontSize="20px"
fontWeight="book"
lineHeight="120%"
color={palette.neutral[80]}
>
{BA_DOCUMENTS.cta}
</Text>
<Grid container spacing={1.5} direction="row" alignItems="flex-start">
{gridItemsRenderer(inputs, {
show: cantAdd || cantEdit,
message: isLinked
? "Only controllers can edit the bank account"
: !cantEdit
? EDIT_DENY_MESSAGE
: CREATE_DENY_MESSAGE,
})}
</Grid>
</Stack>
);
};
export default CreateOnboardingBankAccount;
|