feat: user activation and emails
This commit is contained in:
@@ -1,65 +1,5 @@
|
||||
'use client';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import React from 'react';
|
||||
import { z } from 'zod';
|
||||
import { Button } from '../../components/Button';
|
||||
import { VerticalLayout } from '../../components/VerticalLayout';
|
||||
import { ResponseSchema } from './../utils/types';
|
||||
import { UnsubscribeForm } from '../../components/pages/unsubscribe';
|
||||
|
||||
export default function Home() {
|
||||
const router = useRouter();
|
||||
|
||||
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
||||
e.preventDefault();
|
||||
const data = new FormData(e.currentTarget);
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/unsubscribe', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
email: data.get('email')
|
||||
})
|
||||
});
|
||||
|
||||
if (!response?.ok) {
|
||||
throw new Error(`Invalid response: ${response.status}`);
|
||||
}
|
||||
|
||||
const formResponse: z.infer<typeof ResponseSchema> =
|
||||
await response.json();
|
||||
|
||||
console.log(formResponse);
|
||||
|
||||
router.push('/success');
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
alert('Error');
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<VerticalLayout>
|
||||
<form className='container' onSubmit={handleSubmit}>
|
||||
<h1>Unsubscribe newsletter</h1>
|
||||
<div className='email block'>
|
||||
<label htmlFor='frm-email'>Email</label>
|
||||
<input
|
||||
placeholder='example@email.com'
|
||||
id='email'
|
||||
type='email'
|
||||
name='email'
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className='button block'>
|
||||
<button type='submit'>Unsubscribe</button>
|
||||
</div>
|
||||
</form>
|
||||
<Button label='Home' onClick={() => router.push('/')} />
|
||||
<Button label='Subscribe' onClick={() => router.push('/subscribe')} />
|
||||
</VerticalLayout>
|
||||
);
|
||||
export default function Unsubscribe() {
|
||||
return <UnsubscribeForm />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user