Skip to content

Commit

Permalink
refactor: edit modal button add
Browse files Browse the repository at this point in the history
  • Loading branch information
swgvenghy committed Sep 19, 2024
1 parent 30e1eda commit 08d83af
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/store/admin/check-question-answer-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const useCheckQuestionAnswerStore = create<CheckQuestionAnswerState>((set, get)
updateIsChecked: (id) =>
set((state) => ({
questionData: state.questionData.map((question) =>
question.id === id ? { ...question, isChecked: true } : question,
question.id === id ? { ...question, isChecked: !question.isChecked } : question,
),
})),

Expand Down
27 changes: 23 additions & 4 deletions src/ui/components/admin/modal/edit-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Button, Modal } from 'antd';
import TextArea from 'antd/es/input/TextArea';
import React, { useEffect, useState } from 'react';
import { AdminEditAnswer } from '../../../../api/admin/question-manage/admin-edit-answer';
import { adminEditQuestion } from '../../../../api/admin/question-manage/admin-edit-question';
import useCheckQuestionAnswerStore from '../../../../store/admin/check-question-answer-store';
import { adminEditQuestion } from '../../../../api/admin/question-manage/admin-edit-question';
import { AdminEditAnswer } from '../../../../api/admin/question-manage/admin-edit-answer';
import { AdminCheckQuestionAnswer } from '../../../../api/admin/question-manage/admin-check-question-answer';

interface CustomModalProps {
open: boolean;
Expand All @@ -12,7 +13,7 @@ interface CustomModalProps {
}

const EditModal = ({ open, setOpen, questionId }: CustomModalProps) => {
const { findQuestion, updateQuestion, updateAnswer } = useCheckQuestionAnswerStore();
const { findQuestion, updateQuestion, updateAnswer, updateIsChecked } = useCheckQuestionAnswerStore();
const question = findQuestion(questionId);

const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -43,6 +44,21 @@ const EditModal = ({ open, setOpen, questionId }: CustomModalProps) => {
}
};

const handleQuestionStatusSubmit = async () => {
if (question?.id !== undefined) {
setLoading(true);
try {
await AdminCheckQuestionAnswer({ questionId });
updateIsChecked(questionId);
setOpen(false);
} catch (error) {
console.error('Error check status failed', error);
} finally {
setLoading(false);
}
}
};

const handleClose = () => {
setOpen(false);
};
Expand All @@ -53,7 +69,10 @@ const EditModal = ({ open, setOpen, questionId }: CustomModalProps) => {
title="질문 및 답변 수정"
onCancel={handleClose}
footer={[
<Button key="submit" onClick={handleEditSubmit} loading={loading} type="dashed">
<Button key="submit" onClick={handleQuestionStatusSubmit} loading={loading} type="dashed">
질문 확인 완료
</Button>,
<Button key="submit" onClick={handleEditSubmit} loading={loading} type="primary">
수정 완료
</Button>,
]}
Expand Down

0 comments on commit 08d83af

Please sign in to comment.