diff --git a/website/components/FunctionPage/CommentCard/CommentCard.js b/website/components/FunctionPage/CommentCard/CommentCard.js index 113f0ed..5f76d84 100644 --- a/website/components/FunctionPage/CommentCard/CommentCard.js +++ b/website/components/FunctionPage/CommentCard/CommentCard.js @@ -1,6 +1,7 @@ import Link from 'next/link'; -import { forwardRef, useContext } from 'react'; +import { useEffect, useState, forwardRef, useContext, Fragment } from 'react'; import date from 'date-and-time'; +import htmlParser from 'html-react-parser'; import { UserContext } from '../../../contexts/UserContext'; import { API_URL } from '../../../utils/config/config'; import api from '../../../utils/api'; @@ -8,7 +9,14 @@ import './CommentCard.css'; const CommentCard = forwardRef((props, ref) => { - const { isAuth, user } = useContext(UserContext); + const { isAuth, user } = useContext(UserContext); + const [isEditing, setEditing] = useState(false); + const [editInput, setEditInput] = useState(""); + const [message, setMessage] = useState(""); + + useEffect(() => { + setEditInput(props.message); + }, []); const deleteCommentById = async () => { props.manageComment.setLoadingComments(true); @@ -24,6 +32,26 @@ const CommentCard = forwardRef((props, ref) => { props.manageComment.setLoadingComments(false); } + const handleChange = (event) => { + setEditInput(event.target.value); + } + + const handleSubmit = (event) => { + event.preventDefault(); + api.put(`/comments/${props.id}`, { message: editInput }, { headers: { 'Authorization': user.token } }) + .then((_response) => { + setEditing(false); + }) + .catch((error) => { + setMessage(`
Erreur: ${error.response.data.message}
`); + }); + } + + const editComment = () => { + setEditing(true); + setMessage(""); + } + return (- {props.message} -
- {(isAuth && user.name === props.user.name) && - + { + (!isEditing) ? ++ {editInput} +
+ {(isAuth && user.name === props.user.name) && + + } +