import { CheckIcon } from "@heroicons/react/outline"; import { ClockIcon } from "@heroicons/react/solid"; import { EventType } from "@prisma/client"; import dayjs from "dayjs"; import timezone from "dayjs/plugin/timezone"; import toArray from "dayjs/plugin/toArray"; import utc from "dayjs/plugin/utc"; import { createEvent } from "ics"; import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import { asStringOrNull } from "@lib/asStringOrNull"; import { getEventName } from "@lib/event"; import useTheme from "@lib/hooks/useTheme"; import { isBrandingHidden } from "@lib/isBrandingHidden"; import prisma from "@lib/prisma"; import { inferSSRProps } from "@lib/types/inferSSRProps"; import { HeadSeo } from "@components/seo/head-seo"; import Button from "@components/ui/Button"; dayjs.extend(utc); dayjs.extend(toArray); dayjs.extend(timezone); export default function Success(props: inferSSRProps) { const router = useRouter(); const { location, name, reschedule } = router.query; const [is24h, setIs24h] = useState(false); 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())); setIs24h(!!localStorage.getItem("timeOption.is24hClock")); }, []); const eventName = getEventName(name, props.eventType.title, props.eventType.eventName); function eventLink(): string { const optional = {}; if (location) { optional["location"] = location; } const event = createEvent({ start: date .utc() .toArray() .slice(0, 6) .map((v, i) => (i === 1 ? v + 1 : v)), startInputType: "utc", title: eventName, description: props.eventType.description, duration: { minutes: props.eventType.length }, ...optional, }); if (event.error) { throw event.error; } return encodeURIComponent(event.value); } const needsConfirmation = props.eventType.requiresConfirmation && reschedule != "true"; return ( (isReady && (
)) || null ); } export async function getServerSideProps(context) { const typeId = parseInt(asStringOrNull(context.query.type) ?? ""); if (isNaN(typeId)) { return { notFound: true, }; } const eventType: EventType = await prisma.eventType.findUnique({ where: { id: typeId, }, select: { id: true, title: true, description: true, 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: { hideBranding: eventType.team ? eventType.team.hideBranding : isBrandingHidden(eventType.users[0]), profile, eventType, }, }; }