Init work with making field required

This commit is contained in:
Ibitoye Rotimi Best
2021-07-26 07:49:05 +03:00
parent 950653d669
commit 2e596cd6fb
4 changed files with 30 additions and 7 deletions
+7 -2
View File
@@ -2,12 +2,17 @@
export let label; export let label;
export let value; export let value;
export let options = []; export let options = [];
export let valueKey = "id"; export let valueKey = 'id';
export let isRequired = false;
</script> </script>
<label class="block"> <label class="block">
{#if label} <span class="text-gray-700">{label}</span> {/if} {#if label} <span class="text-gray-700">{label}</span> {/if}
<select bind:value class="form-select block w-full mt-1"> <select
bind:value
class="form-select block w-full mt-1"
required={isRequired}
>
{#each options as option} {#each options as option}
<option value={option[valueKey]}> <option value={option[valueKey]}>
{option.text} {option.text}
+7 -1
View File
@@ -8,11 +8,16 @@
export let inputClassName = ''; export let inputClassName = '';
export let type = 'text'; export let type = 'text';
export let autoFocus = false; export let autoFocus = false;
export let isRequired = false;
let ref = null; let ref;
function typeAction(node) { function typeAction(node) {
node.type = type; node.type = type;
if (isRequired) {
node.required = '';
}
} }
afterUpdate(() => { afterUpdate(() => {
@@ -31,5 +36,6 @@
{placeholder} {placeholder}
bind:value bind:value
bind:this={ref} bind:this={ref}
required={true}
/> />
</label> </label>
+14 -3
View File
@@ -2,6 +2,7 @@
import TextField from '../components/Form/TextField.svelte'; import TextField from '../components/Form/TextField.svelte';
import Select from '../components/Form/Select.svelte'; import Select from '../components/Form/Select.svelte';
import PrimaryButton from '../components/PrimaryButton/index.svelte'; import PrimaryButton from '../components/PrimaryButton/index.svelte';
import { supabase } from '../utils/functions/supabase';
let email; let email;
let userType = 0; let userType = 0;
@@ -20,9 +21,17 @@
value: 2, value: 2,
}, },
]; ];
async function handleSubmit() {
function handleSubmit() { try {
console.log(`email`, email); loading = true;
const { error } = await supabase.auth.signIn({ email });
if (error) throw error;
alert('Check your email for the login link!');
} catch (error) {
alert(error.error_description || error.message);
} finally {
loading = false;
}
} }
</script> </script>
@@ -52,6 +61,7 @@
bind:value={userType} bind:value={userType}
options={userTypes} options={userTypes}
valueKey="value" valueKey="value"
isRequired={true}
/> />
</div> </div>
@@ -64,6 +74,7 @@
placeholder="Enter your email" placeholder="Enter your email"
onKeyDown={handleSubmit} onKeyDown={handleSubmit}
inputClassName="rounded-md w-full px-2 py-4" inputClassName="rounded-md w-full px-2 py-4"
isRequired={true}
/> />
<p class="py-3 text-sm"> <p class="py-3 text-sm">
A magic link will be sent to your email, please open the link A magic link will be sent to your email, please open the link
+2 -1
View File
@@ -1,6 +1,7 @@
import { createClient } from '@supabase/supabase-js'; import { createClient } from '@supabase/supabase-js';
import config from '../../config'; import getConfig from '../../config';
const config = getConfig();
export const supabase = createClient( export const supabase = createClient(
config.supabaseConfig.url, config.supabaseConfig.url,