Refactor: 리뷰 디테일 리팩토링

This commit is contained in:
정현조 2024-09-27 16:08:50 +09:00
parent 74437db091
commit a3b1a14a4e
3 changed files with 31 additions and 28 deletions

View File

@ -21,23 +21,28 @@ export default function ReviewDetail(): JSX.Element {
const { data: reviewDetail } = useReviewDetailQuery(Number(projectId), Number(reviewId), memberId);
const approveReviewMutation = useApproveReviewQuery({ projectId: Number(projectId), reviewId: Number(reviewId) });
const rejectReviewMutation = useRejectReviewQuery({ projectId: Number(projectId), reviewId: Number(reviewId) });
const approveReviewMutation = useApproveReviewQuery({
projectId: Number(projectId),
reviewId: Number(reviewId),
memberId: memberId,
});
const rejectReviewMutation = useRejectReviewQuery({
projectId: Number(projectId),
reviewId: Number(reviewId),
memberId: memberId,
});
const [activeTab, setActiveTab] = useState<'content' | 'images'>('content');
const [isReviewed, setIsReviewed] = useState(
reviewDetail?.reviewStatus === 'APPROVED' || reviewDetail?.reviewStatus === 'REJECTED'
);
const handleApprove = () => {
approveReviewMutation.mutate(undefined, {
onSuccess: () => setIsReviewed(true),
onSuccess: () => {},
});
};
const handleReject = () => {
rejectReviewMutation.mutate(undefined, {
onSuccess: () => setIsReviewed(true),
onSuccess: () => {},
});
};
@ -124,24 +129,20 @@ export default function ReviewDetail(): JSX.Element {
</div>
)}
{!isReviewed && (
{reviewDetail.reviewStatus !== 'APPROVED' && reviewDetail.reviewStatus !== 'REJECTED' && (
<div className="actions mt-6 flex justify-end space-x-2">
{reviewDetail.reviewStatus !== 'APPROVED' && (
<Button
variant="default"
onClick={handleApprove}
>
{'승인'}
</Button>
)}
{reviewDetail.reviewStatus !== 'REJECTED' && (
<Button
variant="destructive"
onClick={handleReject}
>
{'거부'}
</Button>
)}
<Button
variant="destructive"
onClick={handleReject}
>
{'거부'}
</Button>
<Button
variant="default"
onClick={handleApprove}
>
{'승인'}
</Button>
</div>
)}

View File

@ -4,15 +4,16 @@ import { approveReview } from '@/api/reviewApi';
interface ReviewStatusChangeProps {
projectId: number;
reviewId: number;
memberId: number;
}
export default function useApproveReviewQuery({ projectId, reviewId }: ReviewStatusChangeProps) {
export default function useApproveReviewQuery({ projectId, reviewId, memberId }: ReviewStatusChangeProps) {
const queryClient = useQueryClient();
return useMutation({
mutationFn: () => approveReview(projectId, reviewId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['reviewDetail', reviewId] });
queryClient.invalidateQueries({ queryKey: ['reviewDetail', projectId, reviewId, memberId] });
},
});
}

View File

@ -4,15 +4,16 @@ import { rejectReview } from '@/api/reviewApi';
interface ReviewStatusChangeProps {
projectId: number;
reviewId: number;
memberId: number;
}
export default function useRejectReviewQuery({ projectId, reviewId }: ReviewStatusChangeProps) {
export default function useRejectReviewQuery({ projectId, reviewId, memberId }: ReviewStatusChangeProps) {
const queryClient = useQueryClient();
return useMutation({
mutationFn: () => rejectReview(projectId, reviewId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['reviewDetail', reviewId] });
queryClient.invalidateQueries({ queryKey: ['reviewDetail', projectId, reviewId, memberId] });
},
});
}