diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-06-02 23:02:22 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-06-02 23:02:22 +0200 |
| commit | 83b11393da8f733c0ffc5abed5d1e0e827d04b61 (patch) | |
| tree | 0b8f1062cc7435576165c7eb1d8745842acc6c32 /apps/accounts/src/app/pages/sign-up.svelte | |
| parent | 53865dad18012512f90d235f4d2833469dcc1685 (diff) | |
| download | greatoffice-83b11393da8f733c0ffc5abed5d1e0e827d04b61.tar.xz greatoffice-83b11393da8f733c0ffc5abed5d1e0e827d04b61.zip | |
refactor: Rename accounts to portal
Diffstat (limited to 'apps/accounts/src/app/pages/sign-up.svelte')
| -rw-r--r-- | apps/accounts/src/app/pages/sign-up.svelte | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/apps/accounts/src/app/pages/sign-up.svelte b/apps/accounts/src/app/pages/sign-up.svelte deleted file mode 100644 index 80780e0..0000000 --- a/apps/accounts/src/app/pages/sign-up.svelte +++ /dev/null @@ -1,128 +0,0 @@ -<script> - import {create_account} from "$shared/lib/api/user"; - import {is_email} from "$shared/lib/helpers"; - import Alert from "$shared/components/alert.svelte"; - import Button from "$shared/components/button.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> - <form - on:submit|preventDefault={signupForm.submit_form} - class="margin-bottom-md max-width-xxs" - > - <fieldset> - <legend class="form-legend"> - <span class="margin-bottom-xs">Create your account</span> <br/> - <span class="text-sm" - >... or <a href="/login" - use:link>log in</a></span - > - </legend> - <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="Submit" - type="primary" - loading={signupForm.loading} - /> - </div> - </fieldset> - </form> -</Layout> |
