diff --git a/frontend/scripts/LABEL_ASSOCIATION_CEILING b/frontend/scripts/LABEL_ASSOCIATION_CEILING index 425151f3..e522732c 100644 --- a/frontend/scripts/LABEL_ASSOCIATION_CEILING +++ b/frontend/scripts/LABEL_ASSOCIATION_CEILING @@ -1 +1 @@ -40 +38 diff --git a/frontend/src/components/backups/AddScheduleModal.jsx b/frontend/src/components/backups/AddScheduleModal.jsx index ebdc5acb..1fb4e56d 100644 --- a/frontend/src/components/backups/AddScheduleModal.jsx +++ b/frontend/src/components/backups/AddScheduleModal.jsx @@ -1,3 +1,4 @@ +import { useId } from 'react'; import { useTranslation } from 'react-i18next'; import Modal from '@/components/Modal'; import { FormField } from '@/components/FormField'; @@ -5,6 +6,7 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue } from '@/components/ui/select'; import useForm from '@/hooks/useForm'; +import useFieldErrors from '@/hooks/useFieldErrors'; export default function AddScheduleModal({ open, onClose, onCreate, onCreated, remoteEnabled, timezone }) { const { t } = useTranslation(); @@ -13,9 +15,28 @@ export default function AddScheduleModal({ open, onClose, onCreate, onCreated, r onSubmit: async (values) => { await onCreate(values); form.reset(); + fe.reset(); onCreated(); }, }); + const fieldId = useId(); + const required = t('common.validation.required', 'This field is required.'); + const fe = useFieldErrors({ + name: form.values.name.trim() ? null : required, + target: form.values.target.trim() ? null : required, + scheduleTime: form.values.scheduleTime ? null : required, + }, fieldId); + const submit = (e) => { + if (!fe.attempt()) { e.preventDefault(); return undefined; } + return form.handleSubmit(e); + }; + const close = () => { fe.reset(); onClose(); }; + const err = (name) => fe.error(name) || form.getFieldError(name); + // Wraps getFieldProps so edits/blur also drive the inline-error timing. + const props = (name) => { + const p = form.getFieldProps(name); + return { ...p, onBlur: () => { p.onBlur(); fe.touch(name); }, 'aria-invalid': Boolean(err(name)) }; + }; const targetLabel = form.values.backupType === 'files' ? t('app.backups.schedulePaths', 'Paths (comma-separated)') : form.values.backupType === 'database' @@ -23,11 +44,11 @@ export default function AddScheduleModal({ open, onClose, onCreate, onCreated, r : t('app.backups.applicationName', 'Service name'); return ( - { if (!form.isSubmitting) onClose(); }} title={t('app.backups.addBackupSchedule', 'New backup schedule')}> -
+ { if (!form.isSubmitting) close(); }} title={t('app.backups.addBackupSchedule', 'New backup schedule')}> + {form.submitError &&

{form.submitError}

} - - + + - - + + - - + + {remoteEnabled && ( @@ -60,7 +81,7 @@ export default function AddScheduleModal({ open, onClose, onCreate, onCreated, r )}
- +
diff --git a/frontend/src/components/databases/modals.jsx b/frontend/src/components/databases/modals.jsx index a08066e6..2e8e70da 100644 --- a/frontend/src/components/databases/modals.jsx +++ b/frontend/src/components/databases/modals.jsx @@ -6,6 +6,8 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue } from '@/components/ui/select'; import CopyField from '@/components/CopyField'; +import { FormField, FormRow } from '@/components/FormField'; +import useFieldErrors from '@/hooks/useFieldErrors'; import { EngineIcon } from '../icons/DatabaseBrands'; import { ENGINE_META } from './dbAdapter'; import { useTranslation } from 'react-i18next'; @@ -121,6 +123,11 @@ export function CreateDatabaseModal({ engine: initialEngine = 'mysql', status, o const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [createdInfo, setCreatedInfo] = useState(null); + const fe = useFieldErrors({ + name: !formData.name.trim() + ? t('app.modals.databaseNameRequired', 'Enter the database name.') + : (/^[a-zA-Z0-9_]+$/.test(formData.name) ? null : t('app.modals.databaseNameInvalid', 'Use only letters, numbers and underscores.')), + }, fieldId); // Attaching is optional, so a failed app lookup must not block the create — // the selector just stays empty. @@ -137,6 +144,7 @@ export function CreateDatabaseModal({ engine: initialEngine = 'mysql', status, o async function handleSubmit(e) { e.preventDefault(); + if (!fe.attempt()) return; setError(''); setLoading(true); try { @@ -160,6 +168,7 @@ export function CreateDatabaseModal({ engine: initialEngine = 'mysql', status, o } } } catch (err) { + if (fe.fromServer(err)) return; setError(err.message || 'Failed to create database'); } finally { setLoading(false); @@ -185,26 +194,23 @@ export function CreateDatabaseModal({ engine: initialEngine = 'mysql', status, o return ( {error &&
{error}
} -
-
- + + { onClose(); onInstallEngine(); } : null} /> -
+ -
- - setFormData({ ...formData, name: e.target.value })} placeholder="my_database" required pattern="[a-zA-Z0-9_]+" autoFocus /> -
+ + { fe.clear('name'); setFormData({ ...formData, name: e.target.value }); }} onBlur={() => fe.touch('name')} placeholder="my_database" autoFocus /> + {isMySQL ? ( -
-
- + + -
-
- + + -
-
+ + ) : ( -
- + -
+ )} -
- + - - {appsLoading - ? t('app.modals.loadingServices', 'Loading services…') - : t('app.modals.attachServiceHint', 'Optional. An attached database is listed on the service and is cleaned up with it.')} - -
+