Skip to content

Commit

Permalink
fix: 모달창 닫았다 다시 열었을 때 메모 업데이트 되는 기능 추가 (#197)
Browse files Browse the repository at this point in the history
* fix: 모달창 닫았다 다시 열었을 때 메모 업데이트 되는 기능 추가

* chore: 쓰지 않는 import 제거
  • Loading branch information
chae-won-shin authored Jan 21, 2025
1 parent e591823 commit 8224b48
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/pages/admin/components/docs/ApplyDetailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const ApplyDetailModal = ({
}) => {
const [detail, setDetail] = useState<DetailInfo | null>(null);

const { data, isPending } = useGetDocsDetail(id);
const { data, isPending, refetch } = useGetDocsDetail(id);
useEffect(() => {
if (data) {
setDetail(data);
Expand Down Expand Up @@ -145,7 +145,10 @@ const ApplyDetailModal = ({
const trackData = detail ? getQuestionsByTrack(detail.track) : null;
const emptyAnswer = '해당 질문에 대한 답변이 작성되지 않았습니다.';

console.log(detail);
const handleClose = () => {
refetch(); // 모달 닫을 때 최신 데이터 가져오기
onClose();
};

return (
<ModalBackdrop>
Expand All @@ -157,7 +160,7 @@ const ApplyDetailModal = ({
<Text size='xl' weight='bold' color='black'>
지원자 정보 조회
</Text>
<CloseBtn onClick={onClose}>
<CloseBtn onClick={handleClose}>
<CloseIconImg src={CloseIcon} alt='close' />
</CloseBtn>
</TitleWrapper>
Expand Down
6 changes: 5 additions & 1 deletion src/pages/admin/components/docs/Memo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import styled from '@emotion/styled';
import { useState } from 'react';
import { useQueryClient } from '@tanstack/react-query';

import { usePatchDocsMemo } from '@gdg/apis/hooks/admin/docs/usePatchDocsMemo';
import CommonBtn from '@gdg/components/common/button/CommonBtn';
Expand Down Expand Up @@ -52,6 +53,7 @@ const Memo = ({
version: number;
note: string | null;
}) => {
const queryClient = useQueryClient();
const [memo, setMemo] = useState<IMemo | null>(
note !== null ? { note: note, version: version } : null
);
Expand All @@ -70,11 +72,13 @@ const Memo = ({
{ id, memo },
{
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['docs'] });
queryClient.invalidateQueries({ queryKey: ['memo', id] });
alert('메모가 성공적으로 저장되었습니다.');
},
onError: (error) => {
console.error('API 호출 실패:', error);
alert('메모 저장에 실패했습니다.');
alert(error.message);
},
}
);
Expand Down

0 comments on commit 8224b48

Please sign in to comment.