From b4a8720f6ddb1fb8bf9ee41628982e704852e699 Mon Sep 17 00:00:00 2001
From: ivarlovlie <git@ivarlovlie.no>
Date: Sat, 26 Nov 2022 23:07:00 +0900
Subject: refactor: Final touches for move to service

---
 .../(main)/(public)/reset-password/+page.svelte    | 25 +++++++++++-----------
 1 file changed, 12 insertions(+), 13 deletions(-)

(limited to 'code/app/src/routes/(main)/(public)/reset-password/+page.svelte')

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 eb02b45..2b34dfc 100644
--- a/code/app/src/routes/(main)/(public)/reset-password/+page.svelte
+++ b/code/app/src/routes/(main)/(public)/reset-password/+page.svelte
@@ -12,16 +12,16 @@
     };
 
     const formError = new FormError();
-
     const resetRequests = new PasswordResetService();
 
     let loading = false;
     let showSuccessAlert = false;
-    $: showErrorAlert = formError.has_error() && !showSuccessAlert;
+    let showErrorAlert = false;
 
     async function submit_form_async() {
         formError.set();
         showSuccessAlert = false;
+        showErrorAlert = false;
         loading = true;
         const response = await resetRequests.create_request_async(formData.email.value);
         loading = false;
@@ -31,13 +31,16 @@
             formError.set_from_known_problem(response.knownProblem);
             for (const error of Object.entries(response.knownProblem.errors)) {
                 if (error[0] === "email") {
-                    error[1].forEach(formData.email.errors.push);
+                    let errors = [];
+                    error[1].forEach((e) => errors.push(e));
+                    formData.email.errors = errors;
                 }
             }
         } else {
             formError.title = $LL.unexpectedError();
             formError.subtitle = $LL.tryAgainSoon();
         }
+        showErrorAlert = formError.has_error() && !showSuccessAlert;
     }
 </script>
 
@@ -57,23 +60,19 @@
     <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={submit_form_async}>
-                <Alert title={formError.title} message={formError.subtitle} type="error" visible={showErrorAlert} />
-
-                <Alert
-                    type="success"
-                    title={$LL.success()}
-                    message={$LL.resetPasswordPage.requestSentMessage()}
-                    visible={showSuccessAlert}
-                />
-
+                {#if showErrorAlert}
+                    <Alert title={formError.title} message={formError.subtitle} type="error" />
+                {:else if showSuccessAlert}
+                    <Alert type="success" title={$LL.success()} message={$LL.resetPasswordPage.requestSentMessage()} />
+                {/if}
                 <Input
                     id="email"
                     name="email"
                     type="email"
                     autocomplete="email"
                     errors={formData.email.errors}
-                    required
                     bind:value={formData.email.value}
+                    required
                     label={$LL.emailAddress()}
                 />
                 <Button text={$LL.submit()} type="submit" {loading} fullWidth />
-- 
cgit v1.3

