mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-12-05 17:30:50 +00:00
refactor: Set default colorScheme to purple
Took 1 hour 12 minutes
This commit is contained in:
@@ -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 <SearchFailCard />;
|
||||
}
|
||||
|
||||
if (likeMutation.isLoading || dislikeMutation.isLoading) {
|
||||
return <LoadingPage />;
|
||||
}
|
||||
if (listUsers.length === 0) return <SearchFailCard/>;
|
||||
if (likeMutation.isLoading ||
|
||||
dislikeMutation.isLoading) return <LoadingPage/>;
|
||||
|
||||
return (
|
||||
<Card w={"100%"} h={"100%"} borderRadius={"1rem"} overflow={"hidden"}>
|
||||
<CardHeader>
|
||||
<Carousel borderRadius={"1rem"} images={listUsers?.[0].images} />
|
||||
</CardHeader>
|
||||
<Card w={'100%'} h={'100%'} borderRadius={'1rem'} overflow={'hidden'}>
|
||||
<CardHeader>
|
||||
<Carousel borderRadius={'1rem'} images={listUsers?.[0].images}/>
|
||||
</CardHeader>
|
||||
|
||||
<CardBody>
|
||||
<Flex justify={"space-between"} mb={"20px"}>
|
||||
<Heading fontSize={"1.5rem"} fontWeight={"bold"} flexBasis={"70%"}>
|
||||
{listUsers[0].firstName} {listUsers[0].lastName},{" "}
|
||||
{formateDateToAge(listUsers[0].birthdate)} ans
|
||||
</Heading>
|
||||
<CardBody>
|
||||
<Flex justify={'space-between'} mb={'20px'}>
|
||||
<Heading fontSize={'1.5rem'} fontWeight={'bold'} flexBasis={'70%'}>
|
||||
{listUsers[0].firstName} {listUsers[0].lastName},{' '}
|
||||
{formateDateToAge(listUsers[0].birthdate)} ans
|
||||
</Heading>
|
||||
|
||||
<Flex gap={1}>
|
||||
<IconButton
|
||||
aria-label="like"
|
||||
borderRadius={"1rem"}
|
||||
colorScheme={"purple"}
|
||||
onClick={() => {
|
||||
likeMutation.mutate(listUsers[0].id);
|
||||
}}
|
||||
>
|
||||
<BiHeart />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
aria-label="dislike"
|
||||
borderRadius={"1rem"}
|
||||
colorScheme={"purple"}
|
||||
variant={"outline"}
|
||||
onClick={() => {
|
||||
dislikeMutation.mutate(listUsers[0].id);
|
||||
}}
|
||||
>
|
||||
<RxCross1 />
|
||||
</IconButton>
|
||||
<Flex gap={1}>
|
||||
<IconButton icon={<BiHeart/>} aria-label="like"
|
||||
borderRadius={'1rem'}
|
||||
onClick={() => likeMutation.mutate(listUsers[0].id)
|
||||
}/>
|
||||
<IconButton icon={<RxCross1/>} aria-label="dislike"
|
||||
borderRadius={'1rem'} variant={'outline'}
|
||||
onClick={() => dislikeMutation.mutate(
|
||||
listUsers[0].id)}/>
|
||||
</Flex>
|
||||
</Flex>
|
||||
</Flex>
|
||||
|
||||
<Box mb={"20px"}>
|
||||
<Heading size={"sm"} fontWeight={"bold"} mb="0.5rem">
|
||||
A propos :
|
||||
</Heading>
|
||||
<Text as="i">"{listUsers[0].bio}"</Text>
|
||||
</Box>
|
||||
<Box mb={'20px'}>
|
||||
<Heading size={'sm'} fontWeight={'bold'} mb="0.5rem">
|
||||
A propos :
|
||||
</Heading>
|
||||
<Text as="i">"{listUsers[0].bio}"</Text>
|
||||
</Box>
|
||||
|
||||
<Box>
|
||||
<Heading size={"sm"} fontWeight={"bold"}>
|
||||
Passions :
|
||||
</Heading>
|
||||
{passionLoading ? (
|
||||
<Text>Chargement des passions...</Text>
|
||||
) : passionIsError ? (
|
||||
<Text>Erreur lors du chargement des passions</Text>
|
||||
) : (
|
||||
<PassionTagList
|
||||
passions={listUsers[0].PassionID}
|
||||
userPassions={loggedUser.PassionID}
|
||||
listPassions={listPassions}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
</CardBody>
|
||||
</Card>
|
||||
<Box>
|
||||
<Heading size={'sm'} fontWeight={'bold'}>
|
||||
Passions :
|
||||
</Heading>
|
||||
{passionLoading
|
||||
? <Text>Chargement des passions...</Text>
|
||||
: passionIsError
|
||||
? <Text>Erreur lors du chargement des passions</Text>
|
||||
:
|
||||
<PassionTagList passions={listUsers[0].PassionID}
|
||||
userPassions={loggedUser.PassionID}
|
||||
listPassions={listPassions}/>
|
||||
}
|
||||
</Box>
|
||||
</CardBody>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<Flex gap={"0.5rem"} mt={"1vh"} flexWrap="wrap">
|
||||
const PassionTagList = ({passions, userPassions = [], listPassions}: Props) => (
|
||||
<Flex gap={'0.5rem'} mt={'1vh'} flexWrap="wrap">
|
||||
{passions.map((passionID, index) => (
|
||||
<Tag
|
||||
key={index}
|
||||
variant={userPassions.includes(passionID) ? "subtle" : "outline"}
|
||||
colorScheme={"purple"}
|
||||
>
|
||||
{listPassions?.find((passion) => passion.id === passionID)?.name}
|
||||
</Tag>
|
||||
<Tag variant={userPassions.includes(passionID) ? 'subtle' : 'outline'}
|
||||
key={index}>
|
||||
{listPassions?.find((passion) => passion.id === passionID)?.name}
|
||||
</Tag>
|
||||
))}
|
||||
</Flex>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export default PassionTagList;
|
||||
@@ -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 (
|
||||
<Card w={"100%"} h={"100%"} borderRadius={"1rem"} overflow={"hidden"}>
|
||||
const SearchFailCard = () => (
|
||||
<Card w={'100%'} h={'100%'} borderRadius={'1rem'} overflow={'hidden'}>
|
||||
<CardHeader> Aucun profil correspondant à vos critères </CardHeader>
|
||||
<CardBody>
|
||||
<Text as="b">
|
||||
@@ -10,5 +9,6 @@ export default function SearchFailCard(props) {
|
||||
</Text>
|
||||
</CardBody>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export default SearchFailCard;
|
||||
|
||||
@@ -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 (
|
||||
<Card
|
||||
width={"20vw"}
|
||||
height={"100%"}
|
||||
borderRadius={0}
|
||||
padding={"0px"}
|
||||
bg={"#faf9ff"}
|
||||
>
|
||||
<Flex direction={"column"} height={"100%"} margin={"10%"}>
|
||||
<Box>
|
||||
{user.images.length === 0 ? (
|
||||
<Image src={"/blank_profile_picture.webp"} borderRadius={"1rem"} />
|
||||
) : (
|
||||
<Image
|
||||
src={user.images[0]}
|
||||
borderRadius={"1rem"}
|
||||
objectFit={"contain"}
|
||||
width={"100%"}
|
||||
/>
|
||||
)}
|
||||
<Box mt={"2rem"}>
|
||||
<Flex align={"center"} justifyContent="space-between" mb={"1rem"}>
|
||||
<Text fontSize={"1.5rem"} fontWeight={"bold"}>
|
||||
{user.firstName} {user.lastName}
|
||||
</Text>
|
||||
<Text fontSize={"1rem"} fontWeight={"bold"}>
|
||||
{formateDate(user.birthdate)}
|
||||
</Text>
|
||||
</Flex>
|
||||
<Divider colorScheme={"purple"} mb={"1rem"} />
|
||||
<Text as="i" fontWeight={"bold"}>
|
||||
"{user.bio}"
|
||||
</Text>
|
||||
<Card width={'20vw'} height={'100%'} borderRadius={0} padding={'0px'}
|
||||
bg={'#faf9ff'}>
|
||||
<Flex direction={'column'} height={'100%'} margin={'10%'}>
|
||||
<Box>
|
||||
<Image src={user.images[0] ?? '/blank_profile_picture.webp'}
|
||||
objectFit={'contain'} borderRadius={'1rem'}/>
|
||||
<Box mt={'2rem'}>
|
||||
<Flex align={'center'} justifyContent="space-between" mb={'1rem'}>
|
||||
<Text fontSize={'1.5rem'} fontWeight={'bold'}>
|
||||
{user.firstName} {user.lastName}
|
||||
</Text>
|
||||
<Text fontSize={'1rem'} fontWeight={'bold'}>
|
||||
{formateDate(user.birthdate)}
|
||||
</Text>
|
||||
</Flex>
|
||||
<Divider mb={'1rem'}/>
|
||||
<Text as="i" fontWeight={'bold'}>"{user.bio}"</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
<Spacer />
|
||||
<Flex
|
||||
gap={2}
|
||||
direction={"column"}
|
||||
mt={"1vh"}
|
||||
spacing={3.5}
|
||||
alignContent={"bottom"}
|
||||
>
|
||||
<LeftPanelButton
|
||||
leftIcon={<FaMapMarkedAlt />}
|
||||
onClickHandler={() => router.push("/map")}
|
||||
>
|
||||
Carte
|
||||
</LeftPanelButton>
|
||||
<LeftPanelButton
|
||||
leftIcon={<AiFillMessage />}
|
||||
onClickHandler={() => router.push("/dashboard")}
|
||||
>
|
||||
Messages
|
||||
</LeftPanelButton>
|
||||
<LeftPanelButton
|
||||
leftIcon={<BsFillPersonFill />}
|
||||
onClickHandler={() => router.push("/profile")}
|
||||
>
|
||||
Profile
|
||||
</LeftPanelButton>
|
||||
<LeftPanelButton
|
||||
variant={"outline"}
|
||||
leftIcon={<BiLogOut />}
|
||||
onClickHandler={() => signOut({ callbackUrl: "/" })}
|
||||
>
|
||||
Deconnexion
|
||||
</LeftPanelButton>
|
||||
<Spacer/>
|
||||
<Flex gap={2} direction={'column'} mt={'1vh'}
|
||||
spacing={3.5} alignContent={'bottom'}>
|
||||
<LeftPanelButton leftIcon={<FaMapMarkedAlt/>}
|
||||
onClickHandler={() => router.push('/map')}>
|
||||
Carte
|
||||
</LeftPanelButton>
|
||||
|
||||
<LeftPanelButton leftIcon={<AiFillMessage/>}
|
||||
onClickHandler={() => router.push('/dashboard')}>
|
||||
Messages
|
||||
</LeftPanelButton>
|
||||
|
||||
<LeftPanelButton leftIcon={<BsFillPersonFill/>}
|
||||
onClickHandler={() => router.push('/profile')}>
|
||||
Profil
|
||||
</LeftPanelButton>
|
||||
<LeftPanelButton variant={'outline'} leftIcon={<BiLogOut/>}
|
||||
onClickHandler={() => signOut({callbackUrl: '/'})}>
|
||||
Déconnexion
|
||||
</LeftPanelButton>
|
||||
</Flex>
|
||||
</Flex>
|
||||
</Flex>
|
||||
</Card>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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 (
|
||||
<Button
|
||||
colorScheme={'purple'}
|
||||
variant={variant}
|
||||
width={'100%'}
|
||||
justifyContent={'left'}
|
||||
onClick={onClickHandler}
|
||||
leftIcon={icon}
|
||||
fontWeight={'bold'}
|
||||
fontSize={'1.2rem'}
|
||||
>{children}</Button>
|
||||
<Button variant={variant} width={'100%'} justifyContent={'left'}
|
||||
onClick={onClickHandler} leftIcon={icon} fontWeight={'bold'}
|
||||
fontSize={'1.2rem'}>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user