1
0
Fork 0
mirror of https://github.com/s-frick/effigenix.git synced 2026-03-28 13:49:36 +01:00

feat(cli): Stammdaten-TUI mit Master Data API-Anbindung

- Neue Screens: Kategorien, Lieferanten, Artikel, Kunden (jeweils
  Liste, Detail, Anlegen + Detailaktionen wie Bewertung, Zertifikate,
  Verkaufseinheiten, Lieferadressen, Präferenzen)
- API-Client: Resources für alle 4 Stammdaten-Aggregate implementiert
  (categories, suppliers, articles, customers) mit Mapping von
  verschachtelten Domain-VOs auf flache DTOs
- Lieferant, Artikel, Kategorie: echte HTTP-Calls gegen Backend
  (/api/suppliers, /api/articles, /api/categories, /api/customers)
- 204-No-Content-Endpoints (removeSalesUnit, removeSupplier,
  removeCertificate, removeDeliveryAddress, removeFrameContract)
  lösen Re-Fetch des Aggregats aus
- MasterdataMenu, Navigation-Erweiterung, App.tsx-Routing
This commit is contained in:
Sebastian Frick 2026-02-18 13:35:20 +01:00
parent 797f435a49
commit d27dbaa843
30 changed files with 3882 additions and 1 deletions

View file

@ -0,0 +1,117 @@
import React, { useState } from 'react';
import { Box, Text, useInput } from 'ink';
import { useNavigation } from '../../../state/navigation-context.js';
import { useCustomers } from '../../../hooks/useCustomers.js';
import { FormInput } from '../../shared/FormInput.js';
import { LoadingSpinner } from '../../shared/LoadingSpinner.js';
import { ErrorDisplay } from '../../shared/ErrorDisplay.js';
type Field = 'label' | 'street' | 'houseNumber' | 'postalCode' | 'city' | 'country' | 'contactPerson' | 'deliveryNotes';
const FIELDS: Field[] = ['label', 'street', 'houseNumber', 'postalCode', 'city', 'country', 'contactPerson', 'deliveryNotes'];
const FIELD_LABELS: Record<Field, string> = {
label: 'Bezeichnung * (z.B. Hauptküche)',
street: 'Straße *',
houseNumber: 'Hausnummer *',
postalCode: 'PLZ *',
city: 'Stadt *',
country: 'Land *',
contactPerson: 'Ansprechpartner',
deliveryNotes: 'Lieferhinweis',
};
export function AddDeliveryAddressScreen() {
const { params, navigate, back } = useNavigation();
const customerId = params['customerId'] ?? '';
const { addDeliveryAddress, loading, error, clearError } = useCustomers();
const [values, setValues] = useState<Record<Field, string>>({
label: '', street: '', houseNumber: '', postalCode: '',
city: '', country: 'Deutschland', contactPerson: '', deliveryNotes: '',
});
const [activeField, setActiveField] = useState<Field>('label');
const [fieldErrors, setFieldErrors] = useState<Partial<Record<Field, string>>>({});
const setField = (field: Field) => (value: string) => {
setValues((v) => ({ ...v, [field]: value }));
};
useInput((_input, key) => {
if (loading) return;
if (key.tab || key.downArrow) {
setActiveField((f) => {
const idx = FIELDS.indexOf(f);
return FIELDS[(idx + 1) % FIELDS.length] ?? f;
});
}
if (key.upArrow) {
setActiveField((f) => {
const idx = FIELDS.indexOf(f);
return FIELDS[(idx - 1 + FIELDS.length) % FIELDS.length] ?? f;
});
}
if (key.escape) back();
});
const handleSubmit = async () => {
const errors: Partial<Record<Field, string>> = {};
if (!values.label.trim()) errors.label = 'Bezeichnung ist erforderlich.';
if (!values.street.trim()) errors.street = 'Straße ist erforderlich.';
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 (!values.country.trim()) errors.country = 'Land ist erforderlich.';
setFieldErrors(errors);
if (Object.keys(errors).length > 0) return;
const updated = await addDeliveryAddress(customerId, {
label: values.label.trim(),
street: values.street.trim(),
houseNumber: values.houseNumber.trim(),
postalCode: values.postalCode.trim(),
city: values.city.trim(),
country: values.country.trim(),
...(values.contactPerson.trim() ? { contactPerson: values.contactPerson.trim() } : {}),
...(values.deliveryNotes.trim() ? { deliveryNotes: values.deliveryNotes.trim() } : {}),
});
if (updated) navigate('customer-detail', { customerId });
};
const handleFieldSubmit = (field: Field) => (_value: string) => {
const idx = FIELDS.indexOf(field);
if (idx < FIELDS.length - 1) {
setActiveField(FIELDS[idx + 1] ?? field);
} else {
void handleSubmit();
}
};
if (loading) return <Box paddingY={2}><LoadingSpinner label="Adresse wird hinzugefügt..." /></Box>;
return (
<Box flexDirection="column" gap={1}>
<Text color="cyan" bold>Lieferadresse hinzufügen</Text>
{error && <ErrorDisplay message={error} onDismiss={clearError} />}
<Box flexDirection="column" gap={1} width={60}>
{FIELDS.map((field) => (
<FormInput
key={field}
label={FIELD_LABELS[field]}
value={values[field]}
onChange={setField(field)}
onSubmit={handleFieldSubmit(field)}
focus={activeField === field}
{...(fieldErrors[field] ? { error: fieldErrors[field] } : {})}
/>
))}
</Box>
<Box marginTop={1}>
<Text color="gray" dimColor>
Tab/ Feld wechseln · Enter auf letztem Feld speichern · Escape Abbrechen
</Text>
</Box>
</Box>
);
}