diff --git a/src/pages/admin/settings.tsx b/src/pages/admin/settings.tsx new file mode 100644 index 0000000..d993ca5 --- /dev/null +++ b/src/pages/admin/settings.tsx @@ -0,0 +1,91 @@ +import { + Box, + Button, + Flex, + FormControl, + FormErrorMessage, + FormLabel, + Input, + useToast, + } from '@chakra-ui/react'; +import { useSession } from 'next-auth/react'; +import { useRouter } from 'next/router'; +import { useState } from 'react'; +import { useForm } from 'react-hook-form'; + + export default function settings() { + + const router = useRouter(); + const toast = useToast(); + + const [isLoading, setIsLoading] = useState(false); + + const { + handleSubmit, + register, + formState: { errors, isSubmitting }, + } = useForm() + + const [userData, setUserData] = useState({}); + + const { data: session, status } = useSession(); + if (status === "unauthenticated") router.push("/login"); + + if (status === "authenticated") { + const { user } = session as unknown as Session; + + if (user.role !== "ADMIN") router.push("/login"); + + const savePassion = (passion: any) => { + const options = { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(passion), + }; + + fetch(`/api/passions`, options) + .then((res) => { + setIsLoading(false); + toast({ + position:'top', + title: `Passion ajoutée`, + status: "success", + isClosable: true, + }); + }) + .catch((err) => { + setIsLoading(false); + toast({ + title: `Erreur lors de l'ajout`, + position :'top', + status: "error", + isClosable: true, + }); + }); + } + + return ( + <> + + + Passion + + + {errors.name && errors.name.message} + + + + + + ); + } + } + \ No newline at end of file