add free plan (#549)

- add new fields to support this
- when free:
  - fade out all event types after first
  - hide events after first on booking page
  - make booking page after the first one 404 if accessed directly
- add e2e tests
This commit is contained in:
Alex Johansson authored and GitHub committed 2021-09-06 13:51:15 +00:00
1 parent fa35af7bd8
commit 7e6e935ed3
29 files changed
+880 -261

No files matched your search

+68 -54
View File
@@ -1,51 +1,17 @@
import { GetServerSideProps } from "next";
import { HeadSeo } from "@components/seo/head-seo";
import Link from "next/link";
import prisma, { whereAndSelect } from "@lib/prisma";
import Avatar from "@components/Avatar";
import { HeadSeo } from "@components/seo/head-seo";
import Theme from "@components/Theme";
import { ClockIcon, InformationCircleIcon, UserIcon } from "@heroicons/react/solid";
import React from "react";
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";
export default function User(props): User {
export default function User(props: inferSSRProps<typeof getServerSideProps>) {
const { isReady } = Theme(props.user.theme);
const eventTypes = props.eventTypes.map((type) => (
<div
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={`/${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>
</a>
</Link>
</div>
));
return (
<>
<HeadSeo
@@ -68,8 +34,44 @@ export default function User(props): User {
</h1>
<p className="text-neutral-500 dark:text-white">{props.user.bio}</p>
</div>
<div className="space-y-6">{eventTypes}</div>
{eventTypes.length == 0 && (
<div className="space-y-6" data-testid="event-types">
{props.eventTypes.map((type) => (
<div
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={`/${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>
</a>
</Link>
</div>
))}
</div>
{props.eventTypes.length == 0 && (
<div className="shadow overflow-hidden rounded-sm">
<div className="p-8 text-center text-gray-400 dark:text-white">
<h2 className="font-semibold text-3xl text-gray-600 dark:text-white">Uh oh!</h2>
@@ -84,33 +86,45 @@ export default function User(props): User {
);
}
export const getServerSideProps: GetServerSideProps = async (context) => {
const user = await whereAndSelect(
prisma.user.findFirst,
{
username: context.query.user.toLowerCase(),
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const username = (context.query.user as string).toLowerCase();
const user = await prisma.user.findUnique({
where: {
username,
},
["id", "username", "email", "name", "bio", "avatar", "theme"]
);
select: {
id: true,
username: true,
email: true,
name: true,
bio: true,
avatar: true,
theme: true,
plan: true,
},
});
if (!user) {
return {
notFound: true,
};
}
const eventTypes = await prisma.eventType.findMany({
const eventTypesWithHidden = await prisma.eventType.findMany({
where: {
userId: user.id,
hidden: false,
},
select: {
id: true,
slug: true,
title: true,
length: true,
description: true,
hidden: true,
},
take: user.plan === "FREE" ? 1 : undefined,
});
const eventTypes = eventTypesWithHidden.filter((evt) => !evt.hidden);
return {
props: {
user,
+24 -5
View File
@@ -235,6 +235,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
availability: true,
hideBranding: true,
theme: true,
plan: true,
},
});
@@ -243,11 +244,12 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
notFound: true,
} as const;
}
const eventType = await prisma.eventType.findFirst({
const eventType = await prisma.eventType.findUnique({
where: {
userId: user.id,
slug: typeParam,
userId_slug: {
userId: user.id,
slug: typeParam,
},
},
select: {
id: true,
@@ -262,15 +264,32 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
periodEndDate: true,
periodCountCalendarDays: true,
minimumBookingNotice: true,
hidden: true,
},
});
if (!eventType) {
if (!eventType || eventType.hidden) {
return {
notFound: true,
} as const;
}
// check this is the first event
if (user.plan === "FREE") {
const firstEventType = await prisma.eventType.findFirst({
where: {
userId: user.id,
},
select: {
id: true,
},
});
if (firstEventType?.id !== eventType.id) {
return {
notFound: true,
} as const;
}
}
const getWorkingHours = (providesAvailability: { availability: Availability[] }) =>
providesAvailability.availability && providesAvailability.availability.length
? providesAvailability.availability
+45 -32
View File
@@ -1,8 +1,7 @@
import Link from "next/link";
import { useRouter } from "next/router";
import Modal from "@components/Modal";
import React, { useEffect, useRef, useState } from "react";
import Select, { OptionBase } from "react-select";
import Select, { OptionTypeBase } from "react-select";
import prisma from "@lib/prisma";
import { EventTypeCustomInput, EventTypeCustomInputType } from "@prisma/client";
import { LocationType } from "@lib/location";
@@ -25,7 +24,7 @@ import {
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
import { Availability, EventType, User } from "@prisma/client";
import { Availability } from "@prisma/client";
import { validJson } from "@lib/jsonUtils";
import classnames from "classnames";
import throttle from "lodash.throttle";
@@ -42,6 +41,8 @@ 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 { inferSSRProps } from "@lib/types/inferSSRProps";
import { asStringOrThrow } from "@lib/asStringOrNull";
import Button from "@components/ui/Button";
dayjs.extend(utc);
dayjs.extend(timezone);
@@ -66,7 +67,7 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
const router = useRouter();
const [successModalOpen, setSuccessModalOpen] = useState(false);
const inputOptions: OptionBase[] = [
const inputOptions: OptionTypeBase[] = [
{ value: EventTypeCustomInputType.TEXT, label: "Text" },
{ value: EventTypeCustomInputType.TEXTLONG, label: "Multiline Text" },
{ value: EventTypeCustomInputType.NUMBER, label: "Number" },
@@ -130,8 +131,8 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
const [showLocationModal, setShowLocationModal] = useState(false);
const [showAddCustomModal, setShowAddCustomModal] = useState(false);
const [selectedTimeZone, setSelectedTimeZone] = useState("");
const [selectedLocation, setSelectedLocation] = useState<OptionBase | undefined>(undefined);
const [selectedInputOption, setSelectedInputOption] = useState<OptionBase>(inputOptions[0]);
const [selectedLocation, setSelectedLocation] = useState<OptionTypeBase | undefined>(undefined);
const [selectedInputOption, setSelectedInputOption] = useState<OptionTypeBase>(inputOptions[0]);
const [locations, setLocations] = useState(eventType.locations || []);
const [selectedCustomInput, setSelectedCustomInput] = useState<EventTypeCustomInput | undefined>(undefined);
const [customInputs, setCustomInputs] = useState<EventTypeCustomInput[]>(
@@ -162,14 +163,14 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
});
const [hidden, setHidden] = useState<boolean>(eventType.hidden);
const titleRef = useRef<HTMLInputElement>();
const slugRef = useRef<HTMLInputElement>();
const descriptionRef = useRef<HTMLTextAreaElement>();
const lengthRef = useRef<HTMLInputElement>();
const requiresConfirmationRef = useRef<HTMLInputElement>();
const eventNameRef = useRef<HTMLInputElement>();
const periodDaysRef = useRef<HTMLInputElement>();
const periodDaysTypeRef = useRef<HTMLSelectElement>();
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);
@@ -804,17 +805,11 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
</>
)}
</Disclosure>
<div className="flex justify-end mt-4">
<Link href="/event-types">
<a className="inline-flex items-center px-4 py-2 mr-2 text-sm font-medium bg-white border border-transparent rounded-sm shadow-sm text-neutral-700 hover:bg-neutral-100 border-neutral-300 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black">
Cancel
</a>
</Link>
<button
type="submit"
className="inline-flex items-center px-4 py-2 text-sm font-medium text-white border border-transparent rounded-sm shadow-sm bg-neutral-900 hover:bg-neutral-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black">
Update
</button>
<div className="flex justify-end mt-4 space-x-2">
<Button href="/event-types" color="secondary" tabIndex={-1}>
Cancel
</Button>
<Button type="submit">Update</Button>
</div>
</form>
<Modal
@@ -1033,7 +1028,9 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
const { req, query } = context;
const session = await getSession({ req });
if (!session) {
const typeParam = asStringOrThrow(query.type);
if (!session?.user?.id) {
return {
redirect: {
permanent: false,
@@ -1042,22 +1039,38 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
};
}
const user: User = await prisma.user.findFirst({
const user = await prisma.user.findUnique({
where: {
email: session.user.email,
id: session.user.id,
},
select: {
id: true,
username: true,
timeZone: true,
startTime: true,
endTime: true,
availability: true,
plan: true,
},
});
const eventType: EventType | null = await prisma.eventType.findUnique({
if (!user) {
return {
notFound: true,
} as const;
}
const eventType = await prisma.eventType.findFirst({
where: {
id: parseInt(query.type as string),
userId: user.id,
OR: [
{
slug: typeParam,
},
{
id: parseInt(typeParam),
},
],
},
select: {
id: true,
@@ -1116,10 +1129,10 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
},
];
const locationOptions: OptionBase[] = [
const locationOptions: OptionTypeBase[] = [
{ value: LocationType.InPerson, label: "In-person meeting" },
{ value: LocationType.Phone, label: "Phone call" },
{ value: LocationType.Zoom, label: "Zoom Video" },
{ value: LocationType.Zoom, label: "Zoom Video", disabled: true },
];
const hasGoogleCalendarIntegration = integrations.find(
+129 -80
View File
@@ -1,4 +1,4 @@
import { Dialog, DialogClose, DialogContent } from "@components/Dialog";
import { Dialog, DialogContent } from "@components/Dialog";
import Loader from "@components/Loader";
import { Tooltip } from "@components/Tooltip";
import { Button } from "@components/ui/Button";
@@ -21,81 +21,57 @@ import { useRouter } from "next/router";
import React, { Fragment, useRef } from "react";
import Shell from "@components/Shell";
import prisma from "@lib/prisma";
import { GetServerSidePropsContext, InferGetServerSidePropsType } from "next";
import { GetServerSidePropsContext } from "next";
import { useMutation } from "react-query";
import createEventType from "@lib/mutations/event-types/create-event-type";
import { ONBOARDING_INTRODUCED_AT } from "@lib/getting-started";
import { getSession } from "@lib/auth";
import { ONBOARDING_INTRODUCED_AT } from "@lib/getting-started";
import { useToggleQuery } from "@lib/hooks/useToggleQuery";
import { inferSSRProps } from "@lib/types/inferSSRProps";
import { Alert } from "@components/ui/Alert";
const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideProps>) => {
const EventTypesPage = (props: inferSSRProps<typeof getServerSideProps>) => {
const { user, types } = props;
const [session, loading] = useSession();
const router = useRouter();
const createMutation = useMutation(createEventType, {
onSuccess: async ({ eventType }) => {
await router.replace("/event-types/" + eventType.id);
await router.push("/event-types/" + eventType.id);
showToast(`${eventType.title} event type created successfully`, "success");
},
onError: (err: Error) => {
showToast(err.message, "error");
},
});
const modalOpen = useToggleQuery("new");
const titleRef = useRef<HTMLInputElement>();
const slugRef = useRef<HTMLInputElement>();
const descriptionRef = useRef<HTMLTextAreaElement>();
const lengthRef = useRef<HTMLInputElement>();
const dialogOpen = router.query.new === "1";
async function createEventTypeHandler(event) {
event.preventDefault();
const enteredTitle = titleRef.current.value;
const enteredSlug = slugRef.current.value;
const enteredDescription = descriptionRef.current.value;
const enteredLength = parseInt(lengthRef.current.value);
const body = {
title: enteredTitle,
slug: enteredSlug,
description: enteredDescription,
length: enteredLength,
};
createMutation.mutate(body);
}
function autoPopulateSlug() {
let t = titleRef.current.value;
t = t.replace(/\s+/g, "-").toLowerCase();
slugRef.current.value = t;
}
const slugRef = useRef<HTMLInputElement>(null);
if (loading) {
return <Loader />;
}
const CreateNewEventDialog = () => (
const renderEventDialog = () => (
<Dialog
open={dialogOpen}
open={modalOpen.isOn}
onOpenChange={(isOpen) => {
const newQuery = {
...router.query,
};
delete newQuery["new"];
if (!isOpen) {
router.push({ pathname: router.pathname, query: newQuery });
}
router.push(isOpen ? modalOpen.hrefOn : modalOpen.hrefOff);
}}>
<Button
className="mt-2 hidden sm:block"
StartIcon={PlusIcon}
href={{ query: { ...router.query, new: "1" } }}>
data-testid="new-event-type"
{...(props.canAddEvents
? {
href: modalOpen.hrefOn,
}
: {
disabled: true,
})}>
New event type
</Button>
<Button size="fab" className="block sm:hidden" href={{ query: { ...router.query, new: "1" } }}>
<Button size="fab" className="block sm:hidden" href={modalOpen.hrefOn}>
<PlusIcon className="w-8 h-8 text-white" />
</Button>
@@ -108,7 +84,24 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
<p className="text-sm text-gray-500">Create a new event type for people to book times with.</p>
</div>
</div>
<form onSubmit={createEventTypeHandler}>
<form
onSubmit={(e) => {
e.preventDefault();
const target = e.target as unknown as Record<
"title" | "slug" | "description" | "length",
{ value: string }
>;
const body = {
title: target.title.value,
slug: target.slug.value,
description: target.description.value,
length: parseInt(target.length.value),
};
createMutation.mutate(body);
}}>
<div>
<div className="mb-4">
<label htmlFor="title" className="block text-sm font-medium text-gray-700">
@@ -116,8 +109,13 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
</label>
<div className="mt-1">
<input
onChange={autoPopulateSlug}
ref={titleRef}
onChange={(e) => {
if (!slugRef.current) {
return;
}
const slug = e.target.value.replace(/\s+/g, "-").toLowerCase();
slugRef.current.value = slug;
}}
type="text"
name="title"
id="title"
@@ -137,10 +135,10 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
{location.hostname}/{user.username}/
</span>
<input
ref={slugRef}
type="text"
name="slug"
id="slug"
ref={slugRef}
required
className="flex-1 block w-full min-w-0 border-gray-300 rounded-none focus:border-neutral-900 rounded-r-md focus:ring-neutral-900 sm:text-sm"
/>
@@ -153,7 +151,6 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
</label>
<div className="mt-1">
<textarea
ref={descriptionRef}
name="description"
id="description"
className="block w-full border-gray-300 rounded-sm shadow-sm focus:border-neutral-900 focus:ring-neutral-900 sm:text-sm"
@@ -166,7 +163,6 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
</label>
<div className="relative mt-1 rounded-sm shadow-sm">
<input
ref={lengthRef}
type="number"
name="length"
id="length"
@@ -181,12 +177,12 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
</div>
</div>
<div className="mt-8 sm:flex sm:flex-row-reverse">
<button type="submit" className="btn btn-primary">
<Button type="submit" loading={createMutation.isLoading}>
Continue
</button>
<DialogClose as="button" className="mx-2 btn btn-white">
</Button>
<Button href={modalOpen.hrefOff} color="secondary" className="mr-2">
Cancel
</DialogClose>
</Button>
</div>
</form>
</DialogContent>
@@ -198,19 +194,41 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
<Shell
heading="Event Types"
subtitle="Create events to share for people to book on your calendar."
CTA={types.length !== 0 && <CreateNewEventDialog />}>
CTA={types.length !== 0 && renderEventDialog()}>
{props.user.plan === "FREE" && (
<Alert
severity="warning"
title={<>You need to upgrade your plan to have more than one active event type.</>}
message={
<>
To upgrade go to{" "}
<a href="https://calendso.com/upgrade" className="underline">
calendso.com/upgrade
</a>
</>
}
className="my-4"
/>
)}
<div className="-mx-4 overflow-hidden bg-white border border-gray-200 rounded-sm sm:mx-0">
<ul className="divide-y divide-neutral-200">
{types.map((type) => (
<li key={type.id}>
<div className="hover:bg-neutral-50">
<div className="flex items-center px-4 py-4 sm:px-6">
<Link href={"/event-types/" + type.id}>
<a className="flex-1 min-w-0 sm:flex sm:items-center sm:justify-between">
<ul className="divide-y divide-neutral-200" data-testid="event-types">
{types.map((item) => (
<li
key={item.id}
className={classNames(
item.$disabled && "opacity-30 cursor-not-allowed pointer-events-none select-none"
)}
data-disabled={item.$disabled ? 1 : 0}>
<div
className={classNames("hover:bg-neutral-50", item.$disabled && "pointer-events-none")}
tabIndex={item.$disabled ? -1 : undefined}>
<div className={"flex items-center px-4 py-4 sm:px-6"}>
<Link href={"/event-types/" + item.id}>
<a className="flex-1 min-w-0 sm:flex sm:items-center sm:justify-between hover:bg-neutral-50">
<span className="truncate">
<div className="flex text-sm">
<p className="font-medium truncate text-neutral-900">{type.title}</p>
{type.hidden && (
<p className="font-medium truncate text-neutral-900">{item.title}</p>
{item.hidden && (
<span className="inline-flex items-center ml-2 px-1.5 py-0.5 text-yellow-800 text-xs font-medium bg-yellow-100 rounded-sm">
Hidden
</span>
@@ -222,7 +240,7 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
className="flex-shrink-0 mr-1.5 w-4 h-4 text-neutral-400"
aria-hidden="true"
/>
<p>{type.length}m</p>
<p>{item.length}m</p>
</div>
<div className="flex items-center text-sm text-neutral-500">
<UserIcon
@@ -231,14 +249,14 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
/>
<p>1-on-1</p>
</div>
{type.description && (
{item.description && (
<div className="flex items-center text-sm text-neutral-500">
<InformationCircleIcon
className="flex-shrink-0 mr-1.5 w-4 h-4 text-neutral-400"
aria-hidden="true"
/>
<div className="truncate max-w-32 sm:max-w-full">
{type.description.substring(0, 100)}
{item.description.substring(0, 100)}
</div>
</div>
)}
@@ -251,7 +269,7 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
<div className="flex space-x-5 overflow-hidden">
<Tooltip content="Preview">
<a
href={"/" + session.user.username + "/" + type.slug}
href={"/" + session.user.username + "/" + item.slug}
target="_blank"
rel="noreferrer"
className="p-2 border border-transparent cursor-pointer group text-neutral-400 hover:border-gray-200">
@@ -264,7 +282,7 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
onClick={() => {
showToast("Link copied!", "success");
navigator.clipboard.writeText(
window.location.hostname + "/" + session.user.username + "/" + type.slug
window.location.hostname + "/" + session.user.username + "/" + item.slug
);
}}
className="p-2 border border-transparent group text-neutral-400 hover:border-gray-200">
@@ -300,7 +318,7 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
<Menu.Item>
{({ active }) => (
<a
href={"/" + session.user.username + "/" + type.slug}
href={"/" + session.user.username + "/" + item.slug}
target="_blank"
rel="noreferrer"
className={classNames(
@@ -325,7 +343,7 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
"/" +
session.user.username +
"/" +
type.slug
item.slug
);
}}
className={classNames(
@@ -633,7 +651,7 @@ const EventTypesPage = (props: InferGetServerSidePropsType<typeof getServerSideP
Event types enable you to share links that show available times on your calendar and allow
people to make bookings with you.
</p>
<CreateNewEventDialog />
{renderEventDialog()}
</div>
</div>
)}
@@ -646,13 +664,18 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
const { req } = context;
const session = await getSession({ req });
if (!session) {
return { redirect: { permanent: false, destination: "/auth/login" } };
if (!session?.user?.id) {
return {
redirect: {
permanent: false,
destination: "/auth/login",
},
} as const;
}
const user = await prisma.user.findFirst({
const user = await prisma.user.findUnique({
where: {
email: session.user.email,
id: session.user.id,
},
select: {
id: true,
@@ -662,19 +685,30 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
bufferTime: true,
completedOnboarding: true,
createdDate: true,
plan: true,
},
});
if (!user) {
// this shouldn't happen
return {
redirect: {
permanent: false,
destination: "/auth/login",
},
} as const;
}
if (!user.completedOnboarding && dayjs(user.createdDate).isAfter(ONBOARDING_INTRODUCED_AT)) {
return {
redirect: {
permanent: false,
destination: "/getting-started",
},
};
} as const;
}
const types = await prisma.eventType.findMany({
const typesRaw = await prisma.eventType.findMany({
where: {
userId: user.id,
},
@@ -688,14 +722,29 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>
},
});
const types = typesRaw.map((type, index) =>
user.plan === "FREE" && index > 0
? {
...type,
$disabled: true,
}
: {
...type,
$disabled: false,
}
);
const userObj = Object.assign({}, user, {
createdDate: user.createdDate.toString(),
});
const canAddEvents = user.plan !== "FREE" || types.length < 1;
return {
props: {
user: userObj,
types,
canAddEvents,
},
};
};
+54
View File
@@ -0,0 +1,54 @@
import { Alert, AlertProps } from "@components/ui/Alert";
import Head from "next/head";
import React from "react";
export default function AlertPage() {
const list: AlertProps[] = [
{ title: "Something went wrong", severity: "error" },
{ title: "Something went kinda wrong", severity: "warning" },
{ title: "Something went great", severity: "success" },
{ title: "Something went wrong", severity: "error", message: "Some extra context" },
{
title: "Something went wrong",
severity: "error",
message: (
<p>
Some extra context
<br />
hey
</p>
),
},
];
return (
<>
<Head>
<meta name="googlebot" content="noindex" />
</Head>
<div className="p-4 bg-gray-200">
<h1>Alert component</h1>
<div className="flex flex-col">
{list.map((props, index) => (
<div key={index} className="p-2 m-2 bg-white">
<h3>
<code>
{JSON.stringify(
props,
(key, value) => {
if (key.includes("message")) {
return "..";
}
return value;
},
2
)}
</code>
</h3>
<Alert {...props}>Alert text</Alert>
</div>
))}
</div>
</div>
</>
);
}