diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-11-17 07:53:22 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-11-17 07:53:22 +0100 |
| commit | e351ffdd2adf39c9ba11bbfcda7835da20acba5f (patch) | |
| tree | 2d51714e3c3b4a96c22341895fdfd14098dd2bd3 /code/app/src/routes/(main)/(public) | |
| parent | ab816be12aa36c6622fd48a25872ea57d01a4a39 (diff) | |
| download | greatoffice-e351ffdd2adf39c9ba11bbfcda7835da20acba5f.tar.xz greatoffice-e351ffdd2adf39c9ba11bbfcda7835da20acba5f.zip | |
fix: WIP use new api structure
Diffstat (limited to 'code/app/src/routes/(main)/(public)')
| -rw-r--r-- | code/app/src/routes/(main)/(public)/reset-password/+page.svelte | 51 | ||||
| -rw-r--r-- | code/app/src/routes/(main)/(public)/sign-in/+page.svelte | 106 |
2 files changed, 81 insertions, 76 deletions
diff --git a/code/app/src/routes/(main)/(public)/reset-password/+page.svelte b/code/app/src/routes/(main)/(public)/reset-password/+page.svelte index 32d4e21..3bdba80 100644 --- a/code/app/src/routes/(main)/(public)/reset-password/+page.svelte +++ b/code/app/src/routes/(main)/(public)/reset-password/+page.svelte @@ -1,38 +1,48 @@ <script lang="ts"> - import { create_forgot_password_request } from "$lib/api/account"; import { Alert, Input, Button } from "$lib/components"; + import X from "$lib/components/icons/x.svelte"; import LL from "$lib/i18n/i18n-svelte"; - import type { ErrorResult } from "$lib/models/ErrorResult"; + import { PasswordResetService } from "$lib/services/password-reset-service"; const formData = { - email: "", + email: { + value: "", + error: "", + }, }; - $: showErrorAlert = - (errorData?.text.length ?? 0 + errorData?.title.length ?? 0) > 0 && - !showSuccessAlert; - - const errorData = { - text: "", + const formError = { title: "", - } as ErrorResult; + subtitle: "", + set(title = "", subtitle = "") { + formError.title = title; + formError.subtitle = subtitle; + }, + }; + + const service = new PasswordResetService(); let loading = false; let showSuccessAlert = false; + $: showErrorAlert = formError.title || (formError.subtitle && !showSuccessAlert); async function submitFormAsync() { - errorData.text = ""; - errorData.title = ""; + formError.set(); showSuccessAlert = false; loading = true; - const request = await create_forgot_password_request(formData.email); + const response = await service.create_request_async(formData.email.value); loading = false; - if (!request.ok) { - errorData.text = request.data.text ?? $LL.tryAgainSoon(); - errorData.title = request.data.title ?? $LL.unexpectedError(); + if (response.isCreated) { + showSuccessAlert = true; return; } - showSuccessAlert = true; + if (response.knownProblem) { + if (response.knownProblem.title) formError.title = response.knownProblem.title; + if (response.knownProblem.subtitle) formError.subtitle = response.knownProblem.subtitle; + for (const error of response.knownProblem.errors) { + + } + } } </script> @@ -52,12 +62,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"> <form class="space-y-6" on:submit|preventDefault={submitFormAsync}> - <Alert - title={errorData.title} - message={errorData.text} - type="error" - visible={showErrorAlert} - /> + <Alert title={errorData.title} message={errorData.text} type="error" visible={showErrorAlert} /> <Alert type="success" 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 d7a8c5a..5e2cb56 100644 --- a/code/app/src/routes/(main)/(public)/sign-in/+page.svelte +++ b/code/app/src/routes/(main)/(public)/sign-in/+page.svelte @@ -1,16 +1,15 @@ <script lang="ts"> - import { goto } from "$app/navigation"; - import { login } from "$lib/api/account"; - import { Button, Checkbox, Input, Alert } from "$lib/components"; + import {goto} from "$app/navigation"; + import {http_account} from "$lib/api/account"; + import {Button, Checkbox, Input, Alert} from "$lib/components"; import LL from "$lib/i18n/i18n-svelte"; - import type { ErrorResult } from "$lib/models/internal/ErrorResult"; - import type { LoginPayload } from "$lib/api/account/models/LoginPayload"; import pwKey from "$actions/pwKey"; - import { onMount } from "svelte"; - import { messageQueryKey, signInPageTestKeys, type Message } from "."; + import {isOk} from "rustic"; + import {onMount} from "svelte"; + import {signInPageMessageQueryKey, signInPageTestKeys, type SignInPageMessage} from "."; let loading = false; - let messageType: Message | undefined = undefined; + let messageType: SignInPageMessage | undefined = undefined; const data = { username: "", @@ -26,25 +25,23 @@ onMount(() => { const searcher = new URLSearchParams(window.location.search); - if (searcher.get(messageQueryKey)) { - messageType = searcher.get(messageQueryKey) as Message; - searcher.delete(messageQueryKey); + if (searcher.get(signInPageMessageQueryKey)) { + messageType = searcher.get(signInPageMessageQueryKey) as SignInPageMessage; + searcher.delete(signInPageMessageQueryKey); history.replaceState(null, "", window.location.origin + window.location.pathname); } }); async function submitFormAsync() { - errorData = { text: "", title: "" }; + errorData = {text: "", title: ""}; loading = true; data.persist = !data.persist; - const loginResponse = await login(data); - console.log(loginResponse.data); - - if (loginResponse.ok) { + const loginResponse = await http_account.login_async(data); + if (isOk(loginResponse)) { await goto("/home"); } else { errorData.title = loginResponse.data.title; - errorData.text = loginResponse.data.text; + errorData.text = loginResponse.data.subtitle; if (!errorData.text && !errorData.title) { errorData.text = $LL.tryAgainSoon(); errorData.title = $LL.unexpectedError(); @@ -59,24 +56,24 @@ <div class="sm:max-w-md sm:mx-auto sm:w-full"> {#if messageType === "after-password-reset"} <Alert - title={$LL.signInPage.yourNewPasswordIsApplied()} - _pwKey={signInPageTestKeys.afterPasswordResetAlert} - message={$LL.signInPage.signInBelow()} - closeable + title={$LL.signInPage.yourNewPasswordIsApplied()} + _pwKey={signInPageTestKeys.afterPasswordResetAlert} + message={$LL.signInPage.signInBelow()} + closeable /> {:else if messageType === "user-disabled"} <Alert - title={$LL.signInPage.yourAccountIsDisabled()} - _pwKey={signInPageTestKeys.userDisabledAlert} - message={$LL.signInPage.contactYourAdminIfDisabled()} - closeable + title={$LL.signInPage.yourAccountIsDisabled()} + _pwKey={signInPageTestKeys.userDisabledAlert} + message={$LL.signInPage.contactYourAdminIfDisabled()} + closeable /> {:else if messageType === "user-inactivity"} <Alert - title={$LL.signInPage.youHaveReachedInactivityLimit()} - _pwKey={signInPageTestKeys.userInactivityAlert} - message={$LL.signInPage.feelFreeToSignInAgain()} - closeable + title={$LL.signInPage.youHaveReachedInactivityLimit()} + _pwKey={signInPageTestKeys.userInactivityAlert} + message={$LL.signInPage.feelFreeToSignInAgain()} + closeable /> {/if} </div> @@ -87,43 +84,46 @@ </h2> <p class="mt-2 text-sm text-gray-600"> {$LL.or().toLowerCase()} - <a href="/sign-up" use:pwKey={signInPageTestKeys.signUpAnchor} class="link">{$LL.createANewAccount().toLowerCase()}</a> + <a href="/sign-up" use:pwKey={signInPageTestKeys.signUpAnchor} + class="link">{$LL.createANewAccount().toLowerCase()}</a> </p> </div> <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"> {#if showErrorAlert} - <Alert title={errorData.title} message={errorData.text} type="error" _pwKey={signInPageTestKeys.formErrorAlert} /> + <Alert title={errorData.title} message={errorData.text} type="error" + _pwKey={signInPageTestKeys.formErrorAlert}/> {/if} - <form class="space-y-6 mt-2" 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} - name="username" - type="email" - label={$LL.emailAddress()} - required - bind:value={data.username} + id="username" + _pwKey={signInPageTestKeys.usernameInput} + name="username" + type="email" + label={$LL.emailAddress()} + required + bind:value={data.username} /> <Input - id="password" - name="password" - type="password" - label={$LL.password()} - _pwKey={signInPageTestKeys.passwordInput} - autocomplete="current-password" - required - bind:value={data.password} + id="password" + name="password" + type="password" + label={$LL.password()} + _pwKey={signInPageTestKeys.passwordInput} + autocomplete="current-password" + required + bind:value={data.password} /> <div class="flex items-center justify-between"> <Checkbox - id="remember-me" - _pwKey={signInPageTestKeys.rememberMeCheckbox} - name="remember-me" - bind:checked={data.persist} - label={$LL.signInPage.notMyComputer()} + id="remember-me" + _pwKey={signInPageTestKeys.rememberMeCheckbox} + name="remember-me" + bind:checked={data.persist} + label={$LL.signInPage.notMyComputer()} /> <div class="text-sm"> <a href="/reset-password" class="link" use:pwKey={signInPageTestKeys.resetPasswordAnchor}> @@ -132,7 +132,7 @@ </div> </div> - <Button text={$LL.submit()} fullWidth type="submit" {loading} /> + <Button text={$LL.submit()} fullWidth type="submit" {loading}/> </form> </div> </div> |
