@voyantjs/products-react 0.3.0 → 0.3.1
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.
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/use-product-day-mutation.d.ts +41 -0
- package/dist/hooks/use-product-day-mutation.d.ts.map +1 -0
- package/dist/hooks/use-product-day-mutation.js +41 -0
- package/dist/hooks/use-product-day-service-mutation.d.ts +63 -0
- package/dist/hooks/use-product-day-service-mutation.d.ts.map +1 -0
- package/dist/hooks/use-product-day-service-mutation.js +41 -0
- package/dist/hooks/use-product-day-services.d.ts +20 -0
- package/dist/hooks/use-product-day-services.d.ts.map +1 -0
- package/dist/hooks/use-product-day-services.js +12 -0
- package/dist/hooks/use-product-days.d.ts +16 -0
- package/dist/hooks/use-product-days.d.ts.map +1 -0
- package/dist/hooks/use-product-days.js +12 -0
- package/dist/hooks/use-product-media-mutation.d.ts +98 -0
- package/dist/hooks/use-product-media-mutation.d.ts.map +1 -0
- package/dist/hooks/use-product-media-mutation.js +69 -0
- package/dist/hooks/use-product-media.d.ts +26 -0
- package/dist/hooks/use-product-media.d.ts.map +1 -0
- package/dist/hooks/use-product-media.js +12 -0
- package/dist/hooks/use-product-version-mutation.d.ts +16 -0
- package/dist/hooks/use-product-version-mutation.d.ts.map +1 -0
- package/dist/hooks/use-product-version-mutation.js +22 -0
- package/dist/hooks/use-product-versions.d.ts +15 -0
- package/dist/hooks/use-product-versions.d.ts.map +1 -0
- package/dist/hooks/use-product-versions.js +12 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/query-keys.d.ts +12 -0
- package/dist/query-keys.d.ts.map +1 -1
- package/dist/query-keys.js +6 -0
- package/dist/query-options.d.ts +260 -0
- package/dist/query-options.d.ts.map +1 -1
- package/dist/query-options.js +62 -1
- package/dist/schemas.d.ts +216 -0
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +60 -0
- package/package.json +5 -5
package/dist/hooks/index.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ export * from "./use-product.js";
|
|
|
5
5
|
export * from "./use-product-categories.js";
|
|
6
6
|
export * from "./use-product-category.js";
|
|
7
7
|
export * from "./use-product-category-mutation.js";
|
|
8
|
+
export * from "./use-product-day-mutation.js";
|
|
9
|
+
export * from "./use-product-day-service-mutation.js";
|
|
10
|
+
export * from "./use-product-day-services.js";
|
|
11
|
+
export * from "./use-product-days.js";
|
|
12
|
+
export * from "./use-product-media.js";
|
|
13
|
+
export * from "./use-product-media-mutation.js";
|
|
8
14
|
export * from "./use-product-mutation.js";
|
|
9
15
|
export * from "./use-product-option.js";
|
|
10
16
|
export * from "./use-product-option-mutation.js";
|
|
@@ -15,5 +21,7 @@ export * from "./use-product-tags.js";
|
|
|
15
21
|
export * from "./use-product-type.js";
|
|
16
22
|
export * from "./use-product-type-mutation.js";
|
|
17
23
|
export * from "./use-product-types.js";
|
|
24
|
+
export * from "./use-product-version-mutation.js";
|
|
25
|
+
export * from "./use-product-versions.js";
|
|
18
26
|
export * from "./use-products.js";
|
|
19
27
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,oCAAoC,CAAA;AAClD,cAAc,2BAA2B,CAAA;AACzC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kCAAkC,CAAA;AAChD,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA;AACpC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,oCAAoC,CAAA;AAClD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,uCAAuC,CAAA;AACrD,cAAc,+BAA+B,CAAA;AAC7C,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,iCAAiC,CAAA;AAC/C,cAAc,2BAA2B,CAAA;AACzC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kCAAkC,CAAA;AAChD,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA;AACpC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,mCAAmC,CAAA;AACjD,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -5,6 +5,12 @@ export * from "./use-product.js";
|
|
|
5
5
|
export * from "./use-product-categories.js";
|
|
6
6
|
export * from "./use-product-category.js";
|
|
7
7
|
export * from "./use-product-category-mutation.js";
|
|
8
|
+
export * from "./use-product-day-mutation.js";
|
|
9
|
+
export * from "./use-product-day-service-mutation.js";
|
|
10
|
+
export * from "./use-product-day-services.js";
|
|
11
|
+
export * from "./use-product-days.js";
|
|
12
|
+
export * from "./use-product-media.js";
|
|
13
|
+
export * from "./use-product-media-mutation.js";
|
|
8
14
|
export * from "./use-product-mutation.js";
|
|
9
15
|
export * from "./use-product-option.js";
|
|
10
16
|
export * from "./use-product-option-mutation.js";
|
|
@@ -15,4 +21,6 @@ export * from "./use-product-tags.js";
|
|
|
15
21
|
export * from "./use-product-type.js";
|
|
16
22
|
export * from "./use-product-type-mutation.js";
|
|
17
23
|
export * from "./use-product-types.js";
|
|
24
|
+
export * from "./use-product-version-mutation.js";
|
|
25
|
+
export * from "./use-product-versions.js";
|
|
18
26
|
export * from "./use-products.js";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type UpdateProductDayInput } from "../schemas.js";
|
|
2
|
+
export declare function useProductDayMutation(): {
|
|
3
|
+
create: import("@tanstack/react-query").UseMutationResult<{
|
|
4
|
+
id: string;
|
|
5
|
+
productId: string;
|
|
6
|
+
dayNumber: number;
|
|
7
|
+
title: string | null;
|
|
8
|
+
description: string | null;
|
|
9
|
+
location: string | null;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
updatedAt: string;
|
|
12
|
+
}, Error, {
|
|
13
|
+
dayNumber: number;
|
|
14
|
+
title?: string | null | undefined;
|
|
15
|
+
description?: string | null | undefined;
|
|
16
|
+
location?: string | null | undefined;
|
|
17
|
+
} & {
|
|
18
|
+
productId: string;
|
|
19
|
+
}, unknown>;
|
|
20
|
+
update: import("@tanstack/react-query").UseMutationResult<{
|
|
21
|
+
id: string;
|
|
22
|
+
productId: string;
|
|
23
|
+
dayNumber: number;
|
|
24
|
+
title: string | null;
|
|
25
|
+
description: string | null;
|
|
26
|
+
location: string | null;
|
|
27
|
+
createdAt: string;
|
|
28
|
+
updatedAt: string;
|
|
29
|
+
}, Error, {
|
|
30
|
+
productId: string;
|
|
31
|
+
dayId: string;
|
|
32
|
+
input: UpdateProductDayInput;
|
|
33
|
+
}, unknown>;
|
|
34
|
+
remove: import("@tanstack/react-query").UseMutationResult<{
|
|
35
|
+
success: boolean;
|
|
36
|
+
}, Error, {
|
|
37
|
+
productId: string;
|
|
38
|
+
dayId: string;
|
|
39
|
+
}, unknown>;
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=use-product-day-mutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-product-day-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-product-day-mutation.ts"],"names":[],"mappings":"AAOA,OAAO,EAIL,KAAK,qBAAqB,EAC3B,MAAM,eAAe,CAAA;AAEtB,wBAAgB,qBAAqB;;;;;;;;;;;;;;;;mBAKgD,MAAM;;;;;;;;;;;;mBAsB1E,MAAM;eACV,MAAM;eACN,qBAAqB;;;;;mBAkBwB,MAAM;eAAS,MAAM;;EAe9E"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { fetchWithValidation } from "../client.js";
|
|
4
|
+
import { useVoyantProductsContext } from "../provider.js";
|
|
5
|
+
import { productsQueryKeys } from "../query-keys.js";
|
|
6
|
+
import { productDayResponse, successEnvelope, } from "../schemas.js";
|
|
7
|
+
export function useProductDayMutation() {
|
|
8
|
+
const { baseUrl, fetcher } = useVoyantProductsContext();
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
const create = useMutation({
|
|
11
|
+
mutationFn: async ({ productId, ...input }) => {
|
|
12
|
+
const { data } = await fetchWithValidation(`/v1/products/${productId}/days`, productDayResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
|
|
13
|
+
return data;
|
|
14
|
+
},
|
|
15
|
+
onSuccess: async (data) => {
|
|
16
|
+
await queryClient.invalidateQueries({
|
|
17
|
+
queryKey: productsQueryKeys.productDays(data.productId),
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const update = useMutation({
|
|
22
|
+
mutationFn: async ({ productId, dayId, input, }) => {
|
|
23
|
+
const { data } = await fetchWithValidation(`/v1/products/${productId}/days/${dayId}`, productDayResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
|
|
24
|
+
return data;
|
|
25
|
+
},
|
|
26
|
+
onSuccess: async (data) => {
|
|
27
|
+
await queryClient.invalidateQueries({
|
|
28
|
+
queryKey: productsQueryKeys.productDays(data.productId),
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
const remove = useMutation({
|
|
33
|
+
mutationFn: async ({ productId, dayId }) => fetchWithValidation(`/v1/products/${productId}/days/${dayId}`, successEnvelope, { baseUrl, fetcher }, { method: "DELETE" }),
|
|
34
|
+
onSuccess: async (_data, variables) => {
|
|
35
|
+
await queryClient.invalidateQueries({
|
|
36
|
+
queryKey: productsQueryKeys.productDays(variables.productId),
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
return { create, update, remove };
|
|
41
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type UpdateProductDayServiceInput } from "../schemas.js";
|
|
2
|
+
export declare function useProductDayServiceMutation(): {
|
|
3
|
+
create: import("@tanstack/react-query").UseMutationResult<{
|
|
4
|
+
dayId: string;
|
|
5
|
+
data: {
|
|
6
|
+
id: string;
|
|
7
|
+
dayId: string;
|
|
8
|
+
supplierServiceId: string | null;
|
|
9
|
+
serviceType: "other" | "transfer" | "accommodation" | "experience" | "guide" | "meal";
|
|
10
|
+
name: string;
|
|
11
|
+
description: string | null;
|
|
12
|
+
costCurrency: string;
|
|
13
|
+
costAmountCents: number;
|
|
14
|
+
quantity: number;
|
|
15
|
+
sortOrder: number | null;
|
|
16
|
+
notes: string | null;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
};
|
|
19
|
+
}, Error, {
|
|
20
|
+
serviceType: "other" | "transfer" | "accommodation" | "experience" | "guide" | "meal";
|
|
21
|
+
name: string;
|
|
22
|
+
costCurrency: string;
|
|
23
|
+
costAmountCents: number;
|
|
24
|
+
description?: string | null | undefined;
|
|
25
|
+
supplierServiceId?: string | null | undefined;
|
|
26
|
+
quantity?: number | undefined;
|
|
27
|
+
sortOrder?: number | null | undefined;
|
|
28
|
+
notes?: string | null | undefined;
|
|
29
|
+
} & {
|
|
30
|
+
productId: string;
|
|
31
|
+
dayId: string;
|
|
32
|
+
}, unknown>;
|
|
33
|
+
update: import("@tanstack/react-query").UseMutationResult<{
|
|
34
|
+
dayId: string;
|
|
35
|
+
data: {
|
|
36
|
+
id: string;
|
|
37
|
+
dayId: string;
|
|
38
|
+
supplierServiceId: string | null;
|
|
39
|
+
serviceType: "other" | "transfer" | "accommodation" | "experience" | "guide" | "meal";
|
|
40
|
+
name: string;
|
|
41
|
+
description: string | null;
|
|
42
|
+
costCurrency: string;
|
|
43
|
+
costAmountCents: number;
|
|
44
|
+
quantity: number;
|
|
45
|
+
sortOrder: number | null;
|
|
46
|
+
notes: string | null;
|
|
47
|
+
createdAt: string;
|
|
48
|
+
};
|
|
49
|
+
}, Error, {
|
|
50
|
+
productId: string;
|
|
51
|
+
dayId: string;
|
|
52
|
+
serviceId: string;
|
|
53
|
+
input: UpdateProductDayServiceInput;
|
|
54
|
+
}, unknown>;
|
|
55
|
+
remove: import("@tanstack/react-query").UseMutationResult<{
|
|
56
|
+
success: boolean;
|
|
57
|
+
}, Error, {
|
|
58
|
+
productId: string;
|
|
59
|
+
dayId: string;
|
|
60
|
+
serviceId: string;
|
|
61
|
+
}, unknown>;
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=use-product-day-service-mutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-product-day-service-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-product-day-service-mutation.ts"],"names":[],"mappings":"AAOA,OAAO,EAIL,KAAK,4BAA4B,EAClC,MAAM,eAAe,CAAA;AAEtB,wBAAgB,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBASO,MAAM;eAAS,MAAM;;;;;;;;;;;;;;;;;;;mBAuBvD,MAAM;eACV,MAAM;mBACF,MAAM;eACV,4BAA4B;;;;;mBAuBxB,MAAM;eACV,MAAM;mBACF,MAAM;;EAgBtB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { fetchWithValidation } from "../client.js";
|
|
4
|
+
import { useVoyantProductsContext } from "../provider.js";
|
|
5
|
+
import { productsQueryKeys } from "../query-keys.js";
|
|
6
|
+
import { productDayServiceResponse, successEnvelope, } from "../schemas.js";
|
|
7
|
+
export function useProductDayServiceMutation() {
|
|
8
|
+
const { baseUrl, fetcher } = useVoyantProductsContext();
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
const create = useMutation({
|
|
11
|
+
mutationFn: async ({ productId, dayId, ...input }) => {
|
|
12
|
+
const { data } = await fetchWithValidation(`/v1/products/${productId}/days/${dayId}/services`, productDayServiceResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
|
|
13
|
+
return { dayId, data };
|
|
14
|
+
},
|
|
15
|
+
onSuccess: async ({ dayId }, variables) => {
|
|
16
|
+
await queryClient.invalidateQueries({
|
|
17
|
+
queryKey: productsQueryKeys.productDayServices(variables.productId, dayId),
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const update = useMutation({
|
|
22
|
+
mutationFn: async ({ productId, dayId, serviceId, input, }) => {
|
|
23
|
+
const { data } = await fetchWithValidation(`/v1/products/${productId}/days/${dayId}/services/${serviceId}`, productDayServiceResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
|
|
24
|
+
return { dayId, data };
|
|
25
|
+
},
|
|
26
|
+
onSuccess: async ({ dayId }, variables) => {
|
|
27
|
+
await queryClient.invalidateQueries({
|
|
28
|
+
queryKey: productsQueryKeys.productDayServices(variables.productId, dayId),
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
const remove = useMutation({
|
|
33
|
+
mutationFn: async ({ productId, dayId, serviceId, }) => fetchWithValidation(`/v1/products/${productId}/days/${dayId}/services/${serviceId}`, successEnvelope, { baseUrl, fetcher }, { method: "DELETE" }),
|
|
34
|
+
onSuccess: async (_data, variables) => {
|
|
35
|
+
await queryClient.invalidateQueries({
|
|
36
|
+
queryKey: productsQueryKeys.productDayServices(variables.productId, variables.dayId),
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
return { create, update, remove };
|
|
41
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface UseProductDayServicesOptions {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
}
|
|
4
|
+
export declare function useProductDayServices(productId: string | null | undefined, dayId: string | null | undefined, options?: UseProductDayServicesOptions): import("@tanstack/react-query").UseQueryResult<{
|
|
5
|
+
data: {
|
|
6
|
+
id: string;
|
|
7
|
+
dayId: string;
|
|
8
|
+
supplierServiceId: string | null;
|
|
9
|
+
serviceType: "other" | "transfer" | "accommodation" | "experience" | "guide" | "meal";
|
|
10
|
+
name: string;
|
|
11
|
+
description: string | null;
|
|
12
|
+
costCurrency: string;
|
|
13
|
+
costAmountCents: number;
|
|
14
|
+
quantity: number;
|
|
15
|
+
sortOrder: number | null;
|
|
16
|
+
notes: string | null;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
}[];
|
|
19
|
+
}, Error>;
|
|
20
|
+
//# sourceMappingURL=use-product-day-services.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-product-day-services.d.ts","sourceRoot":"","sources":["../../src/hooks/use-product-day-services.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,4BAA4B;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,OAAO,GAAE,4BAAiC;;;;;;;;;;;;;;;UAS3C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useVoyantProductsContext } from "../provider.js";
|
|
4
|
+
import { getProductDayServicesQueryOptions } from "../query-options.js";
|
|
5
|
+
export function useProductDayServices(productId, dayId, options = {}) {
|
|
6
|
+
const { baseUrl, fetcher } = useVoyantProductsContext();
|
|
7
|
+
const { enabled = true } = options;
|
|
8
|
+
return useQuery({
|
|
9
|
+
...getProductDayServicesQueryOptions({ baseUrl, fetcher }, productId, dayId, options),
|
|
10
|
+
enabled: enabled && Boolean(productId) && Boolean(dayId),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface UseProductDaysOptions {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
}
|
|
4
|
+
export declare function useProductDays(productId: string | null | undefined, options?: UseProductDaysOptions): import("@tanstack/react-query").UseQueryResult<{
|
|
5
|
+
data: {
|
|
6
|
+
id: string;
|
|
7
|
+
productId: string;
|
|
8
|
+
dayNumber: number;
|
|
9
|
+
title: string | null;
|
|
10
|
+
description: string | null;
|
|
11
|
+
location: string | null;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
}[];
|
|
15
|
+
}, Error>;
|
|
16
|
+
//# sourceMappingURL=use-product-days.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-product-days.d.ts","sourceRoot":"","sources":["../../src/hooks/use-product-days.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,qBAAqB;IACpC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,OAAO,GAAE,qBAA0B;;;;;;;;;;;UASpC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useVoyantProductsContext } from "../provider.js";
|
|
4
|
+
import { getProductDaysQueryOptions } from "../query-options.js";
|
|
5
|
+
export function useProductDays(productId, options = {}) {
|
|
6
|
+
const { baseUrl, fetcher } = useVoyantProductsContext();
|
|
7
|
+
const { enabled = true } = options;
|
|
8
|
+
return useQuery({
|
|
9
|
+
...getProductDaysQueryOptions({ baseUrl, fetcher }, productId, options),
|
|
10
|
+
enabled: enabled && Boolean(productId),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type UpdateProductMediaInput } from "../schemas.js";
|
|
2
|
+
export declare function useProductMediaMutation(): {
|
|
3
|
+
create: import("@tanstack/react-query").UseMutationResult<{
|
|
4
|
+
id: string;
|
|
5
|
+
productId: string;
|
|
6
|
+
dayId: string | null;
|
|
7
|
+
mediaType: "image" | "video" | "document";
|
|
8
|
+
name: string;
|
|
9
|
+
url: string;
|
|
10
|
+
storageKey: string | null;
|
|
11
|
+
mimeType: string | null;
|
|
12
|
+
fileSize: number | null;
|
|
13
|
+
altText: string | null;
|
|
14
|
+
sortOrder: number;
|
|
15
|
+
isCover: boolean;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
}, Error, {
|
|
19
|
+
mediaType: "image" | "video" | "document";
|
|
20
|
+
name: string;
|
|
21
|
+
url: string;
|
|
22
|
+
storageKey?: string | null | undefined;
|
|
23
|
+
mimeType?: string | null | undefined;
|
|
24
|
+
fileSize?: number | null | undefined;
|
|
25
|
+
altText?: string | null | undefined;
|
|
26
|
+
sortOrder?: number | undefined;
|
|
27
|
+
isCover?: boolean | undefined;
|
|
28
|
+
dayId?: string | null | undefined;
|
|
29
|
+
} & {
|
|
30
|
+
productId: string;
|
|
31
|
+
}, unknown>;
|
|
32
|
+
update: import("@tanstack/react-query").UseMutationResult<{
|
|
33
|
+
id: string;
|
|
34
|
+
productId: string;
|
|
35
|
+
dayId: string | null;
|
|
36
|
+
mediaType: "image" | "video" | "document";
|
|
37
|
+
name: string;
|
|
38
|
+
url: string;
|
|
39
|
+
storageKey: string | null;
|
|
40
|
+
mimeType: string | null;
|
|
41
|
+
fileSize: number | null;
|
|
42
|
+
altText: string | null;
|
|
43
|
+
sortOrder: number;
|
|
44
|
+
isCover: boolean;
|
|
45
|
+
createdAt: string;
|
|
46
|
+
updatedAt: string;
|
|
47
|
+
}, Error, {
|
|
48
|
+
mediaId: string;
|
|
49
|
+
input: UpdateProductMediaInput;
|
|
50
|
+
}, unknown>;
|
|
51
|
+
remove: import("@tanstack/react-query").UseMutationResult<{
|
|
52
|
+
data: {
|
|
53
|
+
id: string;
|
|
54
|
+
productId: string;
|
|
55
|
+
dayId: string | null;
|
|
56
|
+
mediaType: "image" | "video" | "document";
|
|
57
|
+
name: string;
|
|
58
|
+
url: string;
|
|
59
|
+
storageKey: string | null;
|
|
60
|
+
mimeType: string | null;
|
|
61
|
+
fileSize: number | null;
|
|
62
|
+
altText: string | null;
|
|
63
|
+
sortOrder: number;
|
|
64
|
+
isCover: boolean;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
updatedAt: string;
|
|
67
|
+
};
|
|
68
|
+
}, Error, string, unknown>;
|
|
69
|
+
reorder: import("@tanstack/react-query").UseMutationResult<{
|
|
70
|
+
data: {
|
|
71
|
+
id: string;
|
|
72
|
+
}[];
|
|
73
|
+
}, Error, {
|
|
74
|
+
items: {
|
|
75
|
+
id: string;
|
|
76
|
+
sortOrder: number;
|
|
77
|
+
}[];
|
|
78
|
+
} & {
|
|
79
|
+
productId: string;
|
|
80
|
+
}, unknown>;
|
|
81
|
+
setCover: import("@tanstack/react-query").UseMutationResult<{
|
|
82
|
+
id: string;
|
|
83
|
+
productId: string;
|
|
84
|
+
dayId: string | null;
|
|
85
|
+
mediaType: "image" | "video" | "document";
|
|
86
|
+
name: string;
|
|
87
|
+
url: string;
|
|
88
|
+
storageKey: string | null;
|
|
89
|
+
mimeType: string | null;
|
|
90
|
+
fileSize: number | null;
|
|
91
|
+
altText: string | null;
|
|
92
|
+
sortOrder: number;
|
|
93
|
+
isCover: boolean;
|
|
94
|
+
createdAt: string;
|
|
95
|
+
updatedAt: string;
|
|
96
|
+
}, Error, string, unknown>;
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=use-product-media-mutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-product-media-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-product-media-mutation.ts"],"names":[],"mappings":"AAQA,OAAO,EAIL,KAAK,uBAAuB,EAC7B,MAAM,eAAe,CAAA;AAMtB,wBAAgB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAQO,MAAM;;;;;;;;;;;;;;;;;;iBAoBE,MAAM;eAAS,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAmDP,MAAM;;;;;;;;;;;;;;;;;;EAe1F"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { fetchWithValidation } from "../client.js";
|
|
5
|
+
import { useVoyantProductsContext } from "../provider.js";
|
|
6
|
+
import { productsQueryKeys } from "../query-keys.js";
|
|
7
|
+
import { productMediaResponse, } from "../schemas.js";
|
|
8
|
+
const reorderResponseSchema = z.object({
|
|
9
|
+
data: z.array(z.object({ id: z.string() })),
|
|
10
|
+
});
|
|
11
|
+
export function useProductMediaMutation() {
|
|
12
|
+
const { baseUrl, fetcher } = useVoyantProductsContext();
|
|
13
|
+
const queryClient = useQueryClient();
|
|
14
|
+
const create = useMutation({
|
|
15
|
+
mutationFn: async ({ productId, ...input }) => {
|
|
16
|
+
const path = input.dayId
|
|
17
|
+
? `/v1/products/${productId}/days/${input.dayId}/media`
|
|
18
|
+
: `/v1/products/${productId}/media`;
|
|
19
|
+
const { data } = await fetchWithValidation(path, productMediaResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
|
|
20
|
+
return data;
|
|
21
|
+
},
|
|
22
|
+
onSuccess: async (data) => {
|
|
23
|
+
await queryClient.invalidateQueries({
|
|
24
|
+
queryKey: productsQueryKeys.productMedia(data.productId),
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const update = useMutation({
|
|
29
|
+
mutationFn: async ({ mediaId, input }) => {
|
|
30
|
+
const { data } = await fetchWithValidation(`/v1/products/media/${mediaId}`, productMediaResponse, { baseUrl, fetcher }, { method: "PATCH", body: JSON.stringify(input) });
|
|
31
|
+
return data;
|
|
32
|
+
},
|
|
33
|
+
onSuccess: async (data) => {
|
|
34
|
+
await queryClient.invalidateQueries({
|
|
35
|
+
queryKey: productsQueryKeys.productMedia(data.productId),
|
|
36
|
+
});
|
|
37
|
+
await queryClient.invalidateQueries({ queryKey: productsQueryKeys.productMediaItem(data.id) });
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
const remove = useMutation({
|
|
41
|
+
mutationFn: async (mediaId) => fetchWithValidation(`/v1/products/media/${mediaId}`, productMediaResponse, { baseUrl, fetcher }, { method: "DELETE" }),
|
|
42
|
+
onSuccess: async ({ data }) => {
|
|
43
|
+
await queryClient.invalidateQueries({
|
|
44
|
+
queryKey: productsQueryKeys.productMedia(data.productId),
|
|
45
|
+
});
|
|
46
|
+
await queryClient.invalidateQueries({ queryKey: productsQueryKeys.productMediaItem(data.id) });
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
const setCover = useMutation({
|
|
50
|
+
mutationFn: async (mediaId) => {
|
|
51
|
+
const { data } = await fetchWithValidation(`/v1/products/media/${mediaId}/set-cover`, productMediaResponse, { baseUrl, fetcher }, { method: "PATCH" });
|
|
52
|
+
return data;
|
|
53
|
+
},
|
|
54
|
+
onSuccess: async (data) => {
|
|
55
|
+
await queryClient.invalidateQueries({
|
|
56
|
+
queryKey: productsQueryKeys.productMedia(data.productId),
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
const reorder = useMutation({
|
|
61
|
+
mutationFn: async ({ productId, items }) => fetchWithValidation(`/v1/products/${productId}/media/reorder`, reorderResponseSchema, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify({ items }) }),
|
|
62
|
+
onSuccess: async (_data, variables) => {
|
|
63
|
+
await queryClient.invalidateQueries({
|
|
64
|
+
queryKey: productsQueryKeys.productMedia(variables.productId),
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return { create, update, remove, reorder, setCover };
|
|
69
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ProductMediaListFilters } from "../query-keys.js";
|
|
2
|
+
export interface UseProductMediaOptions extends ProductMediaListFilters {
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function useProductMedia(productId: string | null | undefined, options?: UseProductMediaOptions): import("@tanstack/react-query").UseQueryResult<{
|
|
6
|
+
data: {
|
|
7
|
+
id: string;
|
|
8
|
+
productId: string;
|
|
9
|
+
dayId: string | null;
|
|
10
|
+
mediaType: "image" | "video" | "document";
|
|
11
|
+
name: string;
|
|
12
|
+
url: string;
|
|
13
|
+
storageKey: string | null;
|
|
14
|
+
mimeType: string | null;
|
|
15
|
+
fileSize: number | null;
|
|
16
|
+
altText: string | null;
|
|
17
|
+
sortOrder: number;
|
|
18
|
+
isCover: boolean;
|
|
19
|
+
createdAt: string;
|
|
20
|
+
updatedAt: string;
|
|
21
|
+
}[];
|
|
22
|
+
total: number;
|
|
23
|
+
limit: number;
|
|
24
|
+
offset: number;
|
|
25
|
+
}, Error>;
|
|
26
|
+
//# sourceMappingURL=use-product-media.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-product-media.d.ts","sourceRoot":"","sources":["../../src/hooks/use-product-media.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAG/D,MAAM,WAAW,sBAAuB,SAAQ,uBAAuB;IACrE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,OAAO,GAAE,sBAA2B;;;;;;;;;;;;;;;;;;;;UASrC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useVoyantProductsContext } from "../provider.js";
|
|
4
|
+
import { getProductMediaQueryOptions } from "../query-options.js";
|
|
5
|
+
export function useProductMedia(productId, options = {}) {
|
|
6
|
+
const { baseUrl, fetcher } = useVoyantProductsContext();
|
|
7
|
+
const { enabled = true, ...filters } = options;
|
|
8
|
+
return useQuery({
|
|
9
|
+
...getProductMediaQueryOptions({ baseUrl, fetcher }, productId, filters),
|
|
10
|
+
enabled: enabled && Boolean(productId),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function useProductVersionMutation(): {
|
|
2
|
+
create: import("@tanstack/react-query").UseMutationResult<{
|
|
3
|
+
id: string;
|
|
4
|
+
productId: string;
|
|
5
|
+
versionNumber: number;
|
|
6
|
+
snapshot: unknown;
|
|
7
|
+
authorId: string;
|
|
8
|
+
notes: string | null;
|
|
9
|
+
createdAt: string;
|
|
10
|
+
}, Error, {
|
|
11
|
+
notes?: string | null | undefined;
|
|
12
|
+
} & {
|
|
13
|
+
productId: string;
|
|
14
|
+
}, unknown>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=use-product-version-mutation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-product-version-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-product-version-mutation.ts"],"names":[],"mappings":"AASA,wBAAgB,yBAAyB;;;;;;;;;;;;mBAQO,MAAM;;EAiBrD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { fetchWithValidation } from "../client.js";
|
|
4
|
+
import { useVoyantProductsContext } from "../provider.js";
|
|
5
|
+
import { productsQueryKeys } from "../query-keys.js";
|
|
6
|
+
import { productVersionResponse } from "../schemas.js";
|
|
7
|
+
export function useProductVersionMutation() {
|
|
8
|
+
const { baseUrl, fetcher } = useVoyantProductsContext();
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
const create = useMutation({
|
|
11
|
+
mutationFn: async ({ productId, ...input }) => {
|
|
12
|
+
const { data } = await fetchWithValidation(`/v1/products/${productId}/versions`, productVersionResponse, { baseUrl, fetcher }, { method: "POST", body: JSON.stringify(input) });
|
|
13
|
+
return data;
|
|
14
|
+
},
|
|
15
|
+
onSuccess: async (data) => {
|
|
16
|
+
await queryClient.invalidateQueries({
|
|
17
|
+
queryKey: productsQueryKeys.productVersions(data.productId),
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
return { create };
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface UseProductVersionsOptions {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
}
|
|
4
|
+
export declare function useProductVersions(productId: string | null | undefined, options?: UseProductVersionsOptions): import("@tanstack/react-query").UseQueryResult<{
|
|
5
|
+
data: {
|
|
6
|
+
id: string;
|
|
7
|
+
productId: string;
|
|
8
|
+
versionNumber: number;
|
|
9
|
+
snapshot: unknown;
|
|
10
|
+
authorId: string;
|
|
11
|
+
notes: string | null;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
}[];
|
|
14
|
+
}, Error>;
|
|
15
|
+
//# sourceMappingURL=use-product-versions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-product-versions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-product-versions.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,yBAAyB;IACxC,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,OAAO,GAAE,yBAA8B;;;;;;;;;;UASxC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useQuery } from "@tanstack/react-query";
|
|
3
|
+
import { useVoyantProductsContext } from "../provider.js";
|
|
4
|
+
import { getProductVersionsQueryOptions } from "../query-options.js";
|
|
5
|
+
export function useProductVersions(productId, options = {}) {
|
|
6
|
+
const { baseUrl, fetcher } = useVoyantProductsContext();
|
|
7
|
+
const { enabled = true } = options;
|
|
8
|
+
return useQuery({
|
|
9
|
+
...getProductVersionsQueryOptions({ baseUrl, fetcher }, productId, options),
|
|
10
|
+
enabled: enabled && Boolean(productId),
|
|
11
|
+
});
|
|
12
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export { defaultFetcher, fetchWithValidation, VoyantApiError, type VoyantFetcher
|
|
|
2
2
|
export * from "./hooks/index.js";
|
|
3
3
|
export { useVoyantProductsContext, type VoyantProductsContextValue, VoyantProductsProvider, type VoyantProductsProviderProps, } from "./provider.js";
|
|
4
4
|
export { productsQueryKeys } from "./query-keys.js";
|
|
5
|
-
export { getOptionUnitQueryOptions, getOptionUnitsQueryOptions, getProductCategoriesQueryOptions, getProductOptionQueryOptions, getProductOptionsQueryOptions, getProductQueryOptions, getProductsQueryOptions, getProductTagsQueryOptions, getProductTypeQueryOptions, getProductTypesQueryOptions, } from "./query-options.js";
|
|
5
|
+
export { getOptionUnitQueryOptions, getOptionUnitsQueryOptions, getProductCategoriesQueryOptions, getProductDayServicesQueryOptions, getProductDaysQueryOptions, getProductMediaQueryOptions, getProductOptionQueryOptions, getProductOptionsQueryOptions, getProductQueryOptions, getProductsQueryOptions, getProductTagsQueryOptions, getProductTypeQueryOptions, getProductTypesQueryOptions, getProductVersionsQueryOptions, } from "./query-options.js";
|
|
6
6
|
export * from "./schemas.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,KAAK,aAAa,GACnB,MAAM,aAAa,CAAA;AACpB,cAAc,kBAAkB,CAAA;AAChC,OAAO,EACL,wBAAwB,EACxB,KAAK,0BAA0B,EAC/B,sBAAsB,EACtB,KAAK,2BAA2B,GACjC,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,gCAAgC,EAChC,4BAA4B,EAC5B,6BAA6B,EAC7B,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,KAAK,aAAa,GACnB,MAAM,aAAa,CAAA;AACpB,cAAc,kBAAkB,CAAA;AAChC,OAAO,EACL,wBAAwB,EACxB,KAAK,0BAA0B,EAC/B,sBAAsB,EACtB,KAAK,2BAA2B,GACjC,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,gCAAgC,EAChC,iCAAiC,EACjC,0BAA0B,EAC1B,2BAA2B,EAC3B,4BAA4B,EAC5B,6BAA6B,EAC7B,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAC1B,0BAA0B,EAC1B,2BAA2B,EAC3B,8BAA8B,GAC/B,MAAM,oBAAoB,CAAA;AAC3B,cAAc,cAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2,5 +2,5 @@ export { defaultFetcher, fetchWithValidation, VoyantApiError, } from "./client.j
|
|
|
2
2
|
export * from "./hooks/index.js";
|
|
3
3
|
export { useVoyantProductsContext, VoyantProductsProvider, } from "./provider.js";
|
|
4
4
|
export { productsQueryKeys } from "./query-keys.js";
|
|
5
|
-
export { getOptionUnitQueryOptions, getOptionUnitsQueryOptions, getProductCategoriesQueryOptions, getProductOptionQueryOptions, getProductOptionsQueryOptions, getProductQueryOptions, getProductsQueryOptions, getProductTagsQueryOptions, getProductTypeQueryOptions, getProductTypesQueryOptions, } from "./query-options.js";
|
|
5
|
+
export { getOptionUnitQueryOptions, getOptionUnitsQueryOptions, getProductCategoriesQueryOptions, getProductDayServicesQueryOptions, getProductDaysQueryOptions, getProductMediaQueryOptions, getProductOptionQueryOptions, getProductOptionsQueryOptions, getProductQueryOptions, getProductsQueryOptions, getProductTagsQueryOptions, getProductTypeQueryOptions, getProductTypesQueryOptions, getProductVersionsQueryOptions, } from "./query-options.js";
|
|
6
6
|
export * from "./schemas.js";
|