@voyantjs/bookings-react 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,12 @@
1
1
  import { type BookingRecord } from "../schemas.js";
2
+ type BookingStatus = BookingRecord["status"];
2
3
  export interface UpdateBookingStatusInput {
3
- status: BookingRecord["status"];
4
+ /**
5
+ * Current status — required for client-side dispatch to the right verb
6
+ * endpoint. The dialog has this in its props; pass it through.
7
+ */
8
+ currentStatus: BookingStatus;
9
+ status: BookingStatus;
4
10
  note?: string | null;
5
11
  }
6
12
  export declare function useBookingStatusMutation(bookingId: string): import("@tanstack/react-query").UseMutationResult<{
@@ -47,4 +53,5 @@ export declare function useBookingStatusByIdMutation(): import("@tanstack/react-
47
53
  createdAt: string;
48
54
  updatedAt: string;
49
55
  }, Error, UpdateBookingStatusByIdInput, unknown>;
56
+ export {};
50
57
  //# sourceMappingURL=use-booking-status-mutation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-booking-status-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-booking-status-mutation.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,aAAa,EAAyB,MAAM,eAAe,CAAA;AAEzE,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAA;IAC/B,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACrB;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;6CAoBzD;AAED,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC5E,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B;;;;;;;;;;;;;;;;iDAsB3C"}
1
+ {"version":3,"file":"use-booking-status-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-booking-status-mutation.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,aAAa,EAAyB,MAAM,eAAe,CAAA;AAEzE,KAAK,aAAa,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;AAE5C,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,aAAa,EAAE,aAAa,CAAA;IAC5B,MAAM,EAAE,aAAa,CAAA;IACrB,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACrB;AAkDD,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;6CAqBzD;AAED,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC5E,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B;;;;;;;;;;;;;;;;iDA4B3C"}
@@ -4,12 +4,46 @@ import { fetchWithValidation } from "../client.js";
4
4
  import { useVoyantBookingsContext } from "../provider.js";
5
5
  import { bookingsQueryKeys } from "../query-keys.js";
6
6
  import { bookingSingleResponse } from "../schemas.js";
7
+ /**
8
+ * Map (currentStatus, targetStatus) → which verb endpoint to call. Lifecycle
9
+ * arrows that have a named verb on the server go to that verb; everything else
10
+ * (non-adjacent jumps, e.g. cancelled → confirmed for data correction) falls
11
+ * through to /override-status, which requires a reason. We use the operator's
12
+ * note text as the reason — the server rejects empty reasons with a 400.
13
+ */
14
+ function dispatchStatusChange(bookingId, current, target, note) {
15
+ const noteBody = note ? { note } : {};
16
+ if (current === "on_hold" && target === "confirmed") {
17
+ return { path: `/v1/bookings/${bookingId}/confirm`, body: noteBody };
18
+ }
19
+ if (current === "on_hold" && target === "expired") {
20
+ return { path: `/v1/bookings/${bookingId}/expire`, body: noteBody };
21
+ }
22
+ if (current === "confirmed" && target === "in_progress") {
23
+ return { path: `/v1/bookings/${bookingId}/start`, body: noteBody };
24
+ }
25
+ if (current === "in_progress" && target === "completed") {
26
+ return { path: `/v1/bookings/${bookingId}/complete`, body: noteBody };
27
+ }
28
+ if (target === "cancelled" &&
29
+ (current === "draft" ||
30
+ current === "on_hold" ||
31
+ current === "confirmed" ||
32
+ current === "in_progress")) {
33
+ return { path: `/v1/bookings/${bookingId}/cancel`, body: noteBody };
34
+ }
35
+ return {
36
+ path: `/v1/bookings/${bookingId}/override-status`,
37
+ body: { status: target, reason: note ?? "", ...(note ? { note } : {}) },
38
+ };
39
+ }
7
40
  export function useBookingStatusMutation(bookingId) {
8
41
  const { baseUrl, fetcher } = useVoyantBookingsContext();
9
42
  const queryClient = useQueryClient();
10
43
  return useMutation({
11
44
  mutationFn: async (input) => {
12
- const { data } = await fetchWithValidation(`/v1/bookings/${bookingId}/status`, bookingSingleResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
45
+ const target = dispatchStatusChange(bookingId, input.currentStatus, input.status, input.note);
46
+ const { data } = await fetchWithValidation(target.path, bookingSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(target.body) });
13
47
  return data;
14
48
  },
15
49
  onSuccess: (data) => {
@@ -30,8 +64,9 @@ export function useBookingStatusByIdMutation() {
30
64
  const { baseUrl, fetcher } = useVoyantBookingsContext();
31
65
  const queryClient = useQueryClient();
32
66
  return useMutation({
33
- mutationFn: async ({ bookingId, ...input }) => {
34
- const { data } = await fetchWithValidation(`/v1/bookings/${bookingId}/status`, bookingSingleResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
67
+ mutationFn: async ({ bookingId, currentStatus, status, note, }) => {
68
+ const target = dispatchStatusChange(bookingId, currentStatus, status, note);
69
+ const { data } = await fetchWithValidation(target.path, bookingSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(target.body) });
35
70
  return data;
36
71
  },
37
72
  onSuccess: (data, variables) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyantjs/bookings-react",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "license": "FSL-1.1-Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,7 +35,7 @@
35
35
  "react": "^19.0.0",
36
36
  "react-dom": "^19.0.0",
37
37
  "zod": "^4.0.0",
38
- "@voyantjs/bookings": "0.10.0"
38
+ "@voyantjs/bookings": "0.11.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@tanstack/react-query": "^5.96.2",
@@ -46,12 +46,12 @@
46
46
  "typescript": "^6.0.2",
47
47
  "vitest": "^4.1.2",
48
48
  "zod": "^4.3.6",
49
- "@voyantjs/bookings": "0.10.0",
50
- "@voyantjs/react": "0.10.0",
49
+ "@voyantjs/bookings": "0.11.0",
50
+ "@voyantjs/react": "0.11.0",
51
51
  "@voyantjs/voyant-typescript-config": "0.1.0"
52
52
  },
53
53
  "dependencies": {
54
- "@voyantjs/react": "0.10.0"
54
+ "@voyantjs/react": "0.11.0"
55
55
  },
56
56
  "files": [
57
57
  "dist"