Skip to content

Commit

Permalink
feat: delete, copy plan, style plans page
Browse files Browse the repository at this point in the history
  • Loading branch information
D0dii committed Sep 17, 2024
1 parent 4e0c301 commit 1b35172
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 7 deletions.
103 changes: 103 additions & 0 deletions src/components/DeletePlanConfirmationResponsiveDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import * as React from "react";

import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import {
Drawer,
DrawerContent,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer";
import { useMediaQuery } from "@/lib/useMediaQuery";

export const DeletePlanConfirmationResponsiveDialog = ({
deletePlan,
}: {
deletePlan: () => void;
}) => {
const [open, setOpen] = React.useState(false);
const isDesktop = useMediaQuery("(min-width: 768px)");
const closeDialog = () => {
setOpen(false);
};
if (isDesktop) {
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild={true}>
<button
onClick={deletePlan}
className="w-full rounded-md rounded-t-none p-2 text-left hover:bg-slate-200"
>
Usuń
</button>
</DialogTrigger>
<DialogContent
className="sm:max-w-[425px]"
aria-describedby={undefined}
>
<DialogHeader>
<DialogTitle>Czy na pewno chcesz usunąć plan?</DialogTitle>
</DialogHeader>
<DeletePlan deletePlan={deletePlan} closeDialog={closeDialog} />
</DialogContent>
</Dialog>
);
}

return (
<Drawer open={open} onOpenChange={setOpen}>
<DrawerTrigger asChild={true}>
<button
onClick={deletePlan}
className="w-full rounded-md rounded-t-none p-2 text-left hover:bg-slate-200"
>
Usuń
</button>
</DrawerTrigger>
<DrawerContent
className="items-center px-4 pb-6"
aria-describedby={undefined}
>
<DrawerHeader className="w-full max-w-[400px] text-left">
<DrawerTitle>Czy na pewno chcesz usunąć plan</DrawerTitle>
</DrawerHeader>
<DeletePlan deletePlan={deletePlan} closeDialog={closeDialog} />
</DrawerContent>
</Drawer>
);
};

function DeletePlan({
deletePlan,
closeDialog,
}: {
deletePlan: () => void;
closeDialog: () => void;
}) {
return (
<div className="flex w-full max-w-[400px] items-center justify-end gap-4 space-x-2 pt-4">
<button
onClick={() => {
closeDialog();
}}
>
Anuluj
</button>
<Button
onClick={() => {
deletePlan();
}}
className="rounded-md bg-red-500 text-lg hover:bg-red-400"
>
Tak
</Button>
</div>
);
}
8 changes: 2 additions & 6 deletions src/components/Plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { cn } from "@/lib/utils";
import { planFamily } from "@/pages/createplan/[id]";
import { plansIds } from "@/pages/plans";

import { DeletePlanConfirmationResponsiveDialog } from "./DeletePlanConfirmationResponsiveDialog";
import { buttonVariants } from "./ui/button";

export const Plan = ({ id, name }: { id: string; name: string }) => {
Expand Down Expand Up @@ -60,12 +61,7 @@ export const Plan = ({ id, name }: { id: string; name: string }) => {
>
Kopiuj
</button>
<button
onClick={deletePlan}
className="w-full rounded-md rounded-t-none p-2 text-left hover:bg-slate-200"
>
Usuń
</button>
<DeletePlanConfirmationResponsiveDialog deletePlan={deletePlan} />
</div>
</PopoverContent>
</Popover>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/createplan/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const planFamily = atomFamily(
`${id}-plan`,
{
id,
name: `Nowy plan - ${id}`,
name: `Nowy plan`,
courses: [] as ExtendedCourse[],
groups: [] as ExtendedGroup[],
departments: [] as string[],
Expand Down

0 comments on commit 1b35172

Please sign in to comment.