mirror of
https://github.com/s-frick/effigenix.git
synced 2026-03-28 15:29:34 +01:00
fix(tui): CountryPicker Error-Handling, zentrale DACH-Defaults und Validierung
DACH-Codes und Default-Country in country-defaults.ts zentralisiert statt in jedem Screen hardcoded. API-Fetch-Fehler fallen auf DACH-Fallback zurück statt stiller Fehlerignorierung. Country-Validierung in Pflichtfeld-Formularen ergänzt.
This commit is contained in:
parent
a77f0ec5df
commit
11bda32ffc
5 changed files with 26 additions and 11 deletions
|
|
@ -8,6 +8,7 @@ import { CountryPicker } from '../../shared/CountryPicker.js';
|
|||
import { LoadingSpinner } from '../../shared/LoadingSpinner.js';
|
||||
import { ErrorDisplay } from '../../shared/ErrorDisplay.js';
|
||||
import { client } from '../../../utils/api-client.js';
|
||||
import { DEFAULT_COUNTRY, DACH_FALLBACK } from '../../shared/country-defaults.js';
|
||||
|
||||
type Field = 'name' | 'phone' | 'email' | 'street' | 'houseNumber' | 'postalCode' | 'city' | 'countryPicker' | 'paymentDueDays';
|
||||
const FIELDS: Field[] = ['name', 'phone', 'email', 'street', 'houseNumber', 'postalCode', 'city', 'countryPicker', 'paymentDueDays'];
|
||||
|
|
@ -38,12 +39,12 @@ export function CustomerCreateScreen() {
|
|||
const [activeField, setActiveField] = useState<Field | 'type'>('name');
|
||||
const [fieldErrors, setFieldErrors] = useState<Partial<Record<Field | 'type', string>>>({});
|
||||
const [countryQuery, setCountryQuery] = useState('');
|
||||
const [countryCode, setCountryCode] = useState('DE');
|
||||
const [countryName, setCountryName] = useState('Deutschland');
|
||||
const [countryCode, setCountryCode] = useState(DEFAULT_COUNTRY.code);
|
||||
const [countryName, setCountryName] = useState(DEFAULT_COUNTRY.name);
|
||||
const [countries, setCountries] = useState<CountryDTO[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
client.countries.search().then(setCountries).catch(() => {});
|
||||
client.countries.search().then(setCountries).catch(() => setCountries(DACH_FALLBACK));
|
||||
}, []);
|
||||
|
||||
const setField = (field: Exclude<Field, 'countryPicker'>) => (value: string) => {
|
||||
|
|
@ -85,6 +86,7 @@ export function CustomerCreateScreen() {
|
|||
if (!values.houseNumber.trim()) errors.houseNumber = 'Hausnummer ist erforderlich.';
|
||||
if (!values.postalCode.trim()) errors.postalCode = 'PLZ ist erforderlich.';
|
||||
if (!values.city.trim()) errors.city = 'Stadt ist erforderlich.';
|
||||
if (!countryCode) errors.countryPicker = 'Land ist erforderlich.';
|
||||
setFieldErrors(errors);
|
||||
if (Object.keys(errors).length > 0) return;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue