Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions apps/next/src/components/ui/card/ratings-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useUserStore } from "@/context/useUserStore";
import { formatFoodName, getFoodIcon } from "@/utils/funcs";
import { trpc } from "@/utils/trpc";
import { cn } from "@/utils/tw";
import DeleteRatingDialogContent from "../delete-rating-dialog-content";
import FoodDialogContent from "../food-dialog-content";
import InteractiveStarRating from "../rating";

Expand All @@ -36,6 +37,10 @@ const RatingsCardContent = React.forwardRef<
} & React.HTMLAttributes<HTMLDivElement>
>(({ food, handleDelete, deleteLoading, className, ...divProps }, ref) => {
const IconComponent = getFoodIcon(food.name) ?? Restaurant;
const [openDelete, setOpenDelete] = React.useState(false);

const handleOpenDelete = () => setOpenDelete(true);
const handleCloseDelete = () => setOpenDelete(false);

return (
<div ref={ref} {...divProps} className={cn("w-full", className)}>
Expand Down Expand Up @@ -65,7 +70,7 @@ const RatingsCardContent = React.forwardRef<
restaurant={food.restaurant}
/>
<IconButton
onClick={handleDelete}
onClick={handleOpenDelete}
disabled={deleteLoading}
title="Delete Rating"
size="small"
Expand All @@ -76,6 +81,28 @@ const RatingsCardContent = React.forwardRef<
>
<Delete className="w-4 h-4 text-gray-400 hover:text-red-500" />
</IconButton>
<Dialog
open={openDelete}
onClose={handleCloseDelete}
maxWidth={false}
slotProps={{
paper: {
sx: {
width: "300px",
maxWidth: "90vw",
margin: 2,
padding: 0,
overflow: "hidden",
borderRadius: "6px",
},
},
}}
>
<DeleteRatingDialogContent
cancel={handleCloseDelete}
handleDelete={handleDelete}
/>
</Dialog>
</div>
</div>
</CardContent>
Expand Down Expand Up @@ -116,13 +143,10 @@ export default function RatingsCard({ food }: RatingsCardProps) {

const handleDelete = async (e: React.MouseEvent) => {
e.stopPropagation();
// TODO: Replace this with a MUI dialog instead of relying on browser window.
if (window.confirm("Delete this rating?")) {
await deleteRatingMutation.mutateAsync({
userId: userId ?? "default-user",
dishId: food.id,
});
}
await deleteRatingMutation.mutateAsync({
userId: userId ?? "default-user",
dishId: food.id,
});
};

const handleOpen = () => setOpen(true); // no dialog trigger component in MUI so handling manually
Expand Down
44 changes: 44 additions & 0 deletions apps/next/src/components/ui/delete-rating-dialog-content.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"use client";

import { Button, DialogContent } from "@mui/material";

export default function DeleteRatingDialogContent({
cancel,
handleDelete,
}: {
cancel: () => void;
handleDelete: (e: React.MouseEvent) => Promise<void>;
}) {
return (
<DialogContent
sx={{
padding: "30px 20px",
flex: 1,
display: "flex",
flexDirection: "column",
justifyContent: "center",
alignContent: "center",
flexWrap: "wrap",
gap: "20px",
}}
>
<p className="text-center">Delete this rating?</p>
<div className="flex flex-row justify-center gap-5">
<Button
variant={"contained"}
className="whitespace-nowrap"
onClick={handleDelete}
>
Delete
</Button>
<Button
variant={"outlined"}
className="whitespace-nowrap"
onClick={cancel}
>
Cancel
</Button>
</div>
</DialogContent>
);
}
Loading