-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: plans page styling, change plan id from number to uuid
- Loading branch information
Showing
3 changed files
with
78 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,87 @@ | ||
import { useAtom } from "jotai"; | ||
import { Pencil } from "lucide-react"; | ||
import Link from "next/link"; | ||
import router from "next/router"; | ||
import React from "react"; | ||
|
||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from "@/components/ui/popover"; | ||
import { cn } from "@/lib/utils"; | ||
import { planFamily } from "@/pages/createplan/[id]"; | ||
import { plansIds } from "@/pages/plans"; | ||
|
||
export const Plan = ({ id, name }: { id: number; name: string }) => { | ||
import { buttonVariants } from "./ui/button"; | ||
|
||
export const Plan = ({ id, name }: { id: string; name: string }) => { | ||
const uuid = React.useMemo(() => crypto.randomUUID(), []); | ||
const [plans, setPlans] = useAtom(plansIds); | ||
const [plan] = useAtom(planFamily({ id })); | ||
const [planToCopy, setPlanToCopy] = useAtom(planFamily({ id: uuid })); | ||
|
||
const copyPlan = () => { | ||
const newPlan = { | ||
id: uuid, | ||
}; | ||
|
||
void window.umami?.track("Create plan", { | ||
numberOfPlans: plans.length, | ||
}); | ||
|
||
setPlans([...plans, newPlan]); | ||
setPlanToCopy({ | ||
...planToCopy, | ||
courses: plan.courses, | ||
groups: plan.groups, | ||
}); | ||
|
||
setTimeout(() => { | ||
void router.push(`/createplan/${newPlan.id}`); | ||
}, 200); | ||
}; | ||
const deletePlan = () => { | ||
planFamily.remove({ id }); | ||
setPlans(plans.filter((p) => p.id !== id)); | ||
}; | ||
// return ( | ||
// <Link | ||
// href={`/createplan/${id}`} | ||
// className="flex h-[200px] w-[200px] flex-col items-center justify-center rounded-lg border-2 border-gray-400 bg-white p-4 text-center shadow-lg" | ||
// > | ||
// <div className="text-xl font-semibold">{name}</div> | ||
// <div className="mt-2 text-gray-600"> | ||
// Kliknij w plan, aby wyświetlić szczegóły | ||
// </div> | ||
// </Link> | ||
// ); | ||
const groupCount = plan.groups.filter((group) => group.isChecked).length; | ||
return ( | ||
<div className="flex justify-between bg-slate-600 text-white"> | ||
<Link href={`/app/createplan/${id}`}>{name}</Link> | ||
<button onClick={deletePlan} className="cursor-pointer"> | ||
Delete | ||
</button> | ||
<div className="flex h-[200px] w-[200px] flex-col items-center justify-between rounded-lg border-gray-400 bg-white p-4 text-center shadow-[0_0_5px_5px_rgba(0,0,0,0.10)]"> | ||
<div className="flex w-full justify-between"> | ||
<div className="text-xl font-semibold">{name}</div> | ||
<Popover> | ||
<PopoverTrigger>...</PopoverTrigger> | ||
<PopoverContent className="w-44 p-0"> | ||
<div className="flex flex-col items-start"> | ||
<button | ||
onClick={copyPlan} | ||
className="w-full rounded-md rounded-b-none p-2 text-left hover:bg-slate-200" | ||
> | ||
Kopiuj | ||
</button> | ||
<button | ||
onClick={deletePlan} | ||
className="w-full rounded-md rounded-t-none p-2 text-left hover:bg-slate-200" | ||
> | ||
Usuń | ||
</button> | ||
</div> | ||
</PopoverContent> | ||
</Popover> | ||
</div> | ||
<div className="mt-2 text-gray-600">Wybrane grupy: {groupCount}</div> | ||
<Link | ||
href={`/app/createplan/${id}`} | ||
className={buttonVariants({ | ||
className: cn( | ||
"flex items-center gap-2 text-nowrap rounded-md text-lg", | ||
), | ||
})} | ||
> | ||
Edytuj | ||
<Pencil className="h-4 w-4" /> | ||
</Link> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters