mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-07-09 15:08:06 +00:00
feat(invite Match to bar / create chat on match): Modal to invite match to bar/ create chat on match
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { log } from "console";
|
||||
|
||||
const { PrismaClient } = require("@prisma/client");
|
||||
|
||||
const post = async (req: any, res: any) => {
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const { idUser, idUserMatched, bar } = req.body;
|
||||
|
||||
try {
|
||||
const chat = await prisma.chat.findFirst({
|
||||
where: {
|
||||
AND: [
|
||||
{ User: { some: { id: idUser } } },
|
||||
{ User: { some: { id: idUserMatched } } },
|
||||
],
|
||||
},
|
||||
include: {
|
||||
User: true,
|
||||
},
|
||||
});
|
||||
|
||||
const message = await prisma.message.create({
|
||||
data: {
|
||||
text: `<!lon=${bar.geo_point_2d.lon},lat=${bar.geo_point_2d.lat},name=${bar.name}>`,
|
||||
Chat: {
|
||||
connect: {
|
||||
id: chat.id,
|
||||
},
|
||||
},
|
||||
User: {
|
||||
connect: {
|
||||
id: idUser,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
res
|
||||
.status(200)
|
||||
.json({ message: "invitation envoyée", message_sent: message });
|
||||
} catch (error) {
|
||||
res.status(400).json({ message: "Something went wrong", error: error });
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
};
|
||||
|
||||
export default (req: any, res: any) => {
|
||||
req.method === "POST"
|
||||
? post(req, res)
|
||||
: res.status(404).send({ message: "Wrong method, please use POST" });
|
||||
};
|
||||
@@ -50,9 +50,15 @@ const post = async (req, res) => {
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//faire une notification mais faut qu'on regarde un meilleur moyen dans la BD
|
||||
await prisma.chat.create({
|
||||
data: {
|
||||
User: {
|
||||
connect: [{ id: idUserLiked }, { id: idUser }],
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
|
||||
+27
-29
@@ -1,14 +1,20 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import dynamic from "next/dynamic";
|
||||
import { useToast } from "@chakra-ui/react";
|
||||
import "leaflet/dist/leaflet.css";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import type { Session } from "@/models/auth/Session";
|
||||
|
||||
import LoadingPage from "@/components/LoadingPage";
|
||||
import ErrorPage from "@/components/ErrorPage";
|
||||
import ErrorGeolocation from "@/components/ErrorGeolocation";
|
||||
import Navbar from "@/components/Navbar";
|
||||
import ErrorGeolocation from "@/components/ErrorGeoLocation";
|
||||
|
||||
const MapWithNoSSR = dynamic(
|
||||
() => import("../components/layout/map/MapComponent"),
|
||||
{
|
||||
ssr: false,
|
||||
}
|
||||
);
|
||||
|
||||
export default function Map() {
|
||||
const [location, setLocation] = useState([
|
||||
@@ -17,8 +23,6 @@ export default function Map() {
|
||||
]);
|
||||
|
||||
const [geolocationError, setGeolocationError] = useState(false);
|
||||
const toast = useToast({ position: "bottom" });
|
||||
const idSaveToast = "saved_location";
|
||||
const { data: session, status } = useSession();
|
||||
const [listBars, setListBars] = useState({} as unknown as any);
|
||||
|
||||
@@ -29,6 +33,7 @@ export default function Map() {
|
||||
error,
|
||||
} = useQuery({
|
||||
queryKey: ["LoggedUser"],
|
||||
refetchOnWindowFocus: false,
|
||||
enabled: status === "authenticated",
|
||||
queryFn: async () => {
|
||||
const { user } = session as unknown as Session;
|
||||
@@ -50,8 +55,11 @@ export default function Map() {
|
||||
error: errorListBars,
|
||||
} = useQuery({
|
||||
queryKey: ["listBars"],
|
||||
refetchOnWindowFocus: false,
|
||||
enabled: !isLoading && location[0] !== null,
|
||||
queryFn: async () => {
|
||||
///Utiliser api de noratim
|
||||
|
||||
let urlBars = new URL(
|
||||
"https://data.opendatasoft.com/api/v2/catalog/datasets/osm-fr-bars%40babel/exports/json?"
|
||||
);
|
||||
@@ -80,7 +88,6 @@ export default function Map() {
|
||||
});
|
||||
|
||||
const userSetLocation = useMutation({
|
||||
mutationKey: "userSetLocation",
|
||||
mutationFn: async (position: string) => {
|
||||
const pos = {
|
||||
location: position,
|
||||
@@ -94,14 +101,6 @@ export default function Map() {
|
||||
body: JSON.stringify(pos),
|
||||
})
|
||||
.then((res) => {
|
||||
// if (!toast.isActive(idSaveToast)) {
|
||||
// toast({
|
||||
// id: idSaveToast,
|
||||
// title: "Position enregistrée",
|
||||
// description: "Votre position a bien été enregistrée",
|
||||
// status: "success",
|
||||
// });
|
||||
// }
|
||||
res.json();
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -125,6 +124,13 @@ export default function Map() {
|
||||
}, [loggedUser]);
|
||||
|
||||
function successPosition(position: GeolocationPosition) {
|
||||
if (
|
||||
position.coords.latitude === location[0] &&
|
||||
position.coords.longitude === location[1]
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
setLocation([position.coords.latitude, position.coords.longitude]);
|
||||
setGeolocationError(false);
|
||||
|
||||
@@ -138,29 +144,21 @@ export default function Map() {
|
||||
setGeolocationError(true);
|
||||
}
|
||||
|
||||
const MapWithNoSSR = dynamic(
|
||||
() => import("../components/layout/map/MapComponent"),
|
||||
{
|
||||
ssr: false,
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
{geolocationError ? (
|
||||
<ErrorGeolocation />
|
||||
) : isError || isErrorListBars ? (
|
||||
<ErrorPage />
|
||||
) : isLoading || isLoadingListBars ? (
|
||||
) : isLoading ||
|
||||
isLoadingListBars ||
|
||||
location[0] === null ||
|
||||
location[1] === null ? (
|
||||
<LoadingPage />
|
||||
) : (
|
||||
<>
|
||||
<Navbar />
|
||||
<MapWithNoSSR
|
||||
location={location}
|
||||
loggedUser={loggedUser}
|
||||
listBars={listBars}
|
||||
/>
|
||||
<Navbar variant={"fixed"} />
|
||||
<MapWithNoSSR location={location} listBars={listBars} />
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
|
||||
+40
-30
@@ -9,15 +9,14 @@ import {
|
||||
Center,
|
||||
Container,
|
||||
Divider,
|
||||
Editable,
|
||||
Flex,
|
||||
FormHelperText,
|
||||
FormLabel,
|
||||
Text,
|
||||
useToast,
|
||||
VStack,
|
||||
} from "@chakra-ui/react";
|
||||
|
||||
import { formateDate } from "@/lib/formateDate";
|
||||
import ModalModifyImages from "@/components/layout/profile/ModalModifyImages";
|
||||
import ModalChoosePassion from "@/components/layout/profile/ModalChoosePassion";
|
||||
import ProfileTagList from "@/components/layout/profile/ProfileTagList";
|
||||
@@ -39,6 +38,7 @@ export default function UserProfile() {
|
||||
|
||||
const [currentlyLoading, setCurrentlyLoading] = useState(false);
|
||||
const [passions, setPassions] = useState([] as any[]);
|
||||
const [address, setAddress] = useState({} as any);
|
||||
|
||||
const [showTooltipAge, setShowTooltipAge] = useState(false);
|
||||
const [sliderAgeValue, setSliderAgeValue] = useState([[] as number[]]);
|
||||
@@ -86,6 +86,22 @@ export default function UserProfile() {
|
||||
},
|
||||
});
|
||||
|
||||
const { data: addressData, isSuccess: addressIsSuccess } = useQuery({
|
||||
queryKey: ["address"],
|
||||
enabled: Boolean(userData?.location),
|
||||
queryFn: async () => {
|
||||
const [lat, long] = userData.location.split(",");
|
||||
|
||||
return fetch(
|
||||
`https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=${lat}&lon=${long}`
|
||||
)
|
||||
.then((res) => res.json())
|
||||
.catch((err) => {
|
||||
return err;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
if (isLoading) {
|
||||
if (status === "unauthenticated") router.push("/login");
|
||||
return <LoadingPage />;
|
||||
@@ -131,7 +147,6 @@ export default function UserProfile() {
|
||||
status: "success",
|
||||
isClosable: true,
|
||||
});
|
||||
// router.reload();
|
||||
})
|
||||
.catch((err) => {
|
||||
setCurrentlyLoading(false);
|
||||
@@ -146,27 +161,19 @@ export default function UserProfile() {
|
||||
}
|
||||
};
|
||||
|
||||
const formateDate = (dateString: string) => {
|
||||
var options = { year: "numeric", month: "long", day: "numeric" };
|
||||
return new Date(dateString).toLocaleDateString([], options);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box bgColor={"purple.50"}>
|
||||
<Container justifyContent={"center"} maxW={"70rem"} mt={"1rem"}>
|
||||
<Flex flexDirection={"column"} alignItems={"center"} gap={"1rem"}>
|
||||
<Box width={"50%"}>
|
||||
{userData.images ? (
|
||||
<Carousel
|
||||
images={userData.images}
|
||||
borderRadius={"1rem"}
|
||||
></Carousel>
|
||||
) : (
|
||||
<Carousel
|
||||
images={userData.images}
|
||||
borderRadius={"1rem"}
|
||||
></Carousel>
|
||||
)}
|
||||
<Carousel
|
||||
images={
|
||||
userData.images
|
||||
? userData.images
|
||||
: ["blank_profile_picture.webp"]
|
||||
}
|
||||
borderRadius={"1rem"}
|
||||
></Carousel>
|
||||
</Box>
|
||||
<ModalModifyImages
|
||||
userData={userData}
|
||||
@@ -179,7 +186,12 @@ export default function UserProfile() {
|
||||
Modifiez les champs en les selectionnants
|
||||
</Text>
|
||||
|
||||
<Box as="form" onSubmit={handleSubmit(saveData)} width={"80%"}>
|
||||
<Box
|
||||
position={"relative"}
|
||||
as="form"
|
||||
onSubmit={handleSubmit(saveData)}
|
||||
width={"80%"}
|
||||
>
|
||||
<Flex width={"100%"} justify={"space-between"} mb={"1rem"}>
|
||||
<Box>
|
||||
<CustomEditable
|
||||
@@ -210,7 +222,7 @@ export default function UserProfile() {
|
||||
<Box>
|
||||
<CustomFalseEditable
|
||||
id="birthdate"
|
||||
defaultValue={
|
||||
value={
|
||||
userData.birthdate === undefined ||
|
||||
userData.birthdate === null
|
||||
? "Non renseigné"
|
||||
@@ -225,13 +237,12 @@ export default function UserProfile() {
|
||||
<Box>
|
||||
<CustomFalseEditable
|
||||
id="location"
|
||||
isDisabled={true}
|
||||
defaultValue={
|
||||
userData.location === null || userData.location === ""
|
||||
? "Rendez vous sur la carte"
|
||||
: userData.location
|
||||
value={
|
||||
!addressIsSuccess || addressData === undefined
|
||||
? "Rendez vous sur la carte !"
|
||||
: `${addressData.address.town}, ${addressData.address.county}, ${addressData.address.state}`
|
||||
}
|
||||
label={"Ville :"}
|
||||
label={"Adresse :"}
|
||||
helperText={
|
||||
"Ce champ est modifié automatiquement depuis la carte"
|
||||
}
|
||||
@@ -240,8 +251,7 @@ export default function UserProfile() {
|
||||
<Box>
|
||||
<CustomFalseEditable
|
||||
id="email"
|
||||
isDisabled={true}
|
||||
defaultValue={userData.email}
|
||||
value={userData.email}
|
||||
label={"Adresse mail :"}
|
||||
/>
|
||||
</Box>
|
||||
@@ -334,7 +344,7 @@ export default function UserProfile() {
|
||||
/> */}
|
||||
</Box>
|
||||
<Divider colorScheme={"purple"} />
|
||||
<Center gap={"1rem"} my={"1rem"}>
|
||||
<Center position={"sticky"} bottom={0} gap={"1rem"} my={"1rem"}>
|
||||
<Button
|
||||
colorScheme={"purple"}
|
||||
isLoading={currentlyLoading}
|
||||
|
||||
Reference in New Issue
Block a user