Skip to content

Commit 2f62dec

Browse files
authored
Delete review (#207)
* feat: basic functional feature * modified into working dialogue component * fix: vert padding
1 parent b91e883 commit 2f62dec

File tree

2 files changed

+93
-1
lines changed

2 files changed

+93
-1
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { Trash2 } from "lucide-react";
2+
3+
import { Button } from "@cooper/ui/button";
4+
import {
5+
Dialog,
6+
DialogContent,
7+
DialogDescription,
8+
DialogFooter,
9+
DialogHeader,
10+
DialogTitle,
11+
DialogTrigger,
12+
} from "@cooper/ui/dialog";
13+
import { useToast } from "@cooper/ui/hooks/use-toast";
14+
15+
import { api } from "~/trpc/react";
16+
17+
interface DeleteReviewDialogProps {
18+
reviewId: string;
19+
}
20+
21+
export function DeleteReviewDialog({ reviewId }: DeleteReviewDialogProps) {
22+
const { toast } = useToast();
23+
24+
const deleteReview = api.review.delete.useMutation({
25+
onSuccess: () => {
26+
toast({
27+
title: "Review deleted",
28+
description: "Your review has been successfully deleted.",
29+
});
30+
// Refresh the page to update the UI
31+
window.location.reload();
32+
},
33+
onError: (error) => {
34+
toast({
35+
title: "Error",
36+
description: error.message || "Failed to delete review",
37+
variant: "destructive",
38+
});
39+
},
40+
});
41+
42+
const handleDelete = () => {
43+
deleteReview.mutate(reviewId);
44+
};
45+
46+
return (
47+
<Dialog>
48+
<DialogTrigger asChild>
49+
<Button
50+
variant="ghost"
51+
size="icon"
52+
className="h-6 w-4 cursor-pointer p-0 hover:bg-transparent"
53+
>
54+
<Trash2 className="h-4 w-4 text-cooper-gray-400" />
55+
</Button>
56+
</DialogTrigger>
57+
<DialogContent className="w-full max-w-md bg-white pb-12">
58+
<DialogHeader className="space-y-4 text-center">
59+
<DialogTitle className="text-2xl font-semibold">
60+
Delete Review
61+
</DialogTitle>
62+
<DialogDescription className="text-cooper-gray-600 text-base">
63+
Are you sure you want to delete this review? This action cannot be
64+
undone.
65+
</DialogDescription>
66+
</DialogHeader>
67+
68+
<DialogFooter className="mt-8 flex justify-center">
69+
<Button
70+
type="submit"
71+
className="min-w-[200px] border-none bg-cooper-yellow-500 px-8 py-6 text-base font-medium text-white transition-colors hover:bg-cooper-yellow-300"
72+
onClick={handleDelete}
73+
>
74+
Delete Review
75+
</Button>
76+
</DialogFooter>
77+
</DialogContent>
78+
</Dialog>
79+
);
80+
}

apps/web/src/app/_components/reviews/review-card.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import type { ReviewType, WorkEnvironmentType } from "@cooper/db/schema";
66
import { cn } from "@cooper/ui";
77
import { Card, CardContent } from "@cooper/ui/card";
88

9+
import { api } from "~/trpc/react";
910
import { locationName } from "~/utils/locationHelpers";
1011
import {
1112
abbreviatedWorkTerm,
1213
prettyWorkEnviornment,
1314
} from "~/utils/stringHelpers";
15+
import { DeleteReviewDialog } from "./delete-review-dialogue";
1416
import { ReviewCardStars } from "./review-card-stars";
1517

1618
interface ReviewCardProps {
@@ -19,6 +21,12 @@ interface ReviewCardProps {
1921
}
2022

2123
export function ReviewCard({ reviewObj, className }: ReviewCardProps) {
24+
// Get the current user's profile
25+
const { data: currentProfile } = api.profile.getCurrentUser.useQuery();
26+
27+
// Check if the current user is the author of the review
28+
const isAuthor = currentProfile?.id === reviewObj.profileId;
29+
2230
return (
2331
<Card
2432
className={cn(
@@ -61,7 +69,11 @@ export function ReviewCard({ reviewObj, className }: ReviewCardProps) {
6169
</div>
6270
<div className="w-[65%]">
6371
<CardContent className="flex h-full flex-col justify-between gap-4 pl-0">
64-
<div className="pt-1">{reviewObj.textReview}</div>
72+
<div className="flex flex-row justify-between">
73+
<div className="pt-1">{reviewObj.textReview}</div>
74+
{isAuthor && <DeleteReviewDialog reviewId={reviewObj.id} />}
75+
</div>
76+
6577
<div className="flex justify-between text-sm">
6678
<div className="flex gap-6">
6779
<div>Position type: Co-op</div>

0 commit comments

Comments
 (0)