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 | 3x 227x 227x 227x 7x 227x 3x 3x 227x 227x 227x 227x | import { useCallback } from "react";
import { useFormContext } from "react-hook-form";
import {
IMerchantBankAccount,
TBusinessOwner,
} from "@components/Merchants/MerchantPreview/data.types";
import {
TCreateBusinessProfile,
TCreatePrimaryAccountHolder,
} from "components/Merchants/CreateMerchantPanel/types";
import { TMerchantAgreementPayload } from "components/Merchants/CreateMerchantPanel/hooks/TMerchantAgreementPayload";
export const useModalCloseHandlers = () => {
const { setValue, watch } = useFormContext();
const values = watch();
const handleClosePrimaryAccountHolder = (
data: TCreatePrimaryAccountHolder,
) => {
setValue("primaryAccountHolder", data);
};
const handleCloseBusinessProfile = useCallback(
(data: {
businessProfile: TCreateBusinessProfile;
businessOwners?: TBusinessOwner[];
}) => {
setValue("businessProfile", data.businessProfile);
setValue("businessOwners", data.businessOwners || []);
},
[values.businessProfile, values.businessOwners],
);
const handleCloseBusinessOwner = (data: TBusinessOwner) => {
setValue("businessOwners", [data]);
};
const handleCloseBankAccount = (data: IMerchantBankAccount) => {
setValue("bankAccounts", [data]);
setValue("allowBankAccounts", data?.allowBankAccounts);
setValue("allowTransfers", data?.allowTransfers);
if (data?.isLinked && data?.id) {
setValue("linkedBankAccountID", data?.id);
}
};
const handleCloseMerchantAgreement = (data: TMerchantAgreementPayload) => {
setValue("merchantAgreement", data);
};
return {
handleCloseBankAccount,
handleCloseBusinessProfile,
handleCloseMerchantAgreement,
handleCloseBusinessOwner,
handleClosePrimaryAccountHolder,
};
};
|