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 | 3x 2076x 2076x 2076x 2076x 2076x 66x 66x 66x 24x 96x 66x 5x 66x 8x 66x 7x 14x 66x 5x 66x 7x 14x 2076x 3x 2046x 2046x 1526x 1526x 28x 1498x 1498x 26x 1472x 1472x 304x 1168x 1168x 1162x 1162x 854x 3x 1192x 5936x 1192x | import { Stack } from "@mui/material";
import { useFormContext } from "react-hook-form";
import {
EnterpriseConfigurationList,
RESTRICTED_ON_CREATE_TOOLTIP,
} from "../constants/EnterpriseConfiguration.constants";
import { TEnterpriseConfiguration } from "../hooks/useEnterpriseConfiguration";
import GiveTooltip from "@shared/Tooltip/GiveTooltip";
import GiveText from "@shared/Text/GiveText";
import GiveSwitch from "@shared/Switch/GiveSwitch";
type Props = {
item: TEnterpriseConfiguration;
isCreateMode?: boolean;
};
const GiveProviderConfigurationSwitch = ({ item, isCreateMode }: Props) => {
const { setValue, watch } = useFormContext();
const values = watch();
const isRestrictedOnCreate = Boolean(
isCreateMode && item.restrictedOnCreate,
);
const tooltip = isRestrictedOnCreate
? RESTRICTED_ON_CREATE_TOOLTIP
: checkDisabledConfiguration(item.name, values);
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const value = e.target.checked;
setValue(item.name, value, { shouldDirty: true });
if (item.name === "modify_merchant") {
[
"merchant_underwriting",
"merchant_underwriting_statuses",
"agreement_signing",
"control_mode",
].forEach((permission) => {
setValue(permission, false);
});
}
if (item.name === "merchant_underwriting") {
setValue("merchant_underwriting_statuses", false);
}
if (item.name === "agreement_signing") {
setValue("control_mode", false);
}
if (item.name === "bank_account_linking") {
["manage_bank_account", "money_transfers"].forEach((permission) => {
setValue(permission, false);
});
}
if (item.name === "manage_bank_account") {
setValue("money_transfers", false);
}
if (item.name === "risk_monitoring") {
["merchant_triggers", "risk_activity"].forEach((permission) => {
setValue(permission, false);
});
}
};
return (
<Stack alignItems="flex-start" direction="row" spacing={1.5}>
<GiveTooltip
color="default"
title={tooltip}
disableFocusListener={!tooltip}
disableHoverListener={!tooltip}
disableTouchListener={!tooltip}
customTooltipStyles={{ width: "fit-content", maxWidth: "446px" }}
>
<GiveSwitch
data-testid={`ent-config-switch-${item.name}`}
name={item.name}
onChange={onChange}
checked={values[item.name]}
disabled={Boolean(tooltip)}
/>
</GiveTooltip>
<Stack spacing={0.5} sx={{ opacity: tooltip ? 0.5 : 1 }}>
<GiveText variant="bodyS" color="primary">
{item.displayName}
</GiveText>
<GiveText variant="bodyXS" color="secondary">
{item.description}
</GiveText>
</Stack>
</Stack>
);
};
const checkDisabledConfiguration = (
name: string,
values: { [key: string]: boolean },
) => {
// Permissions Management
const isModifyMerchant =
[
"merchant_underwriting",
"merchant_underwriting_statuses",
"agreement_signing",
"control_mode",
].includes(name) && !values.modify_merchant;
if (isModifyMerchant) return getConfigurationTooltip("modify_merchant");
const isMerchantUnderwriting =
name === "merchant_underwriting_statuses" && !values.merchant_underwriting;
if (isMerchantUnderwriting)
return getConfigurationTooltip("merchant_underwriting");
const isAgreementSigningDependant =
name === "control_mode" && !values.agreement_signing;
if (isAgreementSigningDependant)
return getConfigurationTooltip("agreement_signing");
// Merchant Integration
const isBankAccountLinking =
["manage_bank_account", "money_transfers"].includes(name) &&
!values.bank_account_linking;
if (isBankAccountLinking)
return getConfigurationTooltip("bank_account_linking");
const isMoneyTransfer =
name === "money_transfers" && !values.manage_bank_account;
if (isMoneyTransfer) return getConfigurationTooltip("manage_bank_account");
// Risk Management
const isRiskMonitoring =
["merchant_triggers", "risk_activity"].includes(name) &&
!values.risk_monitoring;
if (isRiskMonitoring) return getConfigurationTooltip("risk_monitoring");
return "";
};
const getConfigurationTooltip = (name: string) => {
const disaplyeName = EnterpriseConfigurationList.find(
(item) => item.name === name,
)?.displayName;
return `"${disaplyeName}" must be enabled`;
};
export default GiveProviderConfigurationSwitch;
|