diff --git a/src/app/calendar/manage/ManageMeetDialog.tsx b/src/app/calendar/manage/ManageMeetDialog.tsx new file mode 100644 index 0000000..a09807a --- /dev/null +++ b/src/app/calendar/manage/ManageMeetDialog.tsx @@ -0,0 +1,101 @@ +"use client"; + +import React from "react"; +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow } from "@/components/ui/table"; +import { Clock } from "lucide-react"; +import { createSupabaseClient } from "@/lib/supabase/clientComponentClient"; + +import getMeetingLog from "./actions"; +import { useQuery } from "@supabase-cache-helpers/postgrest-react-query"; +import { LegacyLoader } from "@/components/loading/LegacyLoader"; + +interface DialogProps { + children?: React.ReactNode; + open?: boolean; + defaultOpen?: boolean; + // eslint-disable-next-line no-unused-vars + onOpenChange?(open: boolean): void; + modal?: boolean; + projectId: number; +} + +export function ManageMeetDialog(props: DialogProps) { + const supabase = createSupabaseClient(); + const { + data: meetingLog, + error: meetingLogError, + isLoading: isLoadingMeetingLog, + } = useQuery(getMeetingLog(supabase, props.projectId), { + enabled: !!props.projectId, + }); + + return ( + + + + + + Meeting Request + + List of meeting you need to attend. + + + {meetingLogError ? ( +
Error Loading data
+ ) : isLoadingMeetingLog ? ( + + ) : meetingLog && meetingLog.length > 0 ? ( + + + + Date + Start Time + End Time + User + Note + + + + {meetingLog.map((log) => ( + + {log.meet_date} + {log.start_time} + {log.end_time} + {log.user_id} + {log.note || "No note provided"} + + ))} + + + + + Total Meetings: {meetingLog.length} + + + +
+ ) : ( +
No meeting logs available
+ )} + + + + + + +
+
+ ); +} diff --git a/src/app/calendar/manage/ProjectCardSection.tsx b/src/app/calendar/manage/ProjectCardSection.tsx new file mode 100644 index 0000000..75f238e --- /dev/null +++ b/src/app/calendar/manage/ProjectCardSection.tsx @@ -0,0 +1,63 @@ +"use client"; + +import { useState } from "react"; +import { Separator } from "@/components/ui/separator"; +import { Card, CardContent, CardDescription, CardTitle, CardHeader, CardFooter } from "@/components/ui/card"; +import { Tooltip, TooltipProvider, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; +import { ManageMeetDialog } from "./ManageMeetDialog"; +import { Button } from "@/components/ui/button"; + +type ProjectCardSectionProps = { + id: number; + project_name: string; + project_short_description: string; + business_id: { + user_id: string; + }; + dataroom_id: number | null; +}; + +type ProjectCardCalendarManageSectionProps = { + projectData: ProjectCardSectionProps[] | null; +}; +export default function ProjectCardCalendarManageSection({ projectData }: ProjectCardCalendarManageSectionProps) { + const [showMeetModal, setShowMeetModal] = useState(false); + const [currentProjectId, setCurrentProjectId] = useState(undefined); + + return ( +
+ {projectData != null ? ( + projectData.map((project) => ( + + + {project.project_name} + + + + {project.project_short_description} + + {project.project_short_description} + + + + + + + + + + )) + ) : ( +
No data
+ )} + +
+ ); +} diff --git a/src/app/calendar/manage/actions.ts b/src/app/calendar/manage/actions.ts new file mode 100644 index 0000000..37121ab --- /dev/null +++ b/src/app/calendar/manage/actions.ts @@ -0,0 +1,20 @@ +import { Database } from "@/types/database.types"; +import { SupabaseClient } from "@supabase/supabase-js"; + +export default function getMeetingLog(client: SupabaseClient, projectId: number) { + return client + .from("meeting_log") + .select( + ` + id, + meet_date, + start_time, + end_time, + note, + user_id, + project_id, + created_at + ` + ) + .eq("project_id", projectId); +} diff --git a/src/app/calendar/manage/page.tsx b/src/app/calendar/manage/page.tsx new file mode 100644 index 0000000..dfcedf1 --- /dev/null +++ b/src/app/calendar/manage/page.tsx @@ -0,0 +1,62 @@ +import { Separator } from "@/components/ui/separator"; +import { Clock } from "lucide-react"; +import { createSupabaseClient } from "@/lib/supabase/serverComponentClient"; +import { getProjectByUserId } from "@/lib/data/projectQuery"; +import { Suspense } from "react"; +import { LegacyLoader } from "@/components/loading/LegacyLoader"; +import { getUserRole } from "@/lib/data/userQuery"; +import { Button } from "@/components/ui/button"; +import Link from "next/link"; +import ProjectCardCalendarManageSection from "./ProjectCardSection"; + +export default async function ManageMeetingPage() { + const supabase = createSupabaseClient(); + const { data: user, error: userError } = await supabase.auth.getUser(); + + if (userError) { + throw "Can't get user data!"; + } + + const userId = user.user?.id; + + const { data: roleData, error: roleDataError } = await getUserRole(supabase, userId); + + if (roleDataError) { + throw "Error fetching user data"; + } + + if (!roleData || roleData.role != "business") { + return ( +
+ + +

Manage Meeting Request

+
+ +
Please apply for business first to access functionalities of busienss account
+ + + +
+ ); + } + + const { data: projectData, error: projectDataError } = await getProjectByUserId(supabase, userId); + + if (projectDataError) { + throw "Can't get project data"; + } + + return ( +
+ + +

Manage Meeting Request

+
+ + }> + + +
+ ); +}