diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-10-09 18:38:10 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-10-09 18:38:10 +0200 |
| commit | c0746289e8ff1c4509ea544469333baf116dbeb8 (patch) | |
| tree | 1f5677342c678bf063ceb64015cdbc1d034cbcd8 /code/app/src/routes | |
| parent | 1bb31b298cab4552446aca9957f9592a34b2134f (diff) | |
| download | greatoffice-c0746289e8ff1c4509ea544469333baf116dbeb8.tar.xz greatoffice-c0746289e8ff1c4509ea544469333baf116dbeb8.zip | |
refactor: Update imports and clean up
Diffstat (limited to 'code/app/src/routes')
5 files changed, 25 insertions, 72 deletions
diff --git a/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.server.js b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.server.js deleted file mode 100644 index 1c7fa30..0000000 --- a/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.server.js +++ /dev/null @@ -1,11 +0,0 @@ -import { is_guid } from '$lib/helpers'; -import { redirect } from '@sveltejs/kit'; -export const load = async ({ params }) => { - const resetRequestId = params.id ?? ""; - if (!is_guid(resetRequestId)) - throw redirect(302, "/reset-password"); - return { - resetRequestId - }; -}; -//# sourceMappingURL=+page.server.js.map
\ No newline at end of file diff --git a/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.server.js.map b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.server.js.map deleted file mode 100644 index 52fb93b..0000000 --- a/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.server.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"+page.server.js","sourceRoot":"","sources":["+page.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,CAAC,MAAM,IAAI,GAAmB,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IACrD,MAAM,cAAc,GAAG,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;IACvC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC;QAAE,MAAM,QAAQ,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;IACrE,OAAO;QACH,cAAc;KACjB,CAAC;AACN,CAAC,CAAC"}
\ No newline at end of file diff --git a/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte index 562d902..c5044b5 100644 --- a/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte +++ b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte @@ -1,15 +1,12 @@ <script lang="ts"> - import { - check_forgot_password_request, - fulfill_forgot_password_request, - } from "$lib/api/user"; + import { check_forgot_password_request, fulfill_forgot_password_request } from "$lib/api/user"; import { onMount } from "svelte"; import LL from "$lib/i18n/i18n-svelte"; import { Alert, Input, Button } from "$lib/components"; import type { PageServerData } from "./$types"; - import type { ErrorResult } from "$lib/models/ErrorResult"; + import type { ErrorResult } from "$lib/models/internal/ErrorResult"; import { goto } from "$app/navigation"; - import { Message, messageQueryKey } from "../../sign-in/+page.svelte"; + import { Message, messageQueryKey } from "$routes/(main)/(public)/sign-in"; export let data: PageServerData; @@ -31,17 +28,9 @@ async function submitFormAsync() { if (!canSubmit) return; loading = true; - const request = await fulfill_forgot_password_request( - data.resetRequestId, - formData.newPassword - ); + const request = await fulfill_forgot_password_request(data.resetRequestId, formData.newPassword); if (request.ok) { - goto( - "/sign-in?" + - messageQueryKey + - "=" + - Message.AFTER_PASSWORD_RESET - ); + goto("/sign-in?" + messageQueryKey + "=" + Message.AFTER_PASSWORD_RESET); } loading = false; @@ -49,9 +38,7 @@ onMount(async () => { errorState = undefined; - const isValidRequest = await check_forgot_password_request( - data.resetRequestId - ); + const isValidRequest = await check_forgot_password_request(data.resetRequestId); if (!isValidRequest.ok && isValidRequest.status !== 404) { errorState = "unknown"; canSubmit = false; @@ -84,15 +71,9 @@ <div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md"> <div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10"> - <form - class="space-y-6" - on:submit|preventDefault={submitFormAsync} - > + <form class="space-y-6" on:submit|preventDefault={submitFormAsync}> {#if errorState === "404"} - <Alert - title={$LL.notFound()} - message={$LL.resetPasswordPage.requestNotFound()} - /> + <Alert title={$LL.notFound()} message={$LL.resetPasswordPage.requestNotFound()} /> {:else if errorState === "expired"} <Alert title={$LL.resetPasswordPage.expired()} @@ -101,10 +82,7 @@ rightLinkText={$LL.resetPasswordPage.requestANewReset()} /> {:else if errorState === "unknown"} - <Alert - title={$LL.unexpectedError()} - message={$LL.tryAgainSoon()} - /> + <Alert title={$LL.unexpectedError()} message={$LL.tryAgainSoon()} /> {/if} <Input @@ -117,12 +95,7 @@ label={$LL.resetPasswordPage.newPassword()} /> - <Button - text={$LL.submit()} - type="submit" - {loading} - fullWidth - /> + <Button text={$LL.submit()} type="submit" {loading} fullWidth /> </form> </div> </div> diff --git a/code/app/src/routes/(main)/(public)/sign-in/+page.svelte b/code/app/src/routes/(main)/(public)/sign-in/+page.svelte index 908e2ba..0e9c07b 100644 --- a/code/app/src/routes/(main)/(public)/sign-in/+page.svelte +++ b/code/app/src/routes/(main)/(public)/sign-in/+page.svelte @@ -3,8 +3,8 @@ import { login } from "$lib/api/user"; import { Button, Checkbox, Input, Alert } from "$lib/components"; import LL from "$lib/i18n/i18n-svelte"; - import type { ErrorResult } from "$lib/models/ErrorResult"; - import type { LoginPayload } from "$lib/models/LoginPayload"; + import type { ErrorResult } from "$lib/models/internal/ErrorResult"; + import type { LoginPayload } from "$lib/models/internal/LoginPayload"; import pwKey from "$actions/pwKey"; import { onMount } from "svelte"; import { messageQueryKey, signInPageTestKeys, type Message } from "."; @@ -22,7 +22,7 @@ text: "", title: "", } as ErrorResult; - $: showErrorAlert = (errorData?.text.length ?? 0 + errorData?.title.length ?? 0) > 0; + $: showErrorAlert = (errorData.text?.length ?? 0 + errorData.title?.length ?? 0) > 0; onMount(() => { const searcher = new URLSearchParams(window.location.search); @@ -38,11 +38,17 @@ loading = true; data.persist = !data.persist; const loginResponse = await login(data); + console.log(loginResponse.data); + if (loginResponse.ok) { await goto("/home"); } else { errorData.title = loginResponse.data.title; errorData.text = loginResponse.data.text; + if (!errorData.text && !errorData.title) { + errorData.text = $LL.tryAgainSoon(); + errorData.title = $LL.unexpectedError(); + } } loading = false; } @@ -89,7 +95,7 @@ {#if showErrorAlert} <Alert title={errorData.title} message={errorData.text} type="error" _pwKey={signInPageTestKeys.formErrorAlert} /> {/if} - <form class="space-y-6" use:pwKey={signInPageTestKeys.signInForm} on:submit|preventDefault={submitFormAsync}> + <form class="space-y-6 mt-2" use:pwKey={signInPageTestKeys.signInForm} on:submit|preventDefault={submitFormAsync}> <Input id="username" _pwKey={signInPageTestKeys.usernameInput} diff --git a/code/app/src/routes/(main)/(public)/sign-up/+page.svelte b/code/app/src/routes/(main)/(public)/sign-up/+page.svelte index 0dfa41a..f2f1695 100644 --- a/code/app/src/routes/(main)/(public)/sign-up/+page.svelte +++ b/code/app/src/routes/(main)/(public)/sign-up/+page.svelte @@ -3,8 +3,8 @@ import { create_account } from "$lib/api/user"; import { Button, Input, Alert } from "$lib/components"; import LL from "$lib/i18n/i18n-svelte"; - import type { CreateAccountPayload } from "$lib/models/CreateAccountPayload"; - import type { ErrorResult } from "$lib/models/ErrorResult"; + import type { CreateAccountPayload } from "$lib/models/internal/CreateAccountPayload"; + import type { ErrorResult } from "$lib/models/internal/ErrorResult"; const formData = { username: "", @@ -16,8 +16,7 @@ title: "", } as ErrorResult; let loading = false; - $: showErrorAlert = - (errorData?.text.length ?? 0 + errorData?.title.length ?? 0) > 0; + $: showErrorAlert = (errorData?.text.length ?? 0 + errorData?.title.length ?? 0) > 0; async function submitFormAsync() { loading = true; @@ -49,13 +48,7 @@ <div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md"> <div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10"> - <Alert - title={errorData.title} - message={errorData.text} - type="error" - class="mb-2" - visible={showErrorAlert} - /> + <Alert title={errorData.title} message={errorData.text} type="error" class="mb-2" visible={showErrorAlert} /> <form class="space-y-6" on:submit|preventDefault={submitFormAsync}> <Input label={$LL.emailAddress()} @@ -67,14 +60,7 @@ bind:value={formData.username} /> - <Input - label={$LL.password()} - id="password" - name="password" - required - type="password" - bind:value={formData.password} - /> + <Input label={$LL.password()} id="password" name="password" required type="password" bind:value={formData.password} /> <Button type="submit" text={$LL.submit()} {loading} fullWidth /> </form> </div> |
