dstpabuaran.com/resources/js/pages/settings/security.tsx
Yoga Pangestu aecd8eaf1f Refactor security settings page and update password functionality
- Translated UI elements to Indonesian for better localization.
- Improved layout by introducing Card components for better visual structure.
- Removed unnecessary imports and props related to passkeys and two-factor authentication.
- Updated tests to cover new password update scenarios and validation rules.
- Ensured proper redirection and error handling for unauthorized access to security settings.
- Enhanced user experience by adding success flash messages on password updates.
2026-07-30 22:08:24 +07:00

127 lines
5.4 KiB
TypeScript

import SecurityController from '@/actions/App/Http/Controllers/Settings/SecurityController';
import InputError from '@/components/input-error';
import PasswordInput from '@/components/password-input';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import { Label } from '@/components/ui/label';
import { edit } from '@/routes/security';
import { Form, Head } from '@inertiajs/react';
import { useRef } from 'react';
type Props = {
passwordRules: string;
};
export default function Security(props: Props) {
const passwordInput = useRef<HTMLInputElement>(null);
const currentPasswordInput = useRef<HTMLInputElement>(null);
return (
<>
<Head title="Kata Sandi" />
<h1 className="sr-only">Kata Sandi</h1>
<div className="flex h-full flex-1 flex-col gap-6 overflow-x-auto px-4 md:px-6">
<Form
{...SecurityController.update.form()}
options={{
preserveScroll: true,
}}
resetOnSuccess
onError={(errors) => {
if (errors.password) {
passwordInput.current?.focus();
}
if (errors.current_password) {
currentPasswordInput.current?.focus();
}
}}
>
{({ errors, processing }) => (
<div className="grid gap-6">
<Card>
<CardContent className="grid grid-cols-1 gap-4 md:grid-cols-3">
<div className="grid gap-2">
<Label htmlFor="current_password">
Kata Sandi Saat <span className="text-destructive">*</span>
</Label>
<PasswordInput
id="current_password"
ref={currentPasswordInput}
name="current_password"
className="mt-1 block w-full"
autoComplete="current-password"
placeholder="Masukkan kata sandi saat ini"
/>
<InputError message={errors.current_password} />
</div>
<div className="grid gap-2">
<Label htmlFor="password">
Kata Sandi Baru <span className="text-destructive">*</span>
</Label>
<PasswordInput
id="password"
ref={passwordInput}
name="password"
className="mt-1 block w-full"
autoComplete="new-password"
placeholder="Masukkan kata sandi baru"
passwordrules={props.passwordRules}
/>
<InputError message={errors.password} />
</div>
<div className="grid gap-2">
<Label htmlFor="password_confirmation">
Konfirmasi Kata Sandi <span className="text-destructive">*</span>
</Label>
<PasswordInput
id="password_confirmation"
name="password_confirmation"
className="mt-1 block w-full"
autoComplete="new-password"
placeholder="Ulangi kata sandi baru"
passwordrules={props.passwordRules}
/>
<InputError
message={errors.password_confirmation}
/>
</div>
</CardContent>
</Card>
<div className="flex items-center gap-4">
<Button
type="submit"
disabled={processing}
data-test="update-password-button"
>
Simpan
</Button>
</div>
</div>
)}
</Form>
</div>
</>
);
}
Security.layout = {
breadcrumbs: [
{
title: 'Kata Sandi',
href: edit(),
},
],
};