mirror of
https://github.com/s-frick/effigenix.git
synced 2026-03-28 17:04:49 +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:
parent
f2003a3093
commit
ec736cf294
16 changed files with 553 additions and 16 deletions
41
frontend/apps/cli/src/hooks/useStocks.ts
Normal file
41
frontend/apps/cli/src/hooks/useStocks.ts
Normal 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,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue