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

feat(frontend): TUI-Screens für Rezept-Filter, Archivierung und Chargen-Einbuchung

Production: Rezeptliste mit Status-Filter (Draft/Active/Archived), Rezept
archivieren für aktive Rezepte, list() gibt RecipeSummaryDTO zurück.
Inventory: Charge einbuchen (AddBatch) mit neuem Stocks-Resource und Screens.
This commit is contained in:
Sebastian Frick 2026-02-19 22:46:38 +01:00
parent f2003a3093
commit ec736cf294
16 changed files with 553 additions and 16 deletions

View file

@ -1,9 +1,9 @@
import { useState, useCallback } from 'react';
import type { RecipeDTO, CreateRecipeRequest } from '@effigenix/api-client';
import type { RecipeSummaryDTO, CreateRecipeRequest, RecipeStatus } from '@effigenix/api-client';
import { client } from '../utils/api-client.js';
interface RecipesState {
recipes: RecipeDTO[];
recipes: RecipeSummaryDTO[];
loading: boolean;
error: string | null;
}
@ -19,10 +19,10 @@ export function useRecipes() {
error: null,
});
const fetchRecipes = useCallback(async () => {
const fetchRecipes = useCallback(async (status?: RecipeStatus) => {
setState((s) => ({ ...s, loading: true, error: null }));
try {
const recipes = await client.recipes.list();
const recipes = await client.recipes.list(status);
setState({ recipes, loading: false, error: null });
} catch (err) {
setState((s) => ({ ...s, loading: false, error: errorMessage(err) }));
@ -33,7 +33,8 @@ export function useRecipes() {
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 }));
const recipes = await client.recipes.list();
setState({ recipes, loading: false, error: null });
return recipe;
} catch (err) {
setState((s) => ({ ...s, loading: false, error: errorMessage(err) }));

View file

@ -0,0 +1,41 @@
import { useState, useCallback } from 'react';
import type { StockBatchDTO, AddStockBatchRequest } from '@effigenix/api-client';
import { client } from '../utils/api-client.js';
interface StocksState {
loading: boolean;
error: string | null;
}
function errorMessage(err: unknown): string {
return err instanceof Error ? err.message : 'Unbekannter Fehler';
}
export function useStocks() {
const [state, setState] = useState<StocksState>({
loading: false,
error: null,
});
const addBatch = useCallback(async (stockId: string, request: AddStockBatchRequest): Promise<StockBatchDTO | null> => {
setState({ loading: true, error: null });
try {
const batch = await client.stocks.addBatch(stockId, request);
setState({ loading: false, error: null });
return batch;
} catch (err) {
setState({ loading: false, error: errorMessage(err) });
return null;
}
}, []);
const clearError = useCallback(() => {
setState((s) => ({ ...s, error: null }));
}, []);
return {
...state,
addBatch,
clearError,
};
}