2021-09-14 08:20:24 +00:00
|
|
|
// TODO: replace headlessui with radix-ui
|
2021-07-30 23:05:38 +00:00
|
|
|
import { Menu, Transition } from "@headlessui/react";
|
|
|
|
import {
|
2021-09-14 08:45:28 +00:00
|
|
|
ChevronDownIcon,
|
2021-07-30 23:05:38 +00:00
|
|
|
DotsHorizontalIcon,
|
|
|
|
ExternalLinkIcon,
|
|
|
|
LinkIcon,
|
|
|
|
PlusIcon,
|
2021-09-14 08:45:28 +00:00
|
|
|
UsersIcon,
|
2021-07-30 23:05:38 +00:00
|
|
|
} from "@heroicons/react/solid";
|
2021-10-08 13:10:57 +00:00
|
|
|
import { SchedulingType, Prisma } from "@prisma/client";
|
|
|
|
import { GetServerSidePropsContext } from "next";
|
2021-09-23 08:49:17 +00:00
|
|
|
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
|
2021-09-22 19:52:38 +00:00
|
|
|
import Head from "next/head";
|
|
|
|
import Link from "next/link";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
import React, { Fragment, useRef } from "react";
|
|
|
|
import { useMutation } from "react-query";
|
|
|
|
|
2021-09-15 12:33:00 +00:00
|
|
|
import { asStringOrNull } from "@lib/asStringOrNull";
|
|
|
|
import { getSession } from "@lib/auth";
|
2021-08-03 08:30:35 +00:00
|
|
|
import classNames from "@lib/classNames";
|
2021-09-15 12:33:00 +00:00
|
|
|
import { HttpError } from "@lib/core/http/error";
|
2021-10-08 11:43:48 +00:00
|
|
|
import { getOrSetUserLocaleFromHeaders } from "@lib/core/i18n/i18n.utils";
|
2021-10-08 13:10:57 +00:00
|
|
|
import { shouldShowOnboarding, ONBOARDING_NEXT_REDIRECT } from "@lib/getting-started";
|
2021-09-23 08:49:17 +00:00
|
|
|
import { useLocale } from "@lib/hooks/useLocale";
|
2021-09-15 12:33:00 +00:00
|
|
|
import { useToggleQuery } from "@lib/hooks/useToggleQuery";
|
|
|
|
import createEventType from "@lib/mutations/event-types/create-event-type";
|
|
|
|
import showToast from "@lib/notification";
|
|
|
|
import prisma from "@lib/prisma";
|
|
|
|
import { inferSSRProps } from "@lib/types/inferSSRProps";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
|
|
|
import { Dialog, DialogClose, DialogContent } from "@components/Dialog";
|
|
|
|
import Shell from "@components/Shell";
|
|
|
|
import { Tooltip } from "@components/Tooltip";
|
|
|
|
import EventTypeDescription from "@components/eventtype/EventTypeDescription";
|
|
|
|
import { Alert } from "@components/ui/Alert";
|
|
|
|
import Avatar from "@components/ui/Avatar";
|
|
|
|
import AvatarGroup from "@components/ui/AvatarGroup";
|
|
|
|
import Badge from "@components/ui/Badge";
|
|
|
|
import { Button } from "@components/ui/Button";
|
|
|
|
import Dropdown, {
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
|
|
|
DropdownMenuLabel,
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
} from "@components/ui/Dropdown";
|
|
|
|
import * as RadioArea from "@components/ui/form/radio-area";
|
|
|
|
import UserCalendarIllustration from "@components/ui/svg/UserCalendarIllustration";
|
2021-07-30 23:05:38 +00:00
|
|
|
|
2021-09-15 12:33:00 +00:00
|
|
|
type PageProps = inferSSRProps<typeof getServerSideProps>;
|
|
|
|
type EventType = PageProps["eventTypes"][number];
|
|
|
|
type Profile = PageProps["profiles"][number];
|
|
|
|
type MembershipCount = EventType["metadata"]["membershipCount"];
|
|
|
|
|
|
|
|
const EventTypesPage = (props: PageProps) => {
|
2021-10-11 13:42:43 +00:00
|
|
|
const { t, locale } = useLocale({ localeProp: props.localeProp });
|
2021-09-23 08:49:17 +00:00
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
const CreateFirstEventTypeView = () => (
|
|
|
|
<div className="md:py-20">
|
|
|
|
<UserCalendarIllustration />
|
2021-09-15 12:33:00 +00:00
|
|
|
<div className="block mx-auto text-center md:max-w-screen-sm">
|
2021-10-11 13:42:43 +00:00
|
|
|
<h3 className="mt-2 text-xl font-bold text-neutral-900">{t("new_event_type_heading")}</h3>
|
|
|
|
<p className="mt-1 mb-2 text-md text-neutral-600">{t("new_event_type_description")}</p>
|
2021-09-23 08:49:17 +00:00
|
|
|
<CreateNewEventDialog
|
|
|
|
localeProp={locale}
|
|
|
|
canAddEvents={props.canAddEvents}
|
|
|
|
profiles={props.profiles}
|
|
|
|
/>
|
2021-09-14 08:45:28 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
2021-09-15 12:33:00 +00:00
|
|
|
const EventTypeListHeading = ({
|
|
|
|
profile,
|
|
|
|
membershipCount,
|
|
|
|
}: {
|
2021-09-22 18:36:13 +00:00
|
|
|
profile?: Profile;
|
2021-09-15 12:33:00 +00:00
|
|
|
membershipCount: MembershipCount;
|
|
|
|
}) => (
|
2021-09-14 13:27:41 +00:00
|
|
|
<div className="flex mb-4">
|
|
|
|
<Link href="/settings/teams">
|
|
|
|
<a>
|
2021-09-15 12:33:00 +00:00
|
|
|
<Avatar
|
2021-09-22 18:36:13 +00:00
|
|
|
displayName={profile?.name || ""}
|
|
|
|
imageSrc={profile?.image || undefined}
|
2021-09-15 12:33:00 +00:00
|
|
|
size={8}
|
|
|
|
className="inline mt-1 mr-2"
|
|
|
|
/>
|
2021-09-14 13:27:41 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
2021-09-14 08:45:28 +00:00
|
|
|
<div>
|
2021-09-14 13:27:41 +00:00
|
|
|
<Link href="/settings/teams">
|
2021-09-22 18:36:13 +00:00
|
|
|
<a className="font-bold">{profile?.name || ""}</a>
|
2021-09-14 13:27:41 +00:00
|
|
|
</Link>
|
2021-09-14 08:45:28 +00:00
|
|
|
{membershipCount && (
|
2021-09-15 12:33:00 +00:00
|
|
|
<span className="relative ml-2 text-xs text-neutral-500 -top-px">
|
2021-09-14 13:27:41 +00:00
|
|
|
<Link href="/settings/teams">
|
|
|
|
<a>
|
|
|
|
<Badge variant="gray">
|
2021-09-15 12:33:00 +00:00
|
|
|
<UsersIcon className="inline w-3 h-3 mr-1 -mt-px" />
|
2021-09-14 13:27:41 +00:00
|
|
|
{membershipCount}
|
|
|
|
</Badge>
|
|
|
|
</a>
|
|
|
|
</Link>
|
2021-09-14 08:45:28 +00:00
|
|
|
</span>
|
|
|
|
)}
|
2021-09-24 12:52:00 +00:00
|
|
|
{profile?.slug && (
|
2021-09-24 15:03:28 +00:00
|
|
|
<Link href={`${process.env.NEXT_PUBLIC_APP_URL}/${profile.slug}`}>
|
|
|
|
<a className="block text-xs text-neutral-500">{`${process.env.NEXT_PUBLIC_APP_URL?.replace(
|
|
|
|
"https://",
|
|
|
|
""
|
|
|
|
)}/${profile.slug}`}</a>
|
2021-09-14 08:45:28 +00:00
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
const EventTypeList = ({
|
|
|
|
readOnly,
|
|
|
|
types,
|
|
|
|
profile,
|
|
|
|
}: {
|
2021-09-15 12:33:00 +00:00
|
|
|
profile: PageProps["profiles"][number];
|
2021-09-14 08:45:28 +00:00
|
|
|
readOnly: boolean;
|
2021-09-22 18:36:13 +00:00
|
|
|
types: EventType["eventTypes"];
|
2021-09-14 08:45:28 +00:00
|
|
|
}) => (
|
2021-09-15 12:33:00 +00:00
|
|
|
<div className="mb-16 -mx-4 overflow-hidden bg-white border border-gray-200 rounded-sm sm:mx-0">
|
2021-09-14 08:45:28 +00:00
|
|
|
<ul className="divide-y divide-neutral-200" data-testid="event-types">
|
|
|
|
{types.map((type) => (
|
|
|
|
<li
|
|
|
|
key={type.id}
|
|
|
|
className={classNames(
|
|
|
|
type.$disabled && "opacity-30 cursor-not-allowed pointer-events-none select-none"
|
|
|
|
)}
|
|
|
|
data-disabled={type.$disabled ? 1 : 0}>
|
2021-09-24 11:28:57 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
"hover:bg-neutral-50 flex justify-between items-center ",
|
|
|
|
type.$disabled && "pointer-events-none"
|
|
|
|
)}>
|
2021-10-08 13:10:57 +00:00
|
|
|
<div className="flex items-center justify-between w-full px-4 py-4 sm:px-6 hover:bg-neutral-50">
|
2021-09-14 08:45:28 +00:00
|
|
|
<Link href={"/event-types/" + type.id}>
|
2021-09-15 12:33:00 +00:00
|
|
|
<a className="flex-grow text-sm truncate">
|
2021-09-14 08:45:28 +00:00
|
|
|
<div>
|
2021-09-15 12:33:00 +00:00
|
|
|
<span className="font-medium truncate text-neutral-900">{type.title}</span>
|
2021-09-14 08:45:28 +00:00
|
|
|
{type.hidden && (
|
|
|
|
<span className="ml-2 inline items-center px-1.5 py-0.5 rounded-sm text-xs font-medium bg-yellow-100 text-yellow-800">
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("hidden")}
|
2021-09-14 08:45:28 +00:00
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
{readOnly && (
|
|
|
|
<span className="ml-2 inline items-center px-1.5 py-0.5 rounded-sm text-xs font-medium bg-gray-100 text-gray-800">
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("readonly")}
|
2021-09-14 08:45:28 +00:00
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</div>
|
2021-10-08 11:43:48 +00:00
|
|
|
<EventTypeDescription localeProp={locale} eventType={type} />
|
2021-09-14 08:45:28 +00:00
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
|
2021-09-15 12:33:00 +00:00
|
|
|
<div className="flex-shrink-0 hidden mt-4 sm:flex sm:mt-0 sm:ml-5">
|
2021-10-10 09:46:20 +00:00
|
|
|
<div className="flex items-center space-x-2 overflow-hidden">
|
2021-09-22 18:36:13 +00:00
|
|
|
{type.users?.length > 1 && (
|
2021-09-14 08:45:28 +00:00
|
|
|
<AvatarGroup
|
|
|
|
size={8}
|
|
|
|
truncateAfter={4}
|
|
|
|
items={type.users.map((organizer) => ({
|
2021-09-22 18:36:13 +00:00
|
|
|
alt: organizer.name || "",
|
|
|
|
image: organizer.avatar || "",
|
2021-09-14 08:45:28 +00:00
|
|
|
}))}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<Tooltip content="Preview">
|
|
|
|
<a
|
2021-09-22 18:36:13 +00:00
|
|
|
href={`${process.env.NEXT_PUBLIC_APP_URL}/${profile.slug}/${type.slug}`}
|
2021-09-14 08:45:28 +00:00
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
2021-10-10 09:46:20 +00:00
|
|
|
className="btn-icon">
|
2021-09-15 12:33:00 +00:00
|
|
|
<ExternalLinkIcon className="w-5 h-5 group-hover:text-black" />
|
2021-09-14 08:45:28 +00:00
|
|
|
</a>
|
|
|
|
</Tooltip>
|
|
|
|
|
|
|
|
<Tooltip content="Copy link">
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
showToast("Link copied!", "success");
|
|
|
|
navigator.clipboard.writeText(
|
2021-09-22 18:36:13 +00:00
|
|
|
`${process.env.NEXT_PUBLIC_APP_URL}/${profile.slug}/${type.slug}`
|
2021-09-14 08:45:28 +00:00
|
|
|
);
|
|
|
|
}}
|
2021-10-10 09:46:20 +00:00
|
|
|
className="btn-icon">
|
2021-09-15 12:33:00 +00:00
|
|
|
<LinkIcon className="w-5 h-5 group-hover:text-black" />
|
2021-09-14 08:45:28 +00:00
|
|
|
</button>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-24 11:28:57 +00:00
|
|
|
<div className="flex flex-shrink-0 mr-5 sm:hidden">
|
2021-09-14 08:45:28 +00:00
|
|
|
<Menu as="div" className="inline-block text-left">
|
|
|
|
{({ open }) => (
|
|
|
|
<>
|
|
|
|
<div>
|
2021-09-15 12:33:00 +00:00
|
|
|
<Menu.Button className="p-2 mt-1 border border-transparent text-neutral-400 hover:border-gray-200">
|
2021-10-11 13:42:43 +00:00
|
|
|
<span className="sr-only">{t("open_options")}</span>
|
2021-09-15 12:33:00 +00:00
|
|
|
<DotsHorizontalIcon className="w-5 h-5" aria-hidden="true" />
|
2021-09-14 08:45:28 +00:00
|
|
|
</Menu.Button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Transition
|
|
|
|
show={open}
|
|
|
|
as={Fragment}
|
|
|
|
enter="transition ease-out duration-100"
|
|
|
|
enterFrom="transform opacity-0 scale-95"
|
|
|
|
enterTo="transform opacity-100 scale-100"
|
|
|
|
leave="transition ease-in duration-75"
|
|
|
|
leaveFrom="transform opacity-100 scale-100"
|
|
|
|
leaveTo="transform opacity-0 scale-95">
|
|
|
|
<Menu.Items
|
|
|
|
static
|
2021-10-08 13:10:57 +00:00
|
|
|
className="absolute right-0 z-10 w-56 mt-2 origin-top-right bg-white divide-y rounded-sm shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none divide-neutral-100">
|
2021-09-14 08:45:28 +00:00
|
|
|
<div className="py-1">
|
|
|
|
<Menu.Item>
|
|
|
|
{({ active }) => (
|
|
|
|
<a
|
2021-09-22 18:36:13 +00:00
|
|
|
href={`${process.env.NEXT_PUBLIC_APP_URL}/${profile.slug}/${type.slug}`}
|
2021-09-14 08:45:28 +00:00
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
className={classNames(
|
|
|
|
active ? "bg-neutral-100 text-neutral-900" : "text-neutral-700",
|
|
|
|
"group flex items-center px-4 py-2 text-sm font-medium"
|
|
|
|
)}>
|
|
|
|
<ExternalLinkIcon
|
2021-09-15 12:33:00 +00:00
|
|
|
className="w-4 h-4 mr-3 text-neutral-400 group-hover:text-neutral-500"
|
2021-09-14 08:45:28 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("preview")}
|
2021-09-14 08:45:28 +00:00
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</Menu.Item>
|
|
|
|
<Menu.Item>
|
|
|
|
{({ active }) => (
|
|
|
|
<button
|
|
|
|
onClick={() => {
|
|
|
|
showToast("Link copied!", "success");
|
|
|
|
navigator.clipboard.writeText(
|
2021-09-22 18:36:13 +00:00
|
|
|
`${process.env.NEXT_PUBLIC_APP_URL}/${profile.slug}/${type.slug}`
|
2021-09-14 08:45:28 +00:00
|
|
|
);
|
|
|
|
}}
|
|
|
|
className={classNames(
|
|
|
|
active ? "bg-neutral-100 text-neutral-900" : "text-neutral-700",
|
|
|
|
"group flex items-center px-4 py-2 text-sm w-full font-medium"
|
|
|
|
)}>
|
|
|
|
<LinkIcon
|
2021-09-15 12:33:00 +00:00
|
|
|
className="w-4 h-4 mr-3 text-neutral-400 group-hover:text-neutral-500"
|
2021-09-14 08:45:28 +00:00
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("copy_link")}
|
2021-09-14 08:45:28 +00:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</Menu.Item>
|
|
|
|
</div>
|
|
|
|
</Menu.Items>
|
|
|
|
</Transition>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Menu>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Head>
|
2021-10-11 13:42:43 +00:00
|
|
|
<title>{t("event_types_page_title")}| Cal.com</title>
|
2021-09-14 08:45:28 +00:00
|
|
|
<link rel="icon" href="/favicon.ico" />
|
|
|
|
</Head>
|
|
|
|
<Shell
|
2021-10-11 13:42:43 +00:00
|
|
|
heading={t("event_types_page_title")}
|
|
|
|
subtitle={t("event_types_page_subtitle")}
|
2021-09-14 08:45:28 +00:00
|
|
|
CTA={
|
|
|
|
props.eventTypes.length !== 0 && (
|
|
|
|
<CreateNewEventDialog canAddEvents={props.canAddEvents} profiles={props.profiles} />
|
|
|
|
)
|
|
|
|
}>
|
2021-09-24 12:52:00 +00:00
|
|
|
{props.user.plan === "FREE" && !props.canAddEvents && (
|
2021-09-14 08:45:28 +00:00
|
|
|
<Alert
|
|
|
|
severity="warning"
|
2021-10-11 13:42:43 +00:00
|
|
|
title={<>{t("plan_upgrade")}</>}
|
2021-09-14 08:45:28 +00:00
|
|
|
message={
|
|
|
|
<>
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("to_upgrade_go_to")}{" "}
|
2021-09-24 12:52:00 +00:00
|
|
|
<a href={"https://cal.com/upgrade"} className="underline">
|
|
|
|
{"https://cal.com/upgrade"}
|
2021-09-14 08:45:28 +00:00
|
|
|
</a>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
className="my-4"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{props.eventTypes &&
|
|
|
|
props.eventTypes.map((input) => (
|
2021-09-24 20:02:03 +00:00
|
|
|
<Fragment key={input.profile?.slug}>
|
2021-09-14 08:45:28 +00:00
|
|
|
{/* hide list heading when there is only one (current user) */}
|
|
|
|
{(props.eventTypes.length !== 1 || input.teamId) && (
|
|
|
|
<EventTypeListHeading
|
|
|
|
profile={input.profile}
|
|
|
|
membershipCount={input.metadata?.membershipCount}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<EventTypeList
|
|
|
|
types={input.eventTypes}
|
|
|
|
profile={input.profile}
|
|
|
|
readOnly={input.metadata?.readOnly}
|
|
|
|
/>
|
2021-09-24 20:02:03 +00:00
|
|
|
</Fragment>
|
2021-09-14 08:45:28 +00:00
|
|
|
))}
|
|
|
|
|
|
|
|
{props.eventTypes.length === 0 && <CreateFirstEventTypeView />}
|
|
|
|
</Shell>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-09-23 08:49:17 +00:00
|
|
|
const CreateNewEventDialog = ({
|
|
|
|
profiles,
|
|
|
|
canAddEvents,
|
|
|
|
localeProp,
|
|
|
|
}: {
|
|
|
|
profiles: Profile[];
|
|
|
|
canAddEvents: boolean;
|
|
|
|
localeProp: string;
|
|
|
|
}) => {
|
2021-07-30 23:05:38 +00:00
|
|
|
const router = useRouter();
|
2021-09-14 08:45:28 +00:00
|
|
|
const teamId: number | null = Number(router.query.teamId) || null;
|
|
|
|
const modalOpen = useToggleQuery("new");
|
2021-09-23 08:49:17 +00:00
|
|
|
const { t } = useLocale({ localeProp });
|
2021-09-14 08:45:28 +00:00
|
|
|
|
2021-08-27 12:11:24 +00:00
|
|
|
const createMutation = useMutation(createEventType, {
|
|
|
|
onSuccess: async ({ eventType }) => {
|
2021-09-14 08:45:28 +00:00
|
|
|
await router.push("/event-types/" + eventType.id);
|
2021-08-27 12:11:24 +00:00
|
|
|
showToast(`${eventType.title} event type created successfully`, "success");
|
|
|
|
},
|
2021-09-09 13:51:06 +00:00
|
|
|
onError: (err: HttpError) => {
|
|
|
|
const message = `${err.statusCode}: ${err.message}`;
|
|
|
|
showToast(message, "error");
|
2021-08-27 12:11:24 +00:00
|
|
|
},
|
|
|
|
});
|
2021-07-30 23:05:38 +00:00
|
|
|
|
2021-09-06 13:51:15 +00:00
|
|
|
const slugRef = useRef<HTMLInputElement>(null);
|
2021-08-04 16:06:05 +00:00
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
return (
|
2021-08-23 12:45:25 +00:00
|
|
|
<Dialog
|
2021-09-06 13:51:15 +00:00
|
|
|
open={modalOpen.isOn}
|
2021-08-23 12:45:25 +00:00
|
|
|
onOpenChange={(isOpen) => {
|
2021-09-06 13:51:15 +00:00
|
|
|
router.push(isOpen ? modalOpen.hrefOn : modalOpen.hrefOff);
|
2021-08-23 12:45:25 +00:00
|
|
|
}}>
|
2021-09-14 08:45:28 +00:00
|
|
|
{!profiles.filter((profile) => profile.teamId).length && (
|
|
|
|
<Button
|
|
|
|
data-testid="new-event-type"
|
|
|
|
{...(canAddEvents
|
|
|
|
? {
|
2021-09-21 10:36:29 +00:00
|
|
|
href: modalOpen.hrefOn,
|
|
|
|
}
|
2021-09-14 08:45:28 +00:00
|
|
|
: {
|
2021-09-21 10:36:29 +00:00
|
|
|
disabled: true,
|
|
|
|
})}
|
2021-09-14 08:45:28 +00:00
|
|
|
StartIcon={PlusIcon}>
|
2021-10-08 11:43:48 +00:00
|
|
|
{t("new_event_type_btn")}
|
2021-09-14 08:45:28 +00:00
|
|
|
</Button>
|
|
|
|
)}
|
|
|
|
{profiles.filter((profile) => profile.teamId).length > 0 && (
|
2021-09-15 12:33:00 +00:00
|
|
|
<Dropdown>
|
|
|
|
<DropdownMenuTrigger asChild>
|
2021-10-08 11:43:48 +00:00
|
|
|
<Button EndIcon={ChevronDownIcon}>{t("new_event_type_btn")}</Button>
|
2021-09-15 12:33:00 +00:00
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent align="end">
|
2021-10-11 13:42:43 +00:00
|
|
|
<DropdownMenuLabel>{t("new_event_subtitle")}</DropdownMenuLabel>
|
2021-09-15 12:33:00 +00:00
|
|
|
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
2021-09-14 08:45:28 +00:00
|
|
|
{profiles.map((profile) => (
|
2021-09-15 12:33:00 +00:00
|
|
|
<DropdownMenuItem
|
2021-09-14 08:45:28 +00:00
|
|
|
key={profile.slug}
|
2021-09-14 13:27:41 +00:00
|
|
|
className="px-3 py-2 cursor-pointer hover:bg-neutral-100 focus:outline-none"
|
2021-09-14 08:45:28 +00:00
|
|
|
onSelect={() =>
|
|
|
|
router.push({
|
|
|
|
pathname: router.pathname,
|
|
|
|
query: {
|
|
|
|
...router.query,
|
|
|
|
new: "1",
|
|
|
|
eventPage: profile.slug,
|
|
|
|
...(profile.teamId
|
|
|
|
? {
|
2021-09-21 10:36:29 +00:00
|
|
|
teamId: profile.teamId,
|
|
|
|
}
|
2021-09-14 08:45:28 +00:00
|
|
|
: {}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}>
|
|
|
|
<Avatar
|
|
|
|
displayName={profile.name}
|
|
|
|
imageSrc={profile.image}
|
2021-09-15 12:33:00 +00:00
|
|
|
size={6}
|
2021-09-14 08:45:28 +00:00
|
|
|
className="inline mr-2"
|
|
|
|
/>
|
2021-09-22 10:43:08 +00:00
|
|
|
{profile.name ? profile.name : profile.slug}
|
2021-09-15 12:33:00 +00:00
|
|
|
</DropdownMenuItem>
|
2021-09-14 08:45:28 +00:00
|
|
|
))}
|
2021-09-15 12:33:00 +00:00
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
2021-09-14 08:45:28 +00:00
|
|
|
)}
|
2021-08-03 17:36:55 +00:00
|
|
|
<DialogContent>
|
2021-08-05 11:36:24 +00:00
|
|
|
<div className="mb-8">
|
2021-09-15 12:33:00 +00:00
|
|
|
<h3 className="text-lg font-bold leading-6 text-gray-900" id="modal-title">
|
2021-10-11 13:42:43 +00:00
|
|
|
{teamId ? t("add_new_team_event_type") : t("add_new_event_type")}
|
2021-08-03 17:36:55 +00:00
|
|
|
</h3>
|
|
|
|
<div>
|
2021-10-11 13:42:43 +00:00
|
|
|
<p className="text-sm text-gray-500">{t("new_event_type_to_book_description")}</p>
|
2021-08-03 17:36:55 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-06 13:51:15 +00:00
|
|
|
<form
|
|
|
|
onSubmit={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
const target = e.target as unknown as Record<
|
2021-09-14 08:45:28 +00:00
|
|
|
"title" | "slug" | "description" | "length" | "schedulingType",
|
2021-09-06 13:51:15 +00:00
|
|
|
{ value: string }
|
|
|
|
>;
|
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
const payload = {
|
2021-09-06 13:51:15 +00:00
|
|
|
title: target.title.value,
|
|
|
|
slug: target.slug.value,
|
|
|
|
description: target.description.value,
|
|
|
|
length: parseInt(target.length.value),
|
|
|
|
};
|
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
if (router.query.teamId) {
|
|
|
|
payload.teamId = parseInt(asStringOrNull(router.query.teamId), 10);
|
|
|
|
payload.schedulingType = target.schedulingType.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
createMutation.mutate(payload);
|
2021-09-06 13:51:15 +00:00
|
|
|
}}>
|
2021-08-03 17:36:55 +00:00
|
|
|
<div>
|
|
|
|
<div className="mb-4">
|
|
|
|
<label htmlFor="title" className="block text-sm font-medium text-gray-700">
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("title")}
|
2021-08-03 17:36:55 +00:00
|
|
|
</label>
|
|
|
|
<div className="mt-1">
|
|
|
|
<input
|
2021-09-06 13:51:15 +00:00
|
|
|
onChange={(e) => {
|
|
|
|
if (!slugRef.current) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-14 08:45:28 +00:00
|
|
|
slugRef.current.value = e.target.value.replace(/\s+/g, "-").toLowerCase();
|
2021-09-06 13:51:15 +00:00
|
|
|
}}
|
2021-08-03 17:36:55 +00:00
|
|
|
type="text"
|
|
|
|
name="title"
|
|
|
|
id="title"
|
|
|
|
required
|
2021-09-15 12:33:00 +00:00
|
|
|
className="block w-full border-gray-300 rounded-sm shadow-sm focus:ring-neutral-900 focus:border-neutral-900 sm:text-sm"
|
2021-10-11 13:42:43 +00:00
|
|
|
placeholder={t("quick_chat")}
|
2021-08-03 17:36:55 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mb-4">
|
|
|
|
<label htmlFor="slug" className="block text-sm font-medium text-gray-700">
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("url")}
|
2021-08-03 17:36:55 +00:00
|
|
|
</label>
|
|
|
|
<div className="mt-1">
|
|
|
|
<div className="flex rounded-sm shadow-sm">
|
2021-09-15 12:33:00 +00:00
|
|
|
<span className="inline-flex items-center px-3 text-gray-500 border border-r-0 border-gray-300 rounded-l-md bg-gray-50 sm:text-sm">
|
2021-09-24 10:16:46 +00:00
|
|
|
{process.env.NEXT_PUBLIC_APP_URL}/{router.query.eventPage || profiles[0].slug}/
|
2021-08-03 17:36:55 +00:00
|
|
|
</span>
|
|
|
|
<input
|
2021-09-14 08:45:28 +00:00
|
|
|
ref={slugRef}
|
2021-08-03 17:36:55 +00:00
|
|
|
type="text"
|
|
|
|
name="slug"
|
|
|
|
id="slug"
|
|
|
|
required
|
2021-09-15 12:33:00 +00:00
|
|
|
className="flex-1 block w-full min-w-0 border-gray-300 rounded-none focus:ring-neutral-900 focus:border-neutral-900 rounded-r-md sm:text-sm"
|
2021-08-03 17:36:55 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mb-4">
|
|
|
|
<label htmlFor="description" className="block text-sm font-medium text-gray-700">
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("description")}
|
2021-08-03 17:36:55 +00:00
|
|
|
</label>
|
|
|
|
<div className="mt-1">
|
|
|
|
<textarea
|
|
|
|
name="description"
|
|
|
|
id="description"
|
2021-09-15 12:33:00 +00:00
|
|
|
className="block w-full border-gray-300 rounded-sm shadow-sm focus:ring-neutral-900 focus:border-neutral-900 sm:text-sm"
|
2021-10-11 13:42:43 +00:00
|
|
|
placeholder={t("quick_video_meeting")}
|
2021-09-14 08:45:28 +00:00
|
|
|
/>
|
2021-08-03 17:36:55 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mb-4">
|
|
|
|
<label htmlFor="length" className="block text-sm font-medium text-gray-700">
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("length")}
|
2021-08-03 17:36:55 +00:00
|
|
|
</label>
|
2021-09-15 12:33:00 +00:00
|
|
|
<div className="relative mt-1 rounded-sm shadow-sm">
|
2021-08-03 17:36:55 +00:00
|
|
|
<input
|
|
|
|
type="number"
|
|
|
|
name="length"
|
|
|
|
id="length"
|
|
|
|
required
|
2021-09-15 12:33:00 +00:00
|
|
|
className="block w-full pr-20 border-gray-300 rounded-sm focus:ring-neutral-900 focus:border-neutral-900 sm:text-sm"
|
2021-08-03 17:36:55 +00:00
|
|
|
placeholder="15"
|
2021-10-07 15:43:20 +00:00
|
|
|
defaultValue={15}
|
2021-08-03 17:36:55 +00:00
|
|
|
/>
|
2021-09-15 12:33:00 +00:00
|
|
|
<div className="absolute inset-y-0 right-0 flex items-center pr-3 text-sm text-gray-400">
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("minutes")}
|
2021-08-03 17:36:55 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-14 08:45:28 +00:00
|
|
|
{teamId && (
|
|
|
|
<div className="mb-4">
|
|
|
|
<label htmlFor="schedulingType" className="block text-sm font-medium text-gray-700">
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("scheduling_type")}
|
2021-09-14 08:45:28 +00:00
|
|
|
</label>
|
|
|
|
<RadioArea.Group
|
|
|
|
name="schedulingType"
|
2021-09-15 12:33:00 +00:00
|
|
|
className="relative flex mt-1 space-x-6 rounded-sm shadow-sm">
|
|
|
|
<RadioArea.Item value={SchedulingType.COLLECTIVE} className="w-1/2 text-sm">
|
2021-10-11 13:42:43 +00:00
|
|
|
<strong className="block mb-1">{t("collective")}</strong>
|
|
|
|
<p>{t("collective_description")}</p>
|
2021-09-14 08:45:28 +00:00
|
|
|
</RadioArea.Item>
|
2021-09-15 12:33:00 +00:00
|
|
|
<RadioArea.Item value={SchedulingType.ROUND_ROBIN} className="w-1/2 text-sm">
|
2021-10-11 13:42:43 +00:00
|
|
|
<strong className="block mb-1">{t("round_robin")}</strong>
|
|
|
|
<p>{t("round_robin_description")}</p>
|
2021-09-14 08:45:28 +00:00
|
|
|
</RadioArea.Item>
|
|
|
|
</RadioArea.Group>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div className="mt-8 sm:flex sm:flex-row-reverse gap-x-2">
|
2021-09-06 13:51:15 +00:00
|
|
|
<Button type="submit" loading={createMutation.isLoading}>
|
2021-10-11 13:42:43 +00:00
|
|
|
{t("continue")}
|
2021-09-06 13:51:15 +00:00
|
|
|
</Button>
|
2021-09-15 12:33:00 +00:00
|
|
|
<DialogClose asChild>
|
2021-10-11 13:42:43 +00:00
|
|
|
<Button color="secondary">{t("cancel")}</Button>
|
2021-09-14 08:45:28 +00:00
|
|
|
</DialogClose>
|
2021-08-03 17:36:55 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</DialogContent>
|
|
|
|
</Dialog>
|
|
|
|
);
|
2021-08-27 12:11:24 +00:00
|
|
|
};
|
|
|
|
|
2021-10-08 13:10:57 +00:00
|
|
|
export async function getServerSideProps(context: GetServerSidePropsContext) {
|
2021-09-14 08:45:28 +00:00
|
|
|
const session = await getSession(context);
|
2021-10-08 11:43:48 +00:00
|
|
|
const locale = await getOrSetUserLocaleFromHeaders(context.req);
|
2021-09-23 08:49:17 +00:00
|
|
|
|
2021-09-15 12:33:00 +00:00
|
|
|
if (!session?.user?.id) {
|
2021-09-14 08:45:28 +00:00
|
|
|
return { redirect: { permanent: false, destination: "/auth/login" } };
|
2021-07-30 23:05:38 +00:00
|
|
|
}
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
/**
|
|
|
|
* This makes the select reusable and type safe.
|
|
|
|
* @url https://www.prisma.io/docs/concepts/components/prisma-client/advanced-type-safety/prisma-validator#using-the-prismavalidator
|
|
|
|
* */
|
|
|
|
const eventTypeSelect = Prisma.validator<Prisma.EventTypeSelect>()({
|
|
|
|
id: true,
|
|
|
|
title: true,
|
|
|
|
description: true,
|
|
|
|
length: true,
|
|
|
|
schedulingType: true,
|
|
|
|
slug: true,
|
|
|
|
hidden: true,
|
|
|
|
price: true,
|
|
|
|
currency: true,
|
|
|
|
users: {
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
avatar: true,
|
|
|
|
name: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-09-06 13:51:15 +00:00
|
|
|
const user = await prisma.user.findUnique({
|
2021-07-30 23:05:38 +00:00
|
|
|
where: {
|
2021-09-06 13:51:15 +00:00
|
|
|
id: session.user.id,
|
2021-07-30 23:05:38 +00:00
|
|
|
},
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
username: true,
|
2021-09-14 08:45:28 +00:00
|
|
|
name: true,
|
2021-07-30 23:05:38 +00:00
|
|
|
startTime: true,
|
|
|
|
endTime: true,
|
|
|
|
bufferTime: true,
|
2021-09-14 08:45:28 +00:00
|
|
|
avatar: true,
|
2021-09-02 12:13:19 +00:00
|
|
|
completedOnboarding: true,
|
|
|
|
createdDate: true,
|
2021-09-06 13:51:15 +00:00
|
|
|
plan: true,
|
2021-09-14 08:45:28 +00:00
|
|
|
teams: {
|
|
|
|
where: {
|
|
|
|
accepted: true,
|
|
|
|
},
|
|
|
|
select: {
|
|
|
|
role: true,
|
|
|
|
team: {
|
|
|
|
select: {
|
|
|
|
id: true,
|
|
|
|
name: true,
|
|
|
|
slug: true,
|
|
|
|
logo: true,
|
|
|
|
members: {
|
|
|
|
select: {
|
|
|
|
userId: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
eventTypes: {
|
2021-09-22 18:36:13 +00:00
|
|
|
select: eventTypeSelect,
|
2021-09-14 08:45:28 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
eventTypes: {
|
|
|
|
where: {
|
|
|
|
team: null,
|
|
|
|
},
|
2021-09-22 18:36:13 +00:00
|
|
|
select: eventTypeSelect,
|
2021-09-14 08:45:28 +00:00
|
|
|
},
|
2021-07-30 23:05:38 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-09-06 13:51:15 +00:00
|
|
|
if (!user) {
|
|
|
|
// this shouldn't happen
|
|
|
|
return {
|
|
|
|
redirect: {
|
|
|
|
permanent: false,
|
|
|
|
destination: "/auth/login",
|
|
|
|
},
|
2021-09-15 12:33:00 +00:00
|
|
|
};
|
2021-09-06 13:51:15 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 13:10:57 +00:00
|
|
|
if (
|
|
|
|
shouldShowOnboarding({ completedOnboarding: user.completedOnboarding, createdDate: user.createdDate })
|
|
|
|
) {
|
|
|
|
return ONBOARDING_NEXT_REDIRECT;
|
2021-09-02 12:13:19 +00:00
|
|
|
}
|
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
// backwards compatibility, TMP:
|
2021-09-06 13:51:15 +00:00
|
|
|
const typesRaw = await prisma.eventType.findMany({
|
2021-07-30 23:05:38 +00:00
|
|
|
where: {
|
2021-09-14 08:45:28 +00:00
|
|
|
userId: session.user.id,
|
2021-07-30 23:05:38 +00:00
|
|
|
},
|
2021-09-22 18:36:13 +00:00
|
|
|
select: eventTypeSelect,
|
2021-09-14 08:45:28 +00:00
|
|
|
});
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
type EventTypeGroup = {
|
2021-09-15 12:33:00 +00:00
|
|
|
teamId?: number | null;
|
|
|
|
profile?: {
|
|
|
|
slug: typeof user["username"];
|
|
|
|
name: typeof user["name"];
|
|
|
|
image: typeof user["avatar"];
|
|
|
|
};
|
|
|
|
metadata: {
|
|
|
|
membershipCount: number;
|
|
|
|
readOnly: boolean;
|
|
|
|
};
|
2021-09-22 18:36:13 +00:00
|
|
|
eventTypes: (typeof user.eventTypes[number] & { $disabled?: boolean })[];
|
|
|
|
};
|
2021-09-15 12:33:00 +00:00
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
let eventTypeGroups: EventTypeGroup[] = [];
|
|
|
|
const eventTypesHashMap = user.eventTypes.concat(typesRaw).reduce((hashMap, newItem) => {
|
|
|
|
const oldItem = hashMap[newItem.id] || {};
|
|
|
|
hashMap[newItem.id] = { ...oldItem, ...newItem };
|
|
|
|
return hashMap;
|
|
|
|
}, {} as Record<number, EventTypeGroup["eventTypes"][number]>);
|
|
|
|
const mergedEventTypes = Object.values(eventTypesHashMap).map((et, index) => ({
|
|
|
|
...et,
|
|
|
|
$disabled: user.plan === "FREE" && index > 0,
|
|
|
|
}));
|
2021-09-15 12:33:00 +00:00
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
eventTypeGroups.push({
|
2021-09-14 08:45:28 +00:00
|
|
|
teamId: null,
|
|
|
|
profile: {
|
|
|
|
slug: user.username,
|
|
|
|
name: user.name,
|
|
|
|
image: user.avatar,
|
2021-07-30 23:05:38 +00:00
|
|
|
},
|
2021-09-22 18:36:13 +00:00
|
|
|
eventTypes: mergedEventTypes,
|
2021-09-15 12:33:00 +00:00
|
|
|
metadata: {
|
|
|
|
membershipCount: 1,
|
|
|
|
readOnly: false,
|
|
|
|
},
|
2021-07-30 23:05:38 +00:00
|
|
|
});
|
2021-08-27 12:11:24 +00:00
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
eventTypeGroups = ([] as EventTypeGroup[]).concat(
|
|
|
|
eventTypeGroups,
|
2021-09-14 08:45:28 +00:00
|
|
|
user.teams.map((membership) => ({
|
|
|
|
teamId: membership.team.id,
|
|
|
|
profile: {
|
|
|
|
name: membership.team.name,
|
|
|
|
image: membership.team.logo || "",
|
|
|
|
slug: "team/" + membership.team.slug,
|
|
|
|
},
|
|
|
|
metadata: {
|
|
|
|
membershipCount: membership.team.members.length,
|
|
|
|
readOnly: membership.role !== "OWNER",
|
|
|
|
},
|
|
|
|
eventTypes: membership.team.eventTypes,
|
|
|
|
}))
|
2021-09-06 13:51:15 +00:00
|
|
|
);
|
|
|
|
|
2021-09-02 12:13:19 +00:00
|
|
|
const userObj = Object.assign({}, user, {
|
|
|
|
createdDate: user.createdDate.toString(),
|
|
|
|
});
|
|
|
|
|
2021-09-22 18:36:13 +00:00
|
|
|
const canAddEvents = user.plan !== "FREE" || eventTypeGroups[0].eventTypes.length < 1;
|
2021-09-06 13:51:15 +00:00
|
|
|
|
2021-07-30 23:05:38 +00:00
|
|
|
return {
|
2021-08-27 12:11:24 +00:00
|
|
|
props: {
|
2021-09-24 10:16:46 +00:00
|
|
|
session,
|
2021-09-23 08:49:17 +00:00
|
|
|
localeProp: locale,
|
2021-09-06 13:51:15 +00:00
|
|
|
canAddEvents,
|
2021-09-14 08:45:28 +00:00
|
|
|
user: userObj,
|
|
|
|
// don't display event teams without event types,
|
2021-09-22 18:36:13 +00:00
|
|
|
eventTypes: eventTypeGroups.filter((groupBy) => !!groupBy.eventTypes?.length),
|
2021-09-14 08:45:28 +00:00
|
|
|
// so we can show a dropdown when the user has teams
|
2021-09-22 18:36:13 +00:00
|
|
|
profiles: eventTypeGroups.map((group) => ({
|
2021-09-14 08:45:28 +00:00
|
|
|
teamId: group.teamId,
|
|
|
|
...group.profile,
|
|
|
|
...group.metadata,
|
|
|
|
})),
|
2021-09-23 08:49:17 +00:00
|
|
|
...(await serverSideTranslations(locale, ["common"])),
|
2021-08-27 12:11:24 +00:00
|
|
|
},
|
2021-07-30 23:05:38 +00:00
|
|
|
};
|
2021-09-14 08:45:28 +00:00
|
|
|
}
|
2021-08-27 12:11:24 +00:00
|
|
|
|
|
|
|
export default EventTypesPage;
|