()
| 11 | import { useUnsubscribe, useUnsubscribeMutation } from '@/hooks/queries/unsubscribe' |
| 12 | |
| 13 | function UnsubscribeContent() { |
| 14 | const searchParams = useSearchParams() |
| 15 | const email = searchParams.get('email') |
| 16 | const token = searchParams.get('token') |
| 17 | |
| 18 | const hasParams = Boolean(email) && Boolean(token) |
| 19 | const query = useUnsubscribe(email ?? undefined, token ?? undefined) |
| 20 | const unsubscribe = useUnsubscribeMutation() |
| 21 | |
| 22 | const data = query.data ?? null |
| 23 | const loading = hasParams && query.isLoading |
| 24 | const processing = unsubscribe.isPending |
| 25 | const unsubscribed = unsubscribe.isSuccess |
| 26 | const error = !hasParams |
| 27 | ? 'Missing email or token in URL' |
| 28 | : query.isError |
| 29 | ? getErrorMessage(query.error, 'Failed to validate unsubscribe link') |
| 30 | : unsubscribe.isError |
| 31 | ? getErrorMessage(unsubscribe.error, 'Failed to process unsubscribe request') |
| 32 | : null |
| 33 | |
| 34 | const handleUnsubscribe = (type: UnsubscribeType) => { |
| 35 | if (!email || !token) return |
| 36 | unsubscribe.mutate({ email, token, type }) |
| 37 | } |
| 38 | |
| 39 | if (loading) { |
| 40 | return ( |
| 41 | <InviteLayout> |
| 42 | <div className='space-y-1 text-center'> |
| 43 | <h1 className={'font-medium text-[32px] text-[var(--text-primary)] tracking-tight'}> |
| 44 | Loading |
| 45 | </h1> |
| 46 | <p className={'font-[380] text-[var(--text-muted)] text-md'}> |
| 47 | Validating your unsubscribe link… |
| 48 | </p> |
| 49 | </div> |
| 50 | <div className={'mt-8 flex w-full items-center justify-center py-8'}> |
| 51 | <Loader className='size-8 text-[var(--text-muted)]' animate /> |
| 52 | </div> |
| 53 | </InviteLayout> |
| 54 | ) |
| 55 | } |
| 56 | |
| 57 | if (error) { |
| 58 | return ( |
| 59 | <InviteLayout> |
| 60 | <div className='space-y-1 text-center'> |
| 61 | <h1 className={'font-medium text-[32px] text-[var(--text-primary)] tracking-tight'}> |
| 62 | Invalid Unsubscribe Link |
| 63 | </h1> |
| 64 | <p className={'font-[380] text-[var(--text-muted)] text-md'}>{error}</p> |
| 65 | </div> |
| 66 | |
| 67 | <div className={'mt-8 w-full max-w-[410px] space-y-3'}> |
| 68 | <AuthSubmitButton type='button' onClick={() => window.history.back()} loadingLabel=''> |
| 69 | Go Back |
| 70 | </AuthSubmitButton> |
nothing calls this directly
no test coverage detected