mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-05-16 09:06:54 +00:00
feat: getting-start form
Took 7 hours 1 minute
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import {Button} from '@chakra-ui/react';
|
||||
import {useRouter} from 'next/router';
|
||||
import {Passion, User} from '@prisma/client';
|
||||
import {useSelector} from 'react-redux';
|
||||
import {RootState} from '@/redux/redux';
|
||||
|
||||
export default function SubmitGettingStartForm({user}: { user: User }) {
|
||||
const router = useRouter();
|
||||
const gettingStartForm = useSelector(
|
||||
(state: RootState) => state.gettingStartForm);
|
||||
|
||||
const handleSubmit = () => {
|
||||
const {
|
||||
ownGender,
|
||||
researchGender,
|
||||
ages,
|
||||
birth,
|
||||
passions,
|
||||
} = gettingStartForm.inputs;
|
||||
|
||||
const options = {
|
||||
method: 'PUT',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({
|
||||
gender: ownGender,
|
||||
prefGender: researchGender,
|
||||
ageMin: ages[0],
|
||||
ageMax: ages[1],
|
||||
birthdate: new Date(birth),
|
||||
Passion: {
|
||||
connect: passions.map((p: Passion) => {
|
||||
return {id: p.id};
|
||||
}),
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
fetch(`/api/users/${user.id}`, options)
|
||||
.then(() => router.push('/dashboard'))
|
||||
.catch(err => console.error(err));
|
||||
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button onClick={handleSubmit}>Ça marche!</Button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user