Skip to content

Commit

Permalink
Only update action based on task state update when the cancel button …
Browse files Browse the repository at this point in the history
…was clicked

Signed-off-by: Aaron Chong <aaronchongth@gmail.com>
  • Loading branch information
aaronchongth committed Sep 26, 2023
1 parent f8ad29e commit c506c49
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/dashboard/src/components/delivery-alert-store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ const DeliveryWarningDialog = React.memo((props: DeliveryWarningDialogProps) =>
}
const sub = rmf.getTaskStateObs(taskState.booking.id).subscribe((taskStateUpdate) => {
setNewTaskState(taskStateUpdate);
setCancelling((prev) => {
if (
prev &&
deliveryAlert.action === 'waiting' &&
taskStateUpdate.status &&
taskStateUpdate.status === 'canceled'
) {
setCancelling(false);
(async () => {
try {
await rmf.deliveryAlertsApi.updateDeliveryAlertActionDeliveryAlertsDeliveryAlertIdActionPost(
deliveryAlert.id,
'cancelled',
);
} catch (e) {
appController.showAlert(
'error',
`Failed to cancel delivery alert ${deliveryAlert.id}: ${(e as Error).message}`,
);
}
setActionTaken(true);
})();
}
return prev;
});

if (
deliveryAlert.action === 'waiting' &&
taskStateUpdate.status &&
Expand Down

0 comments on commit c506c49

Please sign in to comment.