mirror of
https://github.com/s-frick/effigenix.git
synced 2026-03-28 17:49:57 +01:00
feat(tui): Create-Screen für Produktionsaufträge
Types, API-Client Resource, Hook und TUI-Screen für den neuen POST /api/production/production-orders Endpoint. Menüeintrag im Produktionsmenü ergänzt.
This commit is contained in:
parent
2938628db4
commit
fb8387c10e
10 changed files with 381 additions and 2 deletions
43
frontend/apps/cli/src/hooks/useProductionOrders.ts
Normal file
43
frontend/apps/cli/src/hooks/useProductionOrders.ts
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import { useState, useCallback } from 'react';
|
||||
import type { ProductionOrderDTO, CreateProductionOrderRequest } from '@effigenix/api-client';
|
||||
import { client } from '../utils/api-client.js';
|
||||
|
||||
interface ProductionOrdersState {
|
||||
productionOrder: ProductionOrderDTO | null;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
function errorMessage(err: unknown): string {
|
||||
return err instanceof Error ? err.message : 'Unbekannter Fehler';
|
||||
}
|
||||
|
||||
export function useProductionOrders() {
|
||||
const [state, setState] = useState<ProductionOrdersState>({
|
||||
productionOrder: null,
|
||||
loading: false,
|
||||
error: null,
|
||||
});
|
||||
|
||||
const createProductionOrder = useCallback(async (request: CreateProductionOrderRequest) => {
|
||||
setState((s) => ({ ...s, loading: true, error: null }));
|
||||
try {
|
||||
const productionOrder = await client.productionOrders.create(request);
|
||||
setState({ productionOrder, loading: false, error: null });
|
||||
return productionOrder;
|
||||
} catch (err) {
|
||||
setState((s) => ({ ...s, loading: false, error: errorMessage(err) }));
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const clearError = useCallback(() => {
|
||||
setState((s) => ({ ...s, error: null }));
|
||||
}, []);
|
||||
|
||||
return {
|
||||
...state,
|
||||
createProductionOrder,
|
||||
clearError,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue