diff --git a/pages/unsubscribe.tsx b/pages/unsubscribe.tsx new file mode 100644 index 00000000..484eb365 --- /dev/null +++ b/pages/unsubscribe.tsx @@ -0,0 +1,103 @@ +import { useMutation } from '@tanstack/react-query'; +import { useSearchParams } from 'next/navigation'; +import { FunctionComponent, useEffect } from 'react'; +import Meta from '../components/meta'; +import Spinner from '../components/spinner'; +import Layout from '../layout/layout'; + +const meta = { + title: 'Unsubscribe from Mockoon emails', + description: 'Unsubscribe from all our marketing emails and newsletters' +}; + +const EmailVerification: FunctionComponent = function () { + const queryParams = useSearchParams(); + + const { + mutate: unsubscribe, + isError: isUnsubscribeError, + isPending: isUnsubscribing, + isSuccess: isUnsubscribedSuccess + } = useMutation({ + mutationFn: async (unsubToken: string) => { + const response = await fetch( + `${process.env.NEXT_PUBLIC_BACKEND_URL}/user/emailing?unsubToken=${unsubToken}`, + { + method: 'DELETE' + } + ); + + if (response.status !== 204) { + throw new Error(); + } + } + }); + + useEffect(() => { + if (queryParams.get('unsubToken')) { + unsubscribe(queryParams.get('unsubToken')); + } + }, [queryParams]); + + return ( + + + +
+
+
+
+

+ Unsubscribe from Mockoon emails +

+ {queryParams.get('unsubToken') && isUnsubscribing && } + {!queryParams.get('unsubToken') && ( + <> +

+ To unsubscribe from our marketing emails and newsletters, + please use the link provided in the footer of the email you + received. +

+

+ If you have a Mockoon account, you can also manage your + email preferences from your{' '} + account settings. +

+

+ If you encounter any issue, please{' '} + contact us. We will be happy to + help. +

+ + )} + {queryParams.get('unsubToken') && + !isUnsubscribing && + isUnsubscribedSuccess && ( + <> +
+ + You have been successfully unsubscribed from all our + marketing emails. +
+ + )} + {queryParams.get('unsubToken') && + !isUnsubscribing && + isUnsubscribeError && ( + <> +
+ An error occurred while trying to unsubscribe you from our + marketing emails. Please{' '} + contact us for assistance. +
+ + )} +
+
+
+
+
+ ); +}; + +export default EmailVerification;