-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChooseNewPassword.vue
More file actions
80 lines (72 loc) · 2.49 KB
/
Copy pathChooseNewPassword.vue
File metadata and controls
80 lines (72 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<script setup lang="ts">
import * as yup from 'yup';
import { useForm } from 'vee-validate';
import { usePasswordStore } from '~/stores/auth/password';
import { showToaster } from '@/utils/showToaster';
import { createPasswordSchema } from '~/schemas/auth';
const passwordStore = usePasswordStore();
const { t } = useI18n();
const schema = yup.object({
newPassword: createPasswordSchema(t),
confirmPassword: createPasswordSchema(t).oneOf(
[yup.ref('newPassword')],
t('errors.PASSWORD_MISMATCH'),
),
});
const { defineField, handleSubmit, isSubmitting, meta } = useForm({
validationSchema: schema,
initialValues: { newPassword: '', confirmPassword: '' },
validateOnMount: false,
});
const [_newPassword, newPasswordAttrs] = defineField('newPassword');
const [_confirmPassword, confirmPasswordAttrs] = defineField('confirmPassword');
const onSubmit = handleSubmit(async (values) => {
try {
await passwordStore.resetPassword(values.newPassword.trim());
} catch (err: unknown) {
showToaster('error', (err as Error).message || t('errors.GENERIC_ERROR'));
}
});
</script>
<template>
<form @submit.prevent="onSubmit">
<UiDialogHeader class="mt-3 w-fit px-8 py-4">
<UiDialogTitle class="text-3xl font-bold">
{{ $t('forgot-password.new-password.title') }}
</UiDialogTitle>
<p class="text-muted-foreground mx-auto mt-2 text-sm">
{{ $t('forgot-password.new-password.description') }}
</p>
<p class="text-muted-foreground mx-auto mt-2 text-sm">
{{ $t('forgot-password.new-password.warning') }}
</p>
</UiDialogHeader>
<div class="mx-auto mt-2 px-8">
<section class="flex flex-col gap-6">
<UiFormFieldPassword
:placeholder="$t('forgot-password.new-password.password.label')"
name="newPassword"
v-bind="newPasswordAttrs"
data-testid="new-password-input"
/>
<UiFormFieldPassword
:placeholder="$t('forgot-password.new-password.confirm-password.label')"
name="confirmPassword"
v-bind="confirmPasswordAttrs"
data-testid="confirm-password-input"
/>
</section>
</div>
<UiDialogFooter class="absolute end-0 bottom-8 w-full">
<UiButton
class="w-100"
size="xl"
type="submit"
data-testid="submit-button"
:disabled="!meta.valid || isSubmitting"
>
{{ $t('forgot-password.new-password.change-password-button') }}
</UiButton>
</UiDialogFooter>
</form>
</template>