drawer and upload

This commit is contained in:
2026-09-07 13:02:35 +05:30
parent 8defbd418f
commit 05ac76f5f0
22 changed files with 3194 additions and 1568 deletions

View File

@@ -40,6 +40,47 @@ const MOVES = [
/** The end states. Nothing follows them, so nothing is offered. */
const SETTLED = ['delivered', 'cancelled'];
/**
* The moves, split from their rendering.
*
* The drawer puts the buttons in its fixed footer and the caption in the body,
* and those two need to share one mutation — a second instance would give the
* footer its own pending state and its own error, so a failure would be
* reported in a place the operator is not looking. Returning both from one hook
* keeps a single source of truth for what is happening.
*/
export function useDeliveryMoves(job: DeliveryRow) {
const client = useQueryClient();
const [problem, setProblem] = useState<string | null>(null);
const status = (job.orderstatus ?? '').trim().toLowerCase();
const isSettled = SETTLED.includes(status);
const move = useMutation({
mutationFn: ({ to, stamp }: { to: string; stamp: string }) =>
deliveriesApi.update({
deliveryid: job.deliveryid,
orderheaderid: job.orderheaderid ?? 0,
orderstatus: to,
[stamp]: stampNow(),
}),
onSuccess: () => client.invalidateQueries({ queryKey: queryKeys.insights.all }),
onError: (error) => setProblem(errorMessage(error)),
});
return {
status,
isSettled,
isPending: move.isPending,
problem,
moves: MOVES,
run: (to: string, stamp: string) => {
setProblem(null);
move.mutate({ to, stamp });
},
};
}
export function DeliveryProgress({ job }: { job: DeliveryRow }) {
const client = useQueryClient();
const [problem, setProblem] = useState<string | null>(null);