diff --git a/src/components/AnswerContent/index.jsx b/src/components/AnswerContent/index.jsx
index fb1544b..151c72b 100644
--- a/src/components/AnswerContent/index.jsx
+++ b/src/components/AnswerContent/index.jsx
@@ -4,7 +4,7 @@ import { useEffect, useState } from 'react';
import formatCreatedAt from 'utils/dateUtils';
import { postAnswer } from 'api/answers';
-const AnswerContent = ({ answer, name, imageSource, id, onAnswerSubmit }) => {
+const AnswerContent = ({ answer, name, imageSource, id, onAnswerSubmit, setIsKebabLoading, setIsToast }) => {
AnswerContent.propTypes = {
answer: PropTypes.shape({
id: PropTypes.number.isRequired,
@@ -16,6 +16,8 @@ const AnswerContent = ({ answer, name, imageSource, id, onAnswerSubmit }) => {
imageSource: PropTypes.string,
id: PropTypes.number.isRequired,
onAnswerSubmit: PropTypes.func.isRequired,
+ setIsKebabLoading: PropTypes.func.isRequired,
+ setIsToast: PropTypes.func.isRequired,
};
AnswerContent.defaultProps = {
@@ -45,15 +47,21 @@ const AnswerContent = ({ answer, name, imageSource, id, onAnswerSubmit }) => {
let response;
try {
+ setIsKebabLoading(true);
setIsLoading(true);
response = await postAnswer(id, postBody);
setUpdatedAnswer(response);
onAnswerSubmit(id, response);
+ setIsToast('등록');
} catch (err) {
// eslint-disable-next-line
console.error(err);
} finally {
+ setIsKebabLoading(false);
setIsLoading(false);
+ setTimeout(() => {
+ setIsToast(null);
+ }, 3000);
}
};
diff --git a/src/components/AnswerDelete/index.jsx b/src/components/AnswerDelete/index.jsx
index 4603c3a..79584aa 100644
--- a/src/components/AnswerDelete/index.jsx
+++ b/src/components/AnswerDelete/index.jsx
@@ -3,18 +3,38 @@ import { ReactComponent as Close } from 'assets/images/icons/ic_Close.svg';
import PropTypes from 'prop-types';
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';
+import ConfirmModal from 'components/ConfirmModal'; // Import the modal component
-const AnswerDelete = ({ answerId, onAnswerDeleted }) => {
+const AnswerDelete = ({ id, answerId, onAnswerDeleted, onKebabClick, setIsKebabLoading, setIsToast, editId, setEditId }) => {
AnswerDelete.propTypes = {
+ id: PropTypes.number.isRequired,
answerId: PropTypes.number.isRequired,
onAnswerDeleted: PropTypes.func.isRequired,
+ onKebabClick: PropTypes.func.isRequired,
+ setIsKebabLoading: PropTypes.func.isRequired,
+ setIsToast: PropTypes.func.isRequired,
+ editId: PropTypes.number.isRequired,
+ setEditId: PropTypes.func.isRequired,
};
const [isDeleting, setIsDeleting] = useState(false);
- // const [error, setError] = useState(null);
const navigate = useNavigate();
- const handleAnswerDelete = async () => {
+ const [showModal, setShowModal] = useState(false);
+
+ const handleDelete = async () => {
+ setShowModal(true); // Show the modal when delete is clicked
+ };
+
+ const handleModalCancel = () => {
+ onKebabClick(id);
+ setShowModal(false); // Close the modal if canceled
+ };
+
+ const handleModalConfirm = async () => {
+ onKebabClick(id);
+ setIsKebabLoading(true);
+ setShowModal(false); // Close the modal
setIsDeleting(true);
try {
@@ -23,23 +43,34 @@ const AnswerDelete = ({ answerId, onAnswerDeleted }) => {
throw new Error('답변 삭제 중 오류가 발생했습니다.');
}
onAnswerDeleted(answerId);
+ setIsToast('답변');
} catch (err) {
navigate('/');
} finally {
setIsDeleting(false);
+ setIsKebabLoading(false);
+ if (editId !== null) {
+ setEditId(null);
+ }
+ setTimeout(() => {
+ setIsToast(null);
+ }, 3000);
}
};
return (
-
+ <>
+
+ ;
const renderAnswerForm = () => (
-