From 7a5ba5ea4aec0704070cfe8d63ba504a07d88cc6 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Sat, 1 Oct 2022 16:44:31 +0800 Subject: feat: Functionality complete public sites --- apps/kit/src/app.d.ts | 2 +- apps/kit/src/lib/components/alert.svelte | 4 +- apps/kit/src/lib/components/button.svelte | 12 +- apps/kit/src/lib/components/checkbox.svelte | 2 + apps/kit/src/lib/i18n/en/index.ts | 41 +++- apps/kit/src/lib/i18n/i18n-types.ts | 252 ++++++++++++++++----- apps/kit/src/lib/models/LoginPayload.ts | 3 +- apps/kit/src/routes/(main)/(public)/+layout.svelte | 18 ++ .../(main)/(public)/reset-password/+page.svelte | 16 +- .../(public)/reset-password/[id]/+page.svelte | 79 ++++--- .../routes/(main)/(public)/sign-in/+page.svelte | 79 +++++-- .../routes/(main)/(public)/sign-up/+page.svelte | 61 +++-- apps/kit/src/routes/(main)/+layout.svelte | 7 +- 13 files changed, 425 insertions(+), 151 deletions(-) create mode 100644 apps/kit/src/routes/(main)/(public)/+layout.svelte (limited to 'apps/kit') diff --git a/apps/kit/src/app.d.ts b/apps/kit/src/app.d.ts index 4ab4e43..220ddc1 100644 --- a/apps/kit/src/app.d.ts +++ b/apps/kit/src/app.d.ts @@ -6,4 +6,4 @@ declare namespace App { interface Platform {} interface PrivateEnv {} interface PublicEnv {} -} +} \ No newline at end of file diff --git a/apps/kit/src/lib/components/alert.svelte b/apps/kit/src/lib/components/alert.svelte index 5bcb3ae..fa36a63 100644 --- a/apps/kit/src/lib/components/alert.svelte +++ b/apps/kit/src/lib/components/alert.svelte @@ -193,7 +193,9 @@ {#if visible} -
+
{#if loading} @@ -89,8 +90,9 @@ {:else}
diff --git a/apps/kit/src/routes/(main)/(public)/reset-password/[id]/+page.svelte b/apps/kit/src/routes/(main)/(public)/reset-password/[id]/+page.svelte index 7b46d2d..562d902 100644 --- a/apps/kit/src/routes/(main)/(public)/reset-password/[id]/+page.svelte +++ b/apps/kit/src/routes/(main)/(public)/reset-password/[id]/+page.svelte @@ -9,6 +9,7 @@ import type { PageServerData } from "./$types"; import type { ErrorResult } from "$lib/models/ErrorResult"; import { goto } from "$app/navigation"; + import { Message, messageQueryKey } from "../../sign-in/+page.svelte"; export let data: PageServerData; @@ -16,18 +17,15 @@ newPassword: "", }; - $: showErrorAlert = - (errorData?.text.length ?? 0 + errorData?.title.length ?? 0) > 0 && - !showSuccessAlert; - const errorData = { text: "", title: "", } as ErrorResult; + let errorState: undefined | "expired" | "404" | "unknown"; + let finishedPreliminaryLoading = false; let loading = false; - let showSuccessAlert = false; let canSubmit = true; async function submitFormAsync() { @@ -38,39 +36,48 @@ formData.newPassword ); if (request.ok) { - goto("/sign-in?m=1"); + goto( + "/sign-in?" + + messageQueryKey + + "=" + + Message.AFTER_PASSWORD_RESET + ); } loading = false; } onMount(async () => { + errorState = undefined; const isValidRequest = await check_forgot_password_request( data.resetRequestId ); - if (!isValidRequest.ok) { - errorData.text = isValidRequest.data?.text ?? $LL.tryAgainSoon(); - errorData.title = - isValidRequest.data?.title ?? $LL.unexpectedError(); + if (!isValidRequest.ok && isValidRequest.status !== 404) { + errorState = "unknown"; + canSubmit = false; + } + if (isValidRequest.status === 404) { + errorState = "404"; + canSubmit = false; + } + if (isValidRequest.ok && isValidRequest.data !== true) { + errorState = "expired"; canSubmit = false; } - if (isValidRequest.status === 404) goto("/reset-password"); finishedPreliminaryLoading = true; });
{#if finishedPreliminaryLoading} -
-

- {$LL.requestAPasswordReset()} +
+

+ {$LL.resetPasswordPage.setANewPassword()}

-

+

{$LL.or().toLowerCase()} - {$LL.signIntoYourAccount()} + {$LL.signIntoYourAccount().toLowerCase()}

@@ -81,21 +88,24 @@ class="space-y-6" on:submit|preventDefault={submitFormAsync} > - - - + {#if errorState === "404"} + + {:else if errorState === "expired"} + + {:else if errorState === "unknown"} + + {/if} +

diff --git a/apps/kit/src/routes/(main)/(public)/sign-up/+page.svelte b/apps/kit/src/routes/(main)/(public)/sign-up/+page.svelte index 8b89190..0dfa41a 100644 --- a/apps/kit/src/routes/(main)/(public)/sign-up/+page.svelte +++ b/apps/kit/src/routes/(main)/(public)/sign-up/+page.svelte @@ -1,29 +1,62 @@ -
-
-

- {$LL.createYourNewAccount()} +
+

+ {$LL.signUpPage.createYourNewAccount()}

-

+

{$LL.or().toLowerCase()} - {$LL.signIntoYourAccount()} + + {$LL.signIntoYourAccount().toLowerCase()} +

-
+ + -
diff --git a/apps/kit/src/routes/(main)/+layout.svelte b/apps/kit/src/routes/(main)/+layout.svelte index 3107861..9787e17 100644 --- a/apps/kit/src/routes/(main)/+layout.svelte +++ b/apps/kit/src/routes/(main)/+layout.svelte @@ -1,16 +1,11 @@ - -- cgit v1.3