-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1621 from rockingrohit9639/feature/booking-client…
…-side-modal feat(create-booking): create client side modal for new booking
- Loading branch information
Showing
5 changed files
with
180 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { cloneElement, useState } from "react"; | ||
import type { TeamMember } from "@prisma/client"; | ||
import { useLoaderData } from "@remix-run/react"; | ||
import { CalendarRangeIcon } from "lucide-react"; | ||
import { useSearchParams } from "~/hooks/search-params"; | ||
import { getBookingDefaultStartEndTimes } from "~/utils/date-fns"; | ||
import { tw } from "~/utils/tw"; | ||
import { BookingForm } from "./form"; | ||
import { Dialog, DialogPortal } from "../layout/dialog"; | ||
|
||
type CreateBookingDialogProps = { | ||
className?: string; | ||
trigger: React.ReactElement<{ onClick: () => void }>; | ||
}; | ||
|
||
export default function CreateBookingDialog({ | ||
className, | ||
trigger, | ||
}: CreateBookingDialogProps) { | ||
const { teamMembers, isSelfServiceOrBase } = useLoaderData<{ | ||
teamMembers: TeamMember[]; | ||
isSelfServiceOrBase: boolean; | ||
}>(); | ||
|
||
// The loader already takes care of returning only the current user so we just get the first and only element in the array | ||
const custodianRef = isSelfServiceOrBase ? teamMembers[0]?.id : undefined; | ||
|
||
const [isDialogOpen, setIsDialogOpen] = useState(false); | ||
const [searchParams] = useSearchParams(); | ||
|
||
const assetIds = searchParams.getAll("assetId"); | ||
|
||
const { startDate, endDate } = getBookingDefaultStartEndTimes(); | ||
|
||
function openDialog() { | ||
setIsDialogOpen(true); | ||
} | ||
|
||
function closeDialog() { | ||
setIsDialogOpen(false); | ||
} | ||
|
||
return ( | ||
<> | ||
{cloneElement(trigger, { onClick: openDialog })} | ||
|
||
<DialogPortal> | ||
<Dialog | ||
className={tw("w-[480px] overflow-auto md:h-screen", className)} | ||
open={isDialogOpen} | ||
onClose={closeDialog} | ||
title={ | ||
<div className="mt-4 inline-flex items-center justify-center rounded-full border-4 border-solid border-primary-50 bg-primary-100 p-1.5 text-primary"> | ||
<CalendarRangeIcon /> | ||
</div> | ||
} | ||
> | ||
<div className="px-6 py-4"> | ||
<div className="mb-5"> | ||
<h4>Create new booking</h4> | ||
<p> | ||
Choose a name for your booking, select a start and end time and | ||
choose the custodian. Based on the selected information, asset | ||
availability will be determined. | ||
</p> | ||
</div> | ||
|
||
<BookingForm | ||
startDate={startDate} | ||
endDate={endDate} | ||
assetIds={assetIds.length ? assetIds : undefined} | ||
custodianRef={custodianRef} | ||
action="/bookings/new" | ||
/> | ||
</div> | ||
</Dialog> | ||
</DialogPortal> | ||
</> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useMemo } from "react"; | ||
import { useLoaderData } from "@remix-run/react"; | ||
import { useViewportHeight } from "~/hooks/use-viewport-height"; | ||
|
||
type TitleContainerProps = { | ||
className?: string; | ||
calendarTitle?: string; | ||
calendarSubtitle?: string; | ||
calendarView: string; | ||
}; | ||
|
||
export default function TitleContainer({ | ||
className, | ||
calendarTitle, | ||
calendarSubtitle, | ||
calendarView, | ||
}: TitleContainerProps) { | ||
const { title } = useLoaderData<{ title: string }>(); | ||
const { isMd } = useViewportHeight(); | ||
|
||
const titleToRender = useMemo(() => { | ||
if (calendarTitle) { | ||
return calendarTitle; | ||
} | ||
|
||
return title; | ||
}, [calendarTitle, title]); | ||
|
||
return ( | ||
<div className={className}> | ||
<div className="text-left font-sans text-lg font-semibold leading-[20px] "> | ||
{titleToRender} | ||
</div> | ||
{!isMd || calendarView == "timeGridWeek" ? ( | ||
<div className="text-gray-600">{calendarSubtitle}</div> | ||
) : null} | ||
</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