From 6e894dd765efc12b27bd1d84bd3c27b9aec00ada Mon Sep 17 00:00:00 2001 From: wisse Date: Sat, 15 Mar 2025 19:31:57 +0100 Subject: [PATCH 01/16] Fix typescript strict flag errors (untested) --- .github/workflows/lints_tests.yml | 2 + ui/Makefile | 9 +- ui/src/components/Alert.tsx | 2 +- ui/src/components/BooleanInput.tsx | 6 +- ui/src/components/Button.tsx | 2 +- ui/src/components/LoginModal.tsx | 2 +- ui/src/components/ProfileMenu.tsx | 4 +- ui/src/components/Table.tsx | 8 +- ui/src/components/ThemeSwitcher.tsx | 2 +- ui/src/context/LocaleProvider.tsx | 9 +- ui/src/context/UserProvider.tsx | 6 +- ui/src/index.tsx | 4 + ui/src/pages/{BasePage.tsx => Base.tsx} | 0 ...gotPasswordPage.tsx => ForgotPassword.tsx} | 0 ui/src/pages/{LandingPage.tsx => Landing.tsx} | 0 .../pages/{NotFoundPage.tsx => NotFound.tsx} | 0 ...esetPasswordPage.tsx => ResetPassword.tsx} | 5 +- ui/src/pages/SearchParams.ts | 6 + .../{VerifyEmailPage.tsx => VerifyEmail.tsx} | 10 +- .../admin_page/{AdminPage.tsx => Admin.tsx} | 0 ui/src/pages/admin_page/UsersAdmin.tsx | 22 ++- .../user_account_page/ChangePasswordModal.tsx | 6 +- .../{UserAccountPage.tsx => UserAccount.tsx} | 22 +-- .../modals/ChangePassword.tsx | 170 ++++++++++++++++++ .../DeleteAccount.tsx} | 16 +- .../Disable2FA.tsx} | 14 +- .../Enable2FA.tsx} | 18 +- ui/src/routes.tsx | 20 +-- ui/tsconfig.json | 8 +- 29 files changed, 288 insertions(+), 85 deletions(-) rename ui/src/pages/{BasePage.tsx => Base.tsx} (100%) rename ui/src/pages/{ForgotPasswordPage.tsx => ForgotPassword.tsx} (100%) rename ui/src/pages/{LandingPage.tsx => Landing.tsx} (100%) rename ui/src/pages/{NotFoundPage.tsx => NotFound.tsx} (100%) rename ui/src/pages/{ResetPasswordPage.tsx => ResetPassword.tsx} (97%) create mode 100644 ui/src/pages/SearchParams.ts rename ui/src/pages/{VerifyEmailPage.tsx => VerifyEmail.tsx} (89%) rename ui/src/pages/admin_page/{AdminPage.tsx => Admin.tsx} (100%) rename ui/src/pages/user_account_page/{UserAccountPage.tsx => UserAccount.tsx} (89%) create mode 100644 ui/src/pages/user_account_page/modals/ChangePassword.tsx rename ui/src/pages/user_account_page/{DeleteAccountModal.tsx => modals/DeleteAccount.tsx} (75%) rename ui/src/pages/user_account_page/{Disable2FAModal.tsx => modals/Disable2FA.tsx} (83%) rename ui/src/pages/user_account_page/{Enable2FAModal.tsx => modals/Enable2FA.tsx} (87%) diff --git a/.github/workflows/lints_tests.yml b/.github/workflows/lints_tests.yml index ff3404f..da496bd 100644 --- a/.github/workflows/lints_tests.yml +++ b/.github/workflows/lints_tests.yml @@ -30,6 +30,8 @@ jobs: - name: Lint run: cd ui && make lint + + lint-api: runs-on: ubuntu-latest diff --git a/ui/Makefile b/ui/Makefile index 6e67fcb..358e8f1 100644 --- a/ui/Makefile +++ b/ui/Makefile @@ -15,9 +15,16 @@ format: ## Format code with eslint and prettier pnpm eslint $(LINT_FILES) --fix pnpm prettier --write $(LINT_FILES) -lint: ## Run lint check with eslint and prettier +lint: ## Run lint check with eslint, prettier and typescript pnpm eslint $(LINT_FILES) pnpm prettier --check $(LINT_FILES) + pnpm tsc + +ts_check: ## Run the typescript compiler + pnpm tsc + +ts_watch: ## Run the typescript compiler in watch mode + pnpm tsc --watch formatlint: format lint ## First format code, then run linters diff --git a/ui/src/components/Alert.tsx b/ui/src/components/Alert.tsx index d7ee7e4..dd7779e 100644 --- a/ui/src/components/Alert.tsx +++ b/ui/src/components/Alert.tsx @@ -3,7 +3,7 @@ import { clsx } from 'clsx' interface AlertProps { type: 'info' | 'error' | 'success' | 'warning' - message: string + message?: string extraClasses?: string } diff --git a/ui/src/components/BooleanInput.tsx b/ui/src/components/BooleanInput.tsx index 11d32e4..b0af0ea 100644 --- a/ui/src/components/BooleanInput.tsx +++ b/ui/src/components/BooleanInput.tsx @@ -1,6 +1,6 @@ import { JSX, splitProps, JSXElement } from 'solid-js' -type BooleanInputProps = { +export function BooleanInput(props: { name: string type: 'checkbox' label?: string @@ -10,9 +10,7 @@ type BooleanInputProps = { ref: (element: HTMLInputElement) => void onInput: JSX.EventHandler onChange: JSX.EventHandler -} - -export function BooleanInput(props: BooleanInputProps): JSXElement { +}): JSXElement { const [, inputProps] = splitProps(props, ['value', 'label', 'error']) return (
diff --git a/ui/src/components/Button.tsx b/ui/src/components/Button.tsx index 9c855b7..ea6120d 100644 --- a/ui/src/components/Button.tsx +++ b/ui/src/components/Button.tsx @@ -24,7 +24,7 @@ export function Button(props: { props.class )} type={props.type ?? 'button'} - onClick={() => props.onClick()} + onClick={() => props.onClick?.()} > {props.children} diff --git a/ui/src/components/LoginModal.tsx b/ui/src/components/LoginModal.tsx index d830954..829bdbc 100644 --- a/ui/src/components/LoginModal.tsx +++ b/ui/src/components/LoginModal.tsx @@ -72,7 +72,7 @@ export function LoginModal(props: ModalBaseProps): JSXElement { } const onTotpLogin: SubmitHandler = async (values) => { - const response = await totpLogin(currentEmail(), values.totpCode) + const response = await totpLogin(currentEmail() ?? '', values.totpCode) if (response.status !== 200) { setResponse(totpForm, { diff --git a/ui/src/components/ProfileMenu.tsx b/ui/src/components/ProfileMenu.tsx index 70c030a..dc5c200 100644 --- a/ui/src/components/ProfileMenu.tsx +++ b/ui/src/components/ProfileMenu.tsx @@ -35,7 +35,7 @@ export function ProfileMenu(): JSXElement { return (