Skip to content

Commit

Permalink
chore(demom): add demo signin form
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuagraber committed Jun 18, 2024
1 parent 45418b9 commit 7ef1859
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
113 changes: 113 additions & 0 deletions src/demo/pages/SignupFormDemo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<template>
<main>
<Form
:error="error"
:schema="SCHEMA"

Check failure on line 5 in src/demo/pages/SignupFormDemo.vue

View workflow job for this annotation

GitHub Actions / build

Type '({ 'data-test': string; id: string; name: string; label: string; type: string; placeholder: string; value: string; validators: { email: { message: string; value: boolean; }; password?: undefined; }; } | { ...; })[]' is not assignable to type 'PdapFormSchema'.

Check failure on line 5 in src/demo/pages/SignupFormDemo.vue

View workflow job for this annotation

GitHub Actions / lint

Type '({ 'data-test': string; id: string; name: string; label: string; type: string; placeholder: string; value: string; validators: { email: { message: string; value: boolean; }; password?: undefined; }; } | { ...; })[]' is not assignable to type 'PdapFormSchema'.
:reset-on="reset"
@submit="onSubmit"
@change="handleChangeOnError"
>
<Button type="submit">Submit</Button>
</Form>
</main>
</template>

<script setup lang="ts">
import { Button, Form } from '../../components';
import { ref } from 'vue';
// Constants
const SCHEMA = [
{
'data-test': 'email',
id: 'email',
name: 'email',
label: 'Email',
type: 'text',
placeholder: 'Your email address',
value: '',
validators: {
email: {
message: 'Please provide your email address',
value: true,
},
},
},
{
'data-test': 'password',
id: 'password',
name: 'password',
label: 'Password',
type: 'password',
placeholder: 'Your password',
value: '',
validators: {
password: {
message: 'Please provide your password',
value: true,
},
},
},
{
'data-test': 'confirm-password',
id: 'confirmPassword',
name: 'confirmPassword',
label: 'Confirm Password',
type: 'password',
placeholder: 'Confirm your password',
value: '',
validators: {
password: {
message: 'Please confirm your password',
value: true,
},
},
},
];
const error = ref(undefined);
const reset = ref(false);
/**
* When signing up: handles clearing pw-match form errors on change if they exist
*/
function handleChangeOnError(formValues) {

Check failure on line 74 in src/demo/pages/SignupFormDemo.vue

View workflow job for this annotation

GitHub Actions / build

Parameter 'formValues' implicitly has an 'any' type.

Check failure on line 74 in src/demo/pages/SignupFormDemo.vue

View workflow job for this annotation

GitHub Actions / lint

Parameter 'formValues' implicitly has an 'any' type.
console.debug('onchange', { e: error.value, formValues: formValues.value });
if (error.value && formValues.password !== formValues.confirmPassword) {
handlePasswordValidation(formValues);
}
}
/**
* When signing up: validates that passwords match
* @returns {boolean} `false` if passwords do not match, `true` if they do
*/
function handlePasswordValidation(formValues) {

Check failure on line 86 in src/demo/pages/SignupFormDemo.vue

View workflow job for this annotation

GitHub Actions / build

Parameter 'formValues' implicitly has an 'any' type.

Check failure on line 86 in src/demo/pages/SignupFormDemo.vue

View workflow job for this annotation

GitHub Actions / lint

Parameter 'formValues' implicitly has an 'any' type.
console.debug('validate', { e: error.value });
if (formValues.password !== formValues.confirmPassword) {
if (!error.value) {
error.value = 'Passwords do not match, please try again.';

Check failure on line 91 in src/demo/pages/SignupFormDemo.vue

View workflow job for this annotation

GitHub Actions / build

Type '"Passwords do not match, please try again."' is not assignable to type 'undefined'.

Check failure on line 91 in src/demo/pages/SignupFormDemo.vue

View workflow job for this annotation

GitHub Actions / lint

Type '"Passwords do not match, please try again."' is not assignable to type 'undefined'.
}
return false;
} else {
error.value = undefined;
return true;
}
}
/**
* Logs user in or signs user up
*/
function onSubmit(formValues) {

Check failure on line 103 in src/demo/pages/SignupFormDemo.vue

View workflow job for this annotation

GitHub Actions / build

Parameter 'formValues' implicitly has an 'any' type.

Check failure on line 103 in src/demo/pages/SignupFormDemo.vue

View workflow job for this annotation

GitHub Actions / lint

Parameter 'formValues' implicitly has an 'any' type.
console.debug('onsubmit', { e: error.value });
if (!handlePasswordValidation(formValues)) {
return;
} else {
reset.value = true;
}
console.debug({ formValues });
}
</script>
6 changes: 6 additions & 0 deletions src/demo/router.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createRouter, createWebHistory } from 'vue-router';
import ComponentDemo from './pages/ComponentDemo.vue';
import SignupFormDemo from './pages/SignupFormDemo.vue';

const routes = [
{
Expand Down Expand Up @@ -40,6 +41,11 @@ const routes = [
},
],
},
{
path: '/sign-up-demo',
component: SignupFormDemo,
name: 'Login Demo',
},
];

const router = createRouter({
Expand Down

0 comments on commit 7ef1859

Please sign in to comment.