123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import { Transition } from '@headlessui/react';
- import { Form, Head } from '@inertiajs/react';
- import { useRef } from 'react';
- import PasswordController from '@/actions/App/Http/Controllers/Settings/PasswordController';
- import { HeadingSmall } from '@/common/HeadingSmall';
- import { InputError } from '@/common/InputError';
- import { type BreadcrumbItem } from '@/common/types';
- import AppLayout from '@/pages/layouts/AppLayout';
- import SettingsLayout from '@/pages/layouts/settings/layout';
- import { edit } from '@/routes/password';
- import { Button } from '@/shadcn/button';
- import { Input } from '@/shadcn/input';
- import { Label } from '@/shadcn/label';
- const breadcrumbs: BreadcrumbItem[] = [
- {
- title: 'Password settings',
- href: edit().url,
- },
- ];
- export default function PasswordPage() {
- const passwordInput = useRef<HTMLInputElement>(null);
- const currentPasswordInput = useRef<HTMLInputElement>(null);
- return (
- <AppLayout breadcrumbs={breadcrumbs}>
- <Head title="Password settings" />
- <SettingsLayout>
- <div className="space-y-6">
- <HeadingSmall title="Update password" description="Ensure your account is using a long, random password to stay secure" />
- <Form
- {...PasswordController.update.form()}
- options={{
- preserveScroll: true,
- }}
- resetOnError={['password', 'password_confirmation', 'current_password']}
- resetOnSuccess
- onError={(errors) => {
- if (errors.password) {
- passwordInput.current?.focus();
- }
- if (errors.current_password) {
- currentPasswordInput.current?.focus();
- }
- }}
- className="space-y-6"
- >
- {({ errors, processing, recentlySuccessful }) => (
- <>
- <div className="grid gap-2">
- <Label htmlFor="current_password">Current password</Label>
- <Input
- id="current_password"
- ref={currentPasswordInput}
- name="current_password"
- type="password"
- className="mt-1 block w-full"
- autoComplete="current-password"
- placeholder="Current password"
- />
- <InputError message={errors.current_password} />
- </div>
- <div className="grid gap-2">
- <Label htmlFor="password">New password</Label>
- <Input
- id="password"
- ref={passwordInput}
- name="password"
- type="password"
- className="mt-1 block w-full"
- autoComplete="new-password"
- placeholder="New password"
- />
- <InputError message={errors.password} />
- </div>
- <div className="grid gap-2">
- <Label htmlFor="password_confirmation">Confirm password</Label>
- <Input
- id="password_confirmation"
- name="password_confirmation"
- type="password"
- className="mt-1 block w-full"
- autoComplete="new-password"
- placeholder="Confirm password"
- />
- <InputError message={errors.password_confirmation} />
- </div>
- <div className="flex items-center gap-4">
- <Button disabled={processing}>Save password</Button>
- <Transition
- show={recentlySuccessful}
- enter="transition ease-in-out"
- enterFrom="opacity-0"
- leave="transition ease-in-out"
- leaveTo="opacity-0"
- >
- <p className="text-sm text-neutral-600">Saved</p>
- </Transition>
- </div>
- </>
- )}
- </Form>
- </div>
- </SettingsLayout>
- </AppLayout>
- );
- }
|