Fixes some linting + codacy issues
This commit is contained in:
parent
5206fb4f88
commit
4d7427ad91
7 changed files with 563 additions and 556 deletions
|
@ -1,6 +1,6 @@
|
|||
import { useEffect, useState } from "react";
|
||||
|
||||
const Theme = (theme?: string) => {
|
||||
export default function Theme(theme?: string) {
|
||||
const [isReady, setIsReady] = useState(false);
|
||||
useEffect(() => {
|
||||
if (!theme && window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||
|
@ -12,8 +12,6 @@ const Theme = (theme?: string) => {
|
|||
}, []);
|
||||
|
||||
return {
|
||||
isReady
|
||||
}
|
||||
isReady,
|
||||
};
|
||||
|
||||
export default Theme;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ 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,7 +23,8 @@ export default function User(props): User {
|
|||
</Link>
|
||||
</li>
|
||||
));
|
||||
return isReady && (
|
||||
return (
|
||||
isReady && (
|
||||
<div>
|
||||
<Head>
|
||||
<title>{props.user.name || props.user.username} | Calendso</title>
|
||||
|
@ -50,16 +50,17 @@ export default function User(props): User {
|
|||
</div>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
|
@ -47,12 +47,13 @@ export default function Type(props): Type {
|
|||
setTimeFormat(is24hClock ? "HH:mm" : "h:mma");
|
||||
};
|
||||
|
||||
return isReady && (
|
||||
return (
|
||||
isReady && (
|
||||
<div>
|
||||
<Head>
|
||||
<title>
|
||||
{rescheduleUid && "Reschedule"} {props.eventType.title} | {props.user.name || props.user.username} |
|
||||
Calendso
|
||||
{rescheduleUid && "Reschedule"} {props.eventType.title} | {props.user.name || props.user.username}{" "}
|
||||
| Calendso
|
||||
</title>
|
||||
<meta name="title" content={"Meet " + (props.user.name || props.user.username) + " via Calendso"} />
|
||||
<meta name="description" content={props.eventType.description} />
|
||||
|
@ -154,6 +155,7 @@ export default function Type(props): Type {
|
|||
{!props.user.hideBranding && <PoweredByCalendso />}
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,8 @@ export default function Book(props: any): JSX.Element {
|
|||
book();
|
||||
};
|
||||
|
||||
return isReady && (
|
||||
return (
|
||||
isReady && (
|
||||
<div>
|
||||
<Head>
|
||||
<title>
|
||||
|
@ -198,7 +199,9 @@ export default function Book(props: any): JSX.Element {
|
|||
</div>
|
||||
</div>
|
||||
<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
|
||||
</label>
|
||||
<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"
|
||||
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}
|
||||
</label>
|
||||
</div>
|
||||
|
@ -366,22 +371,17 @@ export default function Book(props: any): JSX.Element {
|
|||
</div>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
|
||||
const user = await whereAndSelect(prisma.user.findFirst, {
|
||||
const user = await whereAndSelect(
|
||||
prisma.user.findFirst,
|
||||
{
|
||||
username: context.query.user,
|
||||
}, [
|
||||
"username",
|
||||
"name",
|
||||
"email",
|
||||
"bio",
|
||||
"avatar",
|
||||
"eventTypes",
|
||||
"theme",
|
||||
]
|
||||
},
|
||||
["username", "name", "email", "bio", "avatar", "eventTypes", "theme"]
|
||||
);
|
||||
|
||||
const eventType = await prisma.eventType.findUnique({
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getSession } from 'next-auth/client';
|
||||
import prisma, {whereAndSelect} from '@lib/prisma';
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getSession } from "next-auth/client";
|
||||
import prisma, { whereAndSelect } from "@lib/prisma";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await getSession({ req: req });
|
||||
|
@ -11,13 +11,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||
}
|
||||
|
||||
// Get user
|
||||
const user = await whereAndSelect(prisma.user.findUnique, {
|
||||
const user = await whereAndSelect(
|
||||
prisma.user.findUnique,
|
||||
{
|
||||
id: session.user.id,
|
||||
},
|
||||
["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;
|
||||
// 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({
|
||||
where: {
|
||||
username,
|
||||
}
|
||||
},
|
||||
});
|
||||
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 theme = req.body.theme;
|
||||
|
||||
const updateUser = await prisma.user.update({
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
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" });
|
||||
}
|
||||
|
|
|
@ -27,12 +27,14 @@ export default function Settings(props) {
|
|||
const [errorMessage, setErrorMessage] = useState("");
|
||||
|
||||
const themeOptions = [
|
||||
{value: 'light', label: 'Light'},
|
||||
{value: 'dark', label: 'Dark'}
|
||||
{ value: "light", label: "Light" },
|
||||
{ value: "dark", label: "Dark" },
|
||||
];
|
||||
|
||||
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 });
|
||||
}, []);
|
||||
|
||||
|
@ -138,8 +140,7 @@ export default function Settings(props) {
|
|||
placeholder="A little something about yourself."
|
||||
rows={3}
|
||||
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">
|
||||
</textarea>
|
||||
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>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
|
@ -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" },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
|
@ -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}
|
||||
/>
|
||||
</div>
|
||||
<div className="relative flex items-start">
|
||||
<div className="flex items-center h-5">
|
||||
|
@ -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
|
||||
|
|
|
@ -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,7 +58,8 @@ export default function Success(props) {
|
|||
return encodeURIComponent(event.value);
|
||||
}
|
||||
|
||||
return isReady && (
|
||||
return (
|
||||
isReady && (
|
||||
<div>
|
||||
<Head>
|
||||
<title>Booking Confirmed | {eventName} | Calendso</title>
|
||||
|
@ -210,17 +211,20 @@ export default function Success(props) {
|
|||
</div>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
|
||||
const user = (context.query.user) ? await whereAndSelect(prisma.user.findFirst, {
|
||||
const user = context.query.user
|
||||
? await whereAndSelect(
|
||||
prisma.user.findFirst,
|
||||
{
|
||||
username: context.query.user,
|
||||
}, [
|
||||
"username", "name", "bio", "avatar", "eventTypes", "hideBranding", "theme"
|
||||
]
|
||||
) : null;
|
||||
},
|
||||
["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 {
|
||||
|
|
Loading…
Reference in a new issue