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 { Notification } from "@prisma/client";
|
||||||
import PassionTagList from "../card_user/PassionTagList";
|
import PassionTagList from "../card_user/PassionTagList";
|
||||||
|
|
||||||
|
import { useRef } from "react";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
type modalMatchProps = {
|
type modalMatchProps = {
|
||||||
key: string;
|
key: string;
|
||||||
loggedUser: User;
|
loggedUser: User;
|
||||||
@@ -29,16 +32,25 @@ type modalMatchProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function ModalMatch({ notif, loggedUser }: modalMatchProps) {
|
export default function ModalMatch({ notif, loggedUser }: modalMatchProps) {
|
||||||
|
const salute = useRef(false);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
const options = {
|
const options = {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ notificationId: notif.id }),
|
body: JSON.stringify({
|
||||||
|
notificationId: notif.id,
|
||||||
|
salute: salute.current,
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
fetch(`/api/user/consultNotification`, options)
|
fetch(`/api/user/consultNotification`, options)
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
|
.then((data) => {
|
||||||
|
router.push(`chat/${data.chat.id}`);
|
||||||
|
})
|
||||||
.catch((err) => console.log(err));
|
.catch((err) => console.log(err));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -85,7 +97,7 @@ export default function ModalMatch({ notif, loggedUser }: modalMatchProps) {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{matchedUser && (
|
{matchedUser && (
|
||||||
<Modal isOpen={isOpen} onClose={onClose}>
|
<Modal isOpen={isOpen} onClose={onClose} scrollBehavior={"inside"}>
|
||||||
<ModalOverlay backdropBlur="2px" />
|
<ModalOverlay backdropBlur="2px" />
|
||||||
<ModalContent>
|
<ModalContent>
|
||||||
<ModalHeader>Vous avez un nouveau match</ModalHeader>
|
<ModalHeader>Vous avez un nouveau match</ModalHeader>
|
||||||
@@ -132,7 +144,10 @@ export default function ModalMatch({ notif, loggedUser }: modalMatchProps) {
|
|||||||
<Button
|
<Button
|
||||||
leftIcon={<MdWavingHand />}
|
leftIcon={<MdWavingHand />}
|
||||||
variant={"ghost"}
|
variant={"ghost"}
|
||||||
onClick={onClose}
|
onClick={() => {
|
||||||
|
salute.current = !salute.current;
|
||||||
|
onClose();
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Saluer
|
Saluer
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
|||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import type { Session } from "@/models/auth/Session";
|
import type { Session } from "@/models/auth/Session";
|
||||||
import CardMatchedUser from "./CardMatchedUser";
|
import CardMatchedUser from "./CardMatchedUser";
|
||||||
import { Router } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { log } from "console";
|
|
||||||
|
|
||||||
type ModalInviteBarProps = {
|
type ModalInviteBarProps = {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
@@ -38,6 +37,7 @@ export default function ModalInviteBar({
|
|||||||
}: ModalInviteBarProps) {
|
}: ModalInviteBarProps) {
|
||||||
const { data: session, status } = useSession();
|
const { data: session, status } = useSession();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const { value, getRadioProps, getRootProps } = useRadioGroup({
|
const { value, getRadioProps, getRootProps } = useRadioGroup({
|
||||||
defaultValue: "-1",
|
defaultValue: "-1",
|
||||||
@@ -73,7 +73,7 @@ export default function ModalInviteBar({
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(data);
|
router.push(`/chat/${data.message_sent.ChatID}`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -100,8 +100,6 @@ export default function ModalInviteBar({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(bar);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Modal
|
<Modal
|
||||||
@@ -145,7 +143,6 @@ export default function ModalInviteBar({
|
|||||||
const { user } = session as unknown as Session;
|
const { user } = session as unknown as Session;
|
||||||
inviteToBar.mutate(user.id);
|
inviteToBar.mutate(user.id);
|
||||||
onClose();
|
onClose();
|
||||||
// Router.push("/chat");
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Inviter
|
Inviter
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const { PrismaClient } = require("@prisma/client");
|
|||||||
const patch = async (req: any, res: any) => {
|
const patch = async (req: any, res: any) => {
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
||||||
const { notificationId } = req.body;
|
const { notificationId, salute } = req.body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const notification = await prisma.notification.update({
|
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) {
|
} catch (error) {
|
||||||
res.status(400).json({ message: "Something went wrong" });
|
res.status(400).json({ message: "Something went wrong" });
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user