Feature/round robin (#613)
* Heavy WIP * More WIP * Playing with backwards compat * Moar wip * wip * Email changes for group feature * Committing in redundant migrations for reference * Combine all WIP migrations into a single feature migration * Make backup of current version of radio area pending refactor * Improved accessibility through keyboard * Cleanup in seperate commit so I can cherrypick later * Added RadioArea component * wip * Ignore .yarn file * Kinda stable * Getting closer... * Hide header when there are only personal events * Added uid to event create, updated EventTypeDescription * Delete redundant migration * Committing new team related migrations * Optimising & implemented backwards compatibility * Removed now redundant pages * Undid prototyping to calendarClient I did not end up using * Properly typed Select & fixed lint throughout * How'd that get here, removed. * TODO: investigate why userData is not compatible with passed type * This likely matches the event type that is created for a user * Few bugfixes * Adding datepicker optimisations * Fixed new event type spacing, initial profile should always be there * Gave NEXT_PUBLIC_BASE_URL a try but I think it's not the right solution * Updated EventTypeDescription to account for long titles, added logo to team page. * Added logo to team query * Added cancel Cypress test because an upcoming merge contains changes * Fix for when the event type description is long * Turned Theme into the useTheme hook, and made it fully compatible with teams pages * Built AvatarGroup ui component + moved Avatar to ui * Give the avatar some space fom the description * Fixed timeZone selector * Disabled tooltip +1-... Co-authored-by: Bailey Pumfleet <[email protected]>
This commit is contained in:
1 parent
e9ff62109d
commit
6ab741b927
54 files changed
+3980
-2413
No files matched your search
+18
-29
@@ -1,16 +1,16 @@
|
||||
import Avatar from "@components/Avatar";
|
||||
import Avatar from "@components/ui/Avatar";
|
||||
import { HeadSeo } from "@components/seo/head-seo";
|
||||
import Theme from "@components/Theme";
|
||||
import useTheme from "@lib/hooks/useTheme";
|
||||
import { ArrowRightIcon } from "@heroicons/react/outline";
|
||||
import { ClockIcon, InformationCircleIcon, UserIcon } from "@heroicons/react/solid";
|
||||
import prisma from "@lib/prisma";
|
||||
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
import { GetServerSidePropsContext } from "next";
|
||||
import Link from "next/link";
|
||||
import React from "react";
|
||||
import EventTypeDescription from "@components/eventtype/EventTypeDescription";
|
||||
|
||||
export default function User(props: inferSSRProps<typeof getServerSideProps>) {
|
||||
const { isReady } = Theme(props.user.theme);
|
||||
const { isReady } = useTheme(props.user.theme);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -43,29 +43,7 @@ export default function User(props: inferSSRProps<typeof getServerSideProps>) {
|
||||
<Link href={`/${props.user.username}/${type.slug}`}>
|
||||
<a className="block px-6 py-4">
|
||||
<h2 className="font-semibold text-neutral-900 dark:text-white">{type.title}</h2>
|
||||
<div className="mt-2 flex space-x-4">
|
||||
<div className="flex text-sm text-neutral-500">
|
||||
<ClockIcon
|
||||
className="flex-shrink-0 mt-0.5 mr-1.5 h-4 w-4 text-neutral-400 dark:text-white"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<p className="dark:text-white">{type.length}m</p>
|
||||
</div>
|
||||
<div className="flex text-sm min-w-16 text-neutral-500">
|
||||
<UserIcon
|
||||
className="flex-shrink-0 mt-0.5 mr-1.5 h-4 w-4 text-neutral-400 dark:text-white"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<p className="dark:text-white">1-on-1</p>
|
||||
</div>
|
||||
<div className="flex text-sm text-neutral-500">
|
||||
<InformationCircleIcon
|
||||
className="flex-shrink-0 mt-0.5 mr-1.5 h-4 w-4 text-neutral-400 dark:text-white"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<p className="dark:text-white">{type.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
<EventTypeDescription eventType={type} />
|
||||
</a>
|
||||
</Link>
|
||||
</div>
|
||||
@@ -112,7 +90,18 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
|
||||
const eventTypesWithHidden = await prisma.eventType.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
OR: [
|
||||
{
|
||||
userId: user.id,
|
||||
},
|
||||
{
|
||||
users: {
|
||||
some: {
|
||||
id: user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -127,8 +116,8 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
const eventTypes = eventTypesWithHidden.filter((evt) => !evt.hidden);
|
||||
return {
|
||||
props: {
|
||||
user,
|
||||
eventTypes,
|
||||
user,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
+90
-233
@@ -1,210 +1,12 @@
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
import Avatar from "@components/Avatar";
|
||||
import AvailableTimes from "@components/booking/AvailableTimes";
|
||||
import DatePicker from "@components/booking/DatePicker";
|
||||
import TimeOptions from "@components/booking/TimeOptions";
|
||||
import { HeadSeo } from "@components/seo/head-seo";
|
||||
import Theme from "@components/Theme";
|
||||
import PoweredByCalendso from "@components/ui/PoweredByCalendso";
|
||||
import { ChevronDownIcon, ChevronUpIcon, ClockIcon, GlobeIcon } from "@heroicons/react/solid";
|
||||
import { User } from "@prisma/client";
|
||||
import { asStringOrNull } from "@lib/asStringOrNull";
|
||||
import { timeZone } from "@lib/clock";
|
||||
import { isBrandingHidden } from "@lib/isBrandingHidden";
|
||||
import prisma from "@lib/prisma";
|
||||
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@lib/telemetry";
|
||||
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
import { Availability } from "@prisma/client";
|
||||
import * as Collapsible from "@radix-ui/react-collapsible";
|
||||
import dayjs, { Dayjs } from "dayjs";
|
||||
import { GetServerSidePropsContext } from "next";
|
||||
import { useRouter } from "next/router";
|
||||
import { useEffect, useState } from "react";
|
||||
import AvailabilityPage from "@components/booking/pages/AvailabilityPage";
|
||||
|
||||
export default function Type(props: inferSSRProps<typeof getServerSideProps>) {
|
||||
// Get router variables
|
||||
const router = useRouter();
|
||||
const { rescheduleUid } = router.query;
|
||||
|
||||
const { isReady } = Theme(props.user.theme);
|
||||
|
||||
const [selectedDate, setSelectedDate] = useState<Dayjs>(() => {
|
||||
return props.date && dayjs(props.date).isValid() ? dayjs(props.date) : null;
|
||||
});
|
||||
const [isTimeOptionsOpen, setIsTimeOptionsOpen] = useState(false);
|
||||
const [timeFormat, setTimeFormat] = useState("h:mma");
|
||||
const telemetry = useTelemetry();
|
||||
|
||||
useEffect(() => {
|
||||
handleToggle24hClock(localStorage.getItem("timeOption.is24hClock") === "true");
|
||||
telemetry.withJitsu((jitsu) => jitsu.track(telemetryEventTypes.pageView, collectPageParameters()));
|
||||
}, [telemetry]);
|
||||
|
||||
const changeDate = (date: Dayjs) => {
|
||||
telemetry.withJitsu((jitsu) => jitsu.track(telemetryEventTypes.dateSelected, collectPageParameters()));
|
||||
setSelectedDate(date);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedDate) {
|
||||
return;
|
||||
}
|
||||
|
||||
const formattedDate = selectedDate.utc().format("YYYY-MM-DD");
|
||||
|
||||
router.replace(
|
||||
{
|
||||
query: Object.assign(
|
||||
{},
|
||||
{
|
||||
...router.query,
|
||||
},
|
||||
{
|
||||
date: formattedDate,
|
||||
}
|
||||
),
|
||||
},
|
||||
undefined,
|
||||
{
|
||||
shallow: true,
|
||||
}
|
||||
);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [selectedDate]);
|
||||
|
||||
const handleSelectTimeZone = (selectedTimeZone: string): void => {
|
||||
if (selectedDate) {
|
||||
setSelectedDate(selectedDate.tz(selectedTimeZone));
|
||||
}
|
||||
setIsTimeOptionsOpen(false);
|
||||
};
|
||||
|
||||
const handleToggle24hClock = (is24hClock: boolean) => {
|
||||
setTimeFormat(is24hClock ? "HH:mm" : "h:mma");
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<HeadSeo
|
||||
title={`${rescheduleUid ? "Reschedule" : ""} ${props.eventType.title} | ${
|
||||
props.user.name || props.user.username
|
||||
}`}
|
||||
description={`${rescheduleUid ? "Reschedule" : ""} ${props.eventType.title}`}
|
||||
name={props.user.name || props.user.username}
|
||||
avatar={props.user.avatar}
|
||||
/>
|
||||
{isReady && (
|
||||
<div>
|
||||
<main
|
||||
className={
|
||||
"mx-auto my-0 md:my-24 transition-max-width ease-in-out duration-500 " +
|
||||
(selectedDate ? "max-w-5xl" : "max-w-3xl")
|
||||
}>
|
||||
<div className="bg-white border-gray-200 rounded-sm sm:dark:border-gray-600 dark:bg-gray-900 md:border">
|
||||
{/* mobile: details */}
|
||||
<div className="block p-4 sm:p-8 md:hidden">
|
||||
<div className="flex items-center">
|
||||
<Avatar
|
||||
imageSrc={props.user.avatar}
|
||||
displayName={props.user.name}
|
||||
className="inline-block rounded-full h-9 w-9"
|
||||
/>
|
||||
<div className="ml-3">
|
||||
<p className="text-sm font-medium text-black dark:text-gray-300">{props.user.name}</p>
|
||||
<div className="flex gap-2 text-xs font-medium text-gray-600">
|
||||
{props.eventType.title}
|
||||
<div>
|
||||
<ClockIcon className="inline-block w-4 h-4 mr-1 -mt-1" />
|
||||
{props.eventType.length} minutes
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p className="mt-3 text-gray-600 dark:text-gray-200">{props.eventType.description}</p>
|
||||
</div>
|
||||
|
||||
<div className="px-4 sm:flex sm:py-5 sm:p-4">
|
||||
<div
|
||||
className={
|
||||
"hidden md:block pr-8 sm:border-r sm:dark:border-gray-800 " +
|
||||
(selectedDate ? "sm:w-1/3" : "sm:w-1/2")
|
||||
}>
|
||||
<Avatar
|
||||
imageSrc={props.user.avatar}
|
||||
displayName={props.user.name}
|
||||
className="w-16 h-16 mb-4 rounded-full"
|
||||
/>
|
||||
<h2 className="font-medium text-gray-500 dark:text-gray-300">{props.user.name}</h2>
|
||||
<h1 className="mb-4 text-3xl font-semibold text-gray-800 dark:text-white">
|
||||
{props.eventType.title}
|
||||
</h1>
|
||||
<p className="px-2 py-1 mb-1 -ml-2 text-gray-500">
|
||||
<ClockIcon className="inline-block w-4 h-4 mr-1 -mt-1" />
|
||||
{props.eventType.length} minutes
|
||||
</p>
|
||||
|
||||
<TimezoneDropdown />
|
||||
|
||||
<p className="mt-3 mb-8 text-gray-600 dark:text-gray-200">{props.eventType.description}</p>
|
||||
</div>
|
||||
<DatePicker
|
||||
date={selectedDate}
|
||||
periodType={props.eventType?.periodType}
|
||||
periodStartDate={props.eventType?.periodStartDate}
|
||||
periodEndDate={props.eventType?.periodEndDate}
|
||||
periodDays={props.eventType?.periodDays}
|
||||
periodCountCalendarDays={props.eventType?.periodCountCalendarDays}
|
||||
weekStart={props.user.weekStart}
|
||||
onDatePicked={changeDate}
|
||||
workingHours={props.workingHours}
|
||||
organizerTimeZone={props.eventType.timeZone || props.user.timeZone}
|
||||
inviteeTimeZone={timeZone()}
|
||||
eventLength={props.eventType.length}
|
||||
minimumBookingNotice={props.eventType.minimumBookingNotice}
|
||||
/>
|
||||
|
||||
<div className="block mt-4 ml-1 sm:hidden">
|
||||
<TimezoneDropdown />
|
||||
</div>
|
||||
|
||||
{selectedDate && (
|
||||
<AvailableTimes
|
||||
workingHours={props.workingHours}
|
||||
timeFormat={timeFormat}
|
||||
organizerTimeZone={props.eventType.timeZone || props.user.timeZone}
|
||||
minimumBookingNotice={props.eventType.minimumBookingNotice}
|
||||
eventTypeId={props.eventType.id}
|
||||
eventLength={props.eventType.length}
|
||||
date={selectedDate}
|
||||
user={props.user}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{!isBrandingHidden(props.user) && <PoweredByCalendso />}
|
||||
</main>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
function TimezoneDropdown() {
|
||||
return (
|
||||
<Collapsible.Root open={isTimeOptionsOpen} onOpenChange={setIsTimeOptionsOpen}>
|
||||
<Collapsible.Trigger className="px-2 py-1 mb-1 -ml-2 text-left text-gray-500 min-w-32">
|
||||
<GlobeIcon className="inline-block w-4 h-4 mr-1 -mt-1" />
|
||||
{timeZone()}
|
||||
{isTimeOptionsOpen ? (
|
||||
<ChevronUpIcon className="inline-block w-4 h-4 ml-1 -mt-1" />
|
||||
) : (
|
||||
<ChevronDownIcon className="inline-block w-4 h-4 ml-1 -mt-1" />
|
||||
)}
|
||||
</Collapsible.Trigger>
|
||||
<Collapsible.Content>
|
||||
<TimeOptions onSelectTimeZone={handleSelectTimeZone} onToggle24hClock={handleToggle24hClock} />
|
||||
</Collapsible.Content>
|
||||
</Collapsible.Root>
|
||||
);
|
||||
}
|
||||
return <AvailabilityPage {...props} />;
|
||||
}
|
||||
|
||||
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
||||
@@ -218,7 +20,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
throw new Error(`File is not named [type]/[user]`);
|
||||
}
|
||||
|
||||
const user = await prisma.user.findFirst({
|
||||
const user: User = await prisma.user.findUnique({
|
||||
where: {
|
||||
username: userParam.toLowerCase(),
|
||||
},
|
||||
@@ -237,6 +39,32 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
hideBranding: true,
|
||||
theme: true,
|
||||
plan: true,
|
||||
eventTypes: {
|
||||
where: {
|
||||
AND: [
|
||||
{
|
||||
slug: typeParam,
|
||||
},
|
||||
{
|
||||
teamId: null,
|
||||
},
|
||||
],
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
availability: true,
|
||||
description: true,
|
||||
length: true,
|
||||
users: {
|
||||
select: {
|
||||
avatar: true,
|
||||
name: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -245,41 +73,65 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
const eventType = await prisma.eventType.findUnique({
|
||||
where: {
|
||||
userId_slug: {
|
||||
userId: user.id,
|
||||
slug: typeParam,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
description: true,
|
||||
length: true,
|
||||
availability: true,
|
||||
timeZone: true,
|
||||
periodType: true,
|
||||
periodDays: true,
|
||||
periodStartDate: true,
|
||||
periodEndDate: true,
|
||||
periodCountCalendarDays: true,
|
||||
minimumBookingNotice: true,
|
||||
hidden: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!eventType) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
if (user.eventTypes.length !== 1) {
|
||||
const eventTypeBackwardsCompat = await prisma.eventType.findFirst({
|
||||
where: {
|
||||
AND: [
|
||||
{
|
||||
userId: user.id,
|
||||
},
|
||||
{
|
||||
slug: typeParam,
|
||||
},
|
||||
],
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
availability: true,
|
||||
description: true,
|
||||
length: true,
|
||||
users: {
|
||||
select: {
|
||||
avatar: true,
|
||||
name: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!eventTypeBackwardsCompat) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
eventTypeBackwardsCompat.users.push({
|
||||
avatar: user.avatar,
|
||||
name: user.name,
|
||||
username: user.username,
|
||||
});
|
||||
user.eventTypes.push(eventTypeBackwardsCompat);
|
||||
}
|
||||
|
||||
const eventType = user.eventTypes[0];
|
||||
|
||||
// check this is the first event
|
||||
if (user.plan === "FREE") {
|
||||
const firstEventType = await prisma.eventType.findFirst({
|
||||
where: {
|
||||
userId: user.id,
|
||||
OR: [
|
||||
{
|
||||
userId: user.id,
|
||||
},
|
||||
{
|
||||
users: {
|
||||
some: {
|
||||
id: user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -297,8 +149,8 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
: null;
|
||||
|
||||
const workingHours =
|
||||
getWorkingHours(eventType) ||
|
||||
getWorkingHours(user) ||
|
||||
getWorkingHours(eventType.availability) ||
|
||||
getWorkingHours(user.availability) ||
|
||||
[
|
||||
{
|
||||
days: [0, 1, 2, 3, 4, 5, 6],
|
||||
@@ -316,7 +168,12 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
|
||||
return {
|
||||
props: {
|
||||
user,
|
||||
profile: {
|
||||
name: user.name,
|
||||
image: user.avatar,
|
||||
slug: user.username,
|
||||
theme: user.theme,
|
||||
},
|
||||
date: dateParam,
|
||||
eventType: eventTypeObject,
|
||||
workingHours,
|
||||
|
||||
+30
-416
@@ -1,431 +1,30 @@
|
||||
import { HeadSeo } from "@components/seo/head-seo";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { CalendarIcon, ClockIcon, ExclamationIcon, LocationMarkerIcon } from "@heroicons/react/solid";
|
||||
import prisma, { whereAndSelect } from "@lib/prisma";
|
||||
import { EventTypeCustomInputType } from "@prisma/client";
|
||||
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@lib/telemetry";
|
||||
import { useEffect, useState } from "react";
|
||||
import prisma from "@lib/prisma";
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import PhoneInput from "@components/ui/form/PhoneInput";
|
||||
import { LocationType } from "@lib/location";
|
||||
import Avatar from "@components/Avatar";
|
||||
import { Button } from "@components/ui/Button";
|
||||
import Theme from "@components/Theme";
|
||||
import { ReactMultiEmail } from "react-multi-email";
|
||||
import BookingPage from "@components/booking/pages/BookingPage";
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export default function Book(props: any): JSX.Element {
|
||||
const router = useRouter();
|
||||
const { date, user, rescheduleUid } = router.query;
|
||||
|
||||
const [is24h, setIs24h] = useState(false);
|
||||
const [preferredTimeZone, setPreferredTimeZone] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState(false);
|
||||
const [guestToggle, setGuestToggle] = useState(false);
|
||||
const [guestEmails, setGuestEmails] = useState([]);
|
||||
const locations = props.eventType.locations || [];
|
||||
|
||||
const [selectedLocation, setSelectedLocation] = useState<LocationType>(
|
||||
locations.length === 1 ? locations[0].type : ""
|
||||
);
|
||||
|
||||
const { isReady } = Theme(props.user.theme);
|
||||
const telemetry = useTelemetry();
|
||||
|
||||
useEffect(() => {
|
||||
setPreferredTimeZone(localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess());
|
||||
setIs24h(!!localStorage.getItem("timeOption.is24hClock"));
|
||||
|
||||
telemetry.withJitsu((jitsu) => jitsu.track(telemetryEventTypes.timeSelected, collectPageParameters()));
|
||||
});
|
||||
|
||||
function toggleGuestEmailInput() {
|
||||
setGuestToggle(!guestToggle);
|
||||
}
|
||||
|
||||
const locationInfo = (type: LocationType) => locations.find((location) => location.type === type);
|
||||
|
||||
// TODO: Move to translations
|
||||
const locationLabels = {
|
||||
[LocationType.InPerson]: "In-person meeting",
|
||||
[LocationType.Phone]: "Phone call",
|
||||
[LocationType.GoogleMeet]: "Google Meet",
|
||||
[LocationType.Zoom]: "Zoom Video",
|
||||
};
|
||||
|
||||
const bookingHandler = (event) => {
|
||||
const book = async () => {
|
||||
setLoading(true);
|
||||
setError(false);
|
||||
let notes = "";
|
||||
if (props.eventType.customInputs) {
|
||||
notes = props.eventType.customInputs
|
||||
.map((input) => {
|
||||
const data = event.target["custom_" + input.id];
|
||||
if (data) {
|
||||
if (input.type === EventTypeCustomInputType.BOOL) {
|
||||
return input.label + "\n" + (data.checked ? "Yes" : "No");
|
||||
} else {
|
||||
return input.label + "\n" + data.value;
|
||||
}
|
||||
}
|
||||
})
|
||||
.join("\n\n");
|
||||
}
|
||||
if (!!notes && !!event.target.notes.value) {
|
||||
notes += "\n\nAdditional notes:\n" + event.target.notes.value;
|
||||
} else {
|
||||
notes += event.target.notes.value;
|
||||
}
|
||||
|
||||
const payload = {
|
||||
start: dayjs(date).format(),
|
||||
end: dayjs(date).add(props.eventType.length, "minute").format(),
|
||||
name: event.target.name.value,
|
||||
email: event.target.email.value,
|
||||
notes: notes,
|
||||
guests: guestEmails,
|
||||
timeZone: preferredTimeZone,
|
||||
eventTypeId: props.eventType.id,
|
||||
rescheduleUid: rescheduleUid,
|
||||
};
|
||||
|
||||
if (selectedLocation) {
|
||||
switch (selectedLocation) {
|
||||
case LocationType.Phone:
|
||||
payload["location"] = event.target.phone.value;
|
||||
break;
|
||||
|
||||
case LocationType.InPerson:
|
||||
payload["location"] = locationInfo(selectedLocation).address;
|
||||
break;
|
||||
|
||||
// Catches all other location types, such as Google Meet, Zoom etc.
|
||||
default:
|
||||
payload["location"] = selectedLocation;
|
||||
}
|
||||
}
|
||||
|
||||
telemetry.withJitsu((jitsu) =>
|
||||
jitsu.track(telemetryEventTypes.bookingConfirmed, collectPageParameters())
|
||||
);
|
||||
|
||||
/*const res = await */ fetch("/api/book/" + user, {
|
||||
body: JSON.stringify(payload),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
method: "POST",
|
||||
});
|
||||
// TODO When the endpoint is fixed, change this to await the result again
|
||||
//if (res.ok) {
|
||||
let successUrl = `/success?date=${date}&type=${props.eventType.id}&user=${
|
||||
props.user.username
|
||||
}&reschedule=${!!rescheduleUid}&name=${payload.name}`;
|
||||
if (payload["location"]) {
|
||||
if (payload["location"].includes("integration")) {
|
||||
successUrl += "&location=" + encodeURIComponent("Web conferencing details to follow.");
|
||||
} else {
|
||||
successUrl += "&location=" + encodeURIComponent(payload["location"]);
|
||||
}
|
||||
}
|
||||
|
||||
await router.push(successUrl);
|
||||
/*} else {
|
||||
setLoading(false);
|
||||
setError(true);
|
||||
}*/
|
||||
};
|
||||
|
||||
event.preventDefault();
|
||||
book();
|
||||
};
|
||||
|
||||
return (
|
||||
isReady && (
|
||||
<div>
|
||||
<HeadSeo
|
||||
title={`${rescheduleUid ? "Reschedule" : "Confirm"} your ${props.eventType.title} with ${
|
||||
props.user.name || props.user.username
|
||||
}`}
|
||||
description={`${rescheduleUid ? "Reschedule" : "Confirm"} your ${props.eventType.title} with ${
|
||||
props.user.name || props.user.username
|
||||
}`}
|
||||
/>
|
||||
|
||||
<main className="max-w-3xl mx-auto my-0 sm:my-24">
|
||||
<div className="dark:bg-neutral-900 bg-white overflow-hidden border border-gray-200 dark:border-0 sm:rounded-sm">
|
||||
<div className="sm:flex px-4 py-5 sm:p-4">
|
||||
<div className="sm:w-1/2 sm:border-r sm:dark:border-black">
|
||||
<Avatar
|
||||
displayName={props.user.name}
|
||||
imageSrc={props.user.avatar}
|
||||
className="w-16 h-16 rounded-full mb-4"
|
||||
/>
|
||||
<h2 className="font-medium dark:text-gray-300 text-gray-500">{props.user.name}</h2>
|
||||
<h1 className="text-3xl font-semibold dark:text-white text-gray-800 mb-4">
|
||||
{props.eventType.title}
|
||||
</h1>
|
||||
<p className="text-gray-500 mb-2">
|
||||
<ClockIcon className="inline-block w-4 h-4 mr-1 -mt-1" />
|
||||
{props.eventType.length} minutes
|
||||
</p>
|
||||
{selectedLocation === LocationType.InPerson && (
|
||||
<p className="text-gray-500 mb-2 break-words">
|
||||
<LocationMarkerIcon className="inline-block w-4 h-4 mr-1 -mt-1" />
|
||||
{locationInfo(selectedLocation).address}
|
||||
</p>
|
||||
)}
|
||||
<p className="text-green-500 mb-4">
|
||||
<CalendarIcon className="inline-block w-4 h-4 mr-1 -mt-1" />
|
||||
{preferredTimeZone &&
|
||||
dayjs(date)
|
||||
.tz(preferredTimeZone)
|
||||
.format((is24h ? "H:mm" : "h:mma") + ", dddd DD MMMM YYYY")}
|
||||
</p>
|
||||
<p className="dark:text-white text-gray-600 mb-8">{props.eventType.description}</p>
|
||||
</div>
|
||||
<div className="sm:w-1/2 sm:pl-8 sm:pr-4">
|
||||
<form onSubmit={bookingHandler}>
|
||||
<div className="mb-4">
|
||||
<label htmlFor="name" className="block text-sm font-medium dark:text-white text-gray-700">
|
||||
Your name
|
||||
</label>
|
||||
<div className="mt-1">
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
id="name"
|
||||
required
|
||||
className="shadow-sm dark:bg-black dark:text-white dark:border-gray-900 focus:ring-black focus:border-black block w-full sm:text-sm border-gray-300 rounded-md"
|
||||
placeholder="John Doe"
|
||||
defaultValue={props.booking ? props.booking.attendees[0].name : ""}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<label
|
||||
htmlFor="email"
|
||||
className="block text-sm font-medium dark:text-white text-gray-700">
|
||||
Email address
|
||||
</label>
|
||||
<div className="mt-1">
|
||||
<input
|
||||
type="email"
|
||||
name="email"
|
||||
id="email"
|
||||
required
|
||||
className="shadow-sm dark:bg-black dark:text-white dark:border-gray-900 focus:ring-black focus:border-black block w-full sm:text-sm border-gray-300 rounded-md"
|
||||
placeholder="[email protected]"
|
||||
defaultValue={props.booking ? props.booking.attendees[0].email : ""}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{locations.length > 1 && (
|
||||
<div className="mb-4">
|
||||
<span className="block text-sm font-medium dark:text-white text-gray-700">
|
||||
Location
|
||||
</span>
|
||||
{locations.map((location) => (
|
||||
<label key={location.type} className="block">
|
||||
<input
|
||||
type="radio"
|
||||
required
|
||||
onChange={(e) => setSelectedLocation(e.target.value)}
|
||||
className="location focus:ring-black h-4 w-4 text-black border-gray-300 mr-2"
|
||||
name="location"
|
||||
value={location.type}
|
||||
checked={selectedLocation === location.type}
|
||||
/>
|
||||
<span className="text-sm ml-2 dark:text-gray-500">
|
||||
{locationLabels[location.type]}
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{selectedLocation === LocationType.Phone && (
|
||||
<div className="mb-4">
|
||||
<label
|
||||
htmlFor="phone"
|
||||
className="block text-sm font-medium dark:text-white text-gray-700">
|
||||
Phone number
|
||||
</label>
|
||||
<div className="mt-1">
|
||||
<PhoneInput name="phone" placeholder="Enter phone number" id="phone" required />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{props.eventType.customInputs &&
|
||||
props.eventType.customInputs
|
||||
.sort((a, b) => a.id - b.id)
|
||||
.map((input) => (
|
||||
<div className="mb-4" key={"input-" + input.label.toLowerCase}>
|
||||
{input.type !== EventTypeCustomInputType.BOOL && (
|
||||
<label
|
||||
htmlFor={"custom_" + input.id}
|
||||
className="block text-sm font-medium text-gray-700 dark:text-white mb-1">
|
||||
{input.label}
|
||||
</label>
|
||||
)}
|
||||
{input.type === EventTypeCustomInputType.TEXTLONG && (
|
||||
<textarea
|
||||
name={"custom_" + input.id}
|
||||
id={"custom_" + input.id}
|
||||
required={input.required}
|
||||
rows={3}
|
||||
className="shadow-sm dark:bg-black dark:text-white dark:border-gray-900 focus:ring-black focus:border-black block w-full sm:text-sm border-gray-300 rounded-md"
|
||||
placeholder={input.placeholder}
|
||||
/>
|
||||
)}
|
||||
{input.type === EventTypeCustomInputType.TEXT && (
|
||||
<input
|
||||
type="text"
|
||||
name={"custom_" + input.id}
|
||||
id={"custom_" + input.id}
|
||||
required={input.required}
|
||||
className="shadow-sm dark:bg-black dark:text-white dark:border-gray-900 focus:ring-black focus:border-black block w-full sm:text-sm border-gray-300 rounded-md"
|
||||
placeholder={input.placeholder}
|
||||
/>
|
||||
)}
|
||||
{input.type === EventTypeCustomInputType.NUMBER && (
|
||||
<input
|
||||
type="number"
|
||||
name={"custom_" + input.id}
|
||||
id={"custom_" + input.id}
|
||||
required={input.required}
|
||||
className="shadow-sm dark:bg-black dark:text-white dark:border-gray-900 focus:ring-black focus:border-black block w-full sm:text-sm border-gray-300 rounded-md"
|
||||
placeholder=""
|
||||
/>
|
||||
)}
|
||||
{input.type === EventTypeCustomInputType.BOOL && (
|
||||
<div className="flex items-center h-5">
|
||||
<input
|
||||
type="checkbox"
|
||||
name={"custom_" + input.id}
|
||||
id={"custom_" + input.id}
|
||||
className="focus:ring-black h-4 w-4 text-black border-gray-300 rounded mr-2"
|
||||
placeholder=""
|
||||
/>
|
||||
<label
|
||||
htmlFor={"custom_" + input.id}
|
||||
className="block text-sm font-medium text-gray-700 dark:text-white mb-1">
|
||||
{input.label}
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<div className="mb-4">
|
||||
{!guestToggle && (
|
||||
<label
|
||||
onClick={toggleGuestEmailInput}
|
||||
htmlFor="guests"
|
||||
className="block text-sm font-medium dark:text-white text-blue-500 mb-1 hover:cursor-pointer">
|
||||
+ Additional Guests
|
||||
</label>
|
||||
)}
|
||||
{guestToggle && (
|
||||
<div>
|
||||
<label
|
||||
htmlFor="guests"
|
||||
className="block text-sm font-medium dark:text-white text-gray-700 mb-1">
|
||||
Guests
|
||||
</label>
|
||||
<ReactMultiEmail
|
||||
placeholder="[email protected]"
|
||||
emails={guestEmails}
|
||||
onChange={(_emails: string[]) => {
|
||||
setGuestEmails(_emails);
|
||||
}}
|
||||
getLabel={(email: string, index: number, removeEmail: (index: number) => void) => {
|
||||
return (
|
||||
<div data-tag key={index}>
|
||||
{email}
|
||||
<span data-tag-handle onClick={() => removeEmail(index)}>
|
||||
×
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="mb-4">
|
||||
<label
|
||||
htmlFor="notes"
|
||||
className="block text-sm font-medium dark:text-white text-gray-700 mb-1">
|
||||
Additional notes
|
||||
</label>
|
||||
<textarea
|
||||
name="notes"
|
||||
id="notes"
|
||||
rows={3}
|
||||
className="shadow-sm dark:bg-black dark:text-white dark:border-gray-900 focus:ring-black focus:border-black block w-full sm:text-sm border-gray-300 rounded-md"
|
||||
placeholder="Please share anything that will help prepare for our meeting."
|
||||
defaultValue={props.booking ? props.booking.description : ""}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-start">
|
||||
{/* TODO: add styling props to <Button variant="" color="" /> and get rid of btn-primary */}
|
||||
<Button type="submit" loading={loading}>
|
||||
{rescheduleUid ? "Reschedule" : "Confirm"}
|
||||
</Button>
|
||||
<Link
|
||||
href={
|
||||
"/" +
|
||||
props.user.username +
|
||||
"/" +
|
||||
props.eventType.slug +
|
||||
(rescheduleUid ? "?rescheduleUid=" + rescheduleUid : "")
|
||||
}>
|
||||
<a className="ml-2 text-sm dark:text-white p-2">Cancel</a>
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
{error && (
|
||||
<div className="bg-yellow-50 border-l-4 border-yellow-400 p-4 mt-2">
|
||||
<div className="flex">
|
||||
<div className="flex-shrink-0">
|
||||
<ExclamationIcon className="h-5 w-5 text-yellow-400" aria-hidden="true" />
|
||||
</div>
|
||||
<div className="ml-3">
|
||||
<p className="text-sm text-yellow-700">
|
||||
Could not {rescheduleUid ? "reschedule" : "book"} the meeting. Please try again or{" "}
|
||||
<a
|
||||
href={"mailto:" + props.user.email}
|
||||
className="font-medium underline text-yellow-700 hover:text-yellow-600">
|
||||
Contact {props.user.name} via e-mail
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
return <BookingPage {...props} />;
|
||||
}
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
const user = await whereAndSelect(
|
||||
prisma.user.findFirst,
|
||||
{
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
username: context.query.user,
|
||||
},
|
||||
["username", "name", "email", "bio", "avatar", "theme"]
|
||||
);
|
||||
select: {
|
||||
username: true,
|
||||
name: true,
|
||||
email: true,
|
||||
bio: true,
|
||||
avatar: true,
|
||||
theme: true,
|
||||
},
|
||||
});
|
||||
|
||||
const eventType = await prisma.eventType.findUnique({
|
||||
where: {
|
||||
@@ -444,6 +43,16 @@ export async function getServerSideProps(context) {
|
||||
periodStartDate: true,
|
||||
periodEndDate: true,
|
||||
periodCountCalendarDays: true,
|
||||
users: {
|
||||
select: {
|
||||
username: true,
|
||||
name: true,
|
||||
email: true,
|
||||
bio: true,
|
||||
avatar: true,
|
||||
theme: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -476,7 +85,12 @@ export async function getServerSideProps(context) {
|
||||
|
||||
return {
|
||||
props: {
|
||||
user,
|
||||
profile: {
|
||||
slug: user.username,
|
||||
name: user.name,
|
||||
image: user.avatar,
|
||||
theme: user.theme,
|
||||
},
|
||||
eventType: eventTypeObject,
|
||||
booking,
|
||||
},
|
||||
|
||||
@@ -3,11 +3,19 @@ import prisma from "@lib/prisma";
|
||||
import { getBusyCalendarTimes } from "@lib/calendarClient";
|
||||
// import { getBusyVideoTimes } from "@lib/videoClient";
|
||||
import dayjs from "dayjs";
|
||||
import { asStringOrNull } from "@lib/asStringOrNull";
|
||||
import { User } from "@prisma/client";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { user } = req.query;
|
||||
const user = asStringOrNull(req.query.user);
|
||||
const dateFrom = dayjs(asStringOrNull(req.query.dateFrom));
|
||||
const dateTo = dayjs(asStringOrNull(req.query.dateTo));
|
||||
|
||||
const currentUser = await prisma.user.findFirst({
|
||||
if (!dateFrom.isValid() || !dateTo.isValid()) {
|
||||
return res.status(400).json({ message: "Invalid time range given." });
|
||||
}
|
||||
|
||||
const currentUser: User = await prisma.user.findUnique({
|
||||
where: {
|
||||
username: user,
|
||||
},
|
||||
@@ -15,7 +23,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
credentials: true,
|
||||
timeZone: true,
|
||||
bufferTime: true,
|
||||
availability: true,
|
||||
id: true,
|
||||
startTime: true,
|
||||
endTime: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -25,23 +36,27 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
},
|
||||
});
|
||||
|
||||
const calendarBusyTimes = await getBusyCalendarTimes(
|
||||
const busyTimes = await getBusyCalendarTimes(
|
||||
currentUser.credentials,
|
||||
req.query.dateFrom,
|
||||
req.query.dateTo,
|
||||
dateFrom.format(),
|
||||
dateTo.format(),
|
||||
selectedCalendars
|
||||
);
|
||||
// const videoBusyTimes = await getBusyVideoTimes(
|
||||
// currentUser.credentials,
|
||||
// req.query.dateFrom,
|
||||
// req.query.dateTo
|
||||
// );
|
||||
// calendarBusyTimes.push(...videoBusyTimes);
|
||||
|
||||
const bufferedBusyTimes = calendarBusyTimes.map((a) => ({
|
||||
// busyTimes.push(...await getBusyVideoTimes(currentUser.credentials, dateFrom.format(), dateTo.format()));
|
||||
|
||||
const bufferedBusyTimes = busyTimes.map((a) => ({
|
||||
start: dayjs(a.start).subtract(currentUser.bufferTime, "minute").toString(),
|
||||
end: dayjs(a.end).add(currentUser.bufferTime, "minute").toString(),
|
||||
}));
|
||||
|
||||
res.status(200).json(bufferedBusyTimes);
|
||||
res.status(200).json({
|
||||
busy: bufferedBusyTimes,
|
||||
workingHours: {
|
||||
daysOfWeek: [0, 1, 2, 3, 4, 5, 6],
|
||||
timeZone: currentUser.timeZone,
|
||||
startTime: currentUser.startTime,
|
||||
endTime: currentUser.endTime,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -61,15 +61,38 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
minimumBookingNotice: req.body.minimumBookingNotice,
|
||||
};
|
||||
|
||||
if (req.body.schedulingType) {
|
||||
data.schedulingType = req.body.schedulingType;
|
||||
}
|
||||
|
||||
if (req.method == "POST") {
|
||||
if (req.body.teamId) {
|
||||
data.team = {
|
||||
connect: {
|
||||
id: req.body.teamId,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
const eventType = await prisma.eventType.create({
|
||||
data: {
|
||||
userId: session.user.id,
|
||||
...data,
|
||||
users: {
|
||||
connect: {
|
||||
id: parseInt(session.user.id),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
res.status(201).json({ eventType });
|
||||
} else if (req.method == "PATCH") {
|
||||
if (req.body.users) {
|
||||
data.users = {
|
||||
set: [],
|
||||
connect: req.body.users.map((id: number) => ({ id })),
|
||||
};
|
||||
}
|
||||
|
||||
if (req.body.timeZone) {
|
||||
data.timeZone = req.body.timeZone;
|
||||
}
|
||||
|
||||
@@ -1,330 +0,0 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@lib/prisma";
|
||||
import { EventType, User } from "@prisma/client";
|
||||
import { CalendarEvent, getBusyCalendarTimes } from "@lib/calendarClient";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
import short from "short-uuid";
|
||||
import { getBusyVideoTimes } from "@lib/videoClient";
|
||||
import { getEventName } from "@lib/event";
|
||||
import dayjs from "dayjs";
|
||||
import logger from "../../../lib/logger";
|
||||
import EventManager, { CreateUpdateResult, EventResult } from "@lib/events/EventManager";
|
||||
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import isBetween from "dayjs/plugin/isBetween";
|
||||
import dayjsBusinessDays from "dayjs-business-days";
|
||||
import EventOrganizerRequestMail from "@lib/emails/EventOrganizerRequestMail";
|
||||
|
||||
dayjs.extend(dayjsBusinessDays);
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(isBetween);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
const translator = short();
|
||||
const log = logger.getChildLogger({ prefix: ["[api] book:user"] });
|
||||
|
||||
function isAvailable(busyTimes, time, length) {
|
||||
// Check for conflicts
|
||||
let t = true;
|
||||
|
||||
if (Array.isArray(busyTimes) && busyTimes.length > 0) {
|
||||
busyTimes.forEach((busyTime) => {
|
||||
const startTime = dayjs(busyTime.start);
|
||||
const endTime = dayjs(busyTime.end);
|
||||
|
||||
// Check if time is between start and end times
|
||||
if (dayjs(time).isBetween(startTime, endTime, null, "[)")) {
|
||||
t = false;
|
||||
}
|
||||
|
||||
// Check if slot end time is between start and end time
|
||||
if (dayjs(time).add(length, "minutes").isBetween(startTime, endTime)) {
|
||||
t = false;
|
||||
}
|
||||
|
||||
// Check if startTime is between slot
|
||||
if (startTime.isBetween(dayjs(time), dayjs(time).add(length, "minutes"))) {
|
||||
t = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
function isOutOfBounds(
|
||||
time: dayjs.ConfigType,
|
||||
{ periodType, periodDays, periodCountCalendarDays, periodStartDate, periodEndDate, timeZone }
|
||||
): boolean {
|
||||
const date = dayjs(time);
|
||||
|
||||
switch (periodType) {
|
||||
case "rolling": {
|
||||
const periodRollingEndDay = periodCountCalendarDays
|
||||
? dayjs().tz(timeZone).add(periodDays, "days").endOf("day")
|
||||
: dayjs().tz(timeZone).businessDaysAdd(periodDays, "days").endOf("day");
|
||||
return date.endOf("day").isAfter(periodRollingEndDay);
|
||||
}
|
||||
|
||||
case "range": {
|
||||
const periodRangeStartDay = dayjs(periodStartDate).tz(timeZone).endOf("day");
|
||||
const periodRangeEndDay = dayjs(periodEndDate).tz(timeZone).endOf("day");
|
||||
return date.endOf("day").isBefore(periodRangeStartDay) || date.endOf("day").isAfter(periodRangeEndDay);
|
||||
}
|
||||
|
||||
case "unlimited":
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse): Promise<void> {
|
||||
const { user } = req.query;
|
||||
log.debug(`Booking ${user} started`);
|
||||
|
||||
try {
|
||||
const isTimeInPast = (time) => {
|
||||
return dayjs(time).isBefore(new Date(), "day");
|
||||
};
|
||||
|
||||
if (isTimeInPast(req.body.start)) {
|
||||
const error = {
|
||||
errorCode: "BookingDateInPast",
|
||||
message: "Attempting to create a meeting in the past.",
|
||||
};
|
||||
|
||||
log.error(`Booking ${user} failed`, error);
|
||||
return res.status(400).json(error);
|
||||
}
|
||||
|
||||
let currentUser: User = await prisma.user.findFirst({
|
||||
where: {
|
||||
username: user,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
credentials: true,
|
||||
timeZone: true,
|
||||
email: true,
|
||||
name: true,
|
||||
},
|
||||
});
|
||||
|
||||
const selectedCalendars = await prisma.selectedCalendar.findMany({
|
||||
where: {
|
||||
userId: currentUser.id,
|
||||
},
|
||||
});
|
||||
|
||||
const hasCalendarIntegrations =
|
||||
currentUser.credentials.filter((cred) => cred.type.endsWith("_calendar")).length > 0;
|
||||
const hasVideoIntegrations =
|
||||
currentUser.credentials.filter((cred) => cred.type.endsWith("_video")).length > 0;
|
||||
|
||||
const calendarAvailability = await getBusyCalendarTimes(
|
||||
currentUser.credentials,
|
||||
dayjs(req.body.start).startOf("day").utc().format("YYYY-MM-DDTHH:mm:ss[Z]"),
|
||||
dayjs(req.body.end).endOf("day").utc().format("YYYY-MM-DDTHH:mm:ss[Z]"),
|
||||
selectedCalendars
|
||||
);
|
||||
const videoAvailability = await getBusyVideoTimes(currentUser.credentials);
|
||||
let commonAvailability = [];
|
||||
|
||||
if (hasCalendarIntegrations && hasVideoIntegrations) {
|
||||
commonAvailability = calendarAvailability.filter((availability) =>
|
||||
videoAvailability.includes(availability)
|
||||
);
|
||||
} else if (hasVideoIntegrations) {
|
||||
commonAvailability = videoAvailability;
|
||||
} else if (hasCalendarIntegrations) {
|
||||
commonAvailability = calendarAvailability;
|
||||
}
|
||||
|
||||
// Now, get the newly stored credentials (new refresh token for example).
|
||||
currentUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
username: user,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
credentials: true,
|
||||
timeZone: true,
|
||||
email: true,
|
||||
name: true,
|
||||
},
|
||||
});
|
||||
|
||||
// Initialize EventManager with credentials
|
||||
const eventManager = new EventManager(currentUser.credentials);
|
||||
const rescheduleUid = req.body.rescheduleUid;
|
||||
|
||||
const eventType: EventType = await prisma.eventType.findFirst({
|
||||
where: {
|
||||
userId: currentUser.id,
|
||||
id: req.body.eventTypeId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
eventName: true,
|
||||
title: true,
|
||||
length: true,
|
||||
periodType: true,
|
||||
periodDays: true,
|
||||
periodStartDate: true,
|
||||
periodEndDate: true,
|
||||
periodCountCalendarDays: true,
|
||||
requiresConfirmation: true,
|
||||
},
|
||||
});
|
||||
|
||||
const invitee = [{ email: req.body.email, name: req.body.name, timeZone: req.body.timeZone }];
|
||||
const guests = req.body.guests.map((guest) => {
|
||||
const g = {
|
||||
email: guest,
|
||||
name: "",
|
||||
timeZone: req.body.timeZone,
|
||||
};
|
||||
return g;
|
||||
});
|
||||
const attendeesList = [...invitee, ...guests];
|
||||
|
||||
const evt: CalendarEvent = {
|
||||
type: eventType.title,
|
||||
title: getEventName(req.body.name, eventType.title, eventType.eventName),
|
||||
description: req.body.notes,
|
||||
startTime: req.body.start,
|
||||
endTime: req.body.end,
|
||||
organizer: { email: currentUser.email, name: currentUser.name, timeZone: currentUser.timeZone },
|
||||
attendees: attendeesList,
|
||||
location: req.body.location, // Will be processed by the EventManager later.
|
||||
};
|
||||
|
||||
let isAvailableToBeBooked = true;
|
||||
|
||||
try {
|
||||
isAvailableToBeBooked = isAvailable(commonAvailability, req.body.start, eventType.length);
|
||||
} catch {
|
||||
log.debug({
|
||||
message: "Unable set isAvailableToBeBooked. Using true. ",
|
||||
});
|
||||
}
|
||||
|
||||
if (!isAvailableToBeBooked) {
|
||||
const error = {
|
||||
errorCode: "BookingUserUnAvailable",
|
||||
message: `${currentUser.name} is unavailable at this time.`,
|
||||
};
|
||||
|
||||
log.debug(`Booking ${user} failed`, error);
|
||||
return res.status(400).json(error);
|
||||
}
|
||||
|
||||
let timeOutOfBounds = false;
|
||||
|
||||
try {
|
||||
timeOutOfBounds = isOutOfBounds(req.body.start, {
|
||||
periodType: eventType.periodType,
|
||||
periodDays: eventType.periodDays,
|
||||
periodEndDate: eventType.periodEndDate,
|
||||
periodStartDate: eventType.periodStartDate,
|
||||
periodCountCalendarDays: eventType.periodCountCalendarDays,
|
||||
timeZone: currentUser.timeZone,
|
||||
});
|
||||
} catch {
|
||||
log.debug({
|
||||
message: "Unable set timeOutOfBounds. Using false. ",
|
||||
});
|
||||
}
|
||||
|
||||
if (timeOutOfBounds) {
|
||||
const error = {
|
||||
errorCode: "BookingUserUnAvailable",
|
||||
message: `${currentUser.name} is unavailable at this time.`,
|
||||
};
|
||||
|
||||
log.debug(`Booking ${user} failed`, error);
|
||||
return res.status(400).json(error);
|
||||
}
|
||||
|
||||
let results: Array<EventResult> = [];
|
||||
let referencesToCreate = [];
|
||||
|
||||
if (rescheduleUid) {
|
||||
// Use EventManager to conditionally use all needed integrations.
|
||||
const updateResults: CreateUpdateResult = await eventManager.update(evt, rescheduleUid);
|
||||
|
||||
if (results.length > 0 && results.every((res) => !res.success)) {
|
||||
const error = {
|
||||
errorCode: "BookingReschedulingMeetingFailed",
|
||||
message: "Booking Rescheduling failed",
|
||||
};
|
||||
|
||||
log.error(`Booking ${user} failed`, error, results);
|
||||
return res.status(500).json(error);
|
||||
}
|
||||
|
||||
// Forward results
|
||||
results = updateResults.results;
|
||||
referencesToCreate = updateResults.referencesToCreate;
|
||||
} else if (!eventType.requiresConfirmation) {
|
||||
// Use EventManager to conditionally use all needed integrations.
|
||||
const createResults: CreateUpdateResult = await eventManager.create(evt);
|
||||
|
||||
if (results.length > 0 && results.every((res) => !res.success)) {
|
||||
const error = {
|
||||
errorCode: "BookingCreatingMeetingFailed",
|
||||
message: "Booking failed",
|
||||
};
|
||||
|
||||
log.error(`Booking ${user} failed`, error, results);
|
||||
return res.status(500).json(error);
|
||||
}
|
||||
|
||||
// Forward results
|
||||
results = createResults.results;
|
||||
referencesToCreate = createResults.referencesToCreate;
|
||||
}
|
||||
|
||||
const hashUID =
|
||||
results.length > 0 ? results[0].uid : translator.fromUUID(uuidv5(JSON.stringify(evt), uuidv5.URL));
|
||||
// TODO Should just be set to the true case as soon as we have a "bare email" integration class.
|
||||
// UID generation should happen in the integration itself, not here.
|
||||
|
||||
try {
|
||||
await prisma.booking.create({
|
||||
data: {
|
||||
uid: hashUID,
|
||||
userId: currentUser.id,
|
||||
references: {
|
||||
create: referencesToCreate,
|
||||
},
|
||||
eventTypeId: eventType.id,
|
||||
title: evt.title,
|
||||
description: evt.description,
|
||||
startTime: evt.startTime,
|
||||
endTime: evt.endTime,
|
||||
attendees: {
|
||||
create: evt.attendees,
|
||||
},
|
||||
confirmed: !eventType.requiresConfirmation,
|
||||
location: evt.location,
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
log.error(`Booking ${user} failed`, "Error when saving booking to db", e);
|
||||
res.status(500).json({ message: "Booking already exists" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (eventType.requiresConfirmation) {
|
||||
await new EventOrganizerRequestMail(evt, hashUID).sendEmail();
|
||||
}
|
||||
|
||||
log.debug(`Booking ${user} completed`);
|
||||
return res.status(204).json({ message: "Booking completed" });
|
||||
} catch (reason) {
|
||||
log.error(`Booking ${user} failed`, reason);
|
||||
return res.status(500).json({ message: "Booking failed for some unknown reason" });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,434 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import prisma from "@lib/prisma";
|
||||
import {
|
||||
EventType,
|
||||
User,
|
||||
SchedulingType,
|
||||
Credential,
|
||||
SelectedCalendar,
|
||||
Booking,
|
||||
Prisma,
|
||||
} from "@prisma/client";
|
||||
import { CalendarEvent, getBusyCalendarTimes } from "@lib/calendarClient";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
import short from "short-uuid";
|
||||
import { getBusyVideoTimes } from "@lib/videoClient";
|
||||
import { getEventName } from "@lib/event";
|
||||
import dayjs from "dayjs";
|
||||
import logger from "@lib/logger";
|
||||
import EventManager, { CreateUpdateResult, EventResult } from "@lib/events/EventManager";
|
||||
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import isBetween from "dayjs/plugin/isBetween";
|
||||
import dayjsBusinessDays from "dayjs-business-days";
|
||||
import EventOrganizerRequestMail from "@lib/emails/EventOrganizerRequestMail";
|
||||
|
||||
dayjs.extend(dayjsBusinessDays);
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(isBetween);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
const translator = short();
|
||||
const log = logger.getChildLogger({ prefix: ["[api] book:user"] });
|
||||
|
||||
function isAvailable(busyTimes, time, length) {
|
||||
// Check for conflicts
|
||||
let t = true;
|
||||
|
||||
if (Array.isArray(busyTimes) && busyTimes.length > 0) {
|
||||
busyTimes.forEach((busyTime) => {
|
||||
const startTime = dayjs(busyTime.start);
|
||||
const endTime = dayjs(busyTime.end);
|
||||
|
||||
// Check if time is between start and end times
|
||||
if (dayjs(time).isBetween(startTime, endTime, null, "[)")) {
|
||||
t = false;
|
||||
}
|
||||
|
||||
// Check if slot end time is between start and end time
|
||||
if (dayjs(time).add(length, "minutes").isBetween(startTime, endTime)) {
|
||||
t = false;
|
||||
}
|
||||
|
||||
// Check if startTime is between slot
|
||||
if (startTime.isBetween(dayjs(time), dayjs(time).add(length, "minutes"))) {
|
||||
t = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
function isOutOfBounds(
|
||||
time: dayjs.ConfigType,
|
||||
{ periodType, periodDays, periodCountCalendarDays, periodStartDate, periodEndDate, timeZone }
|
||||
): boolean {
|
||||
const date = dayjs(time);
|
||||
|
||||
switch (periodType) {
|
||||
case "rolling": {
|
||||
const periodRollingEndDay = periodCountCalendarDays
|
||||
? dayjs().tz(timeZone).add(periodDays, "days").endOf("day")
|
||||
: dayjs().tz(timeZone).businessDaysAdd(periodDays, "days").endOf("day");
|
||||
return date.endOf("day").isAfter(periodRollingEndDay);
|
||||
}
|
||||
|
||||
case "range": {
|
||||
const periodRangeStartDay = dayjs(periodStartDate).tz(timeZone).endOf("day");
|
||||
const periodRangeEndDay = dayjs(periodEndDate).tz(timeZone).endOf("day");
|
||||
return date.endOf("day").isBefore(periodRangeStartDay) || date.endOf("day").isAfter(periodRangeEndDay);
|
||||
}
|
||||
|
||||
case "unlimited":
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const eventTypeId = parseInt(req.body.eventTypeId as string);
|
||||
|
||||
log.debug(`Booking eventType ${eventTypeId} started`);
|
||||
|
||||
const isTimeInPast = (time) => {
|
||||
return dayjs(time).isBefore(new Date(), "day");
|
||||
};
|
||||
|
||||
if (isTimeInPast(req.body.start)) {
|
||||
const error = {
|
||||
errorCode: "BookingDateInPast",
|
||||
message: "Attempting to create a meeting in the past.",
|
||||
};
|
||||
|
||||
log.error(`Booking ${eventTypeId} failed`, error);
|
||||
return res.status(400).json(error);
|
||||
}
|
||||
|
||||
const eventType: EventType = await prisma.eventType.findUnique({
|
||||
where: {
|
||||
id: eventTypeId,
|
||||
},
|
||||
select: {
|
||||
users: {
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
name: true,
|
||||
username: true,
|
||||
timeZone: true,
|
||||
},
|
||||
},
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
title: true,
|
||||
length: true,
|
||||
eventName: true,
|
||||
schedulingType: true,
|
||||
periodType: true,
|
||||
periodStartDate: true,
|
||||
periodEndDate: true,
|
||||
periodDays: true,
|
||||
periodCountCalendarDays: true,
|
||||
requiresConfirmation: true,
|
||||
userId: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!eventType.users.length && eventType.userId) {
|
||||
eventType.users.push(
|
||||
await prisma.user.findUnique({
|
||||
where: {
|
||||
id: eventType.userId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
name: true,
|
||||
username: true,
|
||||
timeZone: true,
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
let users: User[] = eventType.users;
|
||||
|
||||
if (eventType.schedulingType === SchedulingType.ROUND_ROBIN) {
|
||||
const selectedUsers = req.body.users || [];
|
||||
// one of these things that can probably be done better
|
||||
// prisma is not well documented.
|
||||
users = await Promise.all(
|
||||
selectedUsers.map(async (username) => {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
username,
|
||||
},
|
||||
select: {
|
||||
bookings: {
|
||||
where: {
|
||||
startTime: {
|
||||
gt: new Date(),
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
return {
|
||||
username,
|
||||
bookingCount: user.bookings.length,
|
||||
};
|
||||
})
|
||||
).then((bookingCounts) => {
|
||||
if (!bookingCounts.length) {
|
||||
return users.slice(0, 1);
|
||||
}
|
||||
const sorted = bookingCounts.sort((a, b) => (a.bookingCount > b.bookingCount ? 1 : -1));
|
||||
return [users.find((user) => user.username === sorted[0].username)];
|
||||
});
|
||||
}
|
||||
|
||||
const invitee = [{ email: req.body.email, name: req.body.name, timeZone: req.body.timeZone }];
|
||||
const guests = req.body.guests.map((guest) => {
|
||||
const g = {
|
||||
email: guest,
|
||||
name: "",
|
||||
timeZone: req.body.timeZone,
|
||||
};
|
||||
return g;
|
||||
});
|
||||
|
||||
const teamMembers =
|
||||
eventType.schedulingType === SchedulingType.COLLECTIVE
|
||||
? users.slice(1).map((user) => ({
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
timeZone: user.timeZone,
|
||||
}))
|
||||
: [];
|
||||
|
||||
const attendeesList = [...invitee, ...guests, ...teamMembers];
|
||||
|
||||
const seed = `${users[0].username}:${dayjs(req.body.start).utc().format()}`;
|
||||
const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL));
|
||||
|
||||
const evt: CalendarEvent = {
|
||||
type: eventType.title,
|
||||
title: getEventName(req.body.name, eventType.title, eventType.eventName),
|
||||
description: req.body.notes,
|
||||
startTime: req.body.start,
|
||||
endTime: req.body.end,
|
||||
organizer: {
|
||||
name: users[0].name,
|
||||
email: users[0].email,
|
||||
timeZone: users[0].timeZone,
|
||||
},
|
||||
attendees: attendeesList,
|
||||
location: req.body.location, // Will be processed by the EventManager later.
|
||||
};
|
||||
|
||||
if (eventType.schedulingType === SchedulingType.COLLECTIVE) {
|
||||
evt.team = {
|
||||
members: users.map((user) => user.name || user.username),
|
||||
name: eventType.team.name,
|
||||
}; // used for invitee emails
|
||||
}
|
||||
|
||||
const bookingCreateInput: Prisma.BookingCreateInput = {
|
||||
uid,
|
||||
title: evt.title,
|
||||
startTime: dayjs(evt.startTime).toDate(),
|
||||
endTime: dayjs(evt.endTime).toDate(),
|
||||
description: evt.description,
|
||||
confirmed: !eventType.requiresConfirmation,
|
||||
location: evt.location,
|
||||
eventType: {
|
||||
connect: {
|
||||
id: eventTypeId,
|
||||
},
|
||||
},
|
||||
attendees: {
|
||||
createMany: {
|
||||
data: evt.attendees,
|
||||
},
|
||||
},
|
||||
user: {
|
||||
connect: {
|
||||
id: users[0].id,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
let booking: Booking | null;
|
||||
try {
|
||||
booking = await prisma.booking.create({
|
||||
data: bookingCreateInput,
|
||||
});
|
||||
} catch (e) {
|
||||
log.error(`Booking ${eventTypeId} failed`, "Error when saving booking to db", e.message);
|
||||
if (e.code === "P2002") {
|
||||
return res.status(409).json({ message: "booking.conflict" });
|
||||
}
|
||||
return res.status(500).end();
|
||||
}
|
||||
|
||||
let results: EventResult[] = [];
|
||||
let referencesToCreate = [];
|
||||
|
||||
const loadUser = async (id): Promise<User> =>
|
||||
await prisma.user.findUnique({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
credentials: true,
|
||||
timeZone: true,
|
||||
email: true,
|
||||
username: true,
|
||||
name: true,
|
||||
bufferTime: true,
|
||||
},
|
||||
});
|
||||
|
||||
let user: User;
|
||||
for (const currentUser of await Promise.all(users.map((user) => loadUser(user.id)))) {
|
||||
if (!user) {
|
||||
user = currentUser;
|
||||
}
|
||||
|
||||
const selectedCalendars: SelectedCalendar[] = await prisma.selectedCalendar.findMany({
|
||||
where: {
|
||||
userId: currentUser.id,
|
||||
},
|
||||
});
|
||||
|
||||
const credentials: Credential[] = currentUser.credentials;
|
||||
if (credentials) {
|
||||
const calendarBusyTimes = await getBusyCalendarTimes(
|
||||
credentials,
|
||||
req.body.start,
|
||||
req.body.end,
|
||||
selectedCalendars
|
||||
);
|
||||
|
||||
const videoBusyTimes = await getBusyVideoTimes(credentials);
|
||||
calendarBusyTimes.push(...videoBusyTimes);
|
||||
|
||||
const bufferedBusyTimes = calendarBusyTimes.map((a) => ({
|
||||
start: dayjs(a.start).subtract(currentUser.bufferTime, "minute").toString(),
|
||||
end: dayjs(a.end).add(currentUser.bufferTime, "minute").toString(),
|
||||
}));
|
||||
|
||||
let isAvailableToBeBooked = true;
|
||||
try {
|
||||
isAvailableToBeBooked = isAvailable(bufferedBusyTimes, req.body.start, eventType.length);
|
||||
} catch {
|
||||
log.debug({
|
||||
message: "Unable set isAvailableToBeBooked. Using true. ",
|
||||
});
|
||||
}
|
||||
|
||||
if (!isAvailableToBeBooked) {
|
||||
const error = {
|
||||
errorCode: "BookingUserUnAvailable",
|
||||
message: `${currentUser.name} is unavailable at this time.`,
|
||||
};
|
||||
|
||||
log.debug(`Booking ${currentUser.name} failed`, error);
|
||||
}
|
||||
|
||||
let timeOutOfBounds = false;
|
||||
|
||||
try {
|
||||
timeOutOfBounds = isOutOfBounds(req.body.start, {
|
||||
periodType: eventType.periodType,
|
||||
periodDays: eventType.periodDays,
|
||||
periodEndDate: eventType.periodEndDate,
|
||||
periodStartDate: eventType.periodStartDate,
|
||||
periodCountCalendarDays: eventType.periodCountCalendarDays,
|
||||
timeZone: currentUser.timeZone,
|
||||
});
|
||||
} catch {
|
||||
log.debug({
|
||||
message: "Unable set timeOutOfBounds. Using false. ",
|
||||
});
|
||||
}
|
||||
|
||||
if (timeOutOfBounds) {
|
||||
const error = {
|
||||
errorCode: "BookingUserUnAvailable",
|
||||
message: `${currentUser.name} is unavailable at this time.`,
|
||||
};
|
||||
|
||||
log.debug(`Booking ${currentUser.name} failed`, error);
|
||||
res.status(400).json(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize EventManager with credentials
|
||||
const eventManager = new EventManager(user.credentials);
|
||||
const rescheduleUid = req.body.rescheduleUid;
|
||||
if (rescheduleUid) {
|
||||
// Use EventManager to conditionally use all needed integrations.
|
||||
const updateResults: CreateUpdateResult = await eventManager.update(evt, rescheduleUid);
|
||||
|
||||
results = updateResults.results;
|
||||
referencesToCreate = updateResults.referencesToCreate;
|
||||
|
||||
if (results.length > 0 && results.every((res) => !res.success)) {
|
||||
const error = {
|
||||
errorCode: "BookingReschedulingMeetingFailed",
|
||||
message: "Booking Rescheduling failed",
|
||||
};
|
||||
|
||||
log.error(`Booking ${user.name} failed`, error, results);
|
||||
}
|
||||
} else if (!eventType.requiresConfirmation) {
|
||||
// Use EventManager to conditionally use all needed integrations.
|
||||
const createResults: CreateUpdateResult = await eventManager.create(evt, uid);
|
||||
|
||||
results = createResults.results;
|
||||
referencesToCreate = createResults.referencesToCreate;
|
||||
|
||||
if (results.length > 0 && results.every((res) => !res.success)) {
|
||||
const error = {
|
||||
errorCode: "BookingCreatingMeetingFailed",
|
||||
message: "Booking failed",
|
||||
};
|
||||
|
||||
log.error(`Booking ${user.username} failed`, error, results);
|
||||
}
|
||||
}
|
||||
|
||||
if (eventType.requiresConfirmation) {
|
||||
await new EventOrganizerRequestMail(evt, uid).sendEmail();
|
||||
}
|
||||
|
||||
log.debug(`Booking ${user.username} completed`);
|
||||
|
||||
await prisma.booking.update({
|
||||
where: {
|
||||
uid: booking.uid,
|
||||
},
|
||||
data: {
|
||||
references: {
|
||||
createMany: {
|
||||
data: referencesToCreate,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
// booking succesfull
|
||||
return res.status(201).json(booking);
|
||||
}
|
||||
+72
-71
@@ -1,79 +1,80 @@
|
||||
import prisma from "@lib/prisma";
|
||||
import { deleteEvent } from "@lib/calendarClient";
|
||||
import async from "async";
|
||||
import { deleteMeeting } from "@lib/videoClient";
|
||||
import { asStringOrNull } from "@lib/asStringOrNull";
|
||||
import async from "async";
|
||||
import { BookingStatus } from "@prisma/client";
|
||||
import { asStringOrNull } from "@lib/asStringOrNull";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
if (req.method == "POST") {
|
||||
const uid = asStringOrNull(req.body.uid);
|
||||
|
||||
const bookingToDelete = await prisma.booking.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
user: {
|
||||
select: {
|
||||
credentials: true,
|
||||
},
|
||||
},
|
||||
attendees: true,
|
||||
references: {
|
||||
select: {
|
||||
uid: true,
|
||||
type: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!bookingToDelete) {
|
||||
return res.status(404).end();
|
||||
}
|
||||
|
||||
// by cancelling first, and blocking whilst doing so; we can ensure a cancel
|
||||
// action always succeeds even if subsequent integrations fail cancellation.
|
||||
await prisma.booking.update({
|
||||
where: {
|
||||
uid,
|
||||
},
|
||||
data: {
|
||||
status: BookingStatus.CANCELLED,
|
||||
},
|
||||
});
|
||||
|
||||
const apiDeletes = async.mapLimit(bookingToDelete.user.credentials, 5, async (credential) => {
|
||||
const bookingRefUid = bookingToDelete.references.filter((ref) => ref.type === credential.type)[0]?.uid;
|
||||
if (bookingRefUid) {
|
||||
if (credential.type.endsWith("_calendar")) {
|
||||
return await deleteEvent(credential, bookingRefUid);
|
||||
} else if (credential.type.endsWith("_video")) {
|
||||
return await deleteMeeting(credential, bookingRefUid);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const attendeeDeletes = prisma.attendee.deleteMany({
|
||||
where: {
|
||||
bookingId: bookingToDelete.id,
|
||||
},
|
||||
});
|
||||
|
||||
const bookingReferenceDeletes = prisma.bookingReference.deleteMany({
|
||||
where: {
|
||||
bookingId: bookingToDelete.id,
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all([apiDeletes, attendeeDeletes, bookingReferenceDeletes]);
|
||||
|
||||
//TODO Perhaps send emails to user and client to tell about the cancellation
|
||||
|
||||
res.status(200).json({ message: "Booking successfully deleted." });
|
||||
} else {
|
||||
res.status(405).json({ message: "This endpoint only accepts POST requests." });
|
||||
// just bail if it not a DELETE
|
||||
if (req.method !== "DELETE") {
|
||||
return res.status(405).end();
|
||||
}
|
||||
|
||||
const uid = asStringOrNull(req.body.uid) || "";
|
||||
|
||||
const bookingToDelete = await prisma.booking.findUnique({
|
||||
where: {
|
||||
uid,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
user: {
|
||||
select: {
|
||||
credentials: true,
|
||||
},
|
||||
},
|
||||
attendees: true,
|
||||
references: {
|
||||
select: {
|
||||
uid: true,
|
||||
type: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!bookingToDelete) {
|
||||
return res.status(404).end();
|
||||
}
|
||||
|
||||
// by cancelling first, and blocking whilst doing so; we can ensure a cancel
|
||||
// action always succeeds even if subsequent integrations fail cancellation.
|
||||
await prisma.booking.update({
|
||||
where: {
|
||||
uid,
|
||||
},
|
||||
data: {
|
||||
status: BookingStatus.CANCELLED,
|
||||
},
|
||||
});
|
||||
|
||||
const apiDeletes = async.mapLimit(bookingToDelete.user.credentials, 5, async (credential) => {
|
||||
const bookingRefUid = bookingToDelete.references.filter((ref) => ref.type === credential.type)[0]?.uid;
|
||||
if (bookingRefUid) {
|
||||
if (credential.type.endsWith("_calendar")) {
|
||||
return await deleteEvent(credential, bookingRefUid);
|
||||
} else if (credential.type.endsWith("_video")) {
|
||||
return await deleteMeeting(credential, bookingRefUid);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const attendeeDeletes = prisma.attendee.deleteMany({
|
||||
where: {
|
||||
bookingId: bookingToDelete.id,
|
||||
},
|
||||
});
|
||||
|
||||
const bookingReferenceDeletes = prisma.bookingReference.deleteMany({
|
||||
where: {
|
||||
bookingId: bookingToDelete.id,
|
||||
},
|
||||
});
|
||||
|
||||
await Promise.all([apiDeletes, attendeeDeletes, bookingReferenceDeletes]);
|
||||
|
||||
//TODO Perhaps send emails to user and client to tell about the cancellation
|
||||
|
||||
res.status(204).end();
|
||||
}
|
||||
+37
-30
@@ -10,6 +10,7 @@ import { DotsHorizontalIcon } from "@heroicons/react/solid";
|
||||
import classNames from "@lib/classNames";
|
||||
import { ClockIcon, XIcon } from "@heroicons/react/outline";
|
||||
import Loader from "@components/Loader";
|
||||
import { Button } from "@components/ui/Button";
|
||||
import { getSession } from "@lib/auth";
|
||||
import { BookingStatus } from "@prisma/client";
|
||||
|
||||
@@ -44,7 +45,7 @@ export default function Bookings({ bookings }) {
|
||||
<div className="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
|
||||
<div className="border border-gray-200 overflow-hidden border-b rounded-sm">
|
||||
<table className="min-w-full divide-y divide-gray-200">
|
||||
<tbody className="bg-white divide-y divide-gray-200">
|
||||
<tbody className="bg-white divide-y divide-gray-200" data-testid="bookings">
|
||||
{bookings
|
||||
.filter((booking) => booking.status !== BookingStatus.CANCELLED)
|
||||
.map((booking) => (
|
||||
@@ -56,6 +57,7 @@ export default function Bookings({ bookings }) {
|
||||
</span>
|
||||
)}
|
||||
<div className="text-sm text-neutral-900 font-medium truncate max-w-60 md:max-w-96">
|
||||
{booking.eventType.team && <strong>{booking.eventType.team.name}: </strong>}
|
||||
{booking.title}
|
||||
</div>
|
||||
<div className="sm:hidden">
|
||||
@@ -100,25 +102,20 @@ export default function Bookings({ bookings }) {
|
||||
</>
|
||||
)}
|
||||
{booking.confirmed && !booking.rejected && (
|
||||
<>
|
||||
<a
|
||||
href={window.location.href + "/../cancel/" + booking.uid}
|
||||
className="hidden text-xs sm:text-sm lg:inline-flex items-center px-4 py-2 border-transparent font-medium rounded-sm shadow-sm text-neutral-700 bg-white hover:bg-neutral-100 border border-neutral-300 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black ml-2">
|
||||
<XIcon
|
||||
className="mr-3 h-5 w-5 text-neutral-400 group-hover:text-neutral-500"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div className="space-x-2">
|
||||
<Button
|
||||
data-testid="cancel"
|
||||
href={"/cancel/" + booking.uid}
|
||||
StartIcon={XIcon}
|
||||
color="secondary">
|
||||
Cancel
|
||||
</a>
|
||||
<a
|
||||
href={window.location.href + "/../reschedule/" + booking.uid}
|
||||
className="hidden text-xs sm:text-sm lg:inline-flex items-center px-4 py-2 border-transparent font-medium rounded-sm shadow-sm text-neutral-700 bg-white hover:bg-neutral-100 border border-neutral-300 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black ml-2">
|
||||
<ClockIcon
|
||||
className="mr-3 h-5 w-5 text-neutral-400 group-hover:text-neutral-500"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</Button>
|
||||
<Button
|
||||
href={"reschedule/" + booking.uid}
|
||||
StartIcon={ClockIcon}
|
||||
color="secondary">
|
||||
Reschedule
|
||||
</a>
|
||||
</Button>
|
||||
<Menu as="div" className="inline-block lg:hidden text-left ">
|
||||
{({ open }) => (
|
||||
<>
|
||||
@@ -186,7 +183,7 @@ export default function Bookings({ bookings }) {
|
||||
</>
|
||||
)}
|
||||
</Menu>
|
||||
</>
|
||||
</div>
|
||||
)}
|
||||
{!booking.confirmed && booking.rejected && (
|
||||
<div className="text-sm text-gray-500">Rejected</div>
|
||||
@@ -211,19 +208,20 @@ export async function getServerSideProps(context) {
|
||||
if (!session) {
|
||||
return { redirect: { permanent: false, destination: "/auth/login" } };
|
||||
}
|
||||
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
email: session.user.email,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
});
|
||||
|
||||
const b = await prisma.booking.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
OR: [
|
||||
{
|
||||
userId: session.user.id,
|
||||
},
|
||||
{
|
||||
attendees: {
|
||||
some: {
|
||||
id: session.user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
select: {
|
||||
uid: true,
|
||||
@@ -235,6 +233,15 @@ export async function getServerSideProps(context) {
|
||||
id: true,
|
||||
startTime: true,
|
||||
endTime: true,
|
||||
eventType: {
|
||||
select: {
|
||||
team: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
status: true,
|
||||
},
|
||||
orderBy: {
|
||||
|
||||
+42
-38
@@ -1,19 +1,14 @@
|
||||
import { CalendarIcon, XIcon } from "@heroicons/react/solid";
|
||||
import dayjs from "dayjs";
|
||||
import isBetween from "dayjs/plugin/isBetween";
|
||||
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import { HeadSeo } from "@components/seo/head-seo";
|
||||
import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
import { Button } from "@components/ui/Button";
|
||||
import prisma from "@lib/prisma";
|
||||
import { collectPageParameters, telemetryEventTypes, useTelemetry } from "@lib/telemetry";
|
||||
|
||||
dayjs.extend(isSameOrBefore);
|
||||
dayjs.extend(isBetween);
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export default function Type(props) {
|
||||
// Get router variables
|
||||
@@ -37,16 +32,21 @@ export default function Type(props) {
|
||||
telemetry.withJitsu((jitsu) =>
|
||||
jitsu.track(telemetryEventTypes.bookingCancelled, collectPageParameters())
|
||||
);
|
||||
|
||||
const res = await fetch("/api/cancel", {
|
||||
body: JSON.stringify(payload),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
method: "POST",
|
||||
method: "DELETE",
|
||||
});
|
||||
|
||||
if (res.status >= 200 && res.status < 300) {
|
||||
router.push("/cancel/success?user=" + props.user.username + "&title=" + props.booking.title);
|
||||
await router.push(
|
||||
`/cancel/success?name=${props.profile.name}&title=${props.booking.title}&eventPage=${
|
||||
props.profile.slug
|
||||
}&team=${props.booking.eventType.team ? 1 : 0}`
|
||||
);
|
||||
} else {
|
||||
setLoading(false);
|
||||
setError("An error with status code " + res.status + " occurred. Please try again later.");
|
||||
@@ -56,10 +56,8 @@ export default function Type(props) {
|
||||
return (
|
||||
<div>
|
||||
<HeadSeo
|
||||
title={`Cancel ${props.booking && props.booking.title} | ${props.user.name || props.user.username}`}
|
||||
description={`Cancel ${props.booking && props.booking.title} | ${
|
||||
props.user.name || props.user.username
|
||||
}`}
|
||||
title={`Cancel ${props.booking && props.booking.title} | ${props.profile.name}`}
|
||||
description={`Cancel ${props.booking && props.booking.title} | ${props.profile.name}`}
|
||||
/>
|
||||
<main className="max-w-3xl mx-auto my-24">
|
||||
<div className="fixed z-50 inset-0 overflow-y-auto">
|
||||
@@ -102,30 +100,22 @@ export default function Type(props) {
|
||||
<h2 className="text-lg font-medium text-gray-600 mb-2">{props.booking.title}</h2>
|
||||
<p className="text-gray-500">
|
||||
<CalendarIcon className="inline-block w-4 h-4 mr-1 -mt-1" />
|
||||
{dayjs
|
||||
.utc(props.booking.startTime)
|
||||
.format((is24h ? "H:mm" : "h:mma") + ", dddd DD MMMM YYYY")}
|
||||
{dayjs(props.booking.startTime).format(
|
||||
(is24h ? "H:mm" : "h:mma") + ", dddd DD MMMM YYYY"
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-5 sm:mt-6 text-center">
|
||||
<div className="mt-5">
|
||||
<button
|
||||
onClick={cancellationHandler}
|
||||
disabled={loading}
|
||||
type="button"
|
||||
className="inline-flex items-center justify-center px-4 py-2 border border-transparent font-medium rounded-md text-red-700 bg-red-100 hover:bg-red-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:text-sm mx-2 btn-white">
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
onClick={() => router.push("/reschedule/" + uid)}
|
||||
disabled={loading}
|
||||
type="button"
|
||||
className="inline-flex items-center justify-center px-4 py-2 border border-transparent font-medium rounded-md text-gray-700 bg-gray-100 hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 sm:text-sm mx-2 btn-white">
|
||||
Reschedule
|
||||
</button>
|
||||
</div>
|
||||
<div className="mt-5 sm:mt-6 text-center space-x-2">
|
||||
<Button
|
||||
color="secondary"
|
||||
data-testid="cancel"
|
||||
onClick={cancellationHandler}
|
||||
loading={loading}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={() => router.push("/reschedule/" + uid)}>Reschedule</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
@@ -139,7 +129,7 @@ export default function Type(props) {
|
||||
}
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
const booking = await prisma.booking.findFirst({
|
||||
const booking = await prisma.booking.findUnique({
|
||||
where: {
|
||||
uid: context.query.uid,
|
||||
},
|
||||
@@ -150,33 +140,47 @@ export async function getServerSideProps(context) {
|
||||
startTime: true,
|
||||
endTime: true,
|
||||
attendees: true,
|
||||
eventType: true,
|
||||
user: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
eventType: {
|
||||
select: {
|
||||
team: {
|
||||
select: {
|
||||
slug: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!booking) {
|
||||
// TODO: Booking is already cancelled
|
||||
return {
|
||||
props: { booking: null },
|
||||
};
|
||||
}
|
||||
|
||||
// Workaround since Next.js has problems serializing date objects (see https://github.com/vercel/next.js/issues/11993)
|
||||
const bookingObj = Object.assign({}, booking, {
|
||||
startTime: booking.startTime.toString(),
|
||||
endTime: booking.endTime.toString(),
|
||||
});
|
||||
|
||||
const profile = booking.eventType.team
|
||||
? {
|
||||
name: booking.eventType.team.name,
|
||||
slug: booking.eventType.team.slug,
|
||||
}
|
||||
: booking.user;
|
||||
|
||||
return {
|
||||
props: {
|
||||
user: booking.user,
|
||||
eventType: booking.eventType,
|
||||
profile,
|
||||
booking: bookingObj,
|
||||
},
|
||||
};
|
||||
|
||||
+18
-48
@@ -1,28 +1,18 @@
|
||||
import { HeadSeo } from "@components/seo/head-seo";
|
||||
import prisma from "../../lib/prisma";
|
||||
import { useRouter } from "next/router";
|
||||
import dayjs from "dayjs";
|
||||
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
|
||||
import isBetween from "dayjs/plugin/isBetween";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import { CheckIcon } from "@heroicons/react/outline";
|
||||
import { useSession } from "next-auth/client";
|
||||
import Button from "@components/ui/Button";
|
||||
import { ArrowRightIcon } from "@heroicons/react/solid";
|
||||
|
||||
dayjs.extend(isSameOrBefore);
|
||||
dayjs.extend(isBetween);
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
export default function Type(props) {
|
||||
export default function CancelSuccess() {
|
||||
// Get router variables
|
||||
const router = useRouter();
|
||||
|
||||
const { title, name, eventPage } = router.query;
|
||||
const [session, loading] = useSession();
|
||||
return (
|
||||
<div>
|
||||
<HeadSeo
|
||||
title={`Cancelled ${props.title} | ${props.user.name || props.user.username}`}
|
||||
description={`Cancelled ${props.title} | ${props.user.name || props.user.username}`}
|
||||
/>
|
||||
<HeadSeo title={`Cancelled ${title} | ${name}`} description={`Cancelled ${title} | ${name}`} />
|
||||
<main className="max-w-3xl mx-auto my-24">
|
||||
<div className="fixed z-50 inset-0 overflow-y-auto">
|
||||
<div className="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
|
||||
@@ -43,19 +33,21 @@ export default function Type(props) {
|
||||
<h3 className="text-lg leading-6 font-medium text-gray-900" id="modal-headline">
|
||||
Cancellation successful
|
||||
</h3>
|
||||
<div className="mt-2">
|
||||
<p className="text-sm text-gray-500">Feel free to pick another event anytime.</p>
|
||||
</div>
|
||||
{!loading && !session.user && (
|
||||
<div className="mt-2">
|
||||
<p className="text-sm text-gray-500">Feel free to pick another event anytime.</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-5 sm:mt-6 text-center">
|
||||
<div className="mt-5">
|
||||
<button
|
||||
onClick={() => router.push("/" + props.user.username)}
|
||||
type="button"
|
||||
className="inline-flex items-center justify-center px-4 py-2 border border-transparent font-medium rounded-md text-gray-700 bg-gray-100 hover:bg-gray-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500 sm:text-sm mx-2 btn-white">
|
||||
Pick another
|
||||
</button>
|
||||
{!loading && !session.user && <Button href={eventPage}>Pick another</Button>}
|
||||
{!loading && session.user && (
|
||||
<Button data-testid="back-to-bookings" href="/bookings" EndIcon={ArrowRightIcon}>
|
||||
Back to bookings
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -66,25 +58,3 @@ export default function Type(props) {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
username: context.query.user,
|
||||
},
|
||||
select: {
|
||||
username: true,
|
||||
name: true,
|
||||
bio: true,
|
||||
avatar: true,
|
||||
eventTypes: true,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
props: {
|
||||
user,
|
||||
title: context.query.title,
|
||||
},
|
||||
};
|
||||
}
|
||||
+344
-231
@@ -3,7 +3,7 @@ import Modal from "@components/Modal";
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import Select, { OptionTypeBase } from "react-select";
|
||||
import prisma from "@lib/prisma";
|
||||
import { EventTypeCustomInput, EventTypeCustomInputType } from "@prisma/client";
|
||||
import { EventTypeCustomInput, EventTypeCustomInputType, SchedulingType } from "@prisma/client";
|
||||
import { LocationType } from "@lib/location";
|
||||
import Shell from "@components/Shell";
|
||||
import { getSession } from "@lib/auth";
|
||||
@@ -21,6 +21,8 @@ import {
|
||||
ClockIcon,
|
||||
TrashIcon,
|
||||
ExternalLinkIcon,
|
||||
UsersIcon,
|
||||
UserAddIcon,
|
||||
} from "@heroicons/react/solid";
|
||||
|
||||
import dayjs from "dayjs";
|
||||
@@ -28,7 +30,6 @@ import utc from "dayjs/plugin/utc";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import { Availability } from "@prisma/client";
|
||||
import { validJson } from "@lib/jsonUtils";
|
||||
import classnames from "classnames";
|
||||
import throttle from "lodash.throttle";
|
||||
import "react-dates/initialize";
|
||||
import "react-dates/lib/css/_datepicker.css";
|
||||
@@ -42,6 +43,10 @@ import { EventTypeInput } from "@lib/types/event-type";
|
||||
import updateEventType from "@lib/mutations/event-types/update-event-type";
|
||||
import deleteEventType from "@lib/mutations/event-types/delete-event-type";
|
||||
import showToast from "@lib/notification";
|
||||
import CheckedSelect from "@components/ui/form/CheckedSelect";
|
||||
import { defaultAvatarSrc } from "@lib/profile";
|
||||
import * as RadioArea from "@components/ui/form/radio-area";
|
||||
import classNames from "@lib/classNames";
|
||||
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
import { asStringOrThrow } from "@lib/asStringOrNull";
|
||||
import Button from "@components/ui/Button";
|
||||
@@ -65,7 +70,8 @@ const PERIOD_TYPES = [
|
||||
];
|
||||
|
||||
const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
const { user, eventType, locationOptions, availability } = props;
|
||||
const { eventType, locationOptions, availability, team, teamMembers } = props;
|
||||
|
||||
const router = useRouter();
|
||||
const [successModalOpen, setSuccessModalOpen] = useState(false);
|
||||
|
||||
@@ -131,6 +137,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
}
|
||||
}, [contentSize]);
|
||||
|
||||
const [users, setUsers] = useState([]);
|
||||
const [enteredAvailability, setEnteredAvailability] = useState();
|
||||
const [showLocationModal, setShowLocationModal] = useState(false);
|
||||
const [showAddCustomModal, setShowAddCustomModal] = useState(false);
|
||||
@@ -169,24 +176,22 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
const [hidden, setHidden] = useState<boolean>(eventType.hidden);
|
||||
const titleRef = useRef<HTMLInputElement>(null);
|
||||
const slugRef = useRef<HTMLInputElement>(null);
|
||||
const descriptionRef = useRef<HTMLTextAreaElement>(null);
|
||||
const lengthRef = useRef<HTMLInputElement>(null);
|
||||
const requiresConfirmationRef = useRef<HTMLInputElement>(null);
|
||||
const eventNameRef = useRef<HTMLInputElement>(null);
|
||||
const periodDaysRef = useRef<HTMLInputElement>(null);
|
||||
const periodDaysTypeRef = useRef<HTMLSelectElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setSelectedTimeZone(eventType.timeZone || user.timeZone);
|
||||
setSelectedTimeZone(eventType.timeZone);
|
||||
}, []);
|
||||
|
||||
async function updateEventTypeHandler(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const formData = Object.fromEntries(new FormData(event.target).entries());
|
||||
|
||||
const enteredTitle: string = titleRef.current.value;
|
||||
const enteredSlug: string = slugRef.current.value;
|
||||
const enteredDescription: string = descriptionRef.current.value;
|
||||
const enteredLength: number = parseInt(lengthRef.current.value);
|
||||
|
||||
const advancedOptionsPayload: AdvancedOptions = {};
|
||||
if (requiresConfirmationRef.current) {
|
||||
@@ -203,14 +208,20 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
id: eventType.id,
|
||||
title: enteredTitle,
|
||||
slug: enteredSlug,
|
||||
description: enteredDescription,
|
||||
length: enteredLength,
|
||||
description: formData.description as string,
|
||||
length: formData.length as number,
|
||||
hidden,
|
||||
locations,
|
||||
customInputs,
|
||||
timeZone: selectedTimeZone,
|
||||
availability: enteredAvailability || null,
|
||||
...advancedOptionsPayload,
|
||||
...(team
|
||||
? {
|
||||
schedulingType: formData.schedulingType as string,
|
||||
users,
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
|
||||
updateMutation.mutate(payload);
|
||||
@@ -334,6 +345,19 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
setCustomInputs([...customInputs]);
|
||||
};
|
||||
|
||||
const schedulingTypeOptions: { value: string; label: string }[] = [
|
||||
{
|
||||
value: SchedulingType.COLLECTIVE,
|
||||
label: "Collective",
|
||||
description: "Schedule meetings when all selected team members are available.",
|
||||
},
|
||||
{
|
||||
value: SchedulingType.ROUND_ROBIN,
|
||||
label: "Round Robin",
|
||||
description: "Cycle meetings between multiple team members.",
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Shell
|
||||
@@ -353,73 +377,72 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
subtitle={eventType.description}>
|
||||
<div className="block sm:flex">
|
||||
<div className="w-full mr-2 sm:w-10/12">
|
||||
<div className="p-4 -mx-4 bg-white border rounded-sm border-neutral-200 sm:mx-0 sm:p-8">
|
||||
<form onSubmit={updateEventTypeHandler} className="space-y-4">
|
||||
<div className="items-center block sm:flex">
|
||||
<div className="mb-4 min-w-44 sm:mb-0">
|
||||
<label htmlFor="slug" className="flex mt-0 text-sm font-medium text-neutral-700">
|
||||
<LinkIcon className="w-4 h-4 mr-2 mt-0.5 text-neutral-500" />
|
||||
URL
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<div className="flex rounded-sm shadow-sm">
|
||||
<span className="inline-flex items-center px-3 text-gray-500 border border-r-0 border-gray-300 rounded-l-sm bg-gray-50 sm:text-sm">
|
||||
{typeof location !== "undefined" ? location.hostname : ""}/{user.username}/
|
||||
</span>
|
||||
<input
|
||||
ref={slugRef}
|
||||
type="text"
|
||||
name="slug"
|
||||
id="slug"
|
||||
required
|
||||
className="flex-1 block w-full min-w-0 border-gray-300 rounded-none rounded-r-sm focus:ring-primary-500 focus:border-primary-500 sm:text-sm"
|
||||
defaultValue={eventType.slug}
|
||||
/>
|
||||
<div className="p-4 py-6 -mx-4 bg-white border rounded-sm border-neutral-200 sm:mx-0 sm:px-8">
|
||||
<form onSubmit={updateEventTypeHandler} className="space-y-6">
|
||||
<div className="space-y-3">
|
||||
<div className="items-center block sm:flex">
|
||||
<div className="mb-4 min-w-44 sm:mb-0">
|
||||
<label htmlFor="slug" className="flex mt-0 text-sm font-medium text-neutral-700">
|
||||
<LinkIcon className="w-4 h-4 mr-2 mt-0.5 text-neutral-500" />
|
||||
URL
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<div className="flex rounded-sm shadow-sm">
|
||||
<span className="inline-flex items-center px-3 text-gray-500 border border-r-0 border-gray-300 rounded-l-sm bg-gray-50 sm:text-sm">
|
||||
{typeof location !== "undefined" ? location.hostname : ""}/
|
||||
{team ? "team/" + team.slug : eventType.users[0].username}/
|
||||
</span>
|
||||
<input
|
||||
ref={slugRef}
|
||||
type="text"
|
||||
name="slug"
|
||||
id="slug"
|
||||
required
|
||||
className="flex-1 block w-full min-w-0 border-gray-300 rounded-none rounded-r-sm focus:ring-primary-500 focus:border-primary-500 sm:text-sm"
|
||||
defaultValue={eventType.slug}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="items-center block sm:flex">
|
||||
<div className="mb-4 min-w-44 sm:mb-0">
|
||||
<label htmlFor="length" className="flex mt-0 text-sm font-medium text-neutral-700">
|
||||
<ClockIcon className="w-4 h-4 mr-2 mt-0.5 text-neutral-500" />
|
||||
Duration
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<div className="relative mt-1 rounded-sm shadow-sm">
|
||||
<input
|
||||
ref={lengthRef}
|
||||
type="number"
|
||||
name="length"
|
||||
id="length"
|
||||
required
|
||||
className="block w-full pl-2 pr-12 border-gray-300 rounded-sm focus:ring-primary-500 focus:border-primary-500 sm:text-sm"
|
||||
placeholder="15"
|
||||
defaultValue={eventType.length}
|
||||
/>
|
||||
<div className="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
|
||||
<span className="text-gray-500 sm:text-sm" id="duration">
|
||||
mins
|
||||
</span>
|
||||
<div className="items-center block sm:flex">
|
||||
<div className="mb-4 min-w-44 sm:mb-0">
|
||||
<label htmlFor="length" className="flex mt-0 text-sm font-medium text-neutral-700">
|
||||
<ClockIcon className="w-4 h-4 mr-2 mt-0.5 text-neutral-500" />
|
||||
Duration
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<div className="relative mt-1 rounded-sm shadow-sm">
|
||||
<input
|
||||
type="number"
|
||||
name="length"
|
||||
id="length"
|
||||
required
|
||||
className="block w-full pl-2 pr-12 border-gray-300 rounded-sm focus:ring-primary-500 focus:border-primary-500 sm:text-sm"
|
||||
placeholder="15"
|
||||
defaultValue={eventType.length}
|
||||
/>
|
||||
<div className="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
|
||||
<span className="text-gray-500 sm:text-sm" id="duration">
|
||||
mins
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
|
||||
<div className="items-center block sm:flex">
|
||||
<div className="mb-4 min-w-44 sm:mb-0">
|
||||
<label htmlFor="location" className="flex mt-0 text-sm font-medium text-neutral-700">
|
||||
<LocationMarkerIcon className="w-4 h-4 mr-2 mt-0.5 text-neutral-500" />
|
||||
Location
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
{locations.length === 0 && (
|
||||
<div className="mt-1 mb-2">
|
||||
<div className="space-y-3">
|
||||
<div className="items-center block sm:flex">
|
||||
<div className="min-w-44 sm:mb-0">
|
||||
<label htmlFor="location" className="flex mt-0 text-sm font-medium text-neutral-700">
|
||||
<LocationMarkerIcon className="w-4 h-4 mr-2 mt-0.5 text-neutral-500" />
|
||||
Location
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
{locations.length === 0 && (
|
||||
<div className="flex">
|
||||
<Select
|
||||
name="location"
|
||||
@@ -431,136 +454,180 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
onChange={(e) => openLocationModal(e.value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{locations.length > 0 && (
|
||||
<ul className="mt-1">
|
||||
{locations.map((location) => (
|
||||
<li
|
||||
key={location.type}
|
||||
className="p-2 mb-2 border rounded-sm shadow-sm border-neutral-300">
|
||||
<div className="flex justify-between">
|
||||
{location.type === LocationType.InPerson && (
|
||||
<div className="flex items-center flex-grow">
|
||||
<LocationMarkerIcon className="w-6 h-6" />
|
||||
<span className="ml-2 text-sm">{location.address}</span>
|
||||
</div>
|
||||
)}
|
||||
{location.type === LocationType.Phone && (
|
||||
<div className="flex items-center flex-grow">
|
||||
<PhoneIcon className="w-6 h-6" />
|
||||
<span className="ml-2 text-sm">Phone call</span>
|
||||
</div>
|
||||
)}
|
||||
{location.type === LocationType.GoogleMeet && (
|
||||
<div className="flex items-center flex-grow">
|
||||
<svg
|
||||
className="w-6 h-6"
|
||||
viewBox="0 0 64 54"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M16 0V16H0" fill="#EA4335" />
|
||||
<path
|
||||
d="M16 0V16H37.3333V27.0222L53.3333 14.0444V5.33332C53.3333 1.77777 51.5555 0 47.9999 0"
|
||||
fill="#FFBA00"
|
||||
/>
|
||||
<path
|
||||
d="M15.6438 53.3341V37.3341H37.3326V26.6675L53.3326 39.2897V48.0008C53.3326 51.5563 51.5548 53.3341 47.9993 53.3341"
|
||||
fill="#00AC47"
|
||||
/>
|
||||
<path d="M37.3335 26.6662L53.3335 13.6885V39.644" fill="#00832D" />
|
||||
<path
|
||||
d="M53.3335 13.6892L60.8001 7.64481C62.4001 6.40037 64.0001 6.40037 64.0001 8.88925V44.4447C64.0001 46.9336 62.4001 46.9336 60.8001 45.6892L53.3335 39.6447"
|
||||
fill="#00AC47"
|
||||
/>
|
||||
<path
|
||||
d="M0 36.9785V48.0007C0 51.5563 1.77777 53.334 5.33332 53.334H16V36.9785"
|
||||
fill="#0066DA"
|
||||
/>
|
||||
<path d="M0 16H16V37.3333H0" fill="#2684FC" />
|
||||
</svg>
|
||||
)}
|
||||
{locations.length > 0 && (
|
||||
<ul>
|
||||
{locations.map((location) => (
|
||||
<li
|
||||
key={location.type}
|
||||
className="p-2 mb-2 border rounded-sm shadow-sm border-neutral-300">
|
||||
<div className="flex justify-between">
|
||||
{location.type === LocationType.InPerson && (
|
||||
<div className="flex items-center flex-grow">
|
||||
<LocationMarkerIcon className="w-6 h-6" />
|
||||
<span className="ml-2 text-sm">{location.address}</span>
|
||||
</div>
|
||||
)}
|
||||
{location.type === LocationType.Phone && (
|
||||
<div className="flex items-center flex-grow">
|
||||
<PhoneIcon className="w-6 h-6" />
|
||||
<span className="ml-2 text-sm">Phone call</span>
|
||||
</div>
|
||||
)}
|
||||
{location.type === LocationType.GoogleMeet && (
|
||||
<div className="flex items-center flex-grow">
|
||||
<svg
|
||||
className="w-6 h-6"
|
||||
viewBox="0 0 64 54"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M16 0V16H0" fill="#EA4335" />
|
||||
<path
|
||||
d="M16 0V16H37.3333V27.0222L53.3333 14.0444V5.33332C53.3333 1.77777 51.5555 0 47.9999 0"
|
||||
fill="#FFBA00"
|
||||
/>
|
||||
<path
|
||||
d="M15.6438 53.3341V37.3341H37.3326V26.6675L53.3326 39.2897V48.0008C53.3326 51.5563 51.5548 53.3341 47.9993 53.3341"
|
||||
fill="#00AC47"
|
||||
/>
|
||||
<path d="M37.3335 26.6662L53.3335 13.6885V39.644" fill="#00832D" />
|
||||
<path
|
||||
d="M53.3335 13.6892L60.8001 7.64481C62.4001 6.40037 64.0001 6.40037 64.0001 8.88925V44.4447C64.0001 46.9336 62.4001 46.9336 60.8001 45.6892L53.3335 39.6447"
|
||||
fill="#00AC47"
|
||||
/>
|
||||
<path
|
||||
d="M0 36.9785V48.0007C0 51.5563 1.77777 53.334 5.33332 53.334H16V36.9785"
|
||||
fill="#0066DA"
|
||||
/>
|
||||
<path d="M0 16H16V37.3333H0" fill="#2684FC" />
|
||||
</svg>
|
||||
|
||||
<span className="ml-2 text-sm">Google Meet</span>
|
||||
<span className="ml-2 text-sm">Google Meet</span>
|
||||
</div>
|
||||
)}
|
||||
{location.type === LocationType.Zoom && (
|
||||
<div className="flex items-center flex-grow">
|
||||
<svg
|
||||
className="w-6 h-6"
|
||||
viewBox="0 0 64 64"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M32 0C49.6733 0 64 14.3267 64 32C64 49.6733 49.6733 64 32 64C14.3267 64 0 49.6733 0 32C0 14.3267 14.3267 0 32 0Z"
|
||||
fill="#E5E5E4"
|
||||
/>
|
||||
<path
|
||||
d="M32.0002 0.623047C49.3292 0.623047 63.3771 14.6709 63.3771 31.9999C63.3771 49.329 49.3292 63.3768 32.0002 63.3768C14.6711 63.3768 0.623291 49.329 0.623291 31.9999C0.623291 14.6709 14.6716 0.623047 32.0002 0.623047Z"
|
||||
fill="white"
|
||||
/>
|
||||
<path
|
||||
d="M31.9998 3.14014C47.9386 3.14014 60.8597 16.0612 60.8597 32C60.8597 47.9389 47.9386 60.8599 31.9998 60.8599C16.0609 60.8599 3.13989 47.9389 3.13989 32C3.13989 16.0612 16.0609 3.14014 31.9998 3.14014Z"
|
||||
fill="#4A8CFF"
|
||||
/>
|
||||
<path
|
||||
d="M13.1711 22.9581V36.5206C13.1832 39.5875 15.6881 42.0558 18.743 42.0433H38.5125C39.0744 42.0433 39.5266 41.5911 39.5266 41.0412V27.4788C39.5145 24.4119 37.0096 21.9435 33.9552 21.956H14.1857C13.6238 21.956 13.1716 22.4082 13.1716 22.9581H13.1711ZM40.7848 28.2487L48.9469 22.2864C49.6557 21.6998 50.2051 21.8462 50.2051 22.9095V41.0903C50.2051 42.2999 49.5329 42.1536 48.9469 41.7134L40.7848 35.7631V28.2487Z"
|
||||
fill="white"
|
||||
/>
|
||||
</svg>
|
||||
<span className="ml-2 text-sm">Zoom Video</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openLocationModal(location.type)}
|
||||
className="mr-2 text-sm text-primary-600">
|
||||
Edit
|
||||
</button>
|
||||
<button onClick={() => removeLocation(location)}>
|
||||
<XIcon className="w-6 h-6 pl-1 border-l-2 hover:text-red-500 " />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{location.type === LocationType.Zoom && (
|
||||
<div className="flex items-center flex-grow">
|
||||
<svg
|
||||
className="w-6 h-6"
|
||||
viewBox="0 0 64 64"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="M32 0C49.6733 0 64 14.3267 64 32C64 49.6733 49.6733 64 32 64C14.3267 64 0 49.6733 0 32C0 14.3267 14.3267 0 32 0Z"
|
||||
fill="#E5E5E4"
|
||||
/>
|
||||
<path
|
||||
d="M32.0002 0.623047C49.3292 0.623047 63.3771 14.6709 63.3771 31.9999C63.3771 49.329 49.3292 63.3768 32.0002 63.3768C14.6711 63.3768 0.623291 49.329 0.623291 31.9999C0.623291 14.6709 14.6716 0.623047 32.0002 0.623047Z"
|
||||
fill="white"
|
||||
/>
|
||||
<path
|
||||
d="M31.9998 3.14014C47.9386 3.14014 60.8597 16.0612 60.8597 32C60.8597 47.9389 47.9386 60.8599 31.9998 60.8599C16.0609 60.8599 3.13989 47.9389 3.13989 32C3.13989 16.0612 16.0609 3.14014 31.9998 3.14014Z"
|
||||
fill="#4A8CFF"
|
||||
/>
|
||||
<path
|
||||
d="M13.1711 22.9581V36.5206C13.1832 39.5875 15.6881 42.0558 18.743 42.0433H38.5125C39.0744 42.0433 39.5266 41.5911 39.5266 41.0412V27.4788C39.5145 24.4119 37.0096 21.9435 33.9552 21.956H14.1857C13.6238 21.956 13.1716 22.4082 13.1716 22.9581H13.1711ZM40.7848 28.2487L48.9469 22.2864C49.6557 21.6998 50.2051 21.8462 50.2051 22.9095V41.0903C50.2051 42.2999 49.5329 42.1536 48.9469 41.7134L40.7848 35.7631V28.2487Z"
|
||||
fill="white"
|
||||
/>
|
||||
</svg>
|
||||
<span className="ml-2 text-sm">Zoom Video</span>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openLocationModal(location.type)}
|
||||
className="mr-2 text-sm text-primary-600">
|
||||
Edit
|
||||
</button>
|
||||
<button onClick={() => removeLocation(location)}>
|
||||
<XIcon className="w-6 h-6 pl-1 border-l-2 hover:text-red-500 " />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
{locations.length > 0 && locations.length !== locationOptions.length && (
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
className="flex px-3 py-2 rounded-sm bg-neutral-100"
|
||||
onClick={() => setShowLocationModal(true)}>
|
||||
<PlusIcon className="h-4 w-4 mt-0.5 text-neutral-900" />
|
||||
<span className="ml-1 text-sm font-medium text-neutral-700">
|
||||
Add another location
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
)}
|
||||
</ul>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
{locations.length > 0 && locations.length !== locationOptions.length && (
|
||||
<li>
|
||||
<button
|
||||
type="button"
|
||||
className="flex px-3 py-2 rounded-sm bg-neutral-100"
|
||||
onClick={() => setShowLocationModal(true)}>
|
||||
<PlusIcon className="h-4 w-4 mt-0.5 text-neutral-900" />
|
||||
<span className="ml-1 text-sm font-medium text-neutral-700">
|
||||
Add another location
|
||||
</span>
|
||||
</button>
|
||||
</li>
|
||||
)}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr className="border-neutral-200" />
|
||||
|
||||
<div className="items-center block sm:flex">
|
||||
<div className="mb-4 min-w-44 sm:mb-0">
|
||||
<label htmlFor="description" className="flex mt-0 text-sm font-medium text-neutral-700">
|
||||
<DocumentIcon className="w-4 h-4 mr-2 mt-0.5 text-neutral-500" />
|
||||
Description
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<textarea
|
||||
ref={descriptionRef}
|
||||
name="description"
|
||||
id="description"
|
||||
className="block w-full border-gray-300 rounded-sm shadow-sm focus:ring-primary-500 focus:border-primary-500 sm:text-sm"
|
||||
placeholder="A quick video meeting."
|
||||
defaultValue={eventType.description}></textarea>
|
||||
<div className="space-y-3">
|
||||
<div className="items-center block sm:flex">
|
||||
<div className="mb-4 min-w-44 sm:mb-0">
|
||||
<label htmlFor="description" className="flex mt-0 text-sm font-medium text-neutral-700">
|
||||
<DocumentIcon className="w-4 h-4 mr-2 mt-0.5 text-neutral-500" />
|
||||
Description
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<textarea
|
||||
name="description"
|
||||
id="description"
|
||||
className="block w-full border-gray-300 rounded-sm shadow-sm focus:ring-primary-500 focus:border-primary-500 sm:text-sm"
|
||||
placeholder="A quick video meeting."
|
||||
defaultValue={eventType.description}></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{team && <hr className="border-neutral-200" />}
|
||||
{team && (
|
||||
<div className="space-y-3">
|
||||
<div className="block sm:flex">
|
||||
<div className="mb-4 min-w-44 sm:mb-0">
|
||||
<label
|
||||
htmlFor="schedulingType"
|
||||
className="flex mt-2 text-sm font-medium text-neutral-700">
|
||||
<UsersIcon className="text-neutral-500 h-5 w-5 mr-2" /> Scheduling Type
|
||||
</label>
|
||||
</div>
|
||||
<RadioArea.Select
|
||||
name="schedulingType"
|
||||
value={eventType.schedulingType}
|
||||
options={schedulingTypeOptions}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="block sm:flex">
|
||||
<div className="mb-4 min-w-44 sm:mb-0">
|
||||
<label htmlFor="users" className="flex mt-2 text-sm font-medium text-neutral-700">
|
||||
<UserAddIcon className="text-neutral-500 h-5 w-5 mr-2" /> Attendees
|
||||
</label>
|
||||
</div>
|
||||
<div className="w-full space-y-2">
|
||||
<CheckedSelect
|
||||
onChange={(options: unknown) => setUsers(options.map((option) => option.value))}
|
||||
defaultValue={eventType.users.map((user: User) => ({
|
||||
value: user.id,
|
||||
label: user.name,
|
||||
avatar: user.avatar,
|
||||
}))}
|
||||
options={teamMembers.map((user: User) => ({
|
||||
value: user.id,
|
||||
label: user.name,
|
||||
avatar: user.avatar,
|
||||
}))}
|
||||
id="users"
|
||||
placeholder="Add attendees"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Disclosure>
|
||||
{({ open }) => (
|
||||
<>
|
||||
@@ -703,7 +770,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
key={period.type}
|
||||
value={period}
|
||||
className={({ checked }) =>
|
||||
classnames(
|
||||
classNames(
|
||||
checked ? "border-secondary-200 z-10" : "border-gray-200",
|
||||
"relative min-h-14 flex items-center cursor-pointer focus:outline-none"
|
||||
)
|
||||
@@ -711,7 +778,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
{({ active, checked }) => (
|
||||
<>
|
||||
<div
|
||||
className={classnames(
|
||||
className={classNames(
|
||||
checked
|
||||
? "bg-primary-600 border-transparent"
|
||||
: "bg-white border-gray-300",
|
||||
@@ -724,7 +791,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
<div className="flex flex-col lg:ml-3">
|
||||
<RadioGroup.Label
|
||||
as="span"
|
||||
className={classnames(
|
||||
className={classNames(
|
||||
checked ? "text-secondary-900" : "text-gray-900",
|
||||
"block text-sm space-y-2 lg:space-y-0 lg:space-x-2"
|
||||
)}>
|
||||
@@ -833,7 +900,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
label="Hide event type"
|
||||
/>
|
||||
<a
|
||||
href={"/" + user.username + "/" + eventType.slug}
|
||||
href={"/" + (team ? "team/" + team.slug : eventType.users[0].username) + "/" + eventType.slug}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
className="flex font-medium text-md text-neutral-700">
|
||||
@@ -843,7 +910,11 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
<button
|
||||
onClick={() => {
|
||||
navigator.clipboard.writeText(
|
||||
window.location.hostname + "/" + user.username + "/" + eventType.slug
|
||||
window.location.hostname +
|
||||
"/" +
|
||||
(team ? "team/" + team.slug : eventType.users[0].username) +
|
||||
"/" +
|
||||
eventType.slug
|
||||
);
|
||||
showToast("Link copied!", "success");
|
||||
}}
|
||||
@@ -1032,7 +1103,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
|
||||
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
||||
const { req, query } = context;
|
||||
const session = await getSession({ req });
|
||||
const typeParam = asStringOrThrow(query.type);
|
||||
const typeParam = parseInt(asStringOrThrow(query.type));
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return {
|
||||
@@ -1043,30 +1114,27 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
};
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: session.user.id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
timeZone: true,
|
||||
startTime: true,
|
||||
endTime: true,
|
||||
availability: true,
|
||||
plan: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
return {
|
||||
notFound: true,
|
||||
} as const;
|
||||
}
|
||||
|
||||
const eventType = await prisma.eventType.findFirst({
|
||||
where: {
|
||||
AND: [{ userId: user.id }, { slug: typeParam }],
|
||||
AND: [
|
||||
{
|
||||
OR: [
|
||||
{
|
||||
users: {
|
||||
some: {
|
||||
id: session.user.id,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
userId: session.user.id,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: typeParam,
|
||||
},
|
||||
],
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -1086,6 +1154,36 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
periodEndDate: true,
|
||||
periodCountCalendarDays: true,
|
||||
requiresConfirmation: true,
|
||||
team: {
|
||||
select: {
|
||||
slug: true,
|
||||
members: {
|
||||
where: {
|
||||
accepted: true,
|
||||
},
|
||||
select: {
|
||||
user: {
|
||||
select: {
|
||||
name: true,
|
||||
id: true,
|
||||
avatar: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
users: {
|
||||
select: {
|
||||
name: true,
|
||||
id: true,
|
||||
avatar: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
schedulingType: true,
|
||||
userId: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1095,9 +1193,23 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
};
|
||||
}
|
||||
|
||||
// backwards compat
|
||||
if (eventType.users.length === 0) {
|
||||
eventType.users.push(
|
||||
await prisma.user.findUnique({
|
||||
where: {
|
||||
id: session.user.id,
|
||||
},
|
||||
select: {
|
||||
username: true,
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const credentials = await prisma.credential.findMany({
|
||||
where: {
|
||||
userId: user.id,
|
||||
userId: session.user.id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -1151,15 +1263,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
? providesAvailability.availability
|
||||
: null;
|
||||
|
||||
const availability: Availability[] = getAvailability(eventType) ||
|
||||
getAvailability(user) || [
|
||||
{
|
||||
days: [0, 1, 2, 3, 4, 5, 6],
|
||||
startTime: user.startTime,
|
||||
endTime: user.endTime,
|
||||
},
|
||||
];
|
||||
|
||||
const availability: Availability[] = getAvailability(eventType) || [];
|
||||
availability.sort((a, b) => a.startTime - b.startTime);
|
||||
|
||||
const eventTypeObject = Object.assign({}, eventType, {
|
||||
@@ -1167,12 +1271,21 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
|
||||
periodEndDate: eventType.periodEndDate?.toString() ?? null,
|
||||
});
|
||||
|
||||
const teamMembers = eventTypeObject.team
|
||||
? eventTypeObject.team.members.map((member) => {
|
||||
const user = member.user;
|
||||
user.avatar = user.avatar || defaultAvatarSrc({ email: user.email });
|
||||
return user;
|
||||
})
|
||||
: [];
|
||||
|
||||
return {
|
||||
props: {
|
||||
user,
|
||||
eventType: eventTypeObject,
|
||||
locationOptions,
|
||||
availability,
|
||||
team: eventTypeObject.team || null,
|
||||
teamMembers,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
+487
-556
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,6 @@
|
||||
import { GetServerSidePropsContext } from "next";
|
||||
import prisma from "../../lib/prisma";
|
||||
import prisma from "@lib/prisma";
|
||||
import { asStringOrNull } from "@lib/asStringOrNull";
|
||||
|
||||
export default function Type() {
|
||||
// Just redirect to the schedule page to reschedule it.
|
||||
@@ -7,14 +8,28 @@ export default function Type() {
|
||||
}
|
||||
|
||||
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
const booking = await prisma.booking.findFirst({
|
||||
const booking = await prisma.booking.findUnique({
|
||||
where: {
|
||||
uid: context.query.uid as string,
|
||||
uid: asStringOrNull(context.query.uid),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
user: { select: { username: true } },
|
||||
eventType: { select: { slug: true } },
|
||||
eventType: {
|
||||
select: {
|
||||
users: {
|
||||
select: {
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
slug: true,
|
||||
team: {
|
||||
select: {
|
||||
slug: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
user: true,
|
||||
title: true,
|
||||
description: true,
|
||||
startTime: true,
|
||||
@@ -22,16 +37,21 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
attendees: true,
|
||||
},
|
||||
});
|
||||
if (!booking?.user || !booking.eventType) {
|
||||
|
||||
if (!booking.eventType) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
const eventType = booking.eventType;
|
||||
|
||||
const eventPage =
|
||||
(eventType.team ? "team/" + eventType.team.slug : booking.user.username) + "/" + booking.eventType.slug;
|
||||
|
||||
return {
|
||||
redirect: {
|
||||
destination:
|
||||
"/" + booking.user.username + "/" + booking.eventType.slug + "?rescheduleUid=" + context.query.uid,
|
||||
destination: "/" + eventPage + "?rescheduleUid=" + context.query.uid,
|
||||
permanent: false,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
import * as RadioArea from "@components/ui/form/radio-area";
|
||||
import Head from "next/head";
|
||||
import React, { useState } from "react";
|
||||
|
||||
const selectOptions = [
|
||||
{
|
||||
value: "rabbit",
|
||||
label: "Rabbit",
|
||||
description: "Fast and hard.",
|
||||
},
|
||||
{
|
||||
value: "turtle",
|
||||
label: "Turtle",
|
||||
description: "Slow and steady.",
|
||||
},
|
||||
];
|
||||
|
||||
export default function RadioAreaPage() {
|
||||
const [formData, setFormData] = useState({});
|
||||
|
||||
const onSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<meta name="googlebot" content="noindex" />
|
||||
</Head>
|
||||
<div className="w-full p-4">
|
||||
<h1 className="text-4xl mb-4">RadioArea component</h1>
|
||||
<form onSubmit={onSubmit} className="space-y-4 mb-2">
|
||||
<RadioArea.Group
|
||||
onChange={(radioGroup_1: string) => setFormData({ ...formData, radioGroup_1 })}
|
||||
className="flex space-x-4 max-w-screen-md"
|
||||
name="radioGroup_1">
|
||||
<RadioArea.Item value="radioGroup_1_radio_1" className="flex-grow bg-white">
|
||||
<strong className="mb-1">radioGroup_1_radio_1</strong>
|
||||
<p>Description #1</p>
|
||||
</RadioArea.Item>
|
||||
<RadioArea.Item value="radioGroup_1_radio_2" className="flex-grow bg-white">
|
||||
<strong className="mb-1">radioGroup_1_radio_2</strong>
|
||||
<p>Description #2</p>
|
||||
</RadioArea.Item>
|
||||
<RadioArea.Item value="radioGroup_1_radio_3" className="flex-grow bg-white">
|
||||
<strong className="mb-1">radioGroup_1_radio_3</strong>
|
||||
<p>Description #3</p>
|
||||
</RadioArea.Item>
|
||||
</RadioArea.Group>
|
||||
<RadioArea.Group
|
||||
onChange={(radioGroup_2: string) => setFormData({ ...formData, radioGroup_2 })}
|
||||
className="flex space-x-4 max-w-screen-md"
|
||||
name="radioGroup_2">
|
||||
<RadioArea.Item value="radioGroup_2_radio_1" className="flex-grow bg-white">
|
||||
<strong className="mb-1">radioGroup_1_radio_1</strong>
|
||||
<p>Description #1</p>
|
||||
</RadioArea.Item>
|
||||
<RadioArea.Item value="radioGroup_2_radio_2" className="flex-grow bg-white" defaultChecked={true}>
|
||||
<strong className="mb-1">radioGroup_1_radio_2</strong>
|
||||
<p>Description #2</p>
|
||||
</RadioArea.Item>
|
||||
<RadioArea.Item value="radioGroup_2_radio_3" className="flex-grow bg-white">
|
||||
<strong className="mb-1">radioGroup_1_radio_3</strong>
|
||||
<p>Description #3</p>
|
||||
</RadioArea.Item>
|
||||
</RadioArea.Group>
|
||||
<div>
|
||||
<p className="text-lg">Disabled RadioAreaSelect</p>
|
||||
<RadioArea.Select options={[]} className="max-w-screen-md" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-lg">RadioArea disabled with custom placeholder</p>
|
||||
<RadioArea.Select
|
||||
className="max-w-screen-md"
|
||||
options={[]}
|
||||
placeholder="Does the rabbit or the turtle win the race?"></RadioArea.Select>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-lg">RadioArea with options</p>
|
||||
<RadioArea.Select
|
||||
className="max-w-screen-md"
|
||||
name="turtleOrRabbitWinsTheRace"
|
||||
onChange={(turtleOrRabbitWinsTheRace: string) =>
|
||||
setFormData({ ...formData, turtleOrRabbitWinsTheRace })
|
||||
}
|
||||
options={selectOptions}
|
||||
placeholder="Does the rabbit or the turtle win the race?"></RadioArea.Select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-lg">RadioArea with default selected (disabled for clarity)</p>
|
||||
<RadioArea.Select
|
||||
disabled={true}
|
||||
className="max-w-screen-md"
|
||||
value="turtle"
|
||||
options={selectOptions}></RadioArea.Select>
|
||||
</div>
|
||||
</form>
|
||||
<pre>{JSON.stringify(formData)}</pre>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import prisma from "@lib/prisma";
|
||||
import Modal from "@components/Modal";
|
||||
import Shell from "@components/Shell";
|
||||
import SettingsShell from "@components/Settings";
|
||||
import Avatar from "@components/Avatar";
|
||||
import Avatar from "@components/ui/Avatar";
|
||||
import { getSession } from "@lib/auth";
|
||||
import Select from "react-select";
|
||||
import TimezoneSelect from "react-timezone-select";
|
||||
|
||||
+57
-34
@@ -11,11 +11,11 @@ import toArray from "dayjs/plugin/toArray";
|
||||
import timezone from "dayjs/plugin/timezone";
|
||||
import { createEvent } from "ics";
|
||||
import { getEventName } from "@lib/event";
|
||||
import Theme from "@components/Theme";
|
||||
import { GetServerSidePropsContext } from "next";
|
||||
import { asStringOrNull } from "../lib/asStringOrNull";
|
||||
import useTheme from "@lib/hooks/useTheme";
|
||||
import { asStringOrNull } from "@lib/asStringOrNull";
|
||||
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
||||
import { isBrandingHidden } from "@lib/isBrandingHidden";
|
||||
import { EventType } from "@prisma/client";
|
||||
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(toArray);
|
||||
@@ -26,8 +26,8 @@ export default function Success(props: inferSSRProps<typeof getServerSideProps>)
|
||||
const { location, name } = router.query;
|
||||
|
||||
const [is24h, setIs24h] = useState(false);
|
||||
const [date, setDate] = useState(dayjs.utc(router.query.date));
|
||||
const { isReady } = Theme(props.user.theme);
|
||||
const [date, setDate] = useState(dayjs.utc(asStringOrNull(router.query.date)));
|
||||
const { isReady } = useTheme(props.profile.theme);
|
||||
|
||||
useEffect(() => {
|
||||
setDate(date.tz(localStorage.getItem("timeOption.preferredTimeZone") || dayjs.tz.guess()));
|
||||
@@ -99,9 +99,9 @@ export default function Success(props: inferSSRProps<typeof getServerSideProps>)
|
||||
<div className="mt-3">
|
||||
<p className="text-sm text-neutral-600 dark:text-gray-300">
|
||||
{props.eventType.requiresConfirmation
|
||||
? `${
|
||||
props.user.name || props.user.username
|
||||
} still needs to confirm or reject the booking.`
|
||||
? props.profile.name !== null
|
||||
? `${props.profile.name} still needs to confirm or reject the booking.`
|
||||
: "Your booking still needs to be confirmed or rejected."
|
||||
: `We emailed you and the other attendees a calendar invitation with all the details.`}
|
||||
</p>
|
||||
</div>
|
||||
@@ -224,7 +224,7 @@ export default function Success(props: inferSSRProps<typeof getServerSideProps>)
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{!isBrandingHidden(props.user) && (
|
||||
{!props.hideBranding && (
|
||||
<div className="mt-4 pt-4 border-t dark:border-gray-900 text-gray-400 text-center text-xs dark:text-white">
|
||||
<a href="https://checkout.calendso.com">Create your own booking link with Calendso</a>
|
||||
</div>
|
||||
@@ -239,35 +239,14 @@ export default function Success(props: inferSSRProps<typeof getServerSideProps>)
|
||||
);
|
||||
}
|
||||
|
||||
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
const username = asStringOrNull(context.query.user);
|
||||
export async function getServerSideProps(context) {
|
||||
const typeId = parseInt(asStringOrNull(context.query.type) ?? "");
|
||||
if (!username || isNaN(typeId)) {
|
||||
if (isNaN(typeId)) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
username,
|
||||
},
|
||||
select: {
|
||||
username: true,
|
||||
name: true,
|
||||
bio: true,
|
||||
avatar: true,
|
||||
hideBranding: true,
|
||||
theme: true,
|
||||
plan: true,
|
||||
},
|
||||
});
|
||||
if (!user) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
const eventType = await prisma.eventType.findUnique({
|
||||
const eventType: EventType = await prisma.eventType.findUnique({
|
||||
where: {
|
||||
id: typeId,
|
||||
},
|
||||
@@ -278,17 +257,61 @@ export async function getServerSideProps(context: GetServerSidePropsContext) {
|
||||
length: true,
|
||||
eventName: true,
|
||||
requiresConfirmation: true,
|
||||
userId: true,
|
||||
users: {
|
||||
select: {
|
||||
name: true,
|
||||
hideBranding: true,
|
||||
plan: true,
|
||||
theme: true,
|
||||
},
|
||||
},
|
||||
team: {
|
||||
select: {
|
||||
name: true,
|
||||
hideBranding: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!eventType) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (!eventType.users.length && eventType.userId) {
|
||||
eventType.users.push(
|
||||
await prisma.user.findUnique({
|
||||
where: {
|
||||
id: eventType.userId,
|
||||
},
|
||||
select: {
|
||||
theme: true,
|
||||
hideBranding: true,
|
||||
name: true,
|
||||
plan: true,
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (!eventType.users.length) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
const profile = {
|
||||
name: eventType.team?.name || eventType.users[0]?.name || null,
|
||||
theme: (!eventType.team?.name && eventType.users[0]?.theme) || null,
|
||||
};
|
||||
|
||||
return {
|
||||
props: {
|
||||
user,
|
||||
hideBranding: eventType.team ? eventType.team.hideBranding : isBrandingHidden(eventType.users[0]),
|
||||
profile,
|
||||
eventType,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
import { GetServerSideProps } from "next";
|
||||
import { HeadSeo } from "@components/seo/head-seo";
|
||||
import Theme from "@components/Theme";
|
||||
import { getTeam } from "@lib/teams/getTeam";
|
||||
import Team from "@components/team/screens/Team";
|
||||
|
||||
export default function Page(props) {
|
||||
const { isReady } = Theme();
|
||||
|
||||
return (
|
||||
isReady && (
|
||||
<div>
|
||||
<HeadSeo title={props.team.name} description={props.team.name} />
|
||||
<main className="mx-auto py-24 px-4">
|
||||
<Team team={props.team} />
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
const teamIdOrSlug = Array.isArray(context.query?.idOrSlug)
|
||||
? context.query.idOrSlug.pop()
|
||||
: context.query.idOrSlug;
|
||||
|
||||
const team = await getTeam(teamIdOrSlug);
|
||||
|
||||
if (!team) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
team,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
// Auxiliary methods
|
||||
export function getRandomColorCode(): string {
|
||||
let color = "#";
|
||||
for (let idx = 0; idx < 6; idx++) {
|
||||
color += Math.floor(Math.random() * 10);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
import { InferGetServerSidePropsType } from "next";
|
||||
import Link from "next/link";
|
||||
import { HeadSeo } from "@components/seo/head-seo";
|
||||
import useTheme from "@lib/hooks/useTheme";
|
||||
import { ArrowRightIcon } from "@heroicons/react/solid";
|
||||
import prisma from "@lib/prisma";
|
||||
import Avatar from "@components/ui/Avatar";
|
||||
import Text from "@components/ui/Text";
|
||||
import React from "react";
|
||||
import { defaultAvatarSrc } from "@lib/profile";
|
||||
import EventTypeDescription from "@components/eventtype/EventTypeDescription";
|
||||
import Team from "@components/team/screens/Team";
|
||||
import { useToggleQuery } from "@lib/hooks/useToggleQuery";
|
||||
import AvatarGroup from "@components/ui/AvatarGroup";
|
||||
|
||||
function TeamPage({ team }: InferGetServerSidePropsType<typeof getServerSideProps>) {
|
||||
const { isReady } = useTheme();
|
||||
const showMembers = useToggleQuery("members");
|
||||
|
||||
const eventTypes = (
|
||||
<ul className="space-y-3">
|
||||
{team.eventTypes.map((type) => (
|
||||
<li
|
||||
key={type.id}
|
||||
className="group relative dark:bg-neutral-900 dark:border-0 dark:hover:border-neutral-600 bg-white hover:bg-gray-50 border border-neutral-200 hover:border-black rounded-sm">
|
||||
<ArrowRightIcon className="absolute transition-opacity h-4 w-4 right-3 top-3 text-black dark:text-white opacity-0 group-hover:opacity-100" />
|
||||
<Link href={`${team.slug}/${type.slug}`}>
|
||||
<a className="block px-6 py-4 flex space-x-2 items-center">
|
||||
<div className="flex-shrink">
|
||||
<h2 className="font-semibold text-neutral-900 dark:text-white">{type.title}</h2>
|
||||
<EventTypeDescription className="text-sm" eventType={type} />
|
||||
</div>
|
||||
<AvatarGroup
|
||||
truncateAfter={4}
|
||||
className="flex-shrink-0"
|
||||
size={10}
|
||||
items={type.users.map((user) => ({
|
||||
alt: user.name,
|
||||
image: user.avatar,
|
||||
}))}
|
||||
/>
|
||||
</a>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
|
||||
return (
|
||||
isReady && (
|
||||
<div>
|
||||
<HeadSeo title={team.name} description={team.name} />
|
||||
<div className="pt-24 pb-12 px-4">
|
||||
<div className="mb-8 text-center">
|
||||
<Avatar
|
||||
displayName={team.name}
|
||||
imageSrc={team.logo}
|
||||
className="mx-auto w-20 h-20 rounded-full mb-4"
|
||||
/>
|
||||
<Text variant="headline">{team.name}</Text>
|
||||
</div>
|
||||
{(showMembers.isOn || !team.eventTypes.length) && <Team team={team} />}
|
||||
{!showMembers.isOn && team.eventTypes.length && (
|
||||
<div className="mx-auto max-w-3xl">
|
||||
{eventTypes}
|
||||
<aside className="text-center dark:text-white mt-8">
|
||||
<Link href={`/team/${team.slug}?members=1`} shallow={true}>
|
||||
<a>
|
||||
Book a team member <ArrowRightIcon className="h-6 w-6 inline text-neutral-500" />
|
||||
</a>
|
||||
</Link>
|
||||
</aside>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export const getServerSideProps = async (context) => {
|
||||
const slug = Array.isArray(context.query?.slug) ? context.query.slug.pop() : context.query.slug;
|
||||
|
||||
const teamSelectInput = {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
logo: true,
|
||||
members: {
|
||||
select: {
|
||||
user: {
|
||||
select: {
|
||||
username: true,
|
||||
avatar: true,
|
||||
name: true,
|
||||
id: true,
|
||||
bio: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
eventTypes: {
|
||||
where: {
|
||||
hidden: false,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
description: true,
|
||||
length: true,
|
||||
slug: true,
|
||||
schedulingType: true,
|
||||
users: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
avatar: true,
|
||||
email: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const team = await prisma.team.findUnique({
|
||||
where: {
|
||||
slug,
|
||||
},
|
||||
select: teamSelectInput,
|
||||
});
|
||||
|
||||
if (!team) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
team.eventTypes = team.eventTypes.map((type) => ({
|
||||
...type,
|
||||
users: type.users.map((user) => ({
|
||||
...user,
|
||||
avatar: user.avatar || defaultAvatarSrc({ email: user.email }),
|
||||
})),
|
||||
}));
|
||||
|
||||
return {
|
||||
props: {
|
||||
team,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default TeamPage;
|
||||
@@ -0,0 +1,90 @@
|
||||
import { Availability, EventType } from "@prisma/client";
|
||||
import prisma from "@lib/prisma";
|
||||
import { GetServerSidePropsContext, InferGetServerSidePropsType } from "next";
|
||||
import { asStringOrNull } from "@lib/asStringOrNull";
|
||||
import AvailabilityPage from "@components/booking/pages/AvailabilityPage";
|
||||
|
||||
export default function TeamType(props: InferGetServerSidePropsType<typeof getServerSideProps>) {
|
||||
return <AvailabilityPage {...props} />;
|
||||
}
|
||||
|
||||
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
|
||||
// get query params and typecast them to string
|
||||
// (would be even better to assert them instead of typecasting)
|
||||
const slugParam = asStringOrNull(context.query.slug);
|
||||
const typeParam = asStringOrNull(context.query.type);
|
||||
|
||||
if (!slugParam || !typeParam) {
|
||||
throw new Error(`File is not named [idOrSlug]/[user]`);
|
||||
}
|
||||
|
||||
const team = await prisma.team.findFirst({
|
||||
where: {
|
||||
slug: slugParam,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
slug: true,
|
||||
logo: true,
|
||||
eventTypes: {
|
||||
where: {
|
||||
slug: typeParam,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
users: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
avatar: true,
|
||||
username: true,
|
||||
timeZone: true,
|
||||
},
|
||||
},
|
||||
title: true,
|
||||
availability: true,
|
||||
description: true,
|
||||
length: true,
|
||||
schedulingType: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!team || team.eventTypes.length != 1) {
|
||||
return {
|
||||
notFound: true,
|
||||
} as const;
|
||||
}
|
||||
|
||||
const profile = {
|
||||
name: team.name,
|
||||
slug: team.slug,
|
||||
image: team.logo || null,
|
||||
};
|
||||
|
||||
const eventType: EventType = team.eventTypes[0];
|
||||
|
||||
const getWorkingHours = (providesAvailability: { availability: Availability[] }) =>
|
||||
providesAvailability.availability && providesAvailability.availability.length
|
||||
? providesAvailability.availability
|
||||
: null;
|
||||
|
||||
const workingHours = getWorkingHours(eventType) || [];
|
||||
workingHours.sort((a, b) => a.startTime - b.startTime);
|
||||
|
||||
const eventTypeObject = Object.assign({}, eventType, {
|
||||
periodStartDate: eventType.periodStartDate?.toString() ?? null,
|
||||
periodEndDate: eventType.periodEndDate?.toString() ?? null,
|
||||
});
|
||||
|
||||
return {
|
||||
props: {
|
||||
profile,
|
||||
team,
|
||||
eventType: eventTypeObject,
|
||||
workingHours,
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,90 @@
|
||||
import prisma from "@lib/prisma";
|
||||
import { EventType } from "@prisma/client";
|
||||
import "react-phone-number-input/style.css";
|
||||
import BookingPage from "@components/booking/pages/BookingPage";
|
||||
import { InferGetServerSidePropsType } from "next";
|
||||
|
||||
export default function TeamBookingPage(props: InferGetServerSidePropsType<typeof getServerSideProps>) {
|
||||
return <BookingPage {...props} />;
|
||||
}
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
const eventTypeId = parseInt(context.query.type);
|
||||
if (typeof eventTypeId !== "number" || eventTypeId % 1 !== 0) {
|
||||
return {
|
||||
notFound: true,
|
||||
} as const;
|
||||
}
|
||||
|
||||
const eventType: EventType = await prisma.eventType.findUnique({
|
||||
where: {
|
||||
id: eventTypeId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
slug: true,
|
||||
description: true,
|
||||
length: true,
|
||||
locations: true,
|
||||
customInputs: true,
|
||||
periodType: true,
|
||||
periodDays: true,
|
||||
periodStartDate: true,
|
||||
periodEndDate: true,
|
||||
periodCountCalendarDays: true,
|
||||
team: {
|
||||
select: {
|
||||
slug: true,
|
||||
name: true,
|
||||
logo: true,
|
||||
},
|
||||
},
|
||||
users: {
|
||||
select: {
|
||||
avatar: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const eventTypeObject = [eventType].map((e) => {
|
||||
return {
|
||||
...e,
|
||||
periodStartDate: e.periodStartDate?.toString() ?? null,
|
||||
periodEndDate: e.periodEndDate?.toString() ?? null,
|
||||
};
|
||||
})[0];
|
||||
|
||||
let booking = null;
|
||||
|
||||
if (context.query.rescheduleUid) {
|
||||
booking = await prisma.booking.findFirst({
|
||||
where: {
|
||||
uid: context.query.rescheduleUid,
|
||||
},
|
||||
select: {
|
||||
description: true,
|
||||
attendees: {
|
||||
select: {
|
||||
email: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
props: {
|
||||
profile: {
|
||||
...eventTypeObject.team,
|
||||
slug: "team/" + eventTypeObject.slug,
|
||||
image: eventTypeObject.team.logo,
|
||||
},
|
||||
eventType: eventTypeObject,
|
||||
booking,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user