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 | 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x | import { FormProvider, SubmitHandler, useForm } from "react-hook-form";
import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import NiceModal from "@ebay/nice-modal-react";
import useUpdateRiskTrigger from "@components/Merchants/MerchantPreview/RiskProfile/hooks/useUpdateRiskTrigger";
import GiveBaseModal from "@shared/modals/GiveBaseModal";
import {
HeaderRight,
ModalTitle,
} from "./GiveRiskTriggerModal/ModalComponents";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import { ConversationMenuProps } from "@features/GiveConversation/types";
import { Stack } from "@mui/material";
import { yupResolver } from "@hookform/resolvers/yup";
import { commentSchema } from "@validation/common";
import GiveButton from "@shared/Button/GiveButton";
import TaskCard from "@features/Merchants/MerchantSidePanel/UnderwritingTasks/components/TaskCard";
import GiveText from "@shared/Text/GiveText";
import HFNotesInput from "@shared/HFInputs/HFNotesInput";
import { MerchantInfoContent } from "@features/Merchants/MerchantSidePanel/UnderwritingTasks/components/Sections";
interface IComponentProps {
isEnabled: boolean;
factorID: number;
profileId: number;
merchantId: number;
triggerTitle: string;
triggerDescription: string;
points: number;
merchantName: string;
merchantProfileImage?: string;
conversationMenuProps: ConversationMenuProps;
merchantLegalName?: string;
taxID?: string;
}
type ReasonType = {
comment: string;
};
const footerDescription =
"Please provide a comment for adjusting this trigger. This information is required and will be added to the conversation log.";
const GiveToggleRiskTriggerModal = NiceModal.create(
({
isEnabled,
factorID,
profileId,
merchantId,
merchantName,
merchantProfileImage,
triggerTitle,
triggerDescription,
points,
conversationMenuProps,
merchantLegalName,
taxID,
}: IComponentProps) => {
const { onRemove, open } = useNiceModal();
const { isMobileView } = useCustomThemeV2();
const methods = useForm<ReasonType>({
mode: "onChange",
reValidateMode: "onChange",
defaultValues: {
comment: "",
},
resolver: yupResolver(commentSchema),
});
const {
formState: { isValid },
watch,
} = methods;
const commentValue = watch("comment");
const buttonTitle = isEnabled ? "Disable" : "Enable";
const { handleUpdateTrigger, isLoading } = useUpdateRiskTrigger({
factorID,
profileId,
merchantId,
triggerTitle,
triggerDescription,
});
const handleSaveChanges: SubmitHandler<ReasonType> = (data) => {
handleUpdateTrigger({
reason: data.comment,
isEnabled: !isEnabled,
onSuccessCb: onRemove,
});
};
const merchantInfo = {
name: merchantName,
legalName: merchantLegalName,
taxID: taxID,
imageURL: merchantProfileImage,
merchantID: merchantId,
threadName: triggerTitle,
images: conversationMenuProps.images,
};
return (
<GiveBaseModal
data-testid="toggle-modal"
open={open}
onClose={onRemove}
height={isMobileView ? "fit-content" : "auto"}
customHeaderStyle={{
position: "relative",
}}
customHeaderHeight="auto"
customContentPadding="20px 20px 94px 20px"
title={
(
<ModalTitle
title={triggerTitle}
description={triggerDescription}
points={points}
/>
) as any
}
headerRightContent={
isMobileView ? undefined : (
<HeaderRight
points={points}
conversationMenuProps={conversationMenuProps}
/>
)
}
buttons={
<Stack gap="12px" direction="row" justifyContent="flex-end">
<GiveButton
label="Cancel"
size="large"
onClick={onRemove}
variant="ghost"
/>
<GiveButton
label={buttonTitle}
size="large"
onClick={methods.handleSubmit(handleSaveChanges)}
disabled={!isValid || !commentValue?.trim() || isLoading}
/>
</Stack>
}
>
<FormProvider {...methods}>
<Stack gap="24px">
<TaskCard title="Merchant">
<MerchantInfoContent {...merchantInfo} actions={[]} />
</TaskCard>
<HFNotesInput
title="Comment"
fieldName="comment"
placeholder="Write a comment"
minHeight={130}
hideActions
/>
<GiveText variant="bodyS" color="secondary">
{footerDescription}
</GiveText>
</Stack>
</FormProvider>
</GiveBaseModal>
);
},
);
export default GiveToggleRiskTriggerModal;
|