rider status
This commit is contained in:
@@ -7,6 +7,7 @@ import { deliveriesApi } from '@/api/deliveries';
|
||||
import type { DeliveryRow } from '@/api/types';
|
||||
import { queryKeys } from '@/queries/keys';
|
||||
import { stampNow } from './assignDelivery';
|
||||
import { isSettled, isStalled, matchesStatus } from './orderStatus';
|
||||
|
||||
/**
|
||||
* Moving a delivery along from the back office.
|
||||
@@ -37,8 +38,12 @@ const MOVES = [
|
||||
{ to: 'cancelled', label: 'Cancelled', stamp: 'canceltime' },
|
||||
] as const;
|
||||
|
||||
/** The end states. Nothing follows them, so nothing is offered. */
|
||||
const SETTLED = ['delivered', 'cancelled'];
|
||||
/** What to do about a stalled job, which is never "nothing". */
|
||||
function stalledAdvice(status: string): string {
|
||||
return matchesStatus('rejected', status)
|
||||
? 'This rider declined the job. The order is waiting for a rider again — assign it to somebody else.'
|
||||
: 'The rider could not hand this over. It is still theirs to re-attempt; reassign it if somebody else should take it.';
|
||||
}
|
||||
|
||||
/**
|
||||
* The moves, split from their rendering.
|
||||
@@ -54,7 +59,8 @@ export function useDeliveryMoves(job: DeliveryRow) {
|
||||
const [problem, setProblem] = useState<string | null>(null);
|
||||
|
||||
const status = (job.orderstatus ?? '').trim().toLowerCase();
|
||||
const isSettled = SETTLED.includes(status);
|
||||
const settled = isSettled(status);
|
||||
const stalled = isStalled(status);
|
||||
|
||||
const move = useMutation({
|
||||
mutationFn: ({ to, stamp }: { to: string; stamp: string }) =>
|
||||
@@ -70,7 +76,8 @@ export function useDeliveryMoves(job: DeliveryRow) {
|
||||
|
||||
return {
|
||||
status,
|
||||
isSettled,
|
||||
isSettled: settled,
|
||||
isStalled: stalled,
|
||||
isPending: move.isPending,
|
||||
problem,
|
||||
moves: MOVES,
|
||||
@@ -86,7 +93,8 @@ export function DeliveryProgress({ job }: { job: DeliveryRow }) {
|
||||
const [problem, setProblem] = useState<string | null>(null);
|
||||
|
||||
const status = (job.orderstatus ?? '').trim().toLowerCase();
|
||||
const isSettled = SETTLED.includes(status);
|
||||
const settled = isSettled(status);
|
||||
const stalled = isStalled(status);
|
||||
|
||||
const move = useMutation({
|
||||
mutationFn: ({ to, stamp }: { to: string; stamp: string }) =>
|
||||
@@ -100,7 +108,7 @@ export function DeliveryProgress({ job }: { job: DeliveryRow }) {
|
||||
onError: (error) => setProblem(errorMessage(error)),
|
||||
});
|
||||
|
||||
if (isSettled) {
|
||||
if (settled) {
|
||||
return (
|
||||
<Text type="body" size="xsm" color="secondary">
|
||||
This job is {status}. Nothing further to record.
|
||||
@@ -108,6 +116,14 @@ export function DeliveryProgress({ job }: { job: DeliveryRow }) {
|
||||
);
|
||||
}
|
||||
|
||||
if (stalled) {
|
||||
return (
|
||||
<Text type="body" size="xsm" color="secondary">
|
||||
This job is {status}. {stalledAdvice(status)}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<VStack gap={1}>
|
||||
<div className="progress-moves">
|
||||
|
||||
Reference in New Issue
Block a user