From 4d7427ad914fd780fa64367484f58e020f6d99c0 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Sun, 11 Jul 2021 19:35:56 +0000 Subject: [PATCH] Fixes some linting + codacy issues --- components/Theme.tsx | 14 +- pages/[user].tsx | 65 +++--- pages/[user]/[type].tsx | 204 ++++++++--------- pages/[user]/book.tsx | 442 ++++++++++++++++++------------------- pages/api/user/profile.ts | 31 +-- pages/settings/profile.tsx | 46 ++-- pages/success.tsx | 317 +++++++++++++------------- 7 files changed, 563 insertions(+), 556 deletions(-) diff --git a/components/Theme.tsx b/components/Theme.tsx index 78350999..2c0dc1ca 100644 --- a/components/Theme.tsx +++ b/components/Theme.tsx @@ -1,8 +1,8 @@ -import {useEffect, useState} from "react"; +import { useEffect, useState } from "react"; -const Theme = (theme?: string) => { +export default function Theme(theme?: string) { const [isReady, setIsReady] = useState(false); - useEffect( () => { + useEffect(() => { if (!theme && window.matchMedia("(prefers-color-scheme: dark)").matches) { document.documentElement.classList.add("dark"); } else { @@ -12,8 +12,6 @@ const Theme = (theme?: string) => { }, []); return { - isReady - } -}; - -export default Theme; + isReady, + }; +} diff --git a/pages/[user].tsx b/pages/[user].tsx index 960e90a0..71c311ce 100644 --- a/pages/[user].tsx +++ b/pages/[user].tsx @@ -1,12 +1,11 @@ import { GetServerSideProps } from "next"; import Head from "next/head"; import Link from "next/link"; -import prisma, {whereAndSelect} from "@lib/prisma"; +import prisma, { whereAndSelect } from "@lib/prisma"; import Avatar from "../components/Avatar"; import Theme from "@components/Theme"; export default function User(props): User { - const { isReady } = Theme(props.user.theme); const eventTypes = props.eventTypes.map((type) => ( @@ -24,42 +23,44 @@ export default function User(props): User { )); - return isReady && ( -
- - {props.user.name || props.user.username} | Calendso - - + return ( + isReady && ( +
+ + {props.user.name || props.user.username} | Calendso + + -
-
- -

- {props.user.name || props.user.username} -

-

{props.user.bio}

-
-
-
    {eventTypes}
- {eventTypes.length == 0 && ( -
-

Uh oh!

-

This user hasn't set up any event types yet.

-
- )} -
-
-
+
+
+ +

+ {props.user.name || props.user.username} +

+

{props.user.bio}

+
+
+
    {eventTypes}
+ {eventTypes.length == 0 && ( +
+

Uh oh!

+

This user hasn't set up any event types yet.

+
+ )} +
+
+
+ ) ); } export const getServerSideProps: GetServerSideProps = async (context) => { - - const user = await whereAndSelect(prisma.user.findFirst, { + const user = await whereAndSelect( + prisma.user.findFirst, + { username: context.query.user.toLowerCase(), - }, [ - "id", "username", "email", "name", "bio", "avatar", "eventTypes", "theme" - ] + }, + ["id", "username", "email", "name", "bio", "avatar", "eventTypes", "theme"] ); if (!user) { return { diff --git a/pages/[user]/[type].tsx b/pages/[user]/[type].tsx index d8ba07bf..ed5262aa 100644 --- a/pages/[user]/[type].tsx +++ b/pages/[user]/[type].tsx @@ -47,113 +47,115 @@ export default function Type(props): Type { setTimeFormat(is24hClock ? "HH:mm" : "h:mma"); }; - return isReady && ( -
- - - {rescheduleUid && "Reschedule"} {props.eventType.title} | {props.user.name || props.user.username} | - Calendso - - - + return ( + isReady && ( +
+ + + {rescheduleUid && "Reschedule"} {props.eventType.title} | {props.user.name || props.user.username}{" "} + | Calendso + + + - - - - - " + props.eventType.description - ).replace(/'/g, "%27") + - ".png?md=1&images=https%3A%2F%2Fcalendso.com%2Fcalendso-logo-white.svg&images=" + - encodeURIComponent(props.user.avatar) - } - /> + + + + + " + props.eventType.description + ).replace(/'/g, "%27") + + ".png?md=1&images=https%3A%2F%2Fcalendso.com%2Fcalendso-logo-white.svg&images=" + + encodeURIComponent(props.user.avatar) + } + /> - - - - - " + props.eventType.description - ).replace(/'/g, "%27") + - ".png?md=1&images=https%3A%2F%2Fcalendso.com%2Fcalendso-logo-white.svg&images=" + - encodeURIComponent(props.user.avatar) - } - /> - -
-
-
-
- -

{props.user.name}

-

- {props.eventType.title} -

-

- - {props.eventType.length} minutes -

- - {isTimeOptionsOpen && ( - + + + + " + props.eventType.description + ).replace(/'/g, "%27") + + ".png?md=1&images=https%3A%2F%2Fcalendso.com%2Fcalendso-logo-white.svg&images=" + + encodeURIComponent(props.user.avatar) + } + /> + +
+
+
+
+ +

{props.user.name}

+

+ {props.eventType.title} +

+

+ + {props.eventType.length} minutes +

+ + {isTimeOptionsOpen && ( + + )} +

{props.eventType.description}

+
+ + {selectedDate && ( + )} -

{props.eventType.description}

- - {selectedDate && ( - - )}
-
- {!props.user.hideBranding && } -
-
+ {!props.user.hideBranding && } + +
+ ) ); } diff --git a/pages/[user]/book.tsx b/pages/[user]/book.tsx index fe305e2c..c03b86da 100644 --- a/pages/[user]/book.tsx +++ b/pages/[user]/book.tsx @@ -2,7 +2,7 @@ import Head from "next/head"; 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 prisma, { whereAndSelect } from "../../lib/prisma"; import { collectPageParameters, telemetryEventTypes, useTelemetry } from "../../lib/telemetry"; import { useEffect, useState } from "react"; import dayjs from "dayjs"; @@ -141,247 +141,247 @@ export default function Book(props: any): JSX.Element { book(); }; - return isReady && ( -
- - - {rescheduleUid ? "Reschedule" : "Confirm"} your {props.eventType.title} with{" "} - {props.user.name || props.user.username} | Calendso - - - + return ( + isReady && ( +
+ + + {rescheduleUid ? "Reschedule" : "Confirm"} your {props.eventType.title} with{" "} + {props.user.name || props.user.username} | Calendso + + + -
-
-
-
- -

{props.user.name}

-

- {props.eventType.title} -

-

- - {props.eventType.length} minutes -

- {selectedLocation === LocationType.InPerson && ( +
+
+
+
+ +

{props.user.name}

+

+ {props.eventType.title} +

- - {locationInfo(selectedLocation).address} + + {props.eventType.length} minutes

- )} -

- - {preferredTimeZone && - dayjs(date) - .tz(preferredTimeZone) - .format((is24h ? "H:mm" : "h:mma") + ", dddd DD MMMM YYYY")} -

-

{props.eventType.description}

-
-
-
-
- -
- -
-
-
- -
- -
-
- {locations.length > 1 && ( -
- Location - {locations.map((location) => ( - - ))} -
+ {selectedLocation === LocationType.InPerson && ( +

+ + {locationInfo(selectedLocation).address} +

)} - {selectedLocation === LocationType.Phone && ( +

+ + {preferredTimeZone && + dayjs(date) + .tz(preferredTimeZone) + .format((is24h ? "H:mm" : "h:mma") + ", dddd DD MMMM YYYY")} +

+

{props.eventType.description}

+
+
+
-
- )} - {props.eventType.customInputs && - props.eventType.customInputs - .sort((a, b) => a.id - b.id) - .map((input) => ( -
- {input.type !== EventTypeCustomInputType.Bool && ( - - )} - {input.type === EventTypeCustomInputType.TextLong && ( - + className="shadow-sm focus:ring-blue-500 focus:border-blue-500 mt-1 block w-full sm:text-sm border-gray-300 rounded-md">
@@ -166,9 +167,10 @@ export default function Settings(props) { onChange={setSelectedWeekStartDay} className="shadow-sm focus:ring-blue-500 focus:border-blue-500 mt-1 block w-full sm:text-sm border-gray-300 rounded-md" options={[ - { value:'Sunday', label:'Sunday' }, - { value:'Monday', label:'Monday' } - ]} /> + { value: "Sunday", label: "Sunday" }, + { value: "Monday", label: "Monday" }, + ]} + />
@@ -182,7 +184,8 @@ export default function Settings(props) { defaultValue={selectedTheme || themeOptions[0]} onChange={setSelectedTheme} className="shadow-sm focus:ring-blue-500 focus:border-blue-500 mt-1 block w-full sm:text-sm border-gray-300 rounded-md" - options={themeOptions} /> + options={themeOptions} + />
@@ -302,20 +305,13 @@ export const getServerSideProps: GetServerSideProps = async (context) => { return { redirect: { permanent: false, destination: "/auth/login" } }; } - const user = await whereAndSelect(prisma.user.findFirst, { + const user = await whereAndSelect( + prisma.user.findFirst, + { id: session.user.id, - }, [ - "id", - "username", - "name", - "email", - "bio", - "avatar", - "timeZone", - "weekStart", - "hideBranding", - "theme" - ]); + }, + ["id", "username", "name", "email", "bio", "avatar", "timeZone", "weekStart", "hideBranding", "theme"] + ); return { props: { user }, // will be passed to the page component as props diff --git a/pages/success.tsx b/pages/success.tsx index 20d9e7c3..9b08377e 100644 --- a/pages/success.tsx +++ b/pages/success.tsx @@ -1,6 +1,6 @@ import Head from "next/head"; import Link from "next/link"; -import prisma, {whereAndSelect} from "../lib/prisma"; +import prisma, { whereAndSelect } from "../lib/prisma"; import { useEffect, useState } from "react"; import { useRouter } from "next/router"; import { CheckIcon } from "@heroicons/react/outline"; @@ -33,7 +33,7 @@ export default function Success(props) { const eventName = getEventName(name, props.eventType.title, props.eventType.eventName); function eventLink(): string { - let optional = {}; + const optional = {}; if (location) { optional["location"] = location; } @@ -58,169 +58,173 @@ export default function Success(props) { return encodeURIComponent(event.value); } - return isReady && ( -
- - Booking Confirmed | {eventName} | Calendso - - -
-
-
-
+
+ ) ); } export async function getServerSideProps(context) { - - const user = (context.query.user) ? await whereAndSelect(prisma.user.findFirst, { - username: context.query.user, - }, [ - "username", "name", "bio", "avatar", "eventTypes", "hideBranding", "theme" - ] - ) : null; + const user = context.query.user + ? await whereAndSelect( + prisma.user.findFirst, + { + username: context.query.user, + }, + ["username", "name", "bio", "avatar", "eventTypes", "hideBranding", "theme"] + ) + : null; if (!user) { return { @@ -228,11 +232,12 @@ export async function getServerSideProps(context) { }; } - const eventType = await whereAndSelect(prisma.eventType.findUnique, { + const eventType = await whereAndSelect( + prisma.eventType.findUnique, + { id: parseInt(context.query.type), - }, [ - "id", "title", "description", "length", "eventName" - ] + }, + ["id", "title", "description", "length", "eventName"] ); return {