mirror of
https://github.com/s-frick/effigenix.git
synced 2026-03-28 17:39:57 +01:00
feat: TUI-Screens für Inventar und Produktion + API-Client Typ-Migration
Neue TUI-Features:
- Inventar: Lageorte auflisten, anlegen, bearbeiten, (de-)aktivieren
- Produktion: Rezepte auflisten, anlegen, Detail-Ansicht
- Navigation erweitert (Hauptmenü, Routing)
API-Client auf generierte OpenAPI-Typen umgestellt:
- 6 neue Alias-Dateien in @effigenix/types (supplier, category, article,
customer, inventory, production)
- api-client Re-Exports direkt von @effigenix/types statt via Resources
- Backend: @Schema(requiredProperties) auf 16 Response-Records
- Backend: OpenApiCustomizer für application-layer DTOs (UserDTO, RoleDTO)
Hinweis: Backend-Endpoints für GET /api/recipes und
GET /api/inventory/storage-locations/{id} fehlen noch (separate Issues).
This commit is contained in:
parent
bee3f28b5f
commit
c26d72fbe7
48 changed files with 2090 additions and 474 deletions
54
frontend/apps/cli/src/hooks/useRecipes.ts
Normal file
54
frontend/apps/cli/src/hooks/useRecipes.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import { useState, useCallback } from 'react';
|
||||
import type { RecipeDTO, CreateRecipeRequest } from '@effigenix/api-client';
|
||||
import { client } from '../utils/api-client.js';
|
||||
|
||||
interface RecipesState {
|
||||
recipes: RecipeDTO[];
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
function errorMessage(err: unknown): string {
|
||||
return err instanceof Error ? err.message : 'Unbekannter Fehler';
|
||||
}
|
||||
|
||||
export function useRecipes() {
|
||||
const [state, setState] = useState<RecipesState>({
|
||||
recipes: [],
|
||||
loading: false,
|
||||
error: null,
|
||||
});
|
||||
|
||||
const fetchRecipes = useCallback(async () => {
|
||||
setState((s) => ({ ...s, loading: true, error: null }));
|
||||
try {
|
||||
const recipes = await client.recipes.list();
|
||||
setState({ recipes, loading: false, error: null });
|
||||
} catch (err) {
|
||||
setState((s) => ({ ...s, loading: false, error: errorMessage(err) }));
|
||||
}
|
||||
}, []);
|
||||
|
||||
const createRecipe = useCallback(async (request: CreateRecipeRequest) => {
|
||||
setState((s) => ({ ...s, loading: true, error: null }));
|
||||
try {
|
||||
const recipe = await client.recipes.create(request);
|
||||
setState((s) => ({ recipes: [...s.recipes, recipe], loading: false, error: null }));
|
||||
return recipe;
|
||||
} catch (err) {
|
||||
setState((s) => ({ ...s, loading: false, error: errorMessage(err) }));
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const clearError = useCallback(() => {
|
||||
setState((s) => ({ ...s, error: null }));
|
||||
}, []);
|
||||
|
||||
return {
|
||||
...state,
|
||||
fetchRecipes,
|
||||
createRecipe,
|
||||
clearError,
|
||||
};
|
||||
}
|
||||
104
frontend/apps/cli/src/hooks/useStorageLocations.ts
Normal file
104
frontend/apps/cli/src/hooks/useStorageLocations.ts
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
import { useState, useCallback } from 'react';
|
||||
import type {
|
||||
StorageLocationDTO,
|
||||
CreateStorageLocationRequest,
|
||||
UpdateStorageLocationRequest,
|
||||
StorageLocationFilter,
|
||||
} from '@effigenix/api-client';
|
||||
import { client } from '../utils/api-client.js';
|
||||
|
||||
interface StorageLocationsState {
|
||||
storageLocations: StorageLocationDTO[];
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
function errorMessage(err: unknown): string {
|
||||
return err instanceof Error ? err.message : 'Unbekannter Fehler';
|
||||
}
|
||||
|
||||
export function useStorageLocations() {
|
||||
const [state, setState] = useState<StorageLocationsState>({
|
||||
storageLocations: [],
|
||||
loading: false,
|
||||
error: null,
|
||||
});
|
||||
|
||||
const fetchStorageLocations = useCallback(async (filter?: StorageLocationFilter) => {
|
||||
setState((s) => ({ ...s, loading: true, error: null }));
|
||||
try {
|
||||
const storageLocations = await client.storageLocations.list(filter);
|
||||
setState({ storageLocations, loading: false, error: null });
|
||||
} catch (err) {
|
||||
setState((s) => ({ ...s, loading: false, error: errorMessage(err) }));
|
||||
}
|
||||
}, []);
|
||||
|
||||
const createStorageLocation = useCallback(async (request: CreateStorageLocationRequest) => {
|
||||
setState((s) => ({ ...s, loading: true, error: null }));
|
||||
try {
|
||||
const location = await client.storageLocations.create(request);
|
||||
setState((s) => ({ storageLocations: [...s.storageLocations, location], loading: false, error: null }));
|
||||
return location;
|
||||
} catch (err) {
|
||||
setState((s) => ({ ...s, loading: false, error: errorMessage(err) }));
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const updateStorageLocation = useCallback(async (id: string, request: UpdateStorageLocationRequest) => {
|
||||
try {
|
||||
const updated = await client.storageLocations.update(id, request);
|
||||
setState((s) => ({
|
||||
...s,
|
||||
storageLocations: s.storageLocations.map((loc) => (loc.id === id ? updated : loc)),
|
||||
}));
|
||||
return updated;
|
||||
} catch (err) {
|
||||
setState((s) => ({ ...s, error: errorMessage(err) }));
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const activateStorageLocation = useCallback(async (id: string) => {
|
||||
try {
|
||||
const updated = await client.storageLocations.activate(id);
|
||||
setState((s) => ({
|
||||
...s,
|
||||
storageLocations: s.storageLocations.map((loc) => (loc.id === id ? updated : loc)),
|
||||
}));
|
||||
return updated;
|
||||
} catch (err) {
|
||||
setState((s) => ({ ...s, error: errorMessage(err) }));
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const deactivateStorageLocation = useCallback(async (id: string) => {
|
||||
try {
|
||||
const updated = await client.storageLocations.deactivate(id);
|
||||
setState((s) => ({
|
||||
...s,
|
||||
storageLocations: s.storageLocations.map((loc) => (loc.id === id ? updated : loc)),
|
||||
}));
|
||||
return updated;
|
||||
} catch (err) {
|
||||
setState((s) => ({ ...s, error: errorMessage(err) }));
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const clearError = useCallback(() => {
|
||||
setState((s) => ({ ...s, error: null }));
|
||||
}, []);
|
||||
|
||||
return {
|
||||
...state,
|
||||
fetchStorageLocations,
|
||||
createStorageLocation,
|
||||
updateStorageLocation,
|
||||
activateStorageLocation,
|
||||
deactivateStorageLocation,
|
||||
clearError,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue