mirror of
https://github.com/LucasVbr/meeting-app.git
synced 2026-05-13 17:21:53 +00:00
feat(Saluer on matchNotification ): Saluer bring you to chat with the user
This commit is contained in:
@@ -22,6 +22,9 @@ import { formateDate } from "@/lib/formateDate";
|
||||
import { Notification } from "@prisma/client";
|
||||
import PassionTagList from "../card_user/PassionTagList";
|
||||
|
||||
import { useRef } from "react";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
type modalMatchProps = {
|
||||
key: string;
|
||||
loggedUser: User;
|
||||
@@ -29,16 +32,25 @@ type modalMatchProps = {
|
||||
};
|
||||
|
||||
export default function ModalMatch({ notif, loggedUser }: modalMatchProps) {
|
||||
const salute = useRef(false);
|
||||
const router = useRouter();
|
||||
|
||||
const handleClose = () => {
|
||||
const options = {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ notificationId: notif.id }),
|
||||
body: JSON.stringify({
|
||||
notificationId: notif.id,
|
||||
salute: salute.current,
|
||||
}),
|
||||
};
|
||||
fetch(`/api/user/consultNotification`, options)
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
router.push(`chat/${data.chat.id}`);
|
||||
})
|
||||
.catch((err) => console.log(err));
|
||||
};
|
||||
|
||||
@@ -85,7 +97,7 @@ export default function ModalMatch({ notif, loggedUser }: modalMatchProps) {
|
||||
return (
|
||||
<>
|
||||
{matchedUser && (
|
||||
<Modal isOpen={isOpen} onClose={onClose}>
|
||||
<Modal isOpen={isOpen} onClose={onClose} scrollBehavior={"inside"}>
|
||||
<ModalOverlay backdropBlur="2px" />
|
||||
<ModalContent>
|
||||
<ModalHeader>Vous avez un nouveau match</ModalHeader>
|
||||
@@ -132,7 +144,10 @@ export default function ModalMatch({ notif, loggedUser }: modalMatchProps) {
|
||||
<Button
|
||||
leftIcon={<MdWavingHand />}
|
||||
variant={"ghost"}
|
||||
onClick={onClose}
|
||||
onClick={() => {
|
||||
salute.current = !salute.current;
|
||||
onClose();
|
||||
}}
|
||||
>
|
||||
Saluer
|
||||
</Button>
|
||||
|
||||
@@ -22,8 +22,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useSession } from "next-auth/react";
|
||||
import type { Session } from "@/models/auth/Session";
|
||||
import CardMatchedUser from "./CardMatchedUser";
|
||||
import { Router } from "next/router";
|
||||
import { log } from "console";
|
||||
import { useRouter } from "next/router";
|
||||
|
||||
type ModalInviteBarProps = {
|
||||
isOpen: boolean;
|
||||
@@ -38,6 +37,7 @@ export default function ModalInviteBar({
|
||||
}: ModalInviteBarProps) {
|
||||
const { data: session, status } = useSession();
|
||||
const toast = useToast();
|
||||
const router = useRouter();
|
||||
|
||||
const { value, getRadioProps, getRootProps } = useRadioGroup({
|
||||
defaultValue: "-1",
|
||||
@@ -73,7 +73,7 @@ export default function ModalInviteBar({
|
||||
});
|
||||
return;
|
||||
}
|
||||
console.log(data);
|
||||
router.push(`/chat/${data.message_sent.ChatID}`);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -100,8 +100,6 @@ export default function ModalInviteBar({
|
||||
},
|
||||
});
|
||||
|
||||
console.log(bar);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal
|
||||
@@ -145,7 +143,6 @@ export default function ModalInviteBar({
|
||||
const { user } = session as unknown as Session;
|
||||
inviteToBar.mutate(user.id);
|
||||
onClose();
|
||||
// Router.push("/chat");
|
||||
}}
|
||||
>
|
||||
Inviter
|
||||
|
||||
@@ -3,7 +3,7 @@ const { PrismaClient } = require("@prisma/client");
|
||||
const patch = async (req: any, res: any) => {
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const { notificationId } = req.body;
|
||||
const { notificationId, salute } = req.body;
|
||||
|
||||
try {
|
||||
const notification = await prisma.notification.update({
|
||||
@@ -15,7 +15,31 @@ const patch = async (req: any, res: any) => {
|
||||
},
|
||||
});
|
||||
|
||||
res.status(200).json(notification);
|
||||
let chat = null;
|
||||
if (!salute) {
|
||||
res.status(200).json({
|
||||
message: "notification has been consulted",
|
||||
notification: notification,
|
||||
});
|
||||
} else {
|
||||
chat = await prisma.chat.findFirst({
|
||||
where: {
|
||||
AND: [
|
||||
{ User: { some: { id: notification.MatchedUserID } } },
|
||||
{ User: { some: { id: notification.UserID } } },
|
||||
],
|
||||
},
|
||||
include: {
|
||||
User: true,
|
||||
},
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
message: "notification has been consulted",
|
||||
notification: notification,
|
||||
chat: chat,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(400).json({ message: "Something went wrong" });
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user