+ {message.author &&
}
- {user.firstName} {user.lastName}
+ {message.author.firstName} {message.author.lastName}
-
+
-
-
-
{date}
+
+
+
{message.createdAt}
diff --git a/client/src/components/MessageWrapper.tsx b/client/src/components/MessageWrapper.tsx
index 259abf3..55e10d9 100644
--- a/client/src/components/MessageWrapper.tsx
+++ b/client/src/components/MessageWrapper.tsx
@@ -28,7 +28,7 @@ const MessageWrapper = () => {
return (
{messages.isLoading ? '' : messages.data?.map((message: any) => (
-
+
))}
);
diff --git a/client/src/components/PopupMessage.tsx b/client/src/components/PopupMessage.tsx
index c940a62..060c3c4 100644
--- a/client/src/components/PopupMessage.tsx
+++ b/client/src/components/PopupMessage.tsx
@@ -1,22 +1,42 @@
import { useEffect, useState } from 'react';
import { FaEllipsisH } from 'react-icons/fa';
import Modal from './Modal';
+import { deleteMessage } from '@controllers/MessageController';
+import { useQueryClient } from '@tanstack/react-query';
const DeleteModal = ({
- id,
+ authorId,
+ messageId,
showDelete,
setShowDelete,
}: {
- id: string;
+ authorId: string;
+ messageId: string;
showDelete: boolean;
setShowDelete: (showDelete: boolean) => void;
}) => {
+ const queryClient = useQueryClient();
+
+ const handleDelete = async () => {
+ try {
+ const response = await deleteMessage(messageId);
+ if (response.status === 200) {
+ console.log(await response.json());
+ queryClient.invalidateQueries(['messages']);
+ setShowDelete(false);
+ }
+ } catch (error) {
+ console.error(error);
+ setShowDelete(false);
+ }
+ };
+
return (
Voulez vous vraiment supprimer ce message ?
@@ -31,11 +51,13 @@ const DeleteModal = ({
};
const EditModal = ({
- id,
+ authorId,
+ messageId,
showEdit,
setShowEdit,
}: {
- id: string;
+ authorId: string;
+ messageId: string;
showEdit: boolean;
setShowEdit: (showEdit: boolean) => void;
}) => {
@@ -46,20 +68,20 @@ const EditModal = ({
);
};
-const PopupMessage = ({ id }: { id: string }) => {
+const PopupMessage = ({ message }: { message: any }) => {
const [show, setShow] = useState(false);
const [showEdit, setShowEdit] = useState(false);
const [showDelete, setShowDelete] = useState(false);
useEffect(() => {
const handleClick = (e: any) => {
- if (e.target.closest('#messageId' + id) === null) {
+ if (e.target.closest('#messageId' + message.id) === null) {
setShow(false);
}
};
document.addEventListener('click', handleClick);
- }, [id]);
+ }, [message.id]);
return (
<>
@@ -98,8 +120,8 @@ const PopupMessage = ({ id }: { id: string }) => {