From c0746289e8ff1c4509ea544469333baf116dbeb8 Mon Sep 17 00:00:00 2001
From: ivarlovlie <git@ivarlovlie.no>
Date: Mon, 10 Oct 2022 00:38:10 +0800
Subject: refactor: Update imports and clean up

---
 code/app/src/routes/(main)/(public)/sign-in/+page.svelte | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

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

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}
-- 
cgit v1.3

