Ts strict mode (#1288)

part of #879
This commit is contained in:
notmd
2023-02-07 17:56:59 +07:00
committed by GitHub
parent 5d10b28b20
commit b7d0c4331c
10 changed files with 51 additions and 24 deletions
+13
View File
@@ -68,6 +68,7 @@
"@storybook/testing-library": "^0.0.13",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@types/accept-language-parser": "^1.5.3",
"@types/node": "^18.11.17",
"@types/react": "18.0.26",
"@typescript-eslint/eslint-plugin": "^5.47.1",
@@ -12619,6 +12620,12 @@
"integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==",
"devOptional": true
},
"node_modules/@types/accept-language-parser": {
"version": "1.5.3",
"resolved": "https://registry.npmjs.org/@types/accept-language-parser/-/accept-language-parser-1.5.3.tgz",
"integrity": "sha512-S8oM29O6nnRC3/+rwYV7GBYIIgNIZ52PCxqBG7OuItq9oATnYWy8FfeLKwvq5F7pIYjeeBSCI7y+l+Z9UEQpVQ==",
"dev": true
},
"node_modules/@types/aria-query": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.1.tgz",
@@ -47865,6 +47872,12 @@
"integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ==",
"devOptional": true
},
"@types/accept-language-parser": {
"version": "1.5.3",
"resolved": "https://registry.npmjs.org/@types/accept-language-parser/-/accept-language-parser-1.5.3.tgz",
"integrity": "sha512-S8oM29O6nnRC3/+rwYV7GBYIIgNIZ52PCxqBG7OuItq9oATnYWy8FfeLKwvq5F7pIYjeeBSCI7y+l+Z9UEQpVQ==",
"dev": true
},
"@types/aria-query": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.1.tgz",
+1
View File
@@ -86,6 +86,7 @@
"@storybook/testing-library": "^0.0.13",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@types/accept-language-parser": "^1.5.3",
"@types/node": "^18.11.17",
"@types/react": "18.0.26",
"@typescript-eslint/eslint-plugin": "^5.47.1",
+1 -1
View File
@@ -84,7 +84,7 @@ export const DataTable = <T,>({
} else {
newValues = filterValues.map((oldValue) => (oldValue.id === value.id ? value : oldValue));
}
onFilterChange(newValues);
onFilterChange && onFilterChange(newValues);
};
return (
<>
+2 -2
View File
@@ -76,14 +76,14 @@ export const UserTable = memo(function UserTable() {
const toPreviousPage = () => {
setPagination({
cursor: data.prev,
cursor: data?.prev || "",
direction: "back",
});
};
const toNextPage = () => {
setPagination({
cursor: data.next,
cursor: data?.next || "",
direction: "forward",
});
};
+11 -6
View File
@@ -32,9 +32,8 @@ const getUserLanguage = (req: NextApiRequest): string => {
*
* @param {string} id The user's web auth id.
*
* @return {BackendUserCore} The most specific auth type and id for the user.
*/
const getBackendUserCore = async (id: string) => {
const getBackendUserCore = async (id: string): Promise<BackendUserCore | null> => {
const user = await prisma.user.findUnique({
where: { id },
select: {
@@ -44,21 +43,27 @@ const getBackendUserCore = async (id: string) => {
},
});
if (!user) {
return null;
}
// If there are no linked accounts, just use what we have locally.
if (user.accounts.length === 0) {
return {
id: user.id,
display_name: user.name,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
display_name: user.name!,
auth_method: "local",
} as BackendUserCore;
};
}
// Otherwise, use the first linked account that the user created.
return {
id: user.accounts[0].providerAccountId,
display_name: user.name,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
display_name: user.name!,
auth_method: user.accounts[0].provider,
} as BackendUserCore;
};
};
export { getBackendUserCore, getUserLanguage };
+6 -5
View File
@@ -7,9 +7,10 @@ import { GetServerSideProps } from "next";
import Head from "next/head";
import Link from "next/link";
import { useRouter } from "next/router";
import { getProviders, signIn } from "next-auth/react";
import { BuiltInProviderType } from "next-auth/providers";
import { ClientSafeProvider, getProviders, signIn } from "next-auth/react";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import React, { useEffect, useRef, useState } from "react";
import React, { ReactNode, useEffect, useRef, useState } from "react";
import { useForm } from "react-hook-form";
import { AuthLayout } from "src/components/AuthLayout";
import { CloudFlareCaptcha } from "src/components/CloudflareCaptcha";
@@ -48,7 +49,7 @@ const errorMessages: Record<SignInErrorTypes, string> = {
};
interface SigninProps {
providers: Awaited<ReturnType<typeof getProviders>>;
providers: Record<BuiltInProviderType, ClientSafeProvider>;
}
function Signin({ providers }: SigninProps) {
@@ -137,7 +138,7 @@ function Signin({ providers }: SigninProps) {
);
}
Signin.getLayout = (page) => (
Signin.getLayout = (page: ReactNode) => (
<div className="grid grid-rows-[min-content_1fr_min-content] h-full justify-items-stretch">
<Header />
{page}
@@ -151,7 +152,7 @@ const emailSigninCaptcha = boolean(process.env.NEXT_PUBLIC_ENABLE_EMAIL_SIGNIN_C
const EmailSignInForm = ({ providerId }: { providerId: string }) => {
const { register, handleSubmit } = useForm<{ email: string }>();
const captcha = useRef<TurnstileInstance>();
const captcha = useRef<TurnstileInstance>(null);
const [captchaSuccess, setCaptchaSuccess] = useState(false);
const signinWithEmail = (data: { email: string }) => {
signIn(providerId, {
+3 -2
View File
@@ -1,4 +1,5 @@
import { useColorMode } from "@chakra-ui/react";
import { GetServerSideProps } from "next";
import Head from "next/head";
import { getCsrfToken, getProviders } from "next-auth/react";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
@@ -22,7 +23,7 @@ export default function Verify() {
);
}
export async function getServerSideProps({ locale }) {
export const getServerSideProps: GetServerSideProps = async ({ locale = "en" }) => {
const csrfToken = await getCsrfToken();
const providers = await getProviders();
return {
@@ -32,4 +33,4 @@ export async function getServerSideProps({ locale }) {
...(await serverSideTranslations(locale, ["common"])),
},
};
}
};
+9 -4
View File
@@ -1,4 +1,5 @@
import { Box, Card, Text, useColorModeValue } from "@chakra-ui/react";
import { GetServerSideProps, InferGetServerSidePropsType } from "next";
import Head from "next/head";
import { useTranslation } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
@@ -10,7 +11,7 @@ import { get } from "src/lib/api";
import { Message } from "src/types/Conversation";
import useSWRImmutable from "swr/immutable";
const MessageDetail = ({ id }: { id: string }) => {
const MessageDetail = ({ id }: InferGetServerSidePropsType<typeof getServerSideProps>) => {
const { t } = useTranslation(["message", "common"]);
const backgroundColor = useColorModeValue("white", "gray.800");
@@ -49,11 +50,15 @@ const MessageDetail = ({ id }: { id: string }) => {
);
};
MessageDetail.getLayout = (page) => getDashboardLayout(page);
MessageDetail.getLayout = getDashboardLayout;
export const getServerSideProps = async ({ locale, query }) => ({
export const getServerSideProps: GetServerSideProps<{ id: string }, { id: string }> = async ({
locale = "en",
params,
}) => ({
props: {
id: query.id,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: params!.id,
...(await serverSideTranslations(locale, ["common", "message", "labelling"])),
},
});
+1 -1
View File
@@ -16,6 +16,6 @@ const AllTasks = () => {
);
};
AllTasks.getLayout = (page) => getDashboardLayout(page);
AllTasks.getLayout = getDashboardLayout;
export default AllTasks;
+4 -3
View File
@@ -1,5 +1,4 @@
import NextAuth, { DefaultSession } from "next-auth";
import { JWT } from "next-auth/jwt";
import { DefaultSession } from "next-auth";
declare module "next-auth" {
interface Session {
@@ -17,9 +16,11 @@ declare module "next-auth" {
declare module "next-auth/jwt" {
interface JWT {
/** The user's role. */
role?: string;
role: string;
/** True when the user is new. */
isNew?: boolean;
sub: string;
/** Iso timestamp of the user's acceptance of the terms of service */
tosAcceptanceDate?: string;
}