From 252a329f09883fa74f8a7fd74cc1d086bccab5a8 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Sat, 14 Aug 2021 17:03:50 +0000 Subject: [PATCH] Fixed issues relating to custom-inputs * Don't duplicate custom input when editing before db persist * Remove correct custom input during delete pre db persist (id undefined) * Moved typings to prisma, keeping backwards compatibility with @map * Updated all usages of the enum --- lib/eventTypeInput.ts | 13 ------------ pages/[user]/book.tsx | 14 ++++++------- pages/event-types/[type].tsx | 39 ++++++++++++++---------------------- prisma/schema.prisma | 9 ++++++++- 4 files changed, 30 insertions(+), 45 deletions(-) delete mode 100644 lib/eventTypeInput.ts diff --git a/lib/eventTypeInput.ts b/lib/eventTypeInput.ts deleted file mode 100644 index e8c76e42..00000000 --- a/lib/eventTypeInput.ts +++ /dev/null @@ -1,13 +0,0 @@ -export enum EventTypeCustomInputType { - Text = 'text', - TextLong = 'textLong', - Number = 'number', - Bool = 'bool', -} - -export interface EventTypeCustomInput { - id?: number; - type: EventTypeCustomInputType; - label: string; - required: boolean; -} diff --git a/pages/[user]/book.tsx b/pages/[user]/book.tsx index 74e2c785..92a27ef9 100644 --- a/pages/[user]/book.tsx +++ b/pages/[user]/book.tsx @@ -3,6 +3,7 @@ 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 dayjs from "dayjs"; @@ -13,7 +14,6 @@ import PhoneInput from "react-phone-number-input"; import { LocationType } from "../../lib/location"; import Avatar from "../../components/Avatar"; import Button from "../../components/ui/Button"; -import { EventTypeCustomInputType } from "../../lib/eventTypeInput"; import Theme from "@components/Theme"; import { ReactMultiEmail } from "react-multi-email"; import "react-multi-email/style.css"; @@ -71,7 +71,7 @@ export default function Book(props: any): JSX.Element { .map((input) => { const data = event.target["custom_" + input.id]; if (data) { - if (input.type === EventTypeCustomInputType.Bool) { + if (input.type === EventTypeCustomInputType.BOOL) { return input.label + "\n" + (data.checked ? "Yes" : "No"); } else { return input.label + "\n" + data.value; @@ -273,14 +273,14 @@ export default function Book(props: any): JSX.Element { .sort((a, b) => a.id - b.id) .map((input) => (
- {input.type !== EventTypeCustomInputType.Bool && ( + {input.type !== EventTypeCustomInputType.BOOL && ( )} - {input.type === EventTypeCustomInputType.TextLong && ( + {input.type === EventTypeCustomInputType.TEXTLONG && (