fix cancel premium btn

This commit is contained in:
AykutSarac 2023-05-23 16:12:14 +03:00
parent 9a8d5f334d
commit 5964b257c3
No known key found for this signature in database

View File

@ -1,17 +1,28 @@
import React from "react"; import React from "react";
import { Modal, Group, Button, Divider, ModalProps, Text, Image } from "@mantine/core"; import { Modal, Group, Button, Divider, ModalProps, Text, Image, Anchor } from "@mantine/core";
import { toast } from "react-hot-toast"; import { toast } from "react-hot-toast";
import { altogic } from "src/api/altogic"; import { altogic } from "src/api/altogic";
export const CancelPremiumModal: React.FC<ModalProps> = ({ opened, onClose }) => { export const CancelPremiumModal: React.FC<ModalProps> = ({ opened, onClose }) => {
const [cancelling, setCancelling] = React.useState(false);
const cancelSub = async () => { const cancelSub = async () => {
altogic.endpoint.delete("/subscription").then(({ data, errors }) => { try {
setCancelling(true);
const { errors } = await altogic.endpoint.delete("/subscription");
if (errors?.items.length) { if (errors?.items.length) {
toast.error("An error occured while cancelling plan!"); return toast.error(
console.log(errors.items); "An error occured while cancelling plan! Please contact support@herowand.com"
);
} }
toast.success("Cancelled premium plan!"); toast.success("Cancelled premium plan!");
}); } catch (err) {
console.error(err);
} finally {
setCancelling(false);
}
}; };
return ( return (
@ -22,13 +33,17 @@ export const CancelPremiumModal: React.FC<ModalProps> = ({ opened, onClose }) =>
<br /> <br />
<br /> <br />
You can restart your subscription anytime. You can restart your subscription anytime.
<br />
<Anchor target="_blank" href="https://patreon.com/herowand">
Click here to cancel if you are Patreon member
</Anchor>
</Text> </Text>
<Divider py="xs" /> <Divider py="xs" />
<Group position="right"> <Group position="right">
<Button color="dark" variant="subtle" onClick={onClose}> <Button color="dark" variant="subtle" onClick={onClose}>
Cancel Cancel
</Button> </Button>
<Button onClick={cancelSub} color="red"> <Button onClick={cancelSub} loading={cancelling} color="red">
QUIT SUBSCRIPTION QUIT SUBSCRIPTION
</Button> </Button>
</Group> </Group>