Enables strict mode in nextjs apps (#2354)

- We need this so zod works correctly

Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
Omar LópezandPeer Richelsen authored and GitHub committed 2022-04-04 20:26:14 +00:00
1 parent 4ff21deb89
commit a7f5250b4a
25 files changed
+178 -68

No files matched your search

+3 -1
View File
@@ -127,6 +127,8 @@ function DatePicker({
eventLength,
minimumBookingNotice,
workingHours,
}: Omit<DatePickerProps, "weekStart" | "onDatePicked" | "date"> & {
browsingDate: Dayjs;
}
) => {
const date = browsingDate.startOf("day").date(day);
@@ -189,7 +191,7 @@ function DatePicker({
batch: 1,
name: "DatePicker",
length: daysInMonth,
callback: (i: number, isLast) => {
callback: (i: number) => {
let day = i + 1;
days[daysInitialOffset + i] = {
disabled: isDisabledMemoized(day, {
@@ -136,6 +136,7 @@ const BookingPage = ({ eventType, booking, profile }: BookingPageProps) => {
const locationLabels = {
[LocationType.InPerson]: t("in_person_meeting"),
[LocationType.Phone]: t("phone_call"),
[LocationType.Link]: t("link_meeting"),
[LocationType.GoogleMeet]: "Google Meet",
[LocationType.Zoom]: "Zoom Video",
[LocationType.Jitsi]: "Jitsi Meet",
+3 -1
View File
@@ -74,7 +74,7 @@ const constructImage = (name: string, description: string, username: string): st
);
};
export const HeadSeo: React.FC<HeadSeoProps & { children?: never }> = (props) => {
export const HeadSeo = (props: HeadSeoProps): JSX.Element => {
const defaultUrl = getBrowserInfo()?.url;
const image = getSeoImage("default");
@@ -113,3 +113,5 @@ export const HeadSeo: React.FC<HeadSeoProps & { children?: never }> = (props) =>
return <NextSeo {...seoProps} />;
};
export default HeadSeo;
+5 -4
View File
@@ -1,12 +1,13 @@
import { HashtagIcon, InformationCircleIcon, LinkIcon, PhotographIcon } from "@heroicons/react/solid";
import React, { useRef, useState } from "react";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import showToast from "@calcom/lib/notification";
import { objectKeys } from "@calcom/lib/objectKeys";
import { Alert } from "@calcom/ui/Alert";
import Button from "@calcom/ui/Button";
import { TextField } from "@calcom/ui/form/fields";
import { useLocale } from "@lib/hooks/useLocale";
import { TeamWithMembers } from "@lib/queries/teams";
import { trpc } from "@lib/trpc";
@@ -54,9 +55,9 @@ export default function TeamSettings(props: Props) {
hideBranding: hideBrandingRef.current?.checked,
};
// remove unchanged variables
for (const key in variables) {
if (variables[key] === team?.[key]) delete variables[key];
}
objectKeys(variables).forEach((key) => {
if (variables[key as keyof typeof variables] === team?.[key]) delete variables[key];
});
mutation.mutate({ id: team.id, ...variables });
}
+2 -2
View File
@@ -11,7 +11,7 @@ export type AvatarProps = {
};
// defaultAvatarSrc from profile.tsx can't be used as it imports crypto
function defaultAvatarSrc({ md5 }) {
function defaultAvatarSrc(md5: string) {
return `https://www.gravatar.com/avatar/${md5}?s=160&d=identicon&r=PG`;
}
@@ -26,7 +26,7 @@ export function AvatarSSR(props: AvatarProps) {
if (user.avatar) {
imgSrc = user.avatar;
} else if (user.emailMd5) {
imgSrc = defaultAvatarSrc({ md5: user.emailMd5 });
imgSrc = defaultAvatarSrc(user.emailMd5);
}
return imgSrc ? <img alt={alt} className={className} src={imgSrc}></img> : null;
}
@@ -1,13 +1,13 @@
import { useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import showToast from "@calcom/lib/notification";
import Button from "@calcom/ui/Button";
import { DialogFooter } from "@calcom/ui/Dialog";
import Switch from "@calcom/ui/Switch";
import { FieldsetLegend, Form, InputGroupBox, TextArea, TextField } from "@calcom/ui/form/fields";
import { useLocale } from "@lib/hooks/useLocale";
import { trpc } from "@lib/trpc";
import { WEBHOOK_TRIGGER_EVENTS } from "@lib/webhooks/constants";
import customTemplate, { hasTemplateIntegration } from "@lib/webhooks/integrationTemplate";
@@ -22,13 +22,6 @@ export default function WebhookDialogForm(props: {
}) {
const { t } = useLocale();
const utils = trpc.useContext();
const handleSubscriberUrlChange = (e) => {
form.setValue("subscriberUrl", e.target.value);
if (hasTemplateIntegration({ url: e.target.value })) {
setUseCustomPayloadTemplate(true);
form.setValue("payloadTemplate", customTemplate({ url: e.target.value }));
}
};
const {
defaultValues = {
id: "",
@@ -88,7 +81,13 @@ export default function WebhookDialogForm(props: {
{...form.register("subscriberUrl")}
required
type="url"
onChange={handleSubscriberUrlChange}
onChange={(e) => {
form.setValue("subscriberUrl", e.target.value);
if (hasTemplateIntegration({ url: e.target.value })) {
setUseCustomPayloadTemplate(true);
form.setValue("payloadTemplate", customTemplate({ url: e.target.value }));
}
}}
/>
<fieldset className="space-y-2">
+1 -1
View File
@@ -1,4 +1,4 @@
const data = {};
const data: Record<string, number> = {};
/**
* Starts an iteration from `0` to `length - 1` with batch size `batch`
*
-7
View File
@@ -65,13 +65,6 @@ plugins.push(withTM);
/** @type {import("next").NextConfig} */
const nextConfig = {
i18n,
eslint: {
// This allows production builds to successfully complete even if the project has ESLint errors.
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
webpack: (config) => {
config.resolve.fallback = {
...config.resolve.fallback, // if you miss it, all the other options in fallback, specified
+2 -2
View File
@@ -90,7 +90,7 @@
"react-digit-input": "^2.1.0",
"react-dom": "^17.0.2",
"react-easy-crop": "^3.5.2",
"react-hook-form": "^7.20.4",
"react-hook-form": "^7.29.0",
"react-hot-toast": "^2.1.0",
"react-intl": "^5.22.0",
"react-live-chat-loader": "^2.7.3",
@@ -108,7 +108,7 @@
"superjson": "1.8.1",
"uuid": "^8.3.2",
"web3": "^1.6.1",
"zod": "^3.8.2"
"zod": "^3.14.3"
},
"devDependencies": {
"@calcom/config": "*",
+1 -1
View File
@@ -21,7 +21,7 @@ import { AvatarSSR } from "@components/ui/AvatarSSR";
import { ssrInit } from "@server/lib/ssr";
const EventTypeDescription = dynamic(() => import("@components/eventtype/EventTypeDescription"));
const HeadSeo = dynamic(() => import("@components/seo/head-seo").then((mod) => mod.HeadSeo));
const HeadSeo = dynamic(() => import("@components/seo/head-seo"));
const CryptoSection = dynamic(() => import("../ee/components/web3/CryptoSection"));
interface EvtsToVerify {
+7 -2
View File
@@ -1,4 +1,4 @@
import { NextApiRequest, NextApiResponse } from "next";
import { NextApiHandler, NextApiRequest, NextApiResponse } from "next";
import appStore from "@calcom/app-store";
@@ -26,7 +26,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
try {
// TODO: Find a way to dynamically import these modules
// const app = (await import(`@calcom/${appName}`)).default;
const handler = appStore[appName].api[apiEndpoint];
const app = appStore[appName as keyof typeof appStore];
if (!(app && "api" in app && apiEndpoint in app.api))
throw new HttpError({ statusCode: 404, message: `API handler not found` });
const handler = app.api[apiEndpoint as keyof typeof app.api] as NextApiHandler;
if (typeof handler !== "function")
throw new HttpError({ statusCode: 404, message: `API handler not found` });
+5 -3
View File
@@ -16,13 +16,15 @@ import App from "@components/App";
import Slider from "@components/apps/Slider";
const components = {
a: ({ href, ...otherProps }) => (
a: ({ href = "", ...otherProps }: JSX.IntrinsicElements["a"]) => (
<Link href={href}>
<a {...otherProps} />
</Link>
),
img: ({ src, alt = "", ...rest }) => <Image src={src} alt={alt} {...rest} />,
Slider: ({ items }) => {
img: ({ src = "", alt = "", placeholder, ...rest }: JSX.IntrinsicElements["img"]) => (
<Image src={src} alt={alt} {...rest} />
),
Slider: ({ items }: { items: string[] }) => {
const isTabletAndUp = useMediaQuery("(min-width: 960px)");
return (
<Slider<string>
+21 -7
View File
@@ -23,7 +23,7 @@ import utc from "dayjs/plugin/utc";
import { GetServerSidePropsContext } from "next";
import { useRouter } from "next/router";
import React, { useEffect, useState } from "react";
import { Controller, useForm } from "react-hook-form";
import { Controller, Noop, useForm } from "react-hook-form";
import { FormattedNumber, IntlProvider } from "react-intl";
import Select, { Props as SelectProps } from "react-select";
import { JSONObject } from "superjson/dist/types";
@@ -86,7 +86,21 @@ type OptionTypeBase = {
disabled?: boolean;
};
const AvailabilitySelect = ({ className, ...props }: SelectProps) => {
type AvailabilityOption = {
label: string;
value: number;
};
const AvailabilitySelect = ({
className = "",
...props
}: {
className?: string;
name: string;
value: number;
onBlur: Noop;
onChange: (value: AvailabilityOption | null) => void;
}) => {
const query = trpc.useQuery(["viewer.availability.list"]);
return (
@@ -105,9 +119,9 @@ const AvailabilitySelect = ({ className, ...props }: SelectProps) => {
);
return (
<Select
{...props}
options={options}
isSearchable={false}
onChange={props.onChange}
classNamePrefix="react-select"
className={classNames(
"react-select-container focus:border-primary-500 focus:ring-primary-500 block w-full min-w-0 flex-1 rounded-sm border border-gray-300 sm:text-sm",
@@ -972,10 +986,10 @@ const EventTypePage = (props: inferSSRProps<typeof getServerSideProps>) => {
control={formMethods.control}
render={({ field }) => (
<AvailabilitySelect
{...field}
onChange={(selected: { label: string; value: number }) =>
field.onChange(selected.value)
}
value={field.value}
onBlur={field.onBlur}
name={field.name}
onChange={(selected) => field.onChange(selected?.value || null)}
/>
)}
/>
+1 -1
View File
@@ -268,7 +268,7 @@ export default function Onboarding(props: inferSSRProps<typeof getServerSideProp
// Should update username on user when being redirected from sign up and doing google/saml
useEffect(() => {
async function validateAndSave(username) {
async function validateAndSave(username: string) {
const { data } = await fetchUsername(username);
// Only persist username if its available and not premium
+1 -1
View File
@@ -7,7 +7,7 @@ import {
todo,
} from "./lib/testUtils";
async function bookFirstEvent(page) {
async function bookFirstEvent(page: Page) {
// Click first event type
await page.click('[data-testid="event-type-link"]');
await selectFirstAvailableTimeSlotNextMonth(page);
+3 -3
View File
@@ -1,4 +1,4 @@
import { expect, test } from "@playwright/test";
import { expect, Locator, test } from "@playwright/test";
import { randomString } from "../lib/random";
import { deleteEventTypeByTitle } from "./lib/teardown";
@@ -11,8 +11,8 @@ test.describe("Event Types tests", () => {
});
test.describe("pro user", () => {
let isCreated;
let eventTitle;
let isCreated: Locator;
let eventTitle: string;
test.afterAll(async () => {
if (isCreated) await deleteEventTypeByTitle(eventTitle);