diff --git a/src/components/BottomBar.tsx b/src/components/BottomBar.tsx index 0b6cab3..f1c0dc1 100644 --- a/src/components/BottomBar.tsx +++ b/src/components/BottomBar.tsx @@ -1,27 +1,15 @@ import { Box, Flex, Text, Button, Image } from "@chakra-ui/react"; import { useRouter } from "next/router"; -export default function BottomBar(props) { +export default function BottomBar(props: { variant: any; saveData: any; }) { const router = useRouter(); const { variant, saveData } = props; return ( - + - diff --git a/src/components/Carousel.tsx b/src/components/Carousel.tsx index d594b47..67fc6cd 100644 --- a/src/components/Carousel.tsx +++ b/src/components/Carousel.tsx @@ -1,13 +1,13 @@ -import { useState } from "react"; -import { Flex, IconButton } from "@chakra-ui/react"; -import { BiLeftArrowAlt, BiRightArrowAlt } from "react-icons/bi"; +import {useState} from 'react'; +import {Flex, IconButton} from '@chakra-ui/react'; +import {BiLeftArrowAlt, BiRightArrowAlt} from 'react-icons/bi'; interface Props { images: string[]; borderRadius?: string | number; } -const Carousel = ({ images, borderRadius: bRadius }: Props) => { +const Carousel = ({images, borderRadius: bRadius}: Props) => { const [currentIndex, setCurrentIndex] = useState(0); const handleClickPrevious = () => { @@ -18,41 +18,22 @@ const Carousel = ({ images, borderRadius: bRadius }: Props) => { setCurrentIndex(currentIndex === images.length - 1 ? 0 : currentIndex + 1); }; - if (images.length === 0) images = ["blank_profile_picture.webp"]; + if (images.length === 0) images = ['blank_profile_picture.webp']; return ( - - - - + + + + - - - - + + + + ); }; diff --git a/src/components/ErrorGeoLocation.tsx b/src/components/ErrorGeoLocation.tsx index d290c87..5a9c749 100644 --- a/src/components/ErrorGeoLocation.tsx +++ b/src/components/ErrorGeoLocation.tsx @@ -6,20 +6,13 @@ export default function LoadingPage() { const router = useRouter(); return ( - + Veillez à autoriser la géolocalisation - + ); } diff --git a/src/components/ErrorPage.tsx b/src/components/ErrorPage.tsx index 2bca489..a5da9da 100644 --- a/src/components/ErrorPage.tsx +++ b/src/components/ErrorPage.tsx @@ -6,20 +6,13 @@ export default function LoadingPage() { const router = useRouter(); return ( - + Une erreur est survenue - + ); } diff --git a/src/components/LoadingPage.tsx b/src/components/LoadingPage.tsx index 68de68b..530d92f 100644 --- a/src/components/LoadingPage.tsx +++ b/src/components/LoadingPage.tsx @@ -2,20 +2,9 @@ import { Flex, Spinner } from "@chakra-ui/react"; export default function LoadingPage() { return ( - - + + ); } diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index f75154b..7e778d5 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -6,87 +6,73 @@ import { Button, Image, Link, -} from "@chakra-ui/react"; -import { useRouter } from "next/router"; -import { signOut, useSession } from "next-auth/react"; +} from '@chakra-ui/react'; +import {useRouter} from 'next/router'; +import {signOut, useSession} from 'next-auth/react'; type Props = { - variant: "static" | "fixed"; + variant: 'static' | 'fixed'; }; -export default function Navbar({ variant = "fixed" }: Props) { +export default function Navbar({variant = 'fixed'}: Props) { const router = useRouter(); - const { data: session, status } = useSession(); + const {data: session, status} = useSession(); + + const MiddleSection = () => { + const authenticatedLinks = ( + <> + Tableau de bord + Profile + Carte + + ); + + return ( + + {status === 'authenticated' + ? authenticatedLinks + : <> + } + + ); + }; const RightSection = () => { - if (status === "authenticated" && session.user) - return ( - + + const authenticatedButtons = ( + + ); + + const unauthenticatedButtons = ( + <> + + + + ); + + return ( + - + {status === 'authenticated' + ? authenticatedButtons + : unauthenticatedButtons + } - ); - else - return ( - - - - - - - ); + ); }; return ( - - - - - + + + + + - - {status === "authenticated" ? ( - <> - - Tableau de bord - - - Profile - - - Carte - - - ) : ( - <> - A propos - Contact - Aide - - )} + + - - - - + ); } diff --git a/src/components/form/FormMessage.tsx b/src/components/form/FormMessage.tsx index f1493d1..35de198 100644 --- a/src/components/form/FormMessage.tsx +++ b/src/components/form/FormMessage.tsx @@ -32,8 +32,8 @@ export default function FormMessage(props: Props) { return ( - setText(evt.target.value) } value={text} /> - + setText(evt.target.value) } value={text}/> + ) } \ No newline at end of file diff --git a/src/components/form/LoginForm.tsx b/src/components/form/LoginForm.tsx index 13b621d..d506744 100644 --- a/src/components/form/LoginForm.tsx +++ b/src/components/form/LoginForm.tsx @@ -8,13 +8,13 @@ import { Input, Container, FormErrorMessage, -} from "@chakra-ui/react"; -import { useState } from "react"; -import { useRouter } from "next/router"; -import { signIn, SignInResponse } from "next-auth/react"; +} from '@chakra-ui/react'; +import {useState} from 'react'; +import {useRouter} from 'next/router'; +import {signIn, SignInResponse} from 'next-auth/react'; -import { LoginData } from "@/models/form/LoginData"; -import { useForm } from "react-hook-form"; +import {LoginData} from '@/models/form/LoginData'; +import {useForm} from 'react-hook-form'; export default function LoginForm() { const router = useRouter(); @@ -24,92 +24,84 @@ export default function LoginForm() { const { handleSubmit, register, - formState: { errors, isSubmitting }, + formState: {errors, isSubmitting}, } = useForm(); - const buttonWidth = { base: "100%", md: "unset" }; + const buttonWidth = {base: '100%', md: 'unset'}; - const errorPassword = "Mot de passe incorrect"; + const errorPassword = 'Mot de passe incorrect'; const loginUser = async (value: LoginData) => { setIsLoading(true); - signIn("credentials", { ...value, redirect: false }).then( - (res: unknown) => { - const { ok: connexionSuccess } = res as SignInResponse; - setIsLoading(false); + signIn('credentials', {...value, redirect: false}).then( + (res: unknown) => { + const {ok: connexionSuccess} = res as SignInResponse; + setIsLoading(false); - if (connexionSuccess) router.push("/dashboard"); - else setWrongPasswordError(true); - } + if (connexionSuccess) router.push('/dashboard'); + else setWrongPasswordError(true); + }, ); }; return ( - - -
- - Connexion - - - {/*Email*/} - - Adresse email - - {errors.email?.message} - - - {/*Mot de passe*/} - - Mot de passe - - {errors.password?.message} - - {wrongPasswordError && errorPassword} - - - - {/*Boutons*/} - - - - -
-
-
+ + + {/*Email*/} + + Adresse email + + {errors.email?.message as string} + + + {/*Mot de passe*/} + + Mot de passe + + {errors.password?.message as string} + {wrongPasswordError && + errorPassword} + + + {/*Boutons*/} + + + + + + +
); } diff --git a/src/components/form/RegisterForm.tsx b/src/components/form/RegisterForm.tsx index 2b7635d..b47d01d 100644 --- a/src/components/form/RegisterForm.tsx +++ b/src/components/form/RegisterForm.tsx @@ -10,7 +10,6 @@ import { FormErrorMessage, } from '@chakra-ui/react'; import {useRouter} from 'next/router'; -import {useState} from 'react'; import {signIn, SignInResponse} from 'next-auth/react'; import {RegisterData} from '@/models/form/RegisterData'; import {SubmitHandler, useForm} from 'react-hook-form'; @@ -48,137 +47,113 @@ export default function RegisterForm() { }), }; - fetch('/api/users', options).then(() => { - signIn('credentials', {email, password, redirect: false}).then( - (res: unknown) => { - const {ok: connexionSuccess} = res as SignInResponse; - - // TODO If success -> goto interactive form else login - router.push(connexionSuccess ? '/dashboard' : '/'); - }, - ); - }).catch((err) => console.error(err)); + fetch('/api/users', options) + .then(() => signIn('credentials', {email, password, redirect: false})) + .then((res: unknown) => { + const {ok: connexionSuccess} = res as SignInResponse; + router.push(connexionSuccess ? '/getting-start' : '/'); + }, + ) + .catch(err => console.error(err)); }; return (
- - Inscription - + Inscription {/*Prénom*/} - + Prénom - + {errors.firstName?.message as string} {/*Nom*/} - + Nom - + {errors.lastName?.message as string} {/*Email*/} - + Adresse email - + {errors.email?.message as string} {/*Date de naissance*/} - + Date de naissance - - { (errors.birthdate) ? {errors.birthdate.message as string} : "" } + + {(errors.birthdate) && + {errors.birthdate.message as string}} {/*Mot de passe*/} - + Mot de passe - + {errors.password?.message as string} {/*Mot de passe (2)*/} - + Confirmation du mot de passe - { - return ( - watch('password') === value || - 'Les mots de passe ne correspondent pas' - ); - }, - })} - /> + ( + watch('password') === value || + 'Les mots de passe ne correspondent pas' + ), + })}/> {errors.confirmPassword?.message as string} - - diff --git a/src/components/layout/dashboard/card_user/CardUser.tsx b/src/components/layout/dashboard/card_user/CardUser.tsx index cddfca3..495d1e4 100644 --- a/src/components/layout/dashboard/card_user/CardUser.tsx +++ b/src/components/layout/dashboard/card_user/CardUser.tsx @@ -8,19 +8,20 @@ import { Box, CardHeader, useToast, -} from "@chakra-ui/react"; -import Carousel from "../../../Carousel"; -import { BiHeart } from "react-icons/bi"; -import { RxCross1 } from "react-icons/rx"; -import { useMutation, useQuery } from "@tanstack/react-query"; -import PassionTagList from "@/components/layout/dashboard/card_user/PassionTagList"; -import { useState } from "react"; -import SearchFailCard from "./SearchFailCard"; -import LoadingPage from "@/components/LoadingPage"; +} from '@chakra-ui/react'; +import Carousel from '../../../Carousel'; +import {BiHeart} from 'react-icons/bi'; +import {RxCross1} from 'react-icons/rx'; +import {useMutation, useQuery} from '@tanstack/react-query'; +import PassionTagList + from '@/components/layout/dashboard/card_user/PassionTagList'; +import {useState} from 'react'; +import SearchFailCard from './SearchFailCard'; +import LoadingPage from '@/components/LoadingPage'; -export default function CardUser({ users, loggedUser, setMatch }) { +export default function CardUser({users, loggedUser, setMatch}) { const toast = useToast({ - position: "top", + position: 'top', duration: 2000, isClosable: true, }); @@ -29,8 +30,8 @@ export default function CardUser({ users, loggedUser, setMatch }) { const likeMutation = useMutation({ mutationFn: async (id) => { const likePostOptions = { - method: "POST", - headers: { "Content-Type": "application/json" }, + method: 'POST', + headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ idUser: loggedUser.id, idUserLiked: id, @@ -48,9 +49,9 @@ export default function CardUser({ users, loggedUser, setMatch }) { onSuccess: (data) => { if (data.error) { toast({ - title: "Erreur", - description: "Une erreur est survenue", - status: "error", + title: 'Erreur', + description: 'Une erreur est survenue', + status: 'error', }); return; } @@ -59,9 +60,9 @@ export default function CardUser({ users, loggedUser, setMatch }) { } setListUsers(listUsers.slice(1)); toast({ - title: "J'aime", - description: "Votre action a bien été prise en compte", - status: "success", + title: 'J\'aime', + description: 'Votre action a bien été prise en compte', + status: 'success', }); //tester si match et afficher un truc @@ -71,8 +72,8 @@ export default function CardUser({ users, loggedUser, setMatch }) { const dislikeMutation = useMutation({ mutationFn: async (id) => { const dislikePostOptions = { - method: "POST", - headers: { "Content-Type": "application/json" }, + method: 'POST', + headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ idUser: loggedUser.id, idUserDisliked: id, @@ -90,18 +91,18 @@ export default function CardUser({ users, loggedUser, setMatch }) { onSuccess: (data) => { if (data.error) { toast({ - title: "Erreur", - description: "Une erreur est survenue", - status: "error", + title: 'Erreur', + description: 'Une erreur est survenue', + status: 'error', duration: 2000, }); return; } setListUsers(listUsers.slice(1)); toast({ - title: "J'aime pas", - description: "Votre action a bien été prise en compte", - status: "success", + title: 'J\'aime pas', + description: 'Votre action a bien été prise en compte', + status: 'success', duration: 2000, }); }, @@ -113,93 +114,72 @@ export default function CardUser({ users, loggedUser, setMatch }) { data: listPassions, error: passionError, } = useQuery({ - queryKey: ["passions"], + queryKey: ['passions'], queryFn: async () => { return fetch(`/api/passions/`) - .then((res) => res.json()) - .catch((err) => { - return err; - }); + .then(res => res.json()) + .catch(err => err); }, }); const formateDateToAge = (birthdate: Date) => { const date = new Date(birthdate); - var ageDifMs = Date.now() - date.getTime(); - var ageDate = new Date(ageDifMs); // miliseconds from epoch + const ageDifMs = Date.now() - date.getTime(); + const ageDate = new Date(ageDifMs); // miliseconds from epoch return Math.abs(ageDate.getUTCFullYear() - 1970); }; - if (listUsers.length === 0) { - return ; - } - - if (likeMutation.isLoading || dislikeMutation.isLoading) { - return ; - } + if (listUsers.length === 0) return ; + if (likeMutation.isLoading || + dislikeMutation.isLoading) return ; return ( - - - - + + + + - - - - {listUsers[0].firstName} {listUsers[0].lastName},{" "} - {formateDateToAge(listUsers[0].birthdate)} ans - + + + + {listUsers[0].firstName} {listUsers[0].lastName},{' '} + {formateDateToAge(listUsers[0].birthdate)} ans + - - { - likeMutation.mutate(listUsers[0].id); - }} - > - - - { - dislikeMutation.mutate(listUsers[0].id); - }} - > - - + + } aria-label="like" + borderRadius={'1rem'} + onClick={() => likeMutation.mutate(listUsers[0].id) + }/> + } aria-label="dislike" + borderRadius={'1rem'} variant={'outline'} + onClick={() => dislikeMutation.mutate( + listUsers[0].id)}/> + - - - - A propos : - - "{listUsers[0].bio}" - + + + A propos : + + "{listUsers[0].bio}" + - - - Passions : - - {passionLoading ? ( - Chargement des passions... - ) : passionIsError ? ( - Erreur lors du chargement des passions - ) : ( - - )} - - - + + + Passions : + + {passionLoading + ? Chargement des passions... + : passionIsError + ? Erreur lors du chargement des passions + : + + } + + + ); } diff --git a/src/components/layout/dashboard/card_user/PassionTagList.tsx b/src/components/layout/dashboard/card_user/PassionTagList.tsx index da7d9f3..48070bd 100644 --- a/src/components/layout/dashboard/card_user/PassionTagList.tsx +++ b/src/components/layout/dashboard/card_user/PassionTagList.tsx @@ -1,4 +1,4 @@ -import { Badge, Flex, Tag } from "@chakra-ui/react"; +import {Flex, Tag} from '@chakra-ui/react'; type Props = { passions: string[]; @@ -6,22 +6,15 @@ type Props = { listPassions?: Object[]; }; -export default function PassionTagList({ - passions, - userPassions = [], - listPassions, -}: Props) { - return ( - +const PassionTagList = ({passions, userPassions = [], listPassions}: Props) => ( + {passions.map((passionID, index) => ( - - {listPassions?.find((passion) => passion.id === passionID)?.name} - + + {listPassions?.find((passion) => passion.id === passionID)?.name} + ))} - ); -} +); + +export default PassionTagList; \ No newline at end of file diff --git a/src/components/layout/dashboard/card_user/SearchFailCard.tsx b/src/components/layout/dashboard/card_user/SearchFailCard.tsx index 08306de..32119ff 100644 --- a/src/components/layout/dashboard/card_user/SearchFailCard.tsx +++ b/src/components/layout/dashboard/card_user/SearchFailCard.tsx @@ -1,8 +1,7 @@ -import { Card, Text, CardBody, CardHeader } from "@chakra-ui/react"; +import {Card, Text, CardBody, CardHeader} from '@chakra-ui/react'; -export default function SearchFailCard(props) { - return ( - +const SearchFailCard = () => ( + Aucun profil correspondant à vos critères @@ -10,5 +9,6 @@ export default function SearchFailCard(props) { - ); -} +); + +export default SearchFailCard; diff --git a/src/components/layout/dashboard/left_panel/LeftPanel.tsx b/src/components/layout/dashboard/left_panel/LeftPanel.tsx index 196698d..e617b61 100644 --- a/src/components/layout/dashboard/left_panel/LeftPanel.tsx +++ b/src/components/layout/dashboard/left_panel/LeftPanel.tsx @@ -1,93 +1,67 @@ -import {Card, Flex, Box, Image, Text, Spacer, Divider} from "@chakra-ui/react"; -import { useRouter } from "next/router"; +import {Card, Flex, Box, Image, Text, Spacer, Divider} from '@chakra-ui/react'; +import {useRouter} from 'next/router'; -import { AiFillMessage } from "react-icons/ai"; -import { BsFillPersonFill } from "react-icons/bs"; -import { BiLogOut } from "react-icons/bi"; -import { FaMapMarkedAlt } from "react-icons/fa"; +import {AiFillMessage} from 'react-icons/ai'; +import {BsFillPersonFill} from 'react-icons/bs'; +import {BiLogOut} from 'react-icons/bi'; +import {FaMapMarkedAlt} from 'react-icons/fa'; -import LeftPanelButton from "@/components/layout/dashboard/left_panel/LeftPanelButton"; -import { signOut } from "next-auth/react"; +import LeftPanelButton + from '@/components/layout/dashboard/left_panel/LeftPanelButton'; +import {signOut} from 'next-auth/react'; export default function LeftPanel(props) { const router = useRouter(); - const { user } = props; + const {user} = props; const formateDate = (dateString) => { - var options = { year: "numeric", month: "long", day: "numeric" }; + const options = {year: 'numeric', month: 'long', day: 'numeric'}; return new Date(dateString).toLocaleDateString([], options); }; return ( - - - - {user.images.length === 0 ? ( - - ) : ( - - )} - - - - {user.firstName} {user.lastName} - - - {formateDate(user.birthdate)} - - - - - "{user.bio}" - + + + + + + + + {user.firstName} {user.lastName} + + + {formateDate(user.birthdate)} + + + + "{user.bio}" + - - - - } - onClickHandler={() => router.push("/map")} - > - Carte - - } - onClickHandler={() => router.push("/dashboard")} - > - Messages - - } - onClickHandler={() => router.push("/profile")} - > - Profile - - } - onClickHandler={() => signOut({ callbackUrl: "/" })} - > - Deconnexion - + + + } + onClickHandler={() => router.push('/map')}> + Carte + + + } + onClickHandler={() => router.push('/dashboard')}> + Messages + + + } + onClickHandler={() => router.push('/profile')}> + Profil + + } + onClickHandler={() => signOut({callbackUrl: '/'})}> + Déconnexion + + - - + ); } diff --git a/src/components/layout/dashboard/left_panel/LeftPanelButton.tsx b/src/components/layout/dashboard/left_panel/LeftPanelButton.tsx index 1af57e4..23aba75 100644 --- a/src/components/layout/dashboard/left_panel/LeftPanelButton.tsx +++ b/src/components/layout/dashboard/left_panel/LeftPanelButton.tsx @@ -2,25 +2,20 @@ import {Button, ResponsiveValue} from '@chakra-ui/react'; import {ReactJSXElement} from '@emotion/react/types/jsx-namespace'; type Props = { - children?: ReactJSXElement + children?: ReactJSXElement | string onClickHandler: () => void leftIcon?: ReactJSXElement, variant?: ResponsiveValue<'link' | 'outline' | string | 'ghost' | 'solid' | 'unstyled'> } export default function LeftPanelButton(props: Props) { - const {children, onClickHandler, leftIcon: icon, variant = "ghost"} = props; + const {children, onClickHandler, leftIcon: icon, variant = 'ghost'} = props; return ( - + ); } \ No newline at end of file diff --git a/src/components/layout/home/HeroBanner.tsx b/src/components/layout/home/HeroBanner.tsx index 7ea8d2c..04ea00f 100644 --- a/src/components/layout/home/HeroBanner.tsx +++ b/src/components/layout/home/HeroBanner.tsx @@ -13,37 +13,29 @@ export default function HeroBanner() { const router = useRouter(); return ( - + Prêt(e) à trouver votre âme sœur ? - + Notre site de rencontre vous offre la possibilité de rencontrer - des personnes intéressantes et de trouver l'amour. Inscrivez-vous + des personnes intéressantes et de trouver l'amour. + Inscrivez-vous dès maintenant pour découvrir toutes nos fonctionnalités ! - - - happy couple + + happy couple diff --git a/src/components/layout/home/PresentationSection.tsx b/src/components/layout/home/PresentationSection.tsx index 181fb70..cb606a1 100644 --- a/src/components/layout/home/PresentationSection.tsx +++ b/src/components/layout/home/PresentationSection.tsx @@ -4,8 +4,7 @@ export default function PresentationSection() { return ( diff --git a/src/components/layout/map/MapComponent.tsx b/src/components/layout/map/MapComponent.tsx index 0323830..a65f5a3 100644 --- a/src/components/layout/map/MapComponent.tsx +++ b/src/components/layout/map/MapComponent.tsx @@ -1,69 +1,60 @@ -import { MapContainer, TileLayer, Marker, Popup } from "react-leaflet"; -import { Flex, Text, useToast } from "@chakra-ui/react"; -import MarkerClusterGroup from "@christopherpickering/react-leaflet-markercluster"; +import {MapContainer, TileLayer, Marker, Popup} from 'react-leaflet'; +import {Flex, Text, useToast} from '@chakra-ui/react'; +import MarkerClusterGroup + from '@christopherpickering/react-leaflet-markercluster'; -import "@christopherpickering/react-leaflet-markercluster/dist/styles.min.css"; +import '@christopherpickering/react-leaflet-markercluster/dist/styles.min.css'; -import MarkerBar from "./MarkerBar"; -import "leaflet/dist/leaflet.css"; +import MarkerBar from './MarkerBar'; +import 'leaflet/dist/leaflet.css'; export default function MapComponent(props: any) { - const { location, listBars } = props; + const {location, listBars} = props; - const toast = useToast({ position: "bottom" }); + const toast = useToast({position: 'bottom'}); - const idToastError = "error_location"; + const idToastError = 'error_location'; const userIcon = new L.Icon({ - iconUrl: "logo.svg", + iconUrl: 'logo.svg', iconSize: [35, 35], }); return ( - <> - {location[0] === null || location[1] === null ? ( - <> - {!toast.isActive(idToastError) - ? toast({ - title: "Erreur", - id: idToastError, - description: "Veuillez autoriser la localisation", - status: "error", - isClosable: false, - duration: 100000, - }) - : null} - - Veuillez autoriser la localisation - - - ) : ( - - - - {/* Pour le user */} - + <> + {location[0] === null || location[1] === null ? ( + <> + {!toast.isActive(idToastError) && + toast({ + title: 'Erreur', + id: idToastError, + description: 'Veuillez autoriser la localisation', + status: 'error', + isClosable: false, + duration: 100000, + })} + + Veuillez autoriser la localisation + + + ) : ( + + + + {/* Pour le user */} + - - {listBars.map((bar, index) => { - return ; - })} - - - - )} - + + {listBars.map((bar: any, index: number) => )} + + + + )} + ); } diff --git a/src/components/layout/map/MarkerBar.tsx b/src/components/layout/map/MarkerBar.tsx index b9bcbf5..e525012 100644 --- a/src/components/layout/map/MarkerBar.tsx +++ b/src/components/layout/map/MarkerBar.tsx @@ -1,6 +1,6 @@ import { Marker, Popup } from "react-leaflet"; import "leaflet/dist/leaflet.css"; -import { Box, Button, Card, CardBody, Text } from "@chakra-ui/react"; +import { Box, Button, Text } from "@chakra-ui/react"; export default function MarkerBar(props) { const { bar } = props; @@ -23,9 +23,7 @@ export default function MarkerBar(props) { {bar.name || '"Nom du bar"'} - + diff --git a/src/components/layout/profile/CustomCheckbox.tsx b/src/components/layout/profile/CustomCheckbox.tsx index 780ee58..bb7b215 100644 --- a/src/components/layout/profile/CustomCheckbox.tsx +++ b/src/components/layout/profile/CustomCheckbox.tsx @@ -4,43 +4,27 @@ import { Tag, TagLeftIcon, TagLabel, -} from "@chakra-ui/react"; +} from '@chakra-ui/react'; -import { IoAdd, IoRemove } from "react-icons/io5"; +import {IoAdd, IoRemove} from 'react-icons/io5'; export default function CustomCheckbox(props) { - const { text } = props; - const { state, getInputProps, getCheckboxProps, getLabelProps, htmlProps } = - useCheckbox(props); + const {text} = props; + const {state, getInputProps, getCheckboxProps, getLabelProps, htmlProps} = + useCheckbox(props); return ( - - - {state.isChecked ? ( - - + + + + + {state.isChecked + ? + : + } {text} - ) : ( - - - {text} - - )} - + ); } diff --git a/src/components/layout/profile/CustomEditable.tsx b/src/components/layout/profile/CustomEditable.tsx index 65c9ab9..89f39cb 100644 --- a/src/components/layout/profile/CustomEditable.tsx +++ b/src/components/layout/profile/CustomEditable.tsx @@ -6,52 +6,40 @@ import { FormErrorMessage, FormHelperText, FormLabel, -} from "@chakra-ui/react"; -import { Controller, ControllerProps } from "react-hook-form"; +} from '@chakra-ui/react'; +import {Controller, ControllerProps} from 'react-hook-form'; type CustomEditableProps = { label: string; isDisabled?: boolean; helperText?: string; -} & Omit; +} & Omit; export default function CustomEditable(props: CustomEditableProps) { const { defaultValue, label, name, - helperText = "", + helperText = '', isDisabled = false, ...controllerProps } = props; return ( - { - return ( - - - {label} - - - - - - {helperText} - {error?.message} - - ); - }} - /> + ( + + {label} + + + + + {helperText} + {error?.message} + + )}/> ); } diff --git a/src/components/layout/profile/CustomEditableArea.tsx b/src/components/layout/profile/CustomEditableArea.tsx index 945b71e..a6092fc 100644 --- a/src/components/layout/profile/CustomEditableArea.tsx +++ b/src/components/layout/profile/CustomEditableArea.tsx @@ -5,13 +5,13 @@ import { FormControl, FormErrorMessage, FormLabel, -} from "@chakra-ui/react"; -import { Controller, ControllerProps } from "react-hook-form"; +} from '@chakra-ui/react'; +import {Controller, ControllerProps} from 'react-hook-form'; type CustomEditableProps = { label: string; isDisabled?: boolean; -} & Omit; +} & Omit; export default function CustomEditableArea(props: CustomEditableProps) { const { @@ -23,32 +23,19 @@ export default function CustomEditableArea(props: CustomEditableProps) { } = props; return ( - { - return ( - - - {label} - - - - - - {error?.message} - - ); - }} - /> + ( + + {label} + + + + + {error?.message} + + )}/> ); } diff --git a/src/components/layout/profile/CustomFalseEditable.tsx b/src/components/layout/profile/CustomFalseEditable.tsx index faaa4bd..6a15e10 100644 --- a/src/components/layout/profile/CustomFalseEditable.tsx +++ b/src/components/layout/profile/CustomFalseEditable.tsx @@ -5,7 +5,7 @@ import { FormHelperText, FormLabel, UseEditableProps, -} from "@chakra-ui/react"; +} from '@chakra-ui/react'; type CustomEditableProps = { id: string; @@ -14,23 +14,16 @@ type CustomEditableProps = { } & UseEditableProps; export default function CustomEditable(props: CustomEditableProps) { - const { label, id, helperText = "", ...UseEditableProps } = props; + const {label, id, helperText = '', ...UseEditableProps} = props; return ( - - - {label} - - - - - {helperText} - + + {label} + + + + {helperText} + ); } diff --git a/src/components/layout/profile/CustomRadioGender.tsx b/src/components/layout/profile/CustomRadioGender.tsx index 157262b..f25ef6c 100644 --- a/src/components/layout/profile/CustomRadioGender.tsx +++ b/src/components/layout/profile/CustomRadioGender.tsx @@ -1,60 +1,35 @@ -import { FormLabel, HStack, Radio, RadioGroup } from "@chakra-ui/react"; -import { Gender } from "@prisma/client"; -import { Controller, ControllerProps } from "react-hook-form"; +import {FormLabel, HStack, Radio, RadioGroup} from '@chakra-ui/react'; +import {Gender} from '@prisma/client'; +import {Controller, ControllerProps} from 'react-hook-form'; type CustomRadioGenderProps = { label: string; -} & Omit; +} & Omit; export default function CustomRadioGender(props: CustomRadioGenderProps) { - const { defaultValue, label, name, ...controllerProps } = props; + const {defaultValue, label, name, ...controllerProps} = props; - const getTextGender = (gender: string) => { - switch (gender) { - case Gender.MALE: - return "Homme"; - case Gender.FEMALE: - return "Femme"; - case Gender.OTHER: - return "Autre"; - case Gender.UNKNOWN: - return "Non renseigné"; - } - }; + const genders = [ + {label: 'Homme', gender: Gender.MALE}, + {label: 'Femme', gender: Gender.FEMALE}, + {label: 'Autre', gender: Gender.OTHER}, + {label: 'Non renseigné', gender: Gender.UNKNOWN}, + ]; return ( - <> - - {label} - - { - return ( - - - {getTextGender(Gender.MALE)} - - {getTextGender(Gender.FEMALE)} - - - {getTextGender(Gender.OTHER)} - - - {getTextGender(Gender.UNKNOWN)} - - - - ); - }} - /> - + <> + {label} + ( + + + {genders.map(({label, gender}, index) => ( + {label} + ))} + + + )}/> + ); } diff --git a/src/components/layout/profile/CustomRangeSlider.tsx b/src/components/layout/profile/CustomRangeSlider.tsx index a5c6165..a00d6c5 100644 --- a/src/components/layout/profile/CustomRangeSlider.tsx +++ b/src/components/layout/profile/CustomRangeSlider.tsx @@ -6,10 +6,10 @@ import { RangeSliderThumb, RangeSliderTrack, Tooltip, -} from "@chakra-ui/react"; -import { Controller, ControllerProps } from "react-hook-form"; +} from '@chakra-ui/react'; +import {Controller, ControllerProps} from 'react-hook-form'; -import { FaGreaterThan, FaLessThan } from "react-icons/fa"; +import {FaGreaterThan, FaLessThan} from 'react-icons/fa'; type CustomRangeSliderProps = { label: string; @@ -19,7 +19,7 @@ type CustomRangeSliderProps = { showTooltipAge: boolean; setShowTooltipAge: React.Dispatch>; name: string; -} & Omit; +} & Omit; export default function CustomRangeSlider(props: CustomRangeSliderProps) { const { @@ -34,60 +34,40 @@ export default function CustomRangeSlider(props: CustomRangeSliderProps) { } = props; return ( - <> - - {label} - - ( - { - setSliderAgeValue(v); - onChange(v); - }} - onMouseEnter={() => setShowTooltipAge(true)} - onMouseLeave={() => setShowTooltipAge(false)} - > - - - - - - - - + <> + {label} + ( + { + setSliderAgeValue(v); + onChange(v); + }} + onMouseEnter={() => setShowTooltipAge(true)} + onMouseLeave={() => setShowTooltipAge(false)}> + + + + + + + + - - - - - - - )} - /> - + + + + + + + )}/> + ); } diff --git a/src/components/layout/profile/CustomSlider.tsx b/src/components/layout/profile/CustomSlider.tsx index d725d0a..54cb3c9 100644 --- a/src/components/layout/profile/CustomSlider.tsx +++ b/src/components/layout/profile/CustomSlider.tsx @@ -6,10 +6,10 @@ import { SliderThumb, SliderTrack, Tooltip, -} from "@chakra-ui/react"; -import { Controller, ControllerProps } from "react-hook-form"; +} from '@chakra-ui/react'; +import {Controller, ControllerProps} from 'react-hook-form'; -import { FaWalking } from "react-icons/fa"; +import {FaWalking} from 'react-icons/fa'; type CustomSliderProps = { label: string; @@ -19,7 +19,7 @@ type CustomSliderProps = { showTooltipDistance: boolean; setShowTooltipDistance: React.Dispatch>; name: string; -} & Omit; +} & Omit; export default function CustomSlider(props: CustomSliderProps) { const { @@ -34,47 +34,31 @@ export default function CustomSlider(props: CustomSliderProps) { } = props; return ( - <> - - {label} - - ( - { - setSliderDistanceValue(v); - onChange(v); - }} - onMouseEnter={() => setShowTooltipDistance(true)} - onMouseLeave={() => setShowTooltipDistance(false)} - > - - - - - - - - - - )} - /> - + <> + {label} + ( + { + setSliderDistanceValue(v); + onChange(v); + }} + onMouseEnter={() => setShowTooltipDistance(true)} + onMouseLeave={() => setShowTooltipDistance(false)}> + + + + + + + + + + )}/> + ); } diff --git a/src/components/layout/profile/ModalChoosePassion.tsx b/src/components/layout/profile/ModalChoosePassion.tsx index e1cfbea..aafb12f 100644 --- a/src/components/layout/profile/ModalChoosePassion.tsx +++ b/src/components/layout/profile/ModalChoosePassion.tsx @@ -13,104 +13,80 @@ import { useCheckboxGroup, useDisclosure, useToast, -} from "@chakra-ui/react"; -import { useQueryClient } from "@tanstack/react-query"; -import { RiEditBoxLine } from "react-icons/ri"; -import CustomCheckbox from "./CustomCheckbox"; +} from '@chakra-ui/react'; +import {useQueryClient} from '@tanstack/react-query'; +import {RiEditBoxLine} from 'react-icons/ri'; +import CustomCheckbox from './CustomCheckbox'; +import {Passion} from '@prisma/client'; export default function ModalChoosePassion(props) { - const { isOpen, onOpen, onClose } = useDisclosure(); - const { user, passions } = props; - const toast = useToast({ position: "top", isClosable: true }); + const {isOpen, onOpen, onClose} = useDisclosure(); + const {user, passions} = props; + const toast = useToast({position: 'top', isClosable: true}); const client = useQueryClient(); - const { value, getCheckboxProps } = useCheckboxGroup({ + const {value, getCheckboxProps} = useCheckboxGroup({ defaultValue: user.PassionID, }); const savePassions = (idPassionList) => { - let jsonPassions = { Passion: { connect: [] } }; + let jsonPassions = {Passion: {connect: []}}; idPassionList.forEach((id) => { - jsonPassions.Passion.connect.push({ id: id }); + jsonPassions.Passion.connect.push({id: id}); }); const options = { - method: "PATCH", - headers: { - "Content-Type": "application/json", - }, + method: 'PATCH', + headers: {'Content-Type': 'application/json'}, body: JSON.stringify(jsonPassions), }; fetch(`/api/users/${user.id}`, options) - .then((res) => res.json()) - .then((data) => { - toast({ - title: "Centres d'intérêts mis à jour", - status: "success", - duration: 9000, - }); - client.invalidateQueries("user"); - onClose(); - }) - .catch((err) => { - console.log(err); - }); + .then(res => res.json()) + .then(() => { + toast({ + title: 'Centres d\'intérêts mis à jour', + status: 'success', + duration: 9000, + }); + client.invalidateQueries('user'); + onClose(); + }) + .catch(err => console.log(err)); }; return ( - <> - + <> + - - - - Choix des centres d'intérèts - - - - {passions !== null ? ( - passions.map((passion, index) => { - return ( - - ); - }) - ) : ( - <> - )} - - + + + + Choix des centres d'intérêts + + + + {passions && ( + passions.map((passion: Passion) => ( + + ) + ) + )} + + - - - - - - + + + + + + ); } diff --git a/src/components/layout/profile/ModalModifyImages.tsx b/src/components/layout/profile/ModalModifyImages.tsx index 2e06a19..260a31e 100644 --- a/src/components/layout/profile/ModalModifyImages.tsx +++ b/src/components/layout/profile/ModalModifyImages.tsx @@ -13,66 +13,65 @@ import { ModalHeader, ModalOverlay, useDisclosure, - useQuery, useToast, -} from "@chakra-ui/react"; -import { useQueryClient } from "@tanstack/react-query"; -import { useState } from "react"; -import { RiEditBoxLine } from "react-icons/ri"; +} from '@chakra-ui/react'; +import {useQueryClient} from '@tanstack/react-query'; +import {useState} from 'react'; +import {RiEditBoxLine} from 'react-icons/ri'; export default function ModalModifyImages(props) { - const { isOpen, onOpen, onClose } = useDisclosure(); - const { images, user, userData, setUserData } = props; + const {isOpen, onOpen, onClose} = useDisclosure(); + const {images, user, userData, setUserData} = props; const [listImage, setlistImage] = useState(images); - const toast = useToast({ position: "top", isClosable: true }); + const toast = useToast({position: 'top', isClosable: true}); const client = useQueryClient(); const uploadImage = async (file) => { const body = new FormData(); - body.append("file", file); + body.append('file', file); const imagePostOptions = { - method: "POST", + method: 'POST', body, }; const imagePatchOptions = { - method: "PUT", - headers: { "Content-Type": "application/json" }, + method: 'PUT', + headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ images: [...listImage, `imageUsers/${file.name}`], }), }; fetch(`/api/file/uploadFile`, imagePostOptions) - .then((res) => { - fetch(`/api/users/${user.id}`, imagePatchOptions) - .then((res) => { - toast({ - title: `Ajout d'image effectué`, - status: "success", - isClosable: true, - }); - setlistImage([...listImage, `imageUsers/${file.name}`]); - // router.reload(); - }) - .catch(() => { - setIsLoading(false); - toast({ - title: `Erreur lors de l'ajout des images`, - status: "error", - isClosable: true, - }); + .then(res => { + fetch(`/api/users/${user.id}`, imagePatchOptions) + .then(res => { + toast({ + title: `Ajout d'image effectué`, + status: 'success', + isClosable: true, + }); + setlistImage([...listImage, `imageUsers/${file.name}`]); + // router.reload(); + }) + .catch(() => { + setIsLoading(false); + toast({ + title: `Erreur lors de l'ajout des images`, + status: 'error', + isClosable: true, + }); + }); + }) + .catch(err => { + toast({ + title: `Erreur lors de l'ajout des images`, + status: 'error', + isClosable: true, }); - }) - .catch((err) => { - toast({ - title: `Erreur lors de l'ajout des images`, - status: "error", - isClosable: true, + console.log(err); }); - console.log(err); - }); }; const deleteImage = async (fileName) => { @@ -85,121 +84,97 @@ export default function ModalModifyImages(props) { } const imageDeleteOptions = { - method: "DELETE", - body: JSON.stringify({ fileName: fileName.split("/").pop() }), + method: 'DELETE', + body: JSON.stringify({fileName: fileName.split('/').pop()}), }; fetch(`/api/file/deleteFile`, imageDeleteOptions).then((res) => { const imagePatchOptions = { - method: "PUT", - headers: { "Content-Type": "application/json" }, + method: 'PUT', + headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ images: [...listImage], }), }; fetch(`/api/users/${user.id}`, imagePatchOptions) - .then((res) => { - toast({ - title: `Suppression d'image effectué`, - status: "success", - isClosable: true, + .then((res) => { + toast({ + title: `Suppression d'image effectué`, + status: 'success', + isClosable: true, + }); + }) + .catch(() => { + toast({ + title: `Erreur lors de la suppression des images`, + status: 'error', + isClosable: true, + }); }); - }) - .catch(() => { - toast({ - title: `Erreur lors de la suppression des images`, - status: "error", - isClosable: true, - }); - }); }); }; return ( - <> - + <> + - - - - Modification des images - - - - {listImage.map((image, index) => ( - - - - - - - ))} - {listImage.length < 5 ? ( - - { - const date = new Date(); - const time = date.getTime(); + + + + Modification des images + + + + {listImage.map((image, index) => ( + + + + + + + ))} + {listImage.length < 5 && ( + + { + const date = new Date(); + const time = date.getTime(); - const file = target.files[0]; - const extension = file.name.split(".").pop(); - const newFile = new File( - [file], - `${user.id}_${time}.${extension}`, - { - type: file.type, - } - ); - uploadImage(newFile); - }} - > - - ) : ( - <> - )} - - + const file = target.files[0]; + const extension = file.name.split('.').pop(); + const newFile = new File( + [file], + `${user.id}_${time}.${extension}`, + { + type: file.type, + }, + ); + uploadImage(newFile); + }}/> + + )} + + - - - - - - + }}> + Save + + + + + ); } diff --git a/src/components/layout/profile/ProfileTagList.tsx b/src/components/layout/profile/ProfileTagList.tsx index 9ad92ef..0c5b052 100644 --- a/src/components/layout/profile/ProfileTagList.tsx +++ b/src/components/layout/profile/ProfileTagList.tsx @@ -5,7 +5,7 @@ export default function ProfileBadgeList(props) { return ( {userPassions.map((idPassion, index) => ( - + {passions !== null && passions !== undefined && passions.length > 0 ? passions.find((element) => element.id === idPassion).name : ""} diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 12aae89..f127d9b 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -3,6 +3,7 @@ import type { AppProps } from "next/app"; import { ChakraProvider } from "@chakra-ui/react"; import { SessionProvider } from "next-auth/react"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import theme from '@/styles/theme'; const queryClient = new QueryClient(); @@ -12,7 +13,7 @@ export default function App({ }: AppProps) { return ( - + diff --git a/src/pages/admin/settings.tsx b/src/pages/admin/settings.tsx index 8575a89..a91be6e 100644 --- a/src/pages/admin/settings.tsx +++ b/src/pages/admin/settings.tsx @@ -1,95 +1,83 @@ 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"; +} 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'; +import LoadingPage from '@/components/LoadingPage'; +import {Session} from '@/models/auth/Session'; export default function settings() { const router = useRouter(); - const toast = useToast({ position: "top", isClosable: true }); + const toast = useToast({position: 'top', isClosable: true}); const [isLoading, setIsLoading] = useState(false); const { handleSubmit, register, - formState: { errors, isSubmitting }, + formState: {errors, isSubmitting}, } = useForm(); const [userData, setUserData] = useState({}); + const {data: session, status} = useSession({required: true}); - const { data: session, status } = useSession(); - if (status === "unauthenticated") router.push("/login"); + if (status === "loading") return + if (status === 'authenticated') { + const {user} = session as unknown as Session; - if (status === "authenticated") { - const { user } = session as unknown as Session; - - if (user.role !== "ADMIN") router.push("/login"); + if (user.role !== 'ADMIN') router.push('/login'); const savePassion = (passion: any) => { const options = { - method: "POST", - headers: { "Content-Type": "application/json" }, + method: 'POST', + headers: {'Content-Type': 'application/json'}, body: JSON.stringify(passion), }; fetch(`/api/passions`, options) - .then((res) => { - setIsLoading(false); - toast({ - title: `Passion ajoutée`, - status: "success", + .then(res => { + setIsLoading(false); + toast({ + title: `Passion ajoutée`, + status: 'success', + }); + }) + .catch(err => { + setIsLoading(false); + toast({ + title: `Erreur lors de l'ajout`, + status: 'error', + }); }); - }) - .catch((err) => { - setIsLoading(false); - toast({ - title: `Erreur lors de l'ajout`, - status: "error", - }); - }); }; return ( - <> - - - Passion - - - {errors.name && errors.name.message} - - - - - + <> + + + Passion + + + {errors.name && errors.name.message as string} + + + + + ); } } diff --git a/src/pages/chat/[id].tsx b/src/pages/chat/[id].tsx index 527a684..086ee62 100644 --- a/src/pages/chat/[id].tsx +++ b/src/pages/chat/[id].tsx @@ -55,7 +55,7 @@ export default function ChatId() { - setText(evt.target.value) } value={text} /> + setText(evt.target.value)} value={text} /> diff --git a/src/styles/theme.ts b/src/styles/theme.ts new file mode 100644 index 0000000..9768ea3 --- /dev/null +++ b/src/styles/theme.ts @@ -0,0 +1,9 @@ +import {extendTheme, withDefaultColorScheme} from '@chakra-ui/react'; + + +const theme = extendTheme( + {}, + withDefaultColorScheme({ colorScheme: 'purple' }) +); + +export default theme; \ No newline at end of file