mirror of
https://github.com/s-frick/effigenix.git
synced 2026-03-28 13:59:36 +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 { LoadingSpinner } from '../../shared/LoadingSpinner.js';
|
||||||
import { ErrorDisplay } from '../../shared/ErrorDisplay.js';
|
import { ErrorDisplay } from '../../shared/ErrorDisplay.js';
|
||||||
import { client } from '../../../utils/api-client.js';
|
import { client } from '../../../utils/api-client.js';
|
||||||
|
import { DEFAULT_COUNTRY, DACH_FALLBACK } from '../../shared/country-defaults.js';
|
||||||
|
|
||||||
type Field = 'label' | 'street' | 'houseNumber' | 'postalCode' | 'city' | 'countryPicker' | 'contactPerson' | 'deliveryNotes';
|
type Field = 'label' | 'street' | 'houseNumber' | 'postalCode' | 'city' | 'countryPicker' | 'contactPerson' | 'deliveryNotes';
|
||||||
const FIELDS: Field[] = ['label', 'street', 'houseNumber', 'postalCode', 'city', 'countryPicker', 'contactPerson', 'deliveryNotes'];
|
const FIELDS: Field[] = ['label', 'street', 'houseNumber', 'postalCode', 'city', 'countryPicker', 'contactPerson', 'deliveryNotes'];
|
||||||
|
|
@ -35,12 +36,12 @@ export function AddDeliveryAddressScreen() {
|
||||||
const [activeField, setActiveField] = useState<Field>('label');
|
const [activeField, setActiveField] = useState<Field>('label');
|
||||||
const [fieldErrors, setFieldErrors] = useState<Partial<Record<Field, string>>>({});
|
const [fieldErrors, setFieldErrors] = useState<Partial<Record<Field, string>>>({});
|
||||||
const [countryQuery, setCountryQuery] = useState('');
|
const [countryQuery, setCountryQuery] = useState('');
|
||||||
const [countryCode, setCountryCode] = useState('DE');
|
const [countryCode, setCountryCode] = useState(DEFAULT_COUNTRY.code);
|
||||||
const [countryName, setCountryName] = useState('Deutschland');
|
const [countryName, setCountryName] = useState(DEFAULT_COUNTRY.name);
|
||||||
const [countries, setCountries] = useState<CountryDTO[]>([]);
|
const [countries, setCountries] = useState<CountryDTO[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
client.countries.search().then(setCountries).catch(() => {});
|
client.countries.search().then(setCountries).catch(() => setCountries(DACH_FALLBACK));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const setField = (field: Exclude<Field, 'countryPicker'>) => (value: string) => {
|
const setField = (field: Exclude<Field, 'countryPicker'>) => (value: string) => {
|
||||||
|
|
@ -71,6 +72,7 @@ export function AddDeliveryAddressScreen() {
|
||||||
if (!values.houseNumber.trim()) errors.houseNumber = 'Hausnummer ist erforderlich.';
|
if (!values.houseNumber.trim()) errors.houseNumber = 'Hausnummer ist erforderlich.';
|
||||||
if (!values.postalCode.trim()) errors.postalCode = 'PLZ ist erforderlich.';
|
if (!values.postalCode.trim()) errors.postalCode = 'PLZ ist erforderlich.';
|
||||||
if (!values.city.trim()) errors.city = 'Stadt ist erforderlich.';
|
if (!values.city.trim()) errors.city = 'Stadt ist erforderlich.';
|
||||||
|
if (!countryCode) errors.countryPicker = 'Land ist erforderlich.';
|
||||||
setFieldErrors(errors);
|
setFieldErrors(errors);
|
||||||
if (Object.keys(errors).length > 0) return;
|
if (Object.keys(errors).length > 0) return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { CountryPicker } from '../../shared/CountryPicker.js';
|
||||||
import { LoadingSpinner } from '../../shared/LoadingSpinner.js';
|
import { LoadingSpinner } from '../../shared/LoadingSpinner.js';
|
||||||
import { ErrorDisplay } from '../../shared/ErrorDisplay.js';
|
import { ErrorDisplay } from '../../shared/ErrorDisplay.js';
|
||||||
import { client } from '../../../utils/api-client.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';
|
type Field = 'name' | 'phone' | 'email' | 'street' | 'houseNumber' | 'postalCode' | 'city' | 'countryPicker' | 'paymentDueDays';
|
||||||
const FIELDS: 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 [activeField, setActiveField] = useState<Field | 'type'>('name');
|
||||||
const [fieldErrors, setFieldErrors] = useState<Partial<Record<Field | 'type', string>>>({});
|
const [fieldErrors, setFieldErrors] = useState<Partial<Record<Field | 'type', string>>>({});
|
||||||
const [countryQuery, setCountryQuery] = useState('');
|
const [countryQuery, setCountryQuery] = useState('');
|
||||||
const [countryCode, setCountryCode] = useState('DE');
|
const [countryCode, setCountryCode] = useState(DEFAULT_COUNTRY.code);
|
||||||
const [countryName, setCountryName] = useState('Deutschland');
|
const [countryName, setCountryName] = useState(DEFAULT_COUNTRY.name);
|
||||||
const [countries, setCountries] = useState<CountryDTO[]>([]);
|
const [countries, setCountries] = useState<CountryDTO[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
client.countries.search().then(setCountries).catch(() => {});
|
client.countries.search().then(setCountries).catch(() => setCountries(DACH_FALLBACK));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const setField = (field: Exclude<Field, 'countryPicker'>) => (value: string) => {
|
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.houseNumber.trim()) errors.houseNumber = 'Hausnummer ist erforderlich.';
|
||||||
if (!values.postalCode.trim()) errors.postalCode = 'PLZ ist erforderlich.';
|
if (!values.postalCode.trim()) errors.postalCode = 'PLZ ist erforderlich.';
|
||||||
if (!values.city.trim()) errors.city = 'Stadt ist erforderlich.';
|
if (!values.city.trim()) errors.city = 'Stadt ist erforderlich.';
|
||||||
|
if (!countryCode) errors.countryPicker = 'Land ist erforderlich.';
|
||||||
setFieldErrors(errors);
|
setFieldErrors(errors);
|
||||||
if (Object.keys(errors).length > 0) return;
|
if (Object.keys(errors).length > 0) return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { CountryPicker } from '../../shared/CountryPicker.js';
|
||||||
import { LoadingSpinner } from '../../shared/LoadingSpinner.js';
|
import { LoadingSpinner } from '../../shared/LoadingSpinner.js';
|
||||||
import { ErrorDisplay } from '../../shared/ErrorDisplay.js';
|
import { ErrorDisplay } from '../../shared/ErrorDisplay.js';
|
||||||
import { client } from '../../../utils/api-client.js';
|
import { client } from '../../../utils/api-client.js';
|
||||||
|
import { DEFAULT_COUNTRY, DACH_FALLBACK } from '../../shared/country-defaults.js';
|
||||||
|
|
||||||
type Field = 'name' | 'phone' | 'email' | 'contactPerson' | 'street' | 'houseNumber' | 'postalCode' | 'city' | 'countryPicker' | 'paymentDueDays';
|
type Field = 'name' | 'phone' | 'email' | 'contactPerson' | 'street' | 'houseNumber' | 'postalCode' | 'city' | 'countryPicker' | 'paymentDueDays';
|
||||||
const FIELDS: Field[] = ['name', 'phone', 'email', 'contactPerson', 'street', 'houseNumber', 'postalCode', 'city', 'countryPicker', 'paymentDueDays'];
|
const FIELDS: Field[] = ['name', 'phone', 'email', 'contactPerson', 'street', 'houseNumber', 'postalCode', 'city', 'countryPicker', 'paymentDueDays'];
|
||||||
|
|
@ -37,12 +38,12 @@ export function SupplierCreateScreen() {
|
||||||
const [activeField, setActiveField] = useState<Field>('name');
|
const [activeField, setActiveField] = useState<Field>('name');
|
||||||
const [fieldErrors, setFieldErrors] = useState<Partial<Record<Field, string>>>({});
|
const [fieldErrors, setFieldErrors] = useState<Partial<Record<Field, string>>>({});
|
||||||
const [countryQuery, setCountryQuery] = useState('');
|
const [countryQuery, setCountryQuery] = useState('');
|
||||||
const [countryCode, setCountryCode] = useState('DE');
|
const [countryCode, setCountryCode] = useState(DEFAULT_COUNTRY.code);
|
||||||
const [countryName, setCountryName] = useState('Deutschland');
|
const [countryName, setCountryName] = useState(DEFAULT_COUNTRY.name);
|
||||||
const [countries, setCountries] = useState<CountryDTO[]>([]);
|
const [countries, setCountries] = useState<CountryDTO[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
client.countries.search().then(setCountries).catch(() => {});
|
client.countries.search().then(setCountries).catch(() => setCountries(DACH_FALLBACK));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const setField = (field: Exclude<Field, 'countryPicker'>) => (value: string) => {
|
const setField = (field: Exclude<Field, 'countryPicker'>) => (value: string) => {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useState, useMemo } from 'react';
|
import { useState, useMemo } from 'react';
|
||||||
import { Box, Text, useInput } from 'ink';
|
import { Box, Text, useInput } from 'ink';
|
||||||
import type { CountryDTO } from '@effigenix/api-client';
|
import type { CountryDTO } from '@effigenix/api-client';
|
||||||
|
import { DACH_CODES } from './country-defaults.js';
|
||||||
|
|
||||||
interface CountryPickerProps {
|
interface CountryPickerProps {
|
||||||
countries: CountryDTO[];
|
countries: CountryDTO[];
|
||||||
|
|
@ -12,8 +13,6 @@ interface CountryPickerProps {
|
||||||
maxVisible?: number;
|
maxVisible?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const DACH_CODES = ['DE', 'AT', 'CH'];
|
|
||||||
|
|
||||||
export function CountryPicker({
|
export function CountryPicker({
|
||||||
countries,
|
countries,
|
||||||
query,
|
query,
|
||||||
|
|
|
||||||
11
frontend/apps/cli/src/components/shared/country-defaults.ts
Normal file
11
frontend/apps/cli/src/components/shared/country-defaults.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import type { CountryDTO } from '@effigenix/api-client';
|
||||||
|
|
||||||
|
export const DACH_CODES: string[] = ['DE', 'AT', 'CH'];
|
||||||
|
|
||||||
|
export const DEFAULT_COUNTRY: CountryDTO = { code: 'DE', name: 'Deutschland' };
|
||||||
|
|
||||||
|
export const DACH_FALLBACK: CountryDTO[] = [
|
||||||
|
{ code: 'DE', name: 'Deutschland' },
|
||||||
|
{ code: 'AT', name: 'Österreich' },
|
||||||
|
{ code: 'CH', name: 'Schweiz' },
|
||||||
|
];
|
||||||
Loading…
Add table
Add a link
Reference in a new issue