-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client validation and more reusable components using generic names fo…
…r async state, also api returns promises and performs store logic
- Loading branch information
1 parent
919144c
commit 40ec139
Showing
3 changed files
with
93 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,53 @@ | ||
<script> | ||
import { updateUserSecuritySettings, authUserStore, updateUserSettings } from "../stores/netlifyUserStore"; | ||
import Spinner from 'svelte-spinner'; | ||
import DefaultSpinner from '../components/DefaultSpinner.svelte' | ||
import { navigate } from "svelte-routing"; | ||
import { authUserStore, updateUserSecuritySettings } from '../stores/netlifyUserStore'; | ||
if (!$authUserStore) { | ||
navigate("/", { replace: true }); | ||
} | ||
const clonedUser = Object.assign({}, $authUserStore); | ||
let pendingUpdateUserSettings = false | ||
let successUpdateUserSettings = false | ||
let successUpdateUserCustomSettings = false | ||
let pendingUpdateUserCustomSettings = false | ||
console.log($authUserStore) | ||
let password = "" | ||
let email = $authUserStore.email | ||
let showSuccessMessage1 = false | ||
let pendingApiCall1 = false | ||
export function handlerSecurity (email, password) { | ||
pendingUpdateUserSettings = true | ||
export function submit1 (event) { | ||
pendingApiCall1 = true | ||
updateUserSecuritySettings(email, password).then(newUser => { | ||
successUpdateUserSettings = true | ||
pendingUpdateUserSettings = false | ||
showSuccessMessage1 = true | ||
pendingApiCall1 = false | ||
}).catch(e => { | ||
pendingUpdateUserSettings = false | ||
}); | ||
} | ||
export function handlerCustomData (name) { | ||
pendingUpdateUserCustomSettings = true | ||
updateUserSettings({name:name}).then(newUser => { | ||
successUpdateUserCustomSettings = true | ||
pendingUpdateUserCustomSettings = false | ||
}).catch(e => { | ||
pendingUpdateUserCustomSettings = false | ||
pendingApiCall1 = false | ||
console.log(e) | ||
alert(e.message) | ||
}); | ||
} | ||
</script> | ||
<h1>Your custom settings</h1> | ||
|
||
<input placeholder="name" bind:value={$authUserStore.name}> | ||
<button on:click={()=>handlerCustomData($authUserStore.email,$authUserStore.password)}>Update Settings</button> | ||
<div> | ||
<input type="checkbox" placeholder="lala"> | ||
</div> | ||
{#if successUpdateUserCustomSettings} | ||
<h2>You have successfully updated your settings</h2> | ||
{:else if pendingUpdateUserCustomSettings} | ||
<Spinner></Spinner> | ||
{/if} | ||
|
||
<hr> | ||
|
||
<h2>Security</h2> | ||
<input placeholder="email" bind:value={clonedUser.email}> | ||
<input placeholder="password" type="password" bind:value={clonedUser.password}> | ||
<button on:click={()=>handlerSecurity(clonedUser.email,clonedUser.password)}>Update Security Settings</button> | ||
<div> | ||
<h1>Security Settings</h1> | ||
<form on:submit|preventDefault={submit1}> | ||
<input | ||
id="inline-full-name" type="email" required placeholder="Email" bind:value="{email}"> | ||
<input | ||
id="inline-username" type="password" required placeholder="Your password" bind:value="{password}"> | ||
|
||
|
||
<button | ||
>Update Security Settings | ||
</button> | ||
{#if pendingApiCall1} | ||
<DefaultSpinner></DefaultSpinner> | ||
{/if} | ||
</form> | ||
{#if showSuccessMessage1} | ||
<p>Your Security Settings have been updated.</p> | ||
{/if} | ||
|
||
{#if successUpdateUserSettings} | ||
<h2>You have successfully updated your settings</h2> | ||
{:else if pendingUpdateUserSettings} | ||
<Spinner></Spinner> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,46 @@ | ||
<script> | ||
import { signin } from "../stores/netlifyUserStore"; | ||
import DefaultSpinner from '../components/DefaultSpinner.svelte' | ||
import { navigate } from "svelte-routing"; | ||
import { authUserStore } from '../stores/netlifyUserStore'; | ||
if ($authUserStore) { | ||
navigate("/", { replace: true }); | ||
} | ||
let password = "" | ||
let email = "" | ||
let pendingApiCall = false | ||
export function submit (event) { | ||
pendingApiCall = true | ||
signin(email, password).catch(e => { | ||
pendingApiCall = false | ||
}); | ||
} | ||
</script> | ||
<h1>Signin</h1> | ||
|
||
<input placeholder="email" bind:value={email}> | ||
<input placeholder="password" type="password" bind:value={password}> | ||
<button on:click={()=>signin(email,password,true)}>Signin</button> | ||
|
||
<div> | ||
|
||
<div> | ||
<h1>Login Details</h1> | ||
<form on:submit|preventDefault={submit} id="main-form"> | ||
|
||
<input | ||
id="inline-full-name" type="email" required placeholder="Email" bind:value="{email}"> | ||
<input | ||
id="inline-username" type="password" required placeholder="Your password" bind:value="{password}"> | ||
|
||
<button | ||
>Signin | ||
</button> | ||
{#if pendingApiCall} | ||
<DefaultSpinner></DefaultSpinner> | ||
{/if} | ||
</form> | ||
|
||
|
||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters