Fixes some linting + codacy issues
This commit is contained in:
parent
5206fb4f88
commit
4d7427ad91
7 changed files with 563 additions and 556 deletions
|
@ -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);
|
const [isReady, setIsReady] = useState(false);
|
||||||
useEffect( () => {
|
useEffect(() => {
|
||||||
if (!theme && window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
if (!theme && window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||||
document.documentElement.classList.add("dark");
|
document.documentElement.classList.add("dark");
|
||||||
} else {
|
} else {
|
||||||
|
@ -12,8 +12,6 @@ const Theme = (theme?: string) => {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isReady
|
isReady,
|
||||||
}
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
export default Theme;
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import { GetServerSideProps } from "next";
|
import { GetServerSideProps } from "next";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import prisma, {whereAndSelect} from "@lib/prisma";
|
import prisma, { whereAndSelect } from "@lib/prisma";
|
||||||
import Avatar from "../components/Avatar";
|
import Avatar from "../components/Avatar";
|
||||||
import Theme from "@components/Theme";
|
import Theme from "@components/Theme";
|
||||||
|
|
||||||
export default function User(props): User {
|
export default function User(props): User {
|
||||||
|
|
||||||
const { isReady } = Theme(props.user.theme);
|
const { isReady } = Theme(props.user.theme);
|
||||||
|
|
||||||
const eventTypes = props.eventTypes.map((type) => (
|
const eventTypes = props.eventTypes.map((type) => (
|
||||||
|
@ -24,7 +23,8 @@ export default function User(props): User {
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
));
|
));
|
||||||
return isReady && (
|
return (
|
||||||
|
isReady && (
|
||||||
<div>
|
<div>
|
||||||
<Head>
|
<Head>
|
||||||
<title>{props.user.name || props.user.username} | Calendso</title>
|
<title>{props.user.name || props.user.username} | Calendso</title>
|
||||||
|
@ -50,16 +50,17 @@ export default function User(props): User {
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getServerSideProps: GetServerSideProps = async (context) => {
|
export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
|
const user = await whereAndSelect(
|
||||||
const user = await whereAndSelect(prisma.user.findFirst, {
|
prisma.user.findFirst,
|
||||||
|
{
|
||||||
username: context.query.user.toLowerCase(),
|
username: context.query.user.toLowerCase(),
|
||||||
}, [
|
},
|
||||||
"id", "username", "email", "name", "bio", "avatar", "eventTypes", "theme"
|
["id", "username", "email", "name", "bio", "avatar", "eventTypes", "theme"]
|
||||||
]
|
|
||||||
);
|
);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -47,12 +47,13 @@ export default function Type(props): Type {
|
||||||
setTimeFormat(is24hClock ? "HH:mm" : "h:mma");
|
setTimeFormat(is24hClock ? "HH:mm" : "h:mma");
|
||||||
};
|
};
|
||||||
|
|
||||||
return isReady && (
|
return (
|
||||||
|
isReady && (
|
||||||
<div>
|
<div>
|
||||||
<Head>
|
<Head>
|
||||||
<title>
|
<title>
|
||||||
{rescheduleUid && "Reschedule"} {props.eventType.title} | {props.user.name || props.user.username} |
|
{rescheduleUid && "Reschedule"} {props.eventType.title} | {props.user.name || props.user.username}{" "}
|
||||||
Calendso
|
| Calendso
|
||||||
</title>
|
</title>
|
||||||
<meta name="title" content={"Meet " + (props.user.name || props.user.username) + " via Calendso"} />
|
<meta name="title" content={"Meet " + (props.user.name || props.user.username) + " via Calendso"} />
|
||||||
<meta name="description" content={props.eventType.description} />
|
<meta name="description" content={props.eventType.description} />
|
||||||
|
@ -154,6 +155,7 @@ export default function Type(props): Type {
|
||||||
{!props.user.hideBranding && <PoweredByCalendso />}
|
{!props.user.hideBranding && <PoweredByCalendso />}
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Head from "next/head";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { CalendarIcon, ClockIcon, ExclamationIcon, LocationMarkerIcon } from "@heroicons/react/solid";
|
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 { collectPageParameters, telemetryEventTypes, useTelemetry } from "../../lib/telemetry";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
@ -141,7 +141,8 @@ export default function Book(props: any): JSX.Element {
|
||||||
book();
|
book();
|
||||||
};
|
};
|
||||||
|
|
||||||
return isReady && (
|
return (
|
||||||
|
isReady && (
|
||||||
<div>
|
<div>
|
||||||
<Head>
|
<Head>
|
||||||
<title>
|
<title>
|
||||||
|
@ -198,7 +199,9 @@ export default function Book(props: any): JSX.Element {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<label htmlFor="email" className="block text-sm font-medium dark:text-white text-gray-700">
|
<label
|
||||||
|
htmlFor="email"
|
||||||
|
className="block text-sm font-medium dark:text-white text-gray-700">
|
||||||
Email address
|
Email address
|
||||||
</label>
|
</label>
|
||||||
<div className="mt-1">
|
<div className="mt-1">
|
||||||
|
@ -304,7 +307,9 @@ export default function Book(props: any): JSX.Element {
|
||||||
className="focus:ring-blue-500 h-4 w-4 text-blue-600 border-gray-300 rounded mr-2"
|
className="focus:ring-blue-500 h-4 w-4 text-blue-600 border-gray-300 rounded mr-2"
|
||||||
placeholder=""
|
placeholder=""
|
||||||
/>
|
/>
|
||||||
<label htmlFor={input.label} className="block text-sm font-medium text-gray-700">
|
<label
|
||||||
|
htmlFor={input.label}
|
||||||
|
className="block text-sm font-medium text-gray-700">
|
||||||
{input.label}
|
{input.label}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -366,22 +371,17 @@ export default function Book(props: any): JSX.Element {
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getServerSideProps(context) {
|
export async function getServerSideProps(context) {
|
||||||
|
const user = await whereAndSelect(
|
||||||
const user = await whereAndSelect(prisma.user.findFirst, {
|
prisma.user.findFirst,
|
||||||
|
{
|
||||||
username: context.query.user,
|
username: context.query.user,
|
||||||
}, [
|
},
|
||||||
"username",
|
["username", "name", "email", "bio", "avatar", "eventTypes", "theme"]
|
||||||
"name",
|
|
||||||
"email",
|
|
||||||
"bio",
|
|
||||||
"avatar",
|
|
||||||
"eventTypes",
|
|
||||||
"theme",
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const eventType = await prisma.eventType.findUnique({
|
const eventType = await prisma.eventType.findUnique({
|
||||||
|
|
|
@ -1,23 +1,28 @@
|
||||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import { getSession } from 'next-auth/client';
|
import { getSession } from "next-auth/client";
|
||||||
import prisma, {whereAndSelect} from '@lib/prisma';
|
import prisma, { whereAndSelect } from "@lib/prisma";
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const session = await getSession({req: req});
|
const session = await getSession({ req: req });
|
||||||
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
res.status(401).json({message: "Not authenticated"});
|
res.status(401).json({ message: "Not authenticated" });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get user
|
// Get user
|
||||||
const user = await whereAndSelect(prisma.user.findUnique, {
|
const user = await whereAndSelect(
|
||||||
|
prisma.user.findUnique,
|
||||||
|
{
|
||||||
id: session.user.id,
|
id: session.user.id,
|
||||||
},
|
},
|
||||||
[ "id", "password" ]
|
["id", "password"]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!user) { res.status(404).json({message: 'User not found'}); return; }
|
if (!user) {
|
||||||
|
res.status(404).json({ message: "User not found" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const username = req.body.username;
|
const username = req.body.username;
|
||||||
// username is changed: username is optional but it is necessary to be unique, enforce here
|
// username is changed: username is optional but it is necessary to be unique, enforce here
|
||||||
|
@ -25,10 +30,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
const userConflict = await prisma.user.findFirst({
|
const userConflict = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
username,
|
username,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
if (userConflict) {
|
if (userConflict) {
|
||||||
return res.status(409).json({ message: 'Username already taken' });
|
return res.status(409).json({ message: "Username already taken" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +45,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
const hideBranding = req.body.hideBranding;
|
const hideBranding = req.body.hideBranding;
|
||||||
const theme = req.body.theme;
|
const theme = req.body.theme;
|
||||||
|
|
||||||
const updateUser = await prisma.user.update({
|
await prisma.user.update({
|
||||||
where: {
|
where: {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
},
|
},
|
||||||
|
@ -56,5 +61,5 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return res.status(200).json({message: 'Profile updated successfully'});
|
return res.status(200).json({ message: "Profile updated successfully" });
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { GetServerSideProps } from "next";
|
import { GetServerSideProps } from "next";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import {useEffect, useRef, useState} from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import prisma, {whereAndSelect} from "@lib/prisma";
|
import prisma, { whereAndSelect } from "@lib/prisma";
|
||||||
import Modal from "../../components/Modal";
|
import Modal from "../../components/Modal";
|
||||||
import Shell from "../../components/Shell";
|
import Shell from "../../components/Shell";
|
||||||
import SettingsShell from "../../components/Settings";
|
import SettingsShell from "../../components/Settings";
|
||||||
|
@ -27,12 +27,14 @@ export default function Settings(props) {
|
||||||
const [errorMessage, setErrorMessage] = useState("");
|
const [errorMessage, setErrorMessage] = useState("");
|
||||||
|
|
||||||
const themeOptions = [
|
const themeOptions = [
|
||||||
{value: 'light', label: 'Light'},
|
{ value: "light", label: "Light" },
|
||||||
{value: 'dark', label: 'Dark'}
|
{ value: "dark", label: "Dark" },
|
||||||
];
|
];
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect(() => {
|
||||||
setSelectedTheme(props.user.theme ? themeOptions.find( (theme) => theme.value === props.user.theme ) : null);
|
setSelectedTheme(
|
||||||
|
props.user.theme ? themeOptions.find((theme) => theme.value === props.user.theme) : null
|
||||||
|
);
|
||||||
setSelectedWeekStartDay({ value: props.user.weekStart, label: props.user.weekStart });
|
setSelectedWeekStartDay({ value: props.user.weekStart, label: props.user.weekStart });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
@ -138,8 +140,7 @@ export default function Settings(props) {
|
||||||
placeholder="A little something about yourself."
|
placeholder="A little something about yourself."
|
||||||
rows={3}
|
rows={3}
|
||||||
defaultValue={props.user.bio}
|
defaultValue={props.user.bio}
|
||||||
className="shadow-sm focus:ring-blue-500 focus:border-blue-500 mt-1 block w-full sm:text-sm border-gray-300 rounded-md">
|
className="shadow-sm focus:ring-blue-500 focus:border-blue-500 mt-1 block w-full sm:text-sm border-gray-300 rounded-md"></textarea>
|
||||||
</textarea>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
@ -166,9 +167,10 @@ export default function Settings(props) {
|
||||||
onChange={setSelectedWeekStartDay}
|
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"
|
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={[
|
options={[
|
||||||
{ value:'Sunday', label:'Sunday' },
|
{ value: "Sunday", label: "Sunday" },
|
||||||
{ value:'Monday', label:'Monday' }
|
{ value: "Monday", label: "Monday" },
|
||||||
]} />
|
]}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
@ -182,7 +184,8 @@ export default function Settings(props) {
|
||||||
defaultValue={selectedTheme || themeOptions[0]}
|
defaultValue={selectedTheme || themeOptions[0]}
|
||||||
onChange={setSelectedTheme}
|
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"
|
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}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="relative flex items-start">
|
<div className="relative flex items-start">
|
||||||
<div className="flex items-center h-5">
|
<div className="flex items-center h-5">
|
||||||
|
@ -302,20 +305,13 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||||
return { redirect: { permanent: false, destination: "/auth/login" } };
|
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: session.user.id,
|
||||||
}, [
|
},
|
||||||
"id",
|
["id", "username", "name", "email", "bio", "avatar", "timeZone", "weekStart", "hideBranding", "theme"]
|
||||||
"username",
|
);
|
||||||
"name",
|
|
||||||
"email",
|
|
||||||
"bio",
|
|
||||||
"avatar",
|
|
||||||
"timeZone",
|
|
||||||
"weekStart",
|
|
||||||
"hideBranding",
|
|
||||||
"theme"
|
|
||||||
]);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: { user }, // will be passed to the page component as props
|
props: { user }, // will be passed to the page component as props
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import prisma, {whereAndSelect} from "../lib/prisma";
|
import prisma, { whereAndSelect } from "../lib/prisma";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { CheckIcon } from "@heroicons/react/outline";
|
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);
|
const eventName = getEventName(name, props.eventType.title, props.eventType.eventName);
|
||||||
|
|
||||||
function eventLink(): string {
|
function eventLink(): string {
|
||||||
let optional = {};
|
const optional = {};
|
||||||
if (location) {
|
if (location) {
|
||||||
optional["location"] = location;
|
optional["location"] = location;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@ export default function Success(props) {
|
||||||
return encodeURIComponent(event.value);
|
return encodeURIComponent(event.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return isReady && (
|
return (
|
||||||
|
isReady && (
|
||||||
<div>
|
<div>
|
||||||
<Head>
|
<Head>
|
||||||
<title>Booking Confirmed | {eventName} | Calendso</title>
|
<title>Booking Confirmed | {eventName} | Calendso</title>
|
||||||
|
@ -210,17 +211,20 @@ export default function Success(props) {
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getServerSideProps(context) {
|
export async function getServerSideProps(context) {
|
||||||
|
const user = context.query.user
|
||||||
const user = (context.query.user) ? await whereAndSelect(prisma.user.findFirst, {
|
? await whereAndSelect(
|
||||||
|
prisma.user.findFirst,
|
||||||
|
{
|
||||||
username: context.query.user,
|
username: context.query.user,
|
||||||
}, [
|
},
|
||||||
"username", "name", "bio", "avatar", "eventTypes", "hideBranding", "theme"
|
["username", "name", "bio", "avatar", "eventTypes", "hideBranding", "theme"]
|
||||||
]
|
)
|
||||||
) : null;
|
: null;
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
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: parseInt(context.query.type),
|
||||||
}, [
|
},
|
||||||
"id", "title", "description", "length", "eventName"
|
["id", "title", "description", "length", "eventName"]
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue