@voyantjs/bookings-react 0.12.0 → 0.13.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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-booking-status-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-booking-status-mutation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-booking-status-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-booking-status-mutation.ts"],"names":[],"mappings":"AAQA,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;AAED,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;6CA0BzD;AAED,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC5E,SAAS,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B;;;;;;;;;;;;;;;;iDA4B3C"}
|
|
@@ -1,48 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { dispatchBookingStatusChange } from "@voyantjs/bookings/status-dispatch";
|
|
3
4
|
import { fetchWithValidation } from "../client.js";
|
|
4
5
|
import { useVoyantBookingsContext } from "../provider.js";
|
|
5
6
|
import { bookingsQueryKeys } from "../query-keys.js";
|
|
6
7
|
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
|
-
}
|
|
40
8
|
export function useBookingStatusMutation(bookingId) {
|
|
41
9
|
const { baseUrl, fetcher } = useVoyantBookingsContext();
|
|
42
10
|
const queryClient = useQueryClient();
|
|
43
11
|
return useMutation({
|
|
44
12
|
mutationFn: async (input) => {
|
|
45
|
-
const target =
|
|
13
|
+
const target = dispatchBookingStatusChange(bookingId, input.currentStatus, input.status, input.note);
|
|
46
14
|
const { data } = await fetchWithValidation(target.path, bookingSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(target.body) });
|
|
47
15
|
return data;
|
|
48
16
|
},
|
|
@@ -65,7 +33,7 @@ export function useBookingStatusByIdMutation() {
|
|
|
65
33
|
const queryClient = useQueryClient();
|
|
66
34
|
return useMutation({
|
|
67
35
|
mutationFn: async ({ bookingId, currentStatus, status, note, }) => {
|
|
68
|
-
const target =
|
|
36
|
+
const target = dispatchBookingStatusChange(bookingId, currentStatus, status, note);
|
|
69
37
|
const { data } = await fetchWithValidation(target.path, bookingSingleResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(target.body) });
|
|
70
38
|
return data;
|
|
71
39
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voyantjs/bookings-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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.
|
|
38
|
+
"@voyantjs/bookings": "0.13.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.
|
|
50
|
-
"@voyantjs/react": "0.
|
|
49
|
+
"@voyantjs/bookings": "0.13.0",
|
|
50
|
+
"@voyantjs/react": "0.13.0",
|
|
51
51
|
"@voyantjs/voyant-typescript-config": "0.1.0"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@voyantjs/react": "0.
|
|
54
|
+
"@voyantjs/react": "0.13.0"
|
|
55
55
|
},
|
|
56
56
|
"files": [
|
|
57
57
|
"dist"
|