11<script setup lang="ts">
2- import { ref } from ' vue' ;
32import * as yup from ' yup' ;
43import { useForm } from ' vee-validate' ;
54import { useLoginStore } from ' ~/stores/auth/login' ;
65import { showToaster } from ' @/utils/showToaster' ;
76
87const loginStore = useLoginStore ();
9- const error = ref (' ' );
108
119const schema = yup .object ({
12- identifier: yup .string (),
10+ identifier: yup .string (). trim (). required ( $t ( ' errors.IDENTIFIER_REQUIRED ' )) ,
1311});
1412
15- const { defineField, handleSubmit, resetForm } = useForm ({
13+ const { defineField, handleSubmit, isSubmitting, meta } = useForm ({
1614 validationSchema: schema ,
1715 initialValues: {
1816 identifier: ' ' ,
1917 },
20- validateOnMount: true ,
18+ validateOnMount: false ,
2119});
2220
2321const onSubmit = handleSubmit (async (values ) => {
24- error .value = ' ' ;
25-
2622 try {
27- if (! values .identifier || values .identifier .trim () === ' ' ) {
28- throw new Error ($t (' errors.IDENTIFIER_REQUIRED' ));
29- }
30- const success = await loginStore .checkIdentifierExists (values .identifier );
23+ const success = await loginStore .checkUserExists (values .identifier .trim ());
3124 if (! success ) {
3225 throw new Error ($t (' errors.USER_NOT_FOUND' ));
3326 }
34- resetForm ({ values: { identifier: ' ' } });
3527 } catch (err : unknown ) {
36- if (err instanceof Error ) {
37- error .value = err .message || $t (' errors.GENERIC_ERROR' );
38- showToaster (' error' , error .value );
39- } else {
40- error .value = $t (' errors.GENERIC_ERROR' );
41- showToaster (' error' , error .value );
42- }
43- console .error (' Identifier check error:' , error .value );
28+ showToaster (' error' , (err as Error ).message || $t (' errors.GENERIC_ERROR' ));
4429 }
4530});
4631const [_identifier, identifierAttrs] = defineField (' identifier' );
4732 </script >
4833
4934<template >
5035 <form @submit.prevent =" onSubmit" >
51- <UiDialogHeader class="mt-3 px-8 py-4">
52- <UiDialogTitle class="mx-auto w-75 text-3xl font-bold">{{
53- $t('Sign in to Raven ')
36+ <UiDialogHeader class="mt-1 px-8 py-4">
37+ <UiDialogTitle class="mx-auto w-75 text-start text- 3xl font-bold">{{
38+ $t('login.identifier-step.title ')
5439 }}</UiDialogTitle >
5540 </UiDialogHeader >
56- <div class =" mx-auto mt-7 w-75" >
41+ <div class =" mx-auto mt-5 w-75" >
5742 <section class =" flex flex-col gap-4" >
5843 <UiButton
5944 class="bg-oauth dark:hover :bg-oauth /80 hover:bg-oauth /110 border-foreground mb-1 border text-black"
@@ -62,7 +47,7 @@ const [_identifier, identifierAttrs] = defineField('identifier');
6247 data-testid="google-button"
6348 >
6449 <Icon name="devicon:google " width="128" height="128"></Icon >
65- {{ $t('root.auth .google-signin') }}</UiButton
50+ {{ $t('login.identifier-step .google-signin') }}</UiButton
6651 >
6752 <UiButton
6853 class="bg-oauth dark:hover :bg-oauth /80 hover:bg-oauth /110 border-foreground mb-1 border text-black"
@@ -71,23 +56,28 @@ const [_identifier, identifierAttrs] = defineField('identifier');
7156 data-testid="github-button"
7257 >
7358 <Icon name="devicon:github " width="128" height="128"></Icon >
74- {{ $t('root.auth .github-signin') }}</UiButton
59+ {{ $t('login.identifier-step .github-signin') }}</UiButton
7560 >
7661 </section >
7762 <p class =" py-2 text-center" >{{ $t('root.auth.separator') }}</p >
7863 <section class =" flex flex-col gap-4" >
7964 <UiFormFieldInput
80- class="mb-4"
81- placeholder="email or username"
65+ :placeholder =" $t (' login.email-or-username' )"
8266 type="text"
8367 name="identifier"
8468 v-bind =" identifierAttrs "
8569 data-testid="identifier-input"
8670 ></UiFormFieldInput >
8771 </section >
8872 </div >
89- <UiDialogFooter >
90- <UiButton class="mb-1 w-75" size="lg" type="submit" data-testid="submit-button">
73+ <UiDialogFooter class="absolute end-0 bottom-15 w-full">
74+ <UiButton
75+ class="mb-1 w-75"
76+ size="lg"
77+ type="submit"
78+ data-testid="submit-button"
79+ :disabled =" ! meta .valid || isSubmitting "
80+ >
9181 {{ $t('ui.next') }}
9282 </UiButton >
9383 <UiButton
@@ -96,18 +86,20 @@ const [_identifier, identifierAttrs] = defineField('identifier');
9686 variant="outline"
9787 type="button"
9888 data-testid="forgot-password-button"
89+ @click =" loginStore .openForgotPasswordDialog "
9990 >
100- {{ $t('root.auth.forget -password') }}
91+ {{ $t('login.forgot -password') }}
10192 </UiButton >
10293 <p class =" mt-6" >
103- {{ $t('root.auth.dont-have-account') }}
104- <NuxtLink to="/auth/signup" class="text-primary" data-testid="signup-link">
105- {{ $t('root.auth.signup') }}
106- </NuxtLink >
94+ {{ $t('login.dont-have-account') }}
95+ <span
96+ class =" text-primary cursor-pointer hover:underline"
97+ data-testid =" signup-link"
98+ @click =" loginStore.openSignupDialog"
99+ >
100+ {{ $t('login.signup') }}
101+ </span >
107102 </p >
108- <!-- <Transition name="fade"
109- ><p v-if="error" class="mt-3 text-red-500">{{ error }}</p></Transition
110- > -->
111103 </UiDialogFooter >
112104 </form >
113105</template >
0 commit comments