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 | 7x 162x 162x 162x 162x 77x 85x 64x 21x 162x 162x 162x 162x 162x 162x 2x 2x 162x 162x 162x 162x 162x 162x 162x 162x 162x 162x 162x 162x 162x 7x | import { Stack } from "@mui/material";
import moment from "moment";
import { PLATFORM_TIMEZONE } from "@utils/timezones";
import { TMerchantAgreementPayload } from "@components/Merchants/CreateMerchantPanel/hooks/TMerchantAgreementPayload";
import { useGetMerchantById } from "@hooks/enterprise-api/account/useGetMerchants";
import { useConversationsModal } from "features/Minibuilders/Conversations/hooks/useConversationsModal";
import { useFormContext } from "react-hook-form";
import NiceModal from "@ebay/nice-modal-react";
import { GIVE_CREATE_MERCHANT_AGREEMENT_MODAL } from "modals/modal_names";
import GiveText from "shared/Text/GiveText";
import { CertificateIcon, ChatCircleIcon } from "@phosphor-icons/react";
import GiveIconButton from "shared/IconButton/GiveIconButton";
import GiveChip, { TChipColors } from "shared/Chip/GiveChip";
import { CaretRightIcon } from "@phosphor-icons/react";
import SectionCardBase from "shared/SidePanel/components/SectionCard/SectionCardBase";
import { useAppTheme } from "@theme/v2/Provider";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
export const getAgreementStatus = (merchantData: any) => {
const isCorrectVersion =
merchantData.msaLastAcceptedVersion === merchantData.tcVersion;
const localFile =
merchantData?.signatureFile?.file || merchantData?.signatureFile;
const isLocalSigned =
localFile !== null &&
typeof localFile !== "undefined" &&
localFile instanceof File;
if ((merchantData.msaHadAgreed && isCorrectVersion) || isLocalSigned)
return "Signed";
if (
(!merchantData.msaHadAgreed && isCorrectVersion) ||
!merchantData.msaLastAcceptedVersion
)
return "Not Signed";
return "Pending";
};
type Props = {
handleCloseMerchantAgreement?: (args: any) => void;
isAcquirer?: boolean;
id?: number;
isEnterprise?: boolean;
handleOpenAgreement?: () => void;
merchantData?: any;
};
//AGREEMENT this component is the agreement card used in setting and creation
function MerchantAgreement({
id,
isEnterprise,
isAcquirer,
handleCloseMerchantAgreement,
handleOpenAgreement,
merchantData,
}: Props) {
const methods = useFormContext();
const values = methods.watch();
const { isMobileView } = useCustomThemeV2();
const { palette } = useAppTheme();
const data: TMerchantAgreementPayload =
values.merchantAgreement || merchantData.merchantAgreement;
const handleOpenMerchantAgreement = () => {
if (handleOpenAgreement) {
handleOpenAgreement();
} else E{
NiceModal.show(GIVE_CREATE_MERCHANT_AGREEMENT_MODAL, {
onClose: handleCloseMerchantAgreement,
data: {
...values.merchantAgreement,
isEnterprise: isEnterprise,
},
merchantData: {
...values,
businessAddress: values.businessProfile.address,
businessOwnersList: values.businessOwners,
bankAccountList: values.bankAccounts,
},
});
}
};
const localFile = data?.signatureFile?.file || data?.signatureFile;
const { data: APIData } = useGetMerchantById();
const { openConversationHandler } = useConversationsModal();
const onClick = (event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
const name = isEnterprise ? "Provider Agreement" : "Merchant Agreement";
openConversationHandler({ id, name, paths: [] });
};
const isLocalSigned =
localFile !== null &&
typeof localFile !== "undefined" &&
localFile instanceof File;
const status = getAgreementStatus(data);
const msaVersion = APIData?.msaVersion || APIData?.aquirerTcVersion;
const msaLastAcceptedVersion = isLocalSigned
? msaVersion
: data?.msaLastAcceptedVersion;
const tcVersion = isLocalSigned ? msaVersion : data?.tcVersion;
const signedDate = isLocalSigned
? moment().tz(PLATFORM_TIMEZONE).format("MM/DD/YYYY")
: data?.msaLastUpdatedAt
? moment.unix(data?.msaLastUpdatedAt).tz(PLATFORM_TIMEZONE).format("MM/DD/YYYY")
: "";
const generateText = {
Signed: `${signedDate} v.${msaLastAcceptedVersion || ""}`,
"Not Signed": `${signedDate} v.${tcVersion || ""}`,
Pending: `${signedDate} v.${tcVersion || ""}`,
};
return (
<SectionCardBase
sx={handleOpenAgreement ? {} : { mx: "20px", width: "auto" }}
leftTitle={handleOpenAgreement ? "" : "Merchant Agreement"}
childrenContainerSx={{ padding: handleOpenAgreement ? "0px" : "20px" }}
>
<Stack
data-testid="agreement-container"
direction="row"
gap={1}
justifyContent="space-between"
borderRadius={handleOpenAgreement ? "12px" : "0px"}
border={
handleOpenAgreement
? `1.5px solid ${palette.primitive?.neutral[20]}`
: ""
}
padding={handleOpenAgreement ? "16px" : "0px"}
sx={() => ({
"&:hover": {
"& .MuiStack-root": {
opacity: "0.7",
},
},
})}
>
<Stack
sx={{ cursor: "pointer" }}
direction="row"
alignItems="center"
gap={1}
flex={1}
data-testid="setting-agreement-card"
onClick={handleOpenMerchantAgreement}
>
<CertificateIcon size={20} />
<Stack
width="100%"
spacing={0.5}
direction={isMobileView ? "column" : "row"}
justifyContent="space-between"
alignItems={isMobileView ? "flex-start" : "center"}
>
<GiveText variant="bodyS" color="secondary">
Agreement
</GiveText>
<GiveText variant="bodyS">{generateText[status]}</GiveText>
</Stack>
</Stack>
<Stack direction="row" alignItems="center" gap={1}>
{isAcquirer && id && (
<GiveIconButton
variant="ghost"
Icon={ChatCircleIcon}
onClick={onClick}
/>
)}
{status && (
<GiveChip
color={statusMap[status].color as TChipColors}
label={status}
variant="light"
/>
)}
<CaretRightIcon size={20} />
</Stack>
</Stack>
</SectionCardBase>
);
}
export default MerchantAgreement;
const statusMap = {
Signed: { color: "success" },
"Not Signed": { color: "error" },
Pending: { color: "warning" },
};
|