From a9072370ca1eb9a5cce928b1d487db0f307edea6 Mon Sep 17 00:00:00 2001
From: ivarlovlie <git@ivarlovlie.no>
Date: Tue, 20 Sep 2022 15:24:27 +0800
Subject: feat: Move old apps into it's own directory

---
 old-apps/portal/src/app/pages/sign-up.svelte | 131 +++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)
 create mode 100644 old-apps/portal/src/app/pages/sign-up.svelte

(limited to 'old-apps/portal/src/app/pages/sign-up.svelte')

diff --git a/old-apps/portal/src/app/pages/sign-up.svelte b/old-apps/portal/src/app/pages/sign-up.svelte
new file mode 100644
index 0000000..3bcab6d
--- /dev/null
+++ b/old-apps/portal/src/app/pages/sign-up.svelte
@@ -0,0 +1,131 @@
+<script>
+	import {create_account} from "$shared/lib/api/user";
+	import {frontpage_base} from "$shared/lib/configuration";
+	import {is_email} from "$shared/lib/helpers";
+	import Alert from "$shared/components/alert.svelte";
+	import Button from "$shared/components/button.svelte";
+	import Tile from "$shared/components/tile.svelte";
+	import {link} from "svelte-spa-router";
+	import Layout from "./_layout.svelte";
+
+	const signupForm = {
+		loading: false,
+		values: {
+			username: "",
+			password: "",
+		},
+		alert: {
+			title: "",
+			type: "",
+			message: "",
+			isVisible: false,
+			show(type, obj) {
+				signupForm.alert.title = obj.title;
+				signupForm.alert.message = obj.text;
+				signupForm.alert.type = type;
+				signupForm.alert.isVisible = true;
+				signupForm.loading = false;
+			},
+			hide() {
+				signupForm.alert.isVisible = false;
+				signupForm.alert.title = "";
+				signupForm.alert.message = "";
+				signupForm.alert.type = "";
+			},
+		},
+		is_valid() {
+			return (
+				is_email(signupForm.values.username) &&
+				signupForm.values.password.length > 0
+			);
+		},
+		async submit_form() {
+			if (signupForm.loading) {
+				return;
+			}
+			if (signupForm.is_valid()) {
+				signupForm.alert.hide();
+				signupForm.loading = true;
+				try {
+					const response = await create_account(signupForm.values);
+					if (response.ok) {
+						location.reload();
+					} else {
+						if (response.data.title || response.data.text) {
+							signupForm.alert.show("error", {
+								title: response.data.title ?? "",
+								text: response.data.text ?? "",
+							});
+						} else {
+							signupForm.alert.show("error", {
+								title: "An unknown error occured",
+								text: "Try again soon",
+							});
+						}
+					}
+				} catch (e) {
+					console.error(e);
+					signupForm.alert.show("error", {
+						title: "An error occured",
+						text: "Could not connect to server, please check your internet connection",
+					});
+				}
+			} else {
+				signupForm.alert.show("error", {
+					title: "Invalid form",
+				});
+			}
+		},
+	};
+</script>
+
+<Layout>
+    <a href="{frontpage_base()}"
+       class="block margin-bottom-xs">Go to {frontpage_base()}</a>
+    <Tile>
+        <form on:submit|preventDefault={signupForm.submit_form}
+              class="max-width-xxs">
+            <fieldset>
+                <legend class="form-legend">
+                    <span class="margin-bottom-xs text-xl">Create your account</span> <br/>
+                    <span class="text-sm"
+                    >... or <a href="/login"
+                               use:link>log in</a></span
+                    >
+                </legend>
+                <div class="margin-bottom-xs">
+                    <p>Provide an email and password to get immediate access to your new environment (30 days full access, no billing details required, no promotion emails).</p>
+                </div>
+                <div class="margin-bottom-xxs max-width-xxs">
+                    <Alert visible={signupForm.alert.isVisible}
+                           title={signupForm.alert.title}
+                           message={signupForm.alert.message}
+                           type={signupForm.alert.type}
+                    />
+                </div>
+                <div class="margin-bottom-xxs">
+                    <input type="email"
+                           placeholder="Email address"
+                           class="form-control width-100%"
+                           id="email-address"
+                           bind:value={signupForm.values.username}
+                    />
+                </div>
+                <div class="margin-bottom-xxs">
+                    <input type="password"
+                           placeholder="Password"
+                           class="form-control width-100%"
+                           bind:value={signupForm.values.password}
+                    />
+                </div>
+                <div class="flex justify-end">
+                    <Button class="margin-bottom-xs"
+                            text="Create account"
+                            type="primary"
+                            loading={signupForm.loading}
+                    />
+                </div>
+            </fieldset>
+        </form>
+    </Tile>
+</Layout>
-- 
cgit v1.3

