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 | import { Box } from "@mui/material";
import { customInstance } from "@services/api";
import GiveText from "@shared/Text/GiveText";
import { styled } from "@theme/v2/Provider";
import { AxiosError } from "axios";
import { useQuery } from "react-query";
import { useState } from "react";
import { useCustomThemeV2 } from "@theme/hooks/useCustomThemeV2";
import GiveLink from "@shared/Link/GiveLink";
import GiveDivider from "@shared/GiveDivider/GiveDivider";
import GiveButton from "@shared/Button/GiveButton";
import { Grid } from "@mui/material";
import NiceModal from "@ebay/nice-modal-react";
import { PRIVACY_POLICY_MODAL, REFUND_POLICY_MODAL } from "modals/modal_names";
//TODO: will be updated when BE is ready
const useGetInfos = (token?: string) => {
return useQuery<any, AxiosError>(
"find-order-by-token",
async () => {
const order = await customInstance({
url: `orders/${token}`,
method: "GET",
});
return order;
},
{
refetchOnWindowFocus: false,
enabled: !!token,
},
);
};
const tempData = {
product: "Mixed Scone Box",
account: "johndoe@gmail.com",
nextPayment: {
date: "25/07/2025",
frequency: "Recurring Monthly",
amount: "$15.00",
card: "VISA **** 4958",
},
};
const CancelMembership = () => {
const [isCanceled, setIsCanceled] = useState<boolean>(false);
const { isMobileView } = useCustomThemeV2();
const membershipEndDate = "July 25, 2025.";
const handleCancelMembership = () => {
setIsCanceled(true);
};
const handleOpenRefundPolicy = () => {
NiceModal.show(REFUND_POLICY_MODAL);
};
const handleOpenPrivacyPolicy = () => {
NiceModal.show(PRIVACY_POLICY_MODAL);
};
return (
<MainContainer isMobileView={isMobileView}>
<MembershipContainer>
<GiveText variant="bodyL">Wayne's Bakery</GiveText>
<Header>
<GiveText variant="h3" fontWeight={300} fontSize="28px">
{isCanceled
? "Your payments were canceled"
: "We're sorry to see you go!"}
</GiveText>
<GiveText variant="bodyS" color="secondary" sx={{ mt: "20px" }}>
{isCanceled ? (
<>
You will no longer receive purchased products after your
membership ends on{" "}
<GiveText variant="bodyS" fontWeight={600} component="span">
{membershipEndDate}
</GiveText>
</>
) : (
<>
Once you cancel your payments, you will retain access until{" "}
<GiveText variant="bodyS" fontWeight={600} component="span">
{membershipEndDate}
</GiveText>{" "}
After that, you will no longer receive purchased products.
</>
)}
</GiveText>
</Header>
{!isCanceled && (
<GiveButton
label="Yes, Cancel Payments"
size="large"
variant="filled"
onClick={handleCancelMembership}
sx={{ mb: "20px" }}
/>
)}
<OrderDetails />
<Footer>
<GiveLink onClick={handleOpenRefundPolicy}>Refund Policy</GiveLink>
<GiveLink onClick={handleOpenPrivacyPolicy}>Privacy Policy</GiveLink>
</Footer>
</MembershipContainer>
</MainContainer>
);
};
export default CancelMembership;
const OrderDetails = () => (
<>
<GiveDivider />
<Box sx={{ width: "100%", my: "32px" }}>
<GiveText variant="bodyL" color="primary" sx={{ mb: "20px" }}>
Order Details
</GiveText>
<Grid container spacing={3}>
{[
{
label: "Product",
value: tempData.product,
variant: "bodyXS" as const,
},
{
label: "Account",
value: tempData.account,
variant: "bodyS" as const,
},
{
label: "Next Payment",
value: (
<>
<GiveText variant="bodyS">{tempData.nextPayment.date}</GiveText>
<GiveText variant="bodyS">
{tempData.nextPayment.frequency}
</GiveText>
<GiveText variant="bodyS">
{tempData.nextPayment.amount}
</GiveText>
<GiveText variant="bodyS">{tempData.nextPayment.card}</GiveText>
</>
),
variant: "bodyS" as const,
},
].map(({ label, value, variant }, index) => (
<Grid item xs={12} sm={6} key={index} spacing={2}>
<Box sx={{ display: "flex", flexDirection: "column", gap: "8px" }}>
<GiveText variant="bodyS" fontWeight={600}>
{label}
</GiveText>
<GiveText variant={variant}>{value}</GiveText>
</Box>
</Grid>
))}
</Grid>
</Box>
<GiveDivider />
</>
);
const MembershipContainer = styled(Box)(() => ({
display: "flex",
flexDirection: "column",
flexWrap: "nowrap",
alignItems: "center",
alignContent: "center",
maxWidth: "650px",
padding: "20px",
paddingTop: "56px",
}));
const MainContainer = styled(Box)<{ isMobileView?: boolean }>(
({ isMobileView }) => ({
width: "100%",
display: "flex",
justifyContent: isMobileView ? "start" : "center",
}),
);
const Header = styled(Box)(() => ({
marginTop: "48px",
marginBottom: "20px",
textAlign: "center",
}));
const Footer = styled(Box)(() => ({
display: "flex",
justifyContent: "center",
gap: "24px",
marginTop: "8px",
width: "100%",
}));
|