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 | 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 21x | import NiceModal, { useModal } from "@ebay/nice-modal-react";
import GiveBaseModal from "shared/modals/GiveBaseModal";
import GiveButton from "shared/Button/GiveButton";
import { Stack } from "@mui/material";
import { WarningIcon } from "@phosphor-icons/react";
import GiveText from "shared/Text/GiveText";
import { useAppTheme } from "theme/v2/Provider";
import { GiveSectionItem } from "features/Merchants/MerchantSidePanel/GiveMerchantFile/GiveSectionItem";
import { Box } from "@mui/material";
import { RecurringPurchasesListItem } from "types/customer.types";
import { capitalize } from "lodash";
import { format } from "date-fns";
import { parseAmount } from "utils";
import { CustomGridContainer } from "features/Merchants/MerchantSidePanel/GiveMerchantFile/bankAccounts/CustomGridContainer";
import { useStopRecurrence } from "features/MerchantPortal/Customer/hooks/useStopRecurrence";
type Props = {
subscription: RecurringPurchasesListItem;
customerName: string;
customerEmail: string;
merchantAccId?: number;
source?: "customer" | "transaction";
};
export const StopRecurrenceModal = NiceModal.create(
({
subscription,
customerName,
customerEmail,
merchantAccId,
source = "transaction",
}: Props) => {
const modal = useModal();
const open = modal.visible;
const {
productName,
nextTransactionAt,
createdAt,
recurringInterval,
cost,
cardNumberLast4,
cardBrandName,
orderRecurringObjID,
} = subscription;
const price = source === "customer" ? cost / 100 : cost;
const { stopRecurrence, isLoadingUpdate } = useStopRecurrence(
orderRecurringObjID,
merchantAccId,
);
const handleCancel = () => {
modal.remove();
};
const theme = useAppTheme();
const displayItems = [
{ title: "Product Name", value: productName },
{ title: "Contact", value: customerEmail },
{
title: "Payment",
value: `Credit Card - ${capitalize(
cardBrandName,
)} **** ${cardNumberLast4}`,
},
{
title: "Payment Started",
value: format(createdAt * 1000, "MM/dd/yyyy"),
},
{ title: "Recurrence Type", value: capitalize(recurringInterval) },
{
title: "Next Payment",
value: nextTransactionAt
? format(nextTransactionAt * 1000, "MM/dd/yyyy")
: "-",
},
{ title: "Recurrent Amount (USD)", value: parseAmount(price) },
];
return (
<GiveBaseModal
open={open}
title="Recurring Transaction"
width="648px"
height="fit-content"
onClose={handleCancel}
buttons={
<>
<GiveButton
variant="ghost"
size="large"
label="Cancel"
onClick={handleCancel}
/>
<GiveButton
size="large"
variant="filled"
label="Stop Recurrence"
data-testid="stop-recurrence-button"
color="destructive"
disabled={isLoadingUpdate}
onClick={stopRecurrence}
/>
</>
}
>
<Stack>
<Stack
direction="row"
alignItems="center"
gap="12px"
sx={{
bgcolor: theme.palette.primitive?.warning[10],
borderRadius: "8px",
}}
mb="24px"
p="14px"
>
<WarningIcon
color={theme.palette.primitive?.warning[100]}
size={24}
/>
<GiveText variant="bodyS" color="warning">
Cancelling this recurrence will trigger an email confirmation to{" "}
{customerName ?? customerEmail}.
</GiveText>
</Stack>
<Box padding="8px 0 16px 0">
{displayItems.map((item, i) => {
return (
<Box padding="16px 0 0 16px" key={item.title}>
<CustomGridContainer
container
spacing={2}
padding="4px"
highlight={i % 2 !== 0}
>
<GiveSectionItem item={item} />
</CustomGridContainer>
</Box>
);
})}
</Box>
</Stack>
</GiveBaseModal>
);
},
);
|