Admin: kreator usera - kolejnosc danych (imie, nazwisko, haslo + powtorzenie, e-mail, wiek) i walidacja zgodnosci hasel

This commit is contained in:
tisachi
2026-10-16 22:43:45 +02:00
parent 60a4ec705f
commit 2fbecb3093
3 changed files with 63 additions and 24 deletions

View File

@@ -87,10 +87,11 @@ export default function UserForm() {
const gyms: Gym[] = gymsData?.gyms ?? [];
const [form, setForm] = useState({
email: '',
password: '',
firstName: '',
lastName: '',
password: '',
password2: '',
email: '',
age: '',
isAdmin: false,
});
@@ -107,10 +108,11 @@ export default function UserForm() {
if (seededRef.current || !user) return;
seededRef.current = true;
setForm({
email: user.email,
password: '',
firstName: user.firstName ?? '',
lastName: user.lastName ?? '',
password: '',
password2: '',
email: user.email,
age: user.age?.toString() ?? '',
isAdmin: user.isAdmin,
});
@@ -148,6 +150,8 @@ export default function UserForm() {
if (!isEdit && form.password.length < 8) return 'Hasło musi mieć co najmniej 8 znaków.';
if (isEdit && form.password && form.password.length < 8)
return 'Nowe hasło musi mieć co najmniej 8 znaków.';
// w edycji oba pola mogą zostać puste (bez zmiany hasła); w tworzeniu muszą się zgadzać
if (form.password !== form.password2) return 'Podane hasła muszą być takie same.';
return '';
};
@@ -271,24 +275,6 @@ export default function UserForm() {
<H3 className="mb-0">Dane</H3>
</div>
<div className="grid grid-cols-1 gap-x-4 sm:grid-cols-2">
<Field label="E-mail">
<Input
type="email"
value={form.email}
onChange={(e) => setForm({ ...form, email: e.target.value })}
required
/>
</Field>
<Field label={isEdit ? 'Nowe hasło (opcjonalnie)' : 'Hasło (min. 8)'}>
<Input
type="password"
value={form.password}
onChange={(e) => setForm({ ...form, password: e.target.value })}
minLength={8}
required={!isEdit}
placeholder={isEdit ? '••••••••' : undefined}
/>
</Field>
<Field label="Imię">
<Input
value={form.firstName}
@@ -301,6 +287,36 @@ export default function UserForm() {
onChange={(e) => setForm({ ...form, lastName: e.target.value })}
/>
</Field>
<Field label={isEdit ? 'Nowe hasło (opcjonalnie)' : 'Hasło (min. 8)'}>
<Input
type="password"
autoComplete="new-password"
value={form.password}
onChange={(e) => setForm({ ...form, password: e.target.value })}
minLength={8}
required={!isEdit}
placeholder={isEdit ? '••••••••' : undefined}
/>
</Field>
<Field label={isEdit ? 'Powtórz nowe hasło' : 'Powtórz hasło'}>
<Input
type="password"
autoComplete="new-password"
value={form.password2}
onChange={(e) => setForm({ ...form, password2: e.target.value })}
minLength={8}
required={!isEdit}
placeholder={isEdit ? '••••••••' : undefined}
/>
</Field>
<Field label="E-mail">
<Input
type="email"
value={form.email}
onChange={(e) => setForm({ ...form, email: e.target.value })}
required
/>
</Field>
<Field label="Wiek">
<Input
type="number"