import { Box, Button, Divider, Flex, Heading, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, Text, useDisclosure, } from "@chakra-ui/react"; import { SetStateAction } from "react"; import { useQuery } from "@tanstack/react-query"; import { User } from "@prisma/client"; import Carousel from "@/components/Carousel"; import { MdWavingHand } from "react-icons/md"; import { formateDate } from "@/lib/formateDate"; import { Notification } from "@prisma/client"; import PassionTagList from "../card_user/PassionTagList"; type modalMatchProps = { key: string; loggedUser: User; notif: Notification; }; export default function ModalMatch({ notif, loggedUser }: modalMatchProps) { const handleClose = () => { const options = { method: "PATCH", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ notificationId: notif.id }), }; fetch(`/api/user/consultNotification`, options) .then((res) => res.json()) .catch((err) => console.log(err)); }; const { isOpen, onClose } = useDisclosure({ defaultIsOpen: true, onClose: () => { handleClose(); }, }); const { isLoading, isError, data: matchedUser, error, } = useQuery({ enabled: notif !== undefined, queryKey: ["matchUser"], queryFn: async () => { return fetch(`/api/users/${notif.MatchedUserID}`) .then((res) => { return res.json(); }) .catch((err) => { return err; }); }, }); const { isLoading: passionLoading, isError: passionIsError, data: listPassions, error: passionError, } = useQuery({ queryKey: ["passions"], queryFn: async () => { return fetch(`/api/passions/`) .then((res) => res.json()) .catch((err) => err); }, }); return ( <> {matchedUser && ( Vous avez un nouveau match {matchedUser.firstName} {matchedUser.lastName} {formateDate(matchedUser.birthdate)} "{matchedUser.bio}" Passions : {passionLoading ? ( Chargement des passions... ) : passionIsError ? ( Erreur lors du chargement des passions ) : ( )} )} ); }