|
| 1 | +import * as React from "react" |
| 2 | +import { notFound, redirect } from "next/navigation" |
| 3 | + |
| 4 | +import { redirects } from "@/config/constants" |
| 5 | +import { getUserSession } from "@/server/data/user" |
| 6 | +import { getWorkshop } from "@/server/data/workshop" |
| 7 | +import { getExactScheduled } from "@/utils/format-scheduled-date" |
| 8 | +import { Button } from "@/components/ui/button" |
| 9 | +import { Separator } from "@/components/ui/separator" |
| 10 | +import { CopyButton } from "@/components/copy-button" |
| 11 | +import { Icons } from "@/components/icons" |
| 12 | +import { ModalShell } from "@/components/modal-shell" |
| 13 | +import { PageHeader, PageHeaderHeading } from "@/components/page-header" |
| 14 | +import { OrganizerSection } from "@/app/(app)/workshop/[workshopId]/_components/organizer-section" |
| 15 | +import { OrganizerSectionSkeleton } from "@/app/(app)/workshop/[workshopId]/_components/organizer-section-skeleton" |
| 16 | +import { WorkshopSettings } from "@/app/(app)/workshop/[workshopId]/_components/workshop-settings" |
| 17 | + |
| 18 | +interface WorkshopModalProps { |
| 19 | + params: { |
| 20 | + workshopId: string |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +export default async function WorkshopModal({ params }: WorkshopModalProps) { |
| 25 | + const workshopId = decodeURIComponent(params.workshopId) |
| 26 | + |
| 27 | + const workshop = await getWorkshop(workshopId) |
| 28 | + |
| 29 | + if (!workshop) { |
| 30 | + return notFound() |
| 31 | + } |
| 32 | + |
| 33 | + const { user } = await getUserSession() |
| 34 | + |
| 35 | + if (!user) { |
| 36 | + redirect(redirects.toLogin) |
| 37 | + } |
| 38 | + |
| 39 | + const isCurrentUserWorkshop = workshop.organizerId === user.id |
| 40 | + |
| 41 | + return ( |
| 42 | + <ModalShell> |
| 43 | + <div className="flex w-full flex-col items-start space-y-1"> |
| 44 | + <div className="flex w-full items-start justify-between"> |
| 45 | + <PageHeader> |
| 46 | + <PageHeaderHeading>{workshop.title}</PageHeaderHeading> |
| 47 | + </PageHeader> |
| 48 | + |
| 49 | + <div className="flex items-center gap-1"> |
| 50 | + <CopyButton |
| 51 | + value={workshop.accessCode} |
| 52 | + size="icon" |
| 53 | + className="rounded-full" |
| 54 | + /> |
| 55 | + {isCurrentUserWorkshop && <WorkshopSettings workshop={workshop} />} |
| 56 | + </div> |
| 57 | + </div> |
| 58 | + |
| 59 | + <div className="flex items-center gap-2"> |
| 60 | + <Icons.clock |
| 61 | + className="size-4 text-muted-foreground" |
| 62 | + aria-hidden="true" |
| 63 | + /> |
| 64 | + <p className="text-sm text-muted-foreground"> |
| 65 | + {getExactScheduled(workshop.scheduled)} |
| 66 | + </p> |
| 67 | + </div> |
| 68 | + <div className="flex items-center gap-2"> |
| 69 | + <Icons.watch |
| 70 | + className="size-4 text-muted-foreground" |
| 71 | + aria-hidden="true" |
| 72 | + /> |
| 73 | + <p className="text-sm text-muted-foreground"> |
| 74 | + {workshop.duration} mins |
| 75 | + </p> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + |
| 79 | + <Separator /> |
| 80 | + |
| 81 | + <div className="flex flex-col items-start space-y-4"> |
| 82 | + <div className="space-y-1"> |
| 83 | + <h4 className="font-medium sm:text-lg">About</h4> |
| 84 | + |
| 85 | + <p className="max-w-lg text-sm text-muted-foreground"> |
| 86 | + {workshop.description} |
| 87 | + </p> |
| 88 | + </div> |
| 89 | + |
| 90 | + <React.Suspense fallback={<OrganizerSectionSkeleton />}> |
| 91 | + <OrganizerSection organizerId={workshop.organizerId} /> |
| 92 | + </React.Suspense> |
| 93 | + |
| 94 | + <div className="flex w-full justify-end"> |
| 95 | + {!isCurrentUserWorkshop ? ( |
| 96 | + <Button size="sm"> |
| 97 | + {/* {isPending && ( |
| 98 | + <Icons.spinner |
| 99 | + className="mr-2 size-4 animate-spin" |
| 100 | + aria-hidden="true" |
| 101 | + /> |
| 102 | + )} */} |
| 103 | + Register |
| 104 | + </Button> |
| 105 | + ) : ( |
| 106 | + <Button size="sm">Start</Button> |
| 107 | + )} |
| 108 | + </div> |
| 109 | + </div> |
| 110 | + </ModalShell> |
| 111 | + ) |
| 112 | +} |
0 commit comments