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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | 1x 1x 1x 145x 145x 145x 145x 145x 145x 145x 250x 145x 145x 145x 145x 145x 145x 4x 4x 145x 145x 145x 3x 3x 2x 3x 145x 145x 52x 52x 25x | import NiceModal from "@ebay/nice-modal-react";
import { FormProvider, useForm } from "react-hook-form";
import useNiceModal from "@common/Modal/ModalFactory/hooks/useNiceModal";
import { TBlockTransaction } from "@services/api/riskProfile/riskProfileActions";
import { useMarkAsFraudActions } from "@components/ManageMoney/TransactionTable/TableActions/hooks/useMarkAsFraudActions";
import GiveBaseModal from "@shared/modals/GiveBaseModal";
import GiveButton from "@shared/Button/GiveButton";
import { Skeleton, Stack } from "@mui/material";
import * as Yup from "yup";
import { yupResolver } from "@hookform/resolvers/yup";
import { HFGiveInput } from "@shared/HFInputs/HFGiveInput/HFGiveInput";
import { HFCheckbox } from "@shared/HFInputs/HFGiveCheckbox/HFGiveCheckbox";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import ButtonWithSpinner from "@shared/Button/ButtonWithSpinner";
import { formatCharCountWithLimit } from "@utils/index";
import GiveAlert from "@shared/GiveAlert/GiveAlert";
import { InfoIcon } from "@phosphor-icons/react";
import { useTransactionHistory } from "@components/ManageMoney/TransactionTable/TransactionInfoModal/hooks";
import RefundItem from "../components/RefundItem";
import { addSizeToImage } from "@utils/image.helpers";
import { VALIDATION_MESSAGES } from "@validation/messages";
type TReasonForm = {
reason: string;
shouldSendNotification: boolean;
shouldRefundTransaction: boolean;
};
type TMarkAsFraudModal = {
shouldRefundDisplayed: boolean;
isPartiallyRefunded?: boolean;
transactionId: string;
isFirst?: boolean;
isLast?: boolean;
setSelectedRow?: React.Dispatch<any>;
refundItems?: any[];
isFromDevAPI?: boolean;
};
const MAX_TEXT_LENGTH = 500;
const schema = Yup.object().shape({
reason: Yup.string()
.required(VALIDATION_MESSAGES.REASON_REQUIRED)
.min(1, "Reason cannot be empty"),
});
const MarkAsFraudModalV2 = NiceModal.create(
({
shouldRefundDisplayed,
isPartiallyRefunded,
transactionId,
refundItems,
isFromDevAPI,
...props
}: TMarkAsFraudModal) => {
const { open, onClose } = useNiceModal();
const { isMobileView } = useCustomThemeV2();
const { displayedData, isLoading } = useTransactionHistory(
transactionId,
false,
);
const isDeclinedOrVoided = ["Declined", "Voided"].includes(
displayedData?.displayStatus || "",
);
const isPartialRefund =
isPartiallyRefunded ||
displayedData?.originalTransactionReversalState === "partially_reversed";
const showRefund =
!isDeclinedOrVoided &&
(shouldRefundDisplayed ||
displayedData?.originalTransactionReversalState !== "fully_reversed");
const usedRefundItems =
refundItems && refundItems.length > 0
? refundItems
: displayedData?.originalTransactionItems?.filter(
(item: any) => !item?.disallowReversalRequests,
);
const isDevAPI =
isFromDevAPI || displayedData?.sourceType === "givesync_api_client";
const defaultValues = {
reason: "",
shouldSendNotification: false,
shouldRefundTransaction: showRefund ? true : false,
};
const methods = useForm<TReasonForm>({
mode: "onChange",
reValidateMode: "onChange",
defaultValues,
resolver: yupResolver(schema),
});
const { reason, shouldSendNotification, shouldRefundTransaction } =
methods.watch();
const { reset } = methods;
const handleClose = () => {
reset();
onClose();
};
const { isFirst, isLast, setSelectedRow } = props;
const { markAsFraudMutation } = useMarkAsFraudActions({
isFirst,
isLast,
setSelectedRow,
onSuccess: handleClose,
currentID: transactionId,
});
const onSubmit = () => {
const usedID =
displayedData?.originalPurchaseTransactionID || transactionId;
const payloadData: TBlockTransaction = {
merchantId: displayedData?.originalTransactionDestination,
id: usedID,
reason: reason,
canNotifyMerchant: shouldSendNotification,
skipRefund: shouldRefundTransaction && showRefund ? false : true,
...(shouldRefundTransaction &&
isPartialRefund && {
refundItemIDs: usedRefundItems.map((item: any) => item.id),
}),
};
markAsFraudMutation.mutate(payloadData);
};
const isValid = methods.formState.isValid;
return (
<GiveBaseModal
open={open}
title="Suspect"
width="560px"
height="fit-content"
onClose={handleClose}
buttons={
<>
<GiveButton
variant="ghost"
size="large"
label="Cancel"
onClick={handleClose}
disabled={markAsFraudMutation.isLoading}
/>
<ButtonWithSpinner isLoading={markAsFraudMutation.isLoading}>
<GiveButton
size="large"
variant="filled"
label="Send"
onClick={onSubmit}
disabled={!isValid}
sx={{ border: "none" }}
/>
</ButtonWithSpinner>
</>
}
sx={{
...(isMobileView && {
"& .MuiDialogActions-root": {
alignItems: "flex-end",
"& div:first-child": {
width: "fit-content",
},
},
}),
}}
>
{isLoading ? (
<LoadingState />
) : (
<FormProvider {...methods}>
<Stack gap="24px">
<GiveAlert
Icon={<InfoIcon size={24} />}
label="The suspect action applies a tag to the original transaction"
description={
showRefund
? ""
: " This transaction has already been refunded"
}
type="warning2"
textContainerSx={{ gap: "6px" }}
iconContainerSx={{
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
/>
<HFGiveInput
name="reason"
placeholder="Please provide a reason why you want to suspect the transaction"
maxLength={MAX_TEXT_LENGTH}
rows={8}
multiline
label="Reason"
{...(!methods.formState?.errors?.reason && {
helperText: formatCharCountWithLimit(reason, MAX_TEXT_LENGTH),
})}
/>
{showRefund && (
<HFCheckbox
data-testid="checkbox-shouldRefundTransaction"
name="shouldRefundTransaction"
label={
isPartialRefund
? "Refund Remaining items"
: "Refund Transaction"
}
/>
)}
{shouldRefundTransaction && isPartialRefund && (
<Stack gap="8px">
{usedRefundItems?.map((item: any, index: number) => {
const imageSrc =
item.product?.variant?.imageURL &&
addSizeToImage(item.product.variant.imageURL, "thumb");
return (
<RefundItem
key={`${index}-${item.id}`}
name={
isDevAPI
? "Item 1"
: item.product?.variant?.name || ""
}
imageUrl={imageSrc}
quantity={item.quantity}
amount={item.price}
currency="USD"
hideCheckbox
/>
);
})}
</Stack>
)}
</Stack>
</FormProvider>
)}
</GiveBaseModal>
);
},
);
export default MarkAsFraudModalV2;
function LoadingState() {
return (
<Stack gap="24px" width="100%">
<Skeleton variant="rounded" width="100%" height="48px" />
<Skeleton variant="rounded" width="100%" height="220px" />
</Stack>
);
}
|