From 521be467a42c3979c14286067dd583cfb9b762c9 Mon Sep 17 00:00:00 2001 From: Heaust Azure <54670936+Heaust-ops@users.noreply.github.com> Date: Wed, 6 Oct 2021 04:23:24 +0530 Subject: [PATCH] resolved typescript problems for success.tsx, useTheme.tsx and event.ts (#786) * resolved typescript problems for success.tsx, useTheme.tsx and event.ts * remove NextRouter inferred type Co-authored-by: Alex Johansson * remove router query inferred type Co-authored-by: Alex Johansson * URIcomponent change ternary Co-authored-by: Alex Johansson * infer types for event type * completed requested changes * Update pages/success.tsx | change context type to proper Co-authored-by: Alex Johansson Co-authored-by: Peer Richelsen Co-authored-by: Alex Johansson Co-authored-by: Alex van Andel Co-authored-by: Bailey Pumfleet --- lib/event.ts | 7 ++++- lib/hooks/useTheme.tsx | 2 ++ pages/success.tsx | 63 +++++++++++++++++++++--------------------- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/lib/event.ts b/lib/event.ts index 30cb201c..82b969d2 100644 --- a/lib/event.ts +++ b/lib/event.ts @@ -1,3 +1,8 @@ -export function getEventName(name: string, eventTitle: string, eventNameTemplate?: string) { +export function getEventName( + name: string | string[] | undefined, + eventTitle: string, + eventNameTemplate: string | null +) { + if (!name || !(typeof name === "string")) name = ""; // If name is not set or is not of proper type return eventNameTemplate ? eventNameTemplate.replace("{USER}", name) : eventTitle + " with " + name; } diff --git a/lib/hooks/useTheme.tsx b/lib/hooks/useTheme.tsx index 99ad205e..bbea7805 100644 --- a/lib/hooks/useTheme.tsx +++ b/lib/hooks/useTheme.tsx @@ -11,6 +11,8 @@ export default function useTheme(theme?: Maybe) { } if (!theme && window.matchMedia("(prefers-color-scheme: dark)").matches) { document.documentElement.classList.add("dark"); + } else if (!theme) { + /** Uncovered case */ } else { document.documentElement.classList.add(theme); } diff --git a/pages/success.tsx b/pages/success.tsx index 6a87e2e8..b708b237 100644 --- a/pages/success.tsx +++ b/pages/success.tsx @@ -1,6 +1,5 @@ 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"; @@ -40,7 +39,7 @@ export default function Success(props: inferSSRProps) const eventName = getEventName(name, props.eventType.title, props.eventType.eventName); function eventLink(): string { - const optional = {}; + const optional: { location?: string | string[] } = {}; if (location) { optional["location"] = location; } @@ -53,7 +52,8 @@ export default function Success(props: inferSSRProps) .map((v, i) => (i === 1 ? v + 1 : v)), startInputType: "utc", title: eventName, - description: props.eventType.description, + description: props.eventType.description ? props.eventType.description : undefined, + /** formatted to required type of description ^ */ duration: { minutes: props.eventType.length }, ...optional, }); @@ -62,38 +62,38 @@ export default function Success(props: inferSSRProps) throw event.error; } - return encodeURIComponent(event.value); + return encodeURIComponent(event.value ? event.value : false); } const needsConfirmation = props.eventType.requiresConfirmation && reschedule != "true"; return ( (isReady && ( -
+
-
-
-
-