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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | import NiceModal, { useModal } from "@ebay/nice-modal-react";
import ModalFactory from "@common/Modal/ModalFactory/ModalFactory";
import { useCustomTheme } from "@theme/hooks/useCustomTheme";
import { ModalActions, ModalTitle } from "@common/Modal/ModalFactory/atoms";
import { Box, Stack, styled } from "@mui/material";
import {
Controller,
FormProvider,
SubmitHandler,
useForm,
} from "react-hook-form";
import React from "react";
import { RadioGroup } from "@mui/material";
import { Radio } from "@common/Radio";
import { FormControlLabel } from "@common/FormControlLabel";
import { Text } from "@common/Text";
import { palette } from "@theme/colors";
import * as Yup from "yup";
import FadeUpWrapper from "@components/animation/FadeUpWrapper";
import { yupResolver } from "@hookform/resolvers/yup";
import { useUpdateUnderwriting } from "../hooks/useUnderwritingUpdate";
import { useQueryClient } from "react-query";
import { showMessage } from "@common/Toast";
import { MERCHANT_INITIAL_APPROVAL_MODAL } from "modals/modal_names";
import {
QKEY_LIST_ACQUIRER_MERCHANTS,
QKEY_LIST_MERCHANT_STATS,
} from "@constants/queryKeys";
import { useRefetchCounters } from "@hooks/acquirer-api/merchants/stats/useGetMerchantCounters";
import { MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS } from "@features/Merchants/MerchantSidePanel/constants";
type InitialApprovalProps = {
merchantId: number;
defaultStatus?: string;
};
export type ApprovalTypeInputs = {
status: string;
};
const schema = Yup.object().shape({
status: Yup.string(),
});
const MerchantInitialApprovalModal = NiceModal.create(
({ merchantId, defaultStatus = "pre-approval" }: InitialApprovalProps) => {
const modal = useModal();
const { handleRefetchCounters } = useRefetchCounters();
const { updateUnderwriting } = useUpdateUnderwriting(merchantId);
const queryClient = useQueryClient();
const methods = useForm<ApprovalTypeInputs>({
mode: "onSubmit",
reValidateMode: "onChange",
defaultValues: {
status: defaultStatus,
},
resolver: yupResolver(schema),
});
const onConfirm: SubmitHandler<ApprovalTypeInputs> = async (data) => {
updateUnderwriting.mutate(data, {
onSuccess: () => {
queryClient.invalidateQueries("get-merchant-msp-status");
queryClient.invalidateQueries(QKEY_LIST_MERCHANT_STATS);
handleRefetchCounters();
queryClient.invalidateQueries(QKEY_LIST_ACQUIRER_MERCHANTS);
queryClient.invalidateQueries([
MERCHANT_SIDE_PANEL_PREVIEW_API_KEYS.GET,
merchantId,
]);
NiceModal.remove(MERCHANT_INITIAL_APPROVAL_MODAL);
},
onError: () => {
showMessage(
"Error",
"Merchant account approval failed. Ensure all required information is accurate and approved",
);
},
});
};
const { isMobileView } = useCustomTheme();
const handleCancel = () => modal.remove();
const isValid = methods.formState.isValid;
return (
<ModalFactory
variant="dialog"
renderMobile={isMobileView}
modalProps={{
open: modal.visible,
onClose: handleCancel,
width: 550,
}}
>
<FormProvider {...methods}>
<Stack
component="form"
id="approve-account-form"
data-testid="approve-account-form"
gap="24px"
onSubmit={methods.handleSubmit(onConfirm)}
>
<Box padding="24px 24px 0 24px">
<ModalTitle
textStyles={{ title: { fontSize: "18px" } }}
title="Approve Account"
onClose={handleCancel}
/>
</Box>
<FadeUpWrapper delay={20}>
<>
<Stack px="24px" sx={{ overflowY: "scroll" }} gap="16px">
<Stack gap="12px">
<Controller
control={methods.control}
name="status"
render={({
field: { onChange, value },
fieldState: { error },
}) => (
<Box>
<RadioGroup sx={{ gap: 2 }}>
{approvalTypes.map((option) => (
<StyledBox
key={option.title}
selected={option.value === value}
>
<FormControlLabel
control={<Radio />}
label={
<Stack gap="4px">
<Text color={palette.neutral[100]}>
{option.title}
</Text>
<Text color={palette.gray[300]}>
{option.subtitle}
</Text>
</Stack>
}
value={option.value}
onChange={onChange}
checked={value === option.value}
/>
</StyledBox>
))}
</RadioGroup>
{error && (
<Text
pt="12px"
pl="12px"
color={palette.neutral[80]}
>
{error.message}
</Text>
)}
</Box>
)}
/>
</Stack>
</Stack>
<ModalActions
containerProps={{ sx: { m: "16px", gap: "16px" } }}
secondaryAction={{
label: "Cancel",
onClick: handleCancel,
}}
primaryAction={{
label: "Confirm",
disabled: !isValid,
type: "submit",
component: "button",
dataTestId: "confirm-account-appoval-button",
form: "approve-account-form",
sx: { backgroundColor: palette.filled.success },
}}
/>
</>
</FadeUpWrapper>
</Stack>
</FormProvider>
</ModalFactory>
);
},
);
const StyledBox = styled(Box)(({ selected }: { selected: boolean }) => ({
padding: "12px",
backgroundColor: "#fff",
borderRadius: "8px",
borderWidth: "2px",
borderStyle: "solid",
borderColor: selected ? palette.accent[3] : "transparent",
}));
export default MerchantInitialApprovalModal;
export const approvalTypes = [
{
value: "auto-approval",
title: "Auto-approval",
subtitle:
"Recommended for merchants categorized as 'Normal' risk. This allows a quicker and more efficient approval process for low-risk merchants.",
},
{
value: "pre-approval",
title: "Pre-approval",
subtitle:
"Recommended for merchants categorized as 'Restricted' or 'High' risk. This allows additional checks and balances before the final approval is granted.",
},
];
|