Skip to content

Commit

Permalink
feat: 리뷰 삭제 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
myoungjinGo-FE committed Dec 19, 2024
1 parent 51b9bee commit 0b74aeb
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
39 changes: 39 additions & 0 deletions src/pages/customer/review/history/components/DeleteReviewModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Text } from "../../../../../components";
import {
ModalOverlay,
ModalContent,
ModalMessage,
ModalButtons,
ModalButton,
} from "../../../pet/info/components/Modal.styles";

interface ModalProps {
isOpen: boolean;
onConfirm: () => void;
onCancel: () => void;
}

const DeleteReviewModal: React.FC<ModalProps> = ({
isOpen,
onConfirm,
onCancel,
}) => {
if (!isOpen) return null;

return (
<ModalOverlay>
<ModalContent>
<ModalMessage>
<Text typo="subtitle200">정말 삭제하시겠습니까?</Text>
<Text typo="body400">삭제한 뒤에는 복구할 수 없어요</Text>
</ModalMessage>
<ModalButtons>
<ModalButton onClick={onConfirm}></ModalButton>
<ModalButton onClick={onCancel}>아니오</ModalButton>
</ModalButtons>
</ModalContent>
</ModalOverlay>
);
};

export default DeleteReviewModal;
50 changes: 48 additions & 2 deletions src/pages/customer/review/history/components/ReviewedService.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { useState, useEffect } from "react";
import ReviewCard from "./ReviewCard";
import { GetUserReviewsResponse } from "../../../../../types/customer/review";
import { getUserReviews } from "../../../../../apis/customer/resources/review";
import {
deleteReview,
getUserReviews,
} from "../../../../../apis/customer/resources/review";
import { useUserDetails } from "../../../../../hooks/useUserDetails";
import NoReview from "./NoReview";
import { useNavigate } from "react-router-dom";
import { ROUTE } from "../../../../../constants/routes";
import { useSetRecoilState } from "recoil";
import { ReviewAtom, ReviewData } from "../../../../../atoms/reviewAtom";
import DeleteReviewModal from "./DeleteReviewModal";

interface review {
reviewId?: number;
Expand Down Expand Up @@ -36,6 +40,43 @@ export default function ReviewedService() {
const navigate = useNavigate();
const setReviewData = useSetRecoilState(ReviewAtom);

const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const [selectedReviewId, setSelectedReviewId] = useState<number | null>(null);

const handleDeleteButton = (review: review) => {
setSelectedReviewId(review.reviewId || null);
setIsDeleteModalOpen(true);
};

const handleDeleteConfirm = async () => {
if (!userId || !selectedReviewId) return;

try {
await deleteReview(userId, selectedReviewId);
// Update local state to remove the deleted review
if (reviews) {
setReviews({
...reviews,
reviews: reviews.reviews?.filter(
(review) => review.reviewId !== selectedReviewId,
),
});
}
alert("리뷰가 삭제되었습니다.");
} catch (error) {
console.error("Failed to delete review:", error);
alert("삭제 중 문제가 발생했습니다. 다시 시도해주세요.");
} finally {
setIsDeleteModalOpen(false);
setSelectedReviewId(null);
}
};

const handleDeleteCancel = () => {
setIsDeleteModalOpen(false);
setSelectedReviewId(null);
};

const handleEditButton = (review: review) => {
const reviewData: ReviewData = {
userId: userId || 0,
Expand Down Expand Up @@ -103,9 +144,14 @@ export default function ReviewedService() {
reviewText={review.contentDetail ?? ""}
reviewImages={review.reviewImages ?? []}
onEdit={() => handleEditButton(review)}
onDelete={() => alert(`리뷰 ${review.reviewId} 삭제 클릭!`)}
onDelete={() => handleDeleteButton(review)}
/>
))}
<DeleteReviewModal
isOpen={isDeleteModalOpen}
onConfirm={handleDeleteConfirm}
onCancel={handleDeleteCancel}
/>
</div>
);
}

0 comments on commit 0b74aeb

Please sign in to comment.