137 lines
5.2 KiB
Vue
137 lines
5.2 KiB
Vue
<script setup lang="ts">
|
|
import { Head, Link, useForm } from '@inertiajs/vue3';
|
|
import { KeyRound } from 'lucide-vue-next';
|
|
import { computed, onUnmounted } from 'vue';
|
|
import AuthFormFeedback from '@/components/AuthFormFeedback.vue';
|
|
import FeedbackState from '@/components/FeedbackState.vue';
|
|
import InputError from '@/components/InputError.vue';
|
|
import PasswordInput from '@/components/PasswordInput.vue';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Label } from '@/components/ui/label';
|
|
import { useFormProtection } from '@/composables/useFormProtection';
|
|
import { useLocalization } from '@/composables/useLocalization';
|
|
import AuthFlowLayout from '@/layouts/auth/AuthFlowLayout.vue';
|
|
import { request, update } from '@/routes/password';
|
|
|
|
const props = defineProps<{ token: string; email: string }>();
|
|
const { t } = useLocalization();
|
|
const form = useForm({
|
|
token: props.token,
|
|
email: props.email,
|
|
password: '',
|
|
password_confirmation: '',
|
|
}).dontRemember('token', 'email', 'password', 'password_confirmation');
|
|
const protection = useFormProtection(form, { isDirty: () => false });
|
|
const invalidLink = computed(() => Boolean(form.errors.email));
|
|
const feedbackState = computed(() =>
|
|
invalidLink.value ? 'idle' : protection.state.value,
|
|
);
|
|
const submit = (): void =>
|
|
protection.submit(update(), {
|
|
onSuccess: () => form.reset('password', 'password_confirmation'),
|
|
});
|
|
onUnmounted(() => form.reset());
|
|
</script>
|
|
|
|
<template>
|
|
<AuthFlowLayout
|
|
:title="t('auth.reset.title')"
|
|
:description="t('auth.reset.description')"
|
|
:icon="KeyRound"
|
|
>
|
|
<Head :title="t('auth.reset.title')" />
|
|
<FeedbackState
|
|
v-if="invalidLink"
|
|
state="error"
|
|
:title="t('auth.reset.invalidTitle')"
|
|
:description="form.errors.email"
|
|
>
|
|
<Button as-child variant="outline" class="w-full">
|
|
<Link :href="request()">{{ t('auth.reset.requestNew') }}</Link>
|
|
</Button>
|
|
</FeedbackState>
|
|
<form
|
|
:action="update.url()"
|
|
method="post"
|
|
class="grid gap-5"
|
|
@submit.prevent="submit"
|
|
>
|
|
<AuthFormFeedback
|
|
:state="feedbackState"
|
|
:response-status="protection.responseStatus.value"
|
|
:loading-title="t('auth.reset.pending')"
|
|
@retry="submit"
|
|
/>
|
|
<input type="hidden" name="token" :value="form.token" />
|
|
<div class="gap-stack grid">
|
|
<Label for="email">{{ t('auth.reset.email') }}</Label>
|
|
<Input
|
|
id="email"
|
|
v-model="form.email"
|
|
name="email"
|
|
type="email"
|
|
autocomplete="username"
|
|
readonly
|
|
:disabled="form.processing"
|
|
:invalid="Boolean(form.errors.email)"
|
|
aria-describedby="email-error"
|
|
/>
|
|
<InputError id="email-error" :message="form.errors.email" />
|
|
</div>
|
|
<div class="gap-stack grid">
|
|
<Label for="password">{{ t('auth.reset.password') }}</Label>
|
|
<PasswordInput
|
|
id="password"
|
|
v-model="form.password"
|
|
name="password"
|
|
autocomplete="new-password"
|
|
required
|
|
autofocus
|
|
:disabled="form.processing"
|
|
:invalid="Boolean(form.errors.password)"
|
|
aria-describedby="password-hint password-error"
|
|
/>
|
|
<p
|
|
id="password-hint"
|
|
class="text-caption text-muted-foreground"
|
|
>
|
|
{{ t('auth.reset.passwordHint') }}
|
|
</p>
|
|
<InputError
|
|
id="password-error"
|
|
:message="form.errors.password"
|
|
/>
|
|
</div>
|
|
<div class="gap-stack grid">
|
|
<Label for="password_confirmation">{{
|
|
t('auth.reset.passwordConfirmation')
|
|
}}</Label>
|
|
<PasswordInput
|
|
id="password_confirmation"
|
|
v-model="form.password_confirmation"
|
|
name="password_confirmation"
|
|
autocomplete="new-password"
|
|
required
|
|
:disabled="form.processing"
|
|
:invalid="Boolean(form.errors.password_confirmation)"
|
|
aria-describedby="password-confirmation-error"
|
|
/>
|
|
<InputError
|
|
id="password-confirmation-error"
|
|
:message="form.errors.password_confirmation"
|
|
/>
|
|
</div>
|
|
<Button
|
|
type="submit"
|
|
class="w-full"
|
|
:loading="form.processing"
|
|
:loading-label="t('auth.reset.pending')"
|
|
data-test="reset-password-button"
|
|
>{{ t('auth.reset.submit') }}</Button
|
|
>
|
|
</form>
|
|
<template #footer>{{ t('auth.reset.footer') }}</template>
|
|
</AuthFlowLayout>
|
|
</template>
|