mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-05-13 17:21:53 +00:00
feat(cardUser with listOfUserFetched): cardUser with listOfUserFetched
users fetched using following parameters : preference (HOMME en dur
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 140 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.0 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 127 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 53 KiB |
@@ -11,41 +11,75 @@ import {
|
|||||||
import Carousel from "../../../Carousel";
|
import Carousel from "../../../Carousel";
|
||||||
import { BiHeart } from "react-icons/bi";
|
import { BiHeart } from "react-icons/bi";
|
||||||
import { RxCross1 } from "react-icons/rx";
|
import { RxCross1 } from "react-icons/rx";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import PassionTagList from "@/components/layout/dashboard/card_user/PassionTagList";
|
import PassionTagList from "@/components/layout/dashboard/card_user/PassionTagList";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
export default function CardUser(props) {
|
export default function CardUser(props) {
|
||||||
const { user } = props;
|
const { user, loggedUser, userLiked, setLiked, userDisliked, setDisliked } =
|
||||||
|
props;
|
||||||
|
|
||||||
const interestingUser = {
|
const [hidden, setHidden] = useState(false);
|
||||||
lastName: "dujardin",
|
|
||||||
firstName: "jean",
|
const {
|
||||||
age: 19,
|
isLoading: passionLoading,
|
||||||
aPropos: "Je suis une personne fictive, pas tres fictive",
|
isError: passionIsError,
|
||||||
images: ["/401446.webp", "/135538.webp"],
|
data: listPassions,
|
||||||
passions: ["Sport", "Piscine", "Formule1"],
|
error: passionError,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["passions"],
|
||||||
|
queryFn: async () => {
|
||||||
|
return fetch(`/api/passions/`)
|
||||||
|
.then((res) => res.json())
|
||||||
|
.catch((err) => {
|
||||||
|
return err;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const formateDateToAge = (birthdate) => {
|
||||||
|
const date = new Date(birthdate);
|
||||||
|
var ageDifMs = Date.now() - date.getTime();
|
||||||
|
var ageDate = new Date(ageDifMs); // miliseconds from epoch
|
||||||
|
return Math.abs(ageDate.getUTCFullYear() - 1970);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card w={"100%"} h={"100%"} borderRadius={"1rem"} overflow={"hidden"}>
|
<Card
|
||||||
|
// position={"absolute"}
|
||||||
|
w={"100%"}
|
||||||
|
h={"100%"}
|
||||||
|
borderRadius={"1rem"}
|
||||||
|
overflow={"hidden"}
|
||||||
|
hidden={hidden}
|
||||||
|
>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<Carousel borderRadius={"1rem"} images={interestingUser.images} />
|
<Carousel borderRadius={"1rem"} images={user.images} />
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<Flex justify={"space-between"} mb={"20px"}>
|
<Flex justify={"space-between"} mb={"20px"}>
|
||||||
<Heading fontSize={"1.5rem"} fontWeight={"bold"} flexBasis={"70%"}>
|
<Heading fontSize={"1.5rem"} fontWeight={"bold"} flexBasis={"70%"}>
|
||||||
{interestingUser.firstName} {interestingUser.lastName},{" "}
|
{user.firstName} {user.lastName}, {formateDateToAge(user.birthdate)}{" "}
|
||||||
{interestingUser.age}ans
|
ans
|
||||||
</Heading>
|
</Heading>
|
||||||
|
|
||||||
<Flex gap={1}>
|
<Flex gap={1}>
|
||||||
<IconButton borderRadius={"1rem"} colorScheme={"purple"}>
|
<IconButton
|
||||||
|
borderRadius={"1rem"}
|
||||||
|
colorScheme={"purple"}
|
||||||
|
onClick={() => {
|
||||||
|
// setLiked([...userLiked, user.id]);
|
||||||
|
setHidden(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
<BiHeart />
|
<BiHeart />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<IconButton
|
||||||
borderRadius={"1rem"}
|
borderRadius={"1rem"}
|
||||||
colorScheme={"purple"}
|
colorScheme={"purple"}
|
||||||
variant={"outline"}
|
variant={"outline"}
|
||||||
|
// onClick={setDisiked([...userDisliked, user.id])}
|
||||||
>
|
>
|
||||||
<RxCross1 />
|
<RxCross1 />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
@@ -53,20 +87,27 @@ export default function CardUser(props) {
|
|||||||
</Flex>
|
</Flex>
|
||||||
|
|
||||||
<Box mb={"20px"}>
|
<Box mb={"20px"}>
|
||||||
<Heading size={"sm"} fontWeight={"bold"}>
|
<Heading size={"sm"} fontWeight={"bold"} mb="0.5rem">
|
||||||
A propos :
|
A propos :
|
||||||
</Heading>
|
</Heading>
|
||||||
<Text>{interestingUser.aPropos}</Text>
|
<Text as="i">"{user.bio}"</Text>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Box>
|
<Box>
|
||||||
<Heading size={"sm"} fontWeight={"bold"}>
|
<Heading size={"sm"} fontWeight={"bold"}>
|
||||||
Passions :
|
Passions :
|
||||||
</Heading>
|
</Heading>
|
||||||
<PassionTagList
|
{passionLoading ? (
|
||||||
passions={interestingUser.passions}
|
<Text>Chargement des passions...</Text>
|
||||||
userPassions={user.passions}
|
) : passionIsError ? (
|
||||||
/>
|
<Text>Erreur lors du chargement des passions</Text>
|
||||||
|
) : (
|
||||||
|
<PassionTagList
|
||||||
|
passions={user.PassionID}
|
||||||
|
userPassions={loggedUser.PassionID}
|
||||||
|
listPassions={listPassions}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -3,18 +3,23 @@ import { Badge, Flex, Tag } from "@chakra-ui/react";
|
|||||||
type Props = {
|
type Props = {
|
||||||
passions: string[];
|
passions: string[];
|
||||||
userPassions?: string[];
|
userPassions?: string[];
|
||||||
|
listPassions?: Object[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function PassionTagList({ passions, userPassions = [] }: Props) {
|
export default function PassionTagList({
|
||||||
|
passions,
|
||||||
|
userPassions = [],
|
||||||
|
listPassions,
|
||||||
|
}: Props) {
|
||||||
return (
|
return (
|
||||||
<Flex gap={"0.5rem"} mt={"1vh"}>
|
<Flex gap={"0.5rem"} mt={"1vh"} flexWrap="wrap">
|
||||||
{passions.map((passion, index) => (
|
{passions.map((passionID, index) => (
|
||||||
<Tag
|
<Tag
|
||||||
key={index}
|
key={index}
|
||||||
variant={userPassions.includes(passion) ? "subtle" : "outline"}
|
variant={userPassions.includes(passionID) ? "subtle" : "outline"}
|
||||||
colorScheme={"purple"}
|
colorScheme={"purple"}
|
||||||
>
|
>
|
||||||
{passion}
|
{listPassions?.find((passion) => passion.id === passionID)?.name}
|
||||||
</Tag>
|
</Tag>
|
||||||
))}
|
))}
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { Card, Text, CardBody, CardHeader } from "@chakra-ui/react";
|
||||||
|
|
||||||
|
export default function SearchFailCard(props) {
|
||||||
|
return (
|
||||||
|
<Card w={"100%"} h={"100%"} borderRadius={"1rem"} overflow={"hidden"}>
|
||||||
|
<CardHeader> Aucun profil correspondant à vos critères </CardHeader>
|
||||||
|
<CardBody>
|
||||||
|
<Text as="b">
|
||||||
|
Modifiez vos critères de recherche ou attendez de nouveaux inscrits
|
||||||
|
</Text>
|
||||||
|
</CardBody>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -36,7 +36,11 @@ export default function LeftPanel(props) {
|
|||||||
>
|
>
|
||||||
<Flex direction={"column"} height={"100%"} margin={"10%"}>
|
<Flex direction={"column"} height={"100%"} margin={"10%"}>
|
||||||
<Box>
|
<Box>
|
||||||
<Image src={user.images[0]} borderRadius={"1rem"} />
|
{user.images.length === 0 ? (
|
||||||
|
<Image src={"/blank_profile_picture.webp"} borderRadius={"1rem"} />
|
||||||
|
) : (
|
||||||
|
<Image src={user.images[0]} borderRadius={"1rem"} />
|
||||||
|
)}
|
||||||
<Box mt={"2rem"}>
|
<Box mt={"2rem"}>
|
||||||
<Flex align={"center"} justifyContent="space-between" mb={"1rem"}>
|
<Flex align={"center"} justifyContent="space-between" mb={"1rem"}>
|
||||||
<Text fontSize={"1.5rem"} fontWeight={"bold"}>
|
<Text fontSize={"1.5rem"} fontWeight={"bold"}>
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
const { PrismaClient } = require("@prisma/client");
|
||||||
|
|
||||||
|
const get = async (req, res) => {
|
||||||
|
const { preference, excludedId } = req.query;
|
||||||
|
const prisma = new PrismaClient();
|
||||||
|
// a terme mettre l'age, la distance
|
||||||
|
const users = await prisma.user.findMany({
|
||||||
|
where: {
|
||||||
|
AND: [
|
||||||
|
{ gender: { equals: preference } },
|
||||||
|
{ images: { isEmpty: false }, NOT: { id: { equals: excludedId } } },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
res.status(200).send(users);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default (req, res) => {
|
||||||
|
req.method === "GET"
|
||||||
|
? get(req, res)
|
||||||
|
: res.status(404).send({ message: "Wrong method, please use GET" });
|
||||||
|
};
|
||||||
+100
-39
@@ -1,57 +1,118 @@
|
|||||||
import { Grid, GridItem, Text, Box } from "@chakra-ui/react";
|
import { Grid, GridItem, Text, Box, useToast } from "@chakra-ui/react";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
import type { Session } from "@/models/auth/Session";
|
import type { Session } from "@/models/auth/Session";
|
||||||
import CardUser from "../components/layout/dashboard/card_user/CardUser";
|
import CardUser from "../components/layout/dashboard/card_user/CardUser";
|
||||||
|
import SearchFailCard from "../components/layout/dashboard/card_user/SearchFailCard";
|
||||||
|
|
||||||
import LeftPanel from "../components/layout/dashboard/left_panel/LeftPanel";
|
import LeftPanel from "../components/layout/dashboard/left_panel/LeftPanel";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import { websiteName } from "@/lib/constants";
|
import { websiteName } from "@/lib/constants";
|
||||||
import Navbar from "@/components/Navbar";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import LoadingPage from "@/components/LoadingPage";
|
||||||
|
|
||||||
export default function Dashboard() {
|
export default function Dashboard() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const toast = useToast({ position: "top", isClosable: true });
|
||||||
|
const [liked, setLiked] = useState(null);
|
||||||
|
const [disliked, setDisliked] = useState(null);
|
||||||
|
|
||||||
const { data: session, status } = useSession();
|
const { data: session, status } = useSession();
|
||||||
|
|
||||||
if (status === "loading") return <Text>Loading...</Text>;
|
const {
|
||||||
if (status === "unauthenticated") router.push("/login");
|
isLoading,
|
||||||
|
isError,
|
||||||
|
data: loggedUser,
|
||||||
|
error,
|
||||||
|
} = useQuery({
|
||||||
|
queryKey: ["LoggedUser"],
|
||||||
|
enabled: status === "authenticated",
|
||||||
|
queryFn: async () => {
|
||||||
|
const { user } = session as unknown as Session;
|
||||||
|
|
||||||
if (status === "authenticated") {
|
return fetch(`/api/users/${user.id}`)
|
||||||
const { user } = session as unknown as Session;
|
.then((res) => res.json())
|
||||||
|
.catch((err) => {
|
||||||
|
return err;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// il faudra l'enlever
|
const {
|
||||||
const refinedUser = {
|
data: listUsers,
|
||||||
...user,
|
isError: isErrorListUsers,
|
||||||
age: 21,
|
isLoading: isLoadingListUsers,
|
||||||
aPropos: "Je suis la personne fictive la plus fictive",
|
error: errorListUsers,
|
||||||
images: ["135538.webp"],
|
} = useQuery({
|
||||||
passions: ["Sport", "Voiture", "Cuisine"],
|
queryKey: ["ListUsers"],
|
||||||
};
|
enabled: status === "authenticated" && !isLoading,
|
||||||
|
queryFn: async () => {
|
||||||
|
return fetch(
|
||||||
|
`/api/user/userDashboard?preference=${loggedUser.gender}&excludedId=${loggedUser.id}`
|
||||||
|
) //exclure les profils déjà like ou dislike
|
||||||
|
.then((res) => res.json())
|
||||||
|
.catch((err) => {
|
||||||
|
return err;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
if (isLoading) {
|
||||||
<>
|
if (status === "unauthenticated") router.push("/login");
|
||||||
<Head>
|
return <LoadingPage />;
|
||||||
<title>{websiteName} | Dashboard</title>
|
|
||||||
</Head>
|
|
||||||
|
|
||||||
<Grid
|
|
||||||
templateColumns={"repeat(5, 1fr)"}
|
|
||||||
templateRows={"repeat(2, 1fr)"}
|
|
||||||
gap={5}
|
|
||||||
minH={"100vh"}
|
|
||||||
>
|
|
||||||
<GridItem area={"1 / 1 / 3 / 2"}>
|
|
||||||
<LeftPanel user={user} />
|
|
||||||
</GridItem>
|
|
||||||
<GridItem area={"1 / 2 / 3 / 4"}>
|
|
||||||
<Box py={3}>
|
|
||||||
<CardUser user={refinedUser} />
|
|
||||||
</Box>
|
|
||||||
</GridItem>
|
|
||||||
<GridItem area={"1 / 4 / 2 / 6"}>{/*Right top*/}</GridItem>
|
|
||||||
<GridItem area={"2 / 4 / 3 / 6"}>{/*Right Bottom*/}</GridItem>
|
|
||||||
</Grid>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isError) {
|
||||||
|
toast({
|
||||||
|
title: `Erreur lors de la récupération des données du profil`,
|
||||||
|
status: "error",
|
||||||
|
position: "top",
|
||||||
|
});
|
||||||
|
if (status === "unauthenticated") router.push("/");
|
||||||
|
return <span>Error: {error.message}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Head>
|
||||||
|
<title>{websiteName} | Dashboard</title>
|
||||||
|
</Head>
|
||||||
|
|
||||||
|
<Grid
|
||||||
|
templateColumns={"repeat(5, 1fr)"}
|
||||||
|
templateRows={"repeat(2, 1fr)"}
|
||||||
|
gap={5}
|
||||||
|
minH={"100vh"}
|
||||||
|
>
|
||||||
|
<GridItem area={"1 / 1 / 3 / 2"}>
|
||||||
|
<LeftPanel user={loggedUser} />
|
||||||
|
</GridItem>
|
||||||
|
<GridItem area={"1 / 2 / 3 / 4"}>
|
||||||
|
<Box py={3}>
|
||||||
|
{isLoadingListUsers ? (
|
||||||
|
<LoadingPage />
|
||||||
|
) : listUsers.length === 0 && !isErrorListUsers ? (
|
||||||
|
<SearchFailCard />
|
||||||
|
) : (
|
||||||
|
listUsers.map((user: any) => (
|
||||||
|
<CardUser
|
||||||
|
key={user.id}
|
||||||
|
user={user}
|
||||||
|
loggedUser={loggedUser}
|
||||||
|
userLiked={liked}
|
||||||
|
setLiked={setLiked}
|
||||||
|
userDisliked={disliked}
|
||||||
|
setDisliked={setDisliked}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
</GridItem>
|
||||||
|
<GridItem area={"1 / 4 / 2 / 6"}>{/*Right top*/}</GridItem>
|
||||||
|
<GridItem area={"2 / 4 / 3 / 6"}>{/*Right Bottom*/}</GridItem>
|
||||||
|
</Grid>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ export default function UserProfile() {
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
// faire un useEffect ou je fetch user
|
|
||||||
|
|
||||||
const { data: session, status } = useSession();
|
const { data: session, status } = useSession();
|
||||||
|
|
||||||
@@ -170,21 +169,11 @@ export default function UserProfile() {
|
|||||||
></Carousel>
|
></Carousel>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
{/* {modal} */}
|
<ModalModifyImages
|
||||||
|
userData={userData}
|
||||||
{!userData.images ? (
|
user={userData}
|
||||||
<ModalModifyImages
|
images={userData.images}
|
||||||
userData={userData}
|
/>
|
||||||
user={userData}
|
|
||||||
images={userData.images}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<ModalModifyImages
|
|
||||||
userData={userData}
|
|
||||||
user={userData}
|
|
||||||
images={userData.images}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Divider colorScheme={"purple"} />
|
<Divider colorScheme={"purple"} />
|
||||||
<Text align={"center"} as="i" color={"grey"}>
|
<Text align={"center"} as="i" color={"grey"}>
|
||||||
@@ -267,7 +256,8 @@ export default function UserProfile() {
|
|||||||
color={"grey"}
|
color={"grey"}
|
||||||
isDisabled={true}
|
isDisabled={true}
|
||||||
defaultValue={
|
defaultValue={
|
||||||
userData.birthdate === undefined
|
userData.birthdate === undefined ||
|
||||||
|
userData.birthdate === null
|
||||||
? "Non renseigné"
|
? "Non renseigné"
|
||||||
: formateDate(userData.birthdate.toString())
|
: formateDate(userData.birthdate.toString())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user