mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 11:18:17 +00:00
Merge branch 'dev' into freight/nati-2
# Conflicts: # apps/edr-freight-api/src/app.module.ts # apps/edr-freight-api/src/seed/freight-permissions.registry.ts # apps/edr-freight-web/backoffice/src/components/layout/sidebar-sections.tsx # apps/edr-freight-web/backoffice/src/constants/URLS.ts # apps/edr-freight-web/backoffice/src/lib/permissions.ts
This commit is contained in:
@@ -121,7 +121,38 @@ export function useBookingMutations(bookingId: string) {
|
||||
onError: (error) => toast.error(parseApiError(error, "Failed to cancel booking")),
|
||||
});
|
||||
|
||||
/**
|
||||
* One staff decision applied to both halves of a consolidated pair. Both
|
||||
* bookings are invalidated on success so whichever tab is open reflects the
|
||||
* new state immediately.
|
||||
*/
|
||||
const pairedDecision = useMutation({
|
||||
mutationFn: (payload: {
|
||||
decision: "accept" | "cancel" | "operationAccept" | "requestChanges";
|
||||
reason?: string;
|
||||
note?: string;
|
||||
validityDays?: number;
|
||||
}) => {
|
||||
const { decision, ...options } = payload;
|
||||
return bookingsService.pairedDecision(bookingId, decision, options);
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
toast.success("Applied to both bookings on the shared wagon");
|
||||
void invalidateBookingDetail(qc, data.booking.id);
|
||||
void invalidateBookingDetail(qc, data.partner.id);
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error(
|
||||
parseApiError(error, "Failed to apply the decision to both bookings"),
|
||||
);
|
||||
// Nothing should have committed (the server runs both halves in one
|
||||
// transaction), but refetch so the UI never shows a stale guess.
|
||||
void invalidateBookingDetail(qc, bookingId);
|
||||
},
|
||||
});
|
||||
|
||||
const isPending =
|
||||
pairedDecision.isPending ||
|
||||
staffAccept.isPending ||
|
||||
requestChanges.isPending ||
|
||||
staffReject.isPending ||
|
||||
@@ -134,6 +165,7 @@ export function useBookingMutations(bookingId: string) {
|
||||
cancel.isPending;
|
||||
|
||||
return {
|
||||
pairedDecision,
|
||||
staffAccept,
|
||||
requestChanges,
|
||||
staffReject,
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
|
||||
import {
|
||||
manualPaymentSettingsService,
|
||||
type ManualPaymentSettings,
|
||||
} from "@/services/manualPaymentSettings.service";
|
||||
import { useErrorHandler } from "@/shared/hooks/useErrorHandler";
|
||||
|
||||
export const MANUAL_PAYMENT_SETTINGS_KEY = ["manualPaymentSettings"];
|
||||
|
||||
export const useManualPaymentSettingsQuery = () =>
|
||||
useQuery({
|
||||
queryKey: MANUAL_PAYMENT_SETTINGS_KEY,
|
||||
queryFn: () => manualPaymentSettingsService.get(),
|
||||
staleTime: 60_000,
|
||||
});
|
||||
|
||||
export const useUpdateManualPaymentSettings = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const { t } = useTranslation();
|
||||
const { handleError } = useErrorHandler(t);
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (
|
||||
patch: Partial<Pick<ManualPaymentSettings, "etbEnabled" | "usdEnabled">>,
|
||||
) => manualPaymentSettingsService.update(patch),
|
||||
onSuccess: (data) => {
|
||||
queryClient.setQueryData(MANUAL_PAYMENT_SETTINGS_KEY, data);
|
||||
// The Manual Payments worklist only lists enabled currencies.
|
||||
queryClient.invalidateQueries({ queryKey: ["invoices"] });
|
||||
toast.success(
|
||||
t("manualPaymentSettings.updated", "Manual payment settings updated"),
|
||||
);
|
||||
},
|
||||
onError: handleError,
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user