@voyantjs/pricing-react 0.6.8 → 0.7.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.
@@ -7,6 +7,7 @@ export * from "./use-cancellation-policy-rules.js";
7
7
  export * from "./use-dropoff-price-rule.js";
8
8
  export * from "./use-dropoff-price-rule-mutation.js";
9
9
  export * from "./use-dropoff-price-rules.js";
10
+ export * from "./use-duplicate-option-pricing-mutation.js";
10
11
  export * from "./use-extra-price-rule.js";
11
12
  export * from "./use-extra-price-rule-mutation.js";
12
13
  export * from "./use-extra-price-rules.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAA;AAC9C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,uCAAuC,CAAA;AACrD,cAAc,mCAAmC,CAAA;AACjD,cAAc,4CAA4C,CAAA;AAC1D,cAAc,oCAAoC,CAAA;AAClD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,sCAAsC,CAAA;AACpD,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA;AACzC,cAAc,oCAAoC,CAAA;AAClD,cAAc,4BAA4B,CAAA;AAC1C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,qCAAqC,CAAA;AACnD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,0CAA0C,CAAA;AACxD,cAAc,kCAAkC,CAAA;AAChD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,0CAA0C,CAAA;AACxD,cAAc,kCAAkC,CAAA;AAChD,cAAc,2BAA2B,CAAA;AACzC,cAAc,oCAAoC,CAAA;AAClD,cAAc,4BAA4B,CAAA;AAC1C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,qCAAqC,CAAA;AACnD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,wBAAwB,CAAA;AACtC,cAAc,i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kCAAkC,CAAA;AAChD,cAAc,0BAA0B,CAAA;AACxC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,wCAAwC,CAAA;AACtD,cAAc,sCAAsC,CAAA;AACpD,cAAc,+CAA+C,CAAA;AAC7D,cAAc,oCAAoC,CAAA"}
@@ -7,6 +7,7 @@ export * from "./use-cancellation-policy-rules.js";
7
7
  export * from "./use-dropoff-price-rule.js";
8
8
  export * from "./use-dropoff-price-rule-mutation.js";
9
9
  export * from "./use-dropoff-price-rules.js";
10
+ export * from "./use-duplicate-option-pricing-mutation.js";
10
11
  export * from "./use-extra-price-rule.js";
11
12
  export * from "./use-extra-price-rule-mutation.js";
12
13
  export * from "./use-extra-price-rules.js";
@@ -0,0 +1,8 @@
1
+ export interface DuplicateOptionPricingInput {
2
+ sourceOptionId: string;
3
+ targetOptionId: string;
4
+ productId: string;
5
+ unitIdMap: Record<string, string>;
6
+ }
7
+ export declare function useDuplicateOptionPricingMutation(): import("@tanstack/react-query").UseMutationResult<void, Error, DuplicateOptionPricingInput, unknown>;
8
+ //# sourceMappingURL=use-duplicate-option-pricing-mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-duplicate-option-pricing-mutation.d.ts","sourceRoot":"","sources":["../../src/hooks/use-duplicate-option-pricing-mutation.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,2BAA2B;IAC1C,cAAc,EAAE,MAAM,CAAA;IACtB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC;AAED,wBAAgB,iCAAiC,yGAwEhD"}
@@ -0,0 +1,64 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { fetchWithValidation } from "../client.js";
4
+ import { useVoyantPricingContext } from "../provider.js";
5
+ import { pricingQueryKeys } from "../query-keys.js";
6
+ import { optionPriceRuleListResponse, optionUnitPriceRuleListResponse } from "../schemas.js";
7
+ import { useOptionPriceRuleMutation } from "./use-option-price-rule-mutation.js";
8
+ import { useOptionUnitPriceRuleMutation } from "./use-option-unit-price-rule-mutation.js";
9
+ export function useDuplicateOptionPricingMutation() {
10
+ const { baseUrl, fetcher } = useVoyantPricingContext();
11
+ const queryClient = useQueryClient();
12
+ const { create: createRule } = useOptionPriceRuleMutation();
13
+ const { create: createUnitPriceRule } = useOptionUnitPriceRuleMutation();
14
+ return useMutation({
15
+ mutationFn: async ({ sourceOptionId, targetOptionId, productId, unitIdMap, }) => {
16
+ const { data: sourceRules } = await fetchWithValidation(`/v1/pricing/option-price-rules?optionId=${encodeURIComponent(sourceOptionId)}&limit=100`, optionPriceRuleListResponse, { baseUrl, fetcher });
17
+ for (const rule of sourceRules) {
18
+ const duplicatedRule = await createRule.mutateAsync({
19
+ productId,
20
+ optionId: targetOptionId,
21
+ priceCatalogId: rule.priceCatalogId,
22
+ priceScheduleId: rule.priceScheduleId,
23
+ cancellationPolicyId: rule.cancellationPolicyId,
24
+ code: rule.code,
25
+ name: rule.name,
26
+ description: rule.description,
27
+ pricingMode: rule.pricingMode,
28
+ baseSellAmountCents: rule.baseSellAmountCents,
29
+ baseCostAmountCents: rule.baseCostAmountCents,
30
+ minPerBooking: rule.minPerBooking,
31
+ maxPerBooking: rule.maxPerBooking,
32
+ allPricingCategories: rule.allPricingCategories,
33
+ isDefault: rule.isDefault,
34
+ active: rule.active,
35
+ notes: rule.notes,
36
+ });
37
+ const { data: sourceUnitPriceRules } = await fetchWithValidation(`/v1/pricing/option-unit-price-rules?optionPriceRuleId=${encodeURIComponent(rule.id)}&limit=500`, optionUnitPriceRuleListResponse, { baseUrl, fetcher });
38
+ for (const unitPriceRule of sourceUnitPriceRules) {
39
+ const duplicatedUnitId = unitIdMap[unitPriceRule.unitId];
40
+ if (!duplicatedUnitId)
41
+ continue;
42
+ await createUnitPriceRule.mutateAsync({
43
+ optionPriceRuleId: duplicatedRule.id,
44
+ optionId: targetOptionId,
45
+ unitId: duplicatedUnitId,
46
+ pricingCategoryId: unitPriceRule.pricingCategoryId,
47
+ pricingMode: unitPriceRule.pricingMode,
48
+ sellAmountCents: unitPriceRule.sellAmountCents,
49
+ costAmountCents: unitPriceRule.costAmountCents,
50
+ minQuantity: unitPriceRule.minQuantity,
51
+ maxQuantity: unitPriceRule.maxQuantity,
52
+ sortOrder: unitPriceRule.sortOrder,
53
+ active: unitPriceRule.active,
54
+ notes: unitPriceRule.notes,
55
+ });
56
+ }
57
+ }
58
+ },
59
+ onSuccess: () => {
60
+ void queryClient.invalidateQueries({ queryKey: pricingQueryKeys.optionPriceRules() });
61
+ void queryClient.invalidateQueries({ queryKey: pricingQueryKeys.optionUnitPriceRules() });
62
+ },
63
+ });
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyantjs/pricing-react",
3
- "version": "0.6.8",
3
+ "version": "0.7.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/pricing": "0.6.8"
38
+ "@voyantjs/pricing": "0.7.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/pricing": "0.6.8",
50
- "@voyantjs/react": "0.6.8",
49
+ "@voyantjs/pricing": "0.7.0",
50
+ "@voyantjs/react": "0.7.0",
51
51
  "@voyantjs/voyant-typescript-config": "0.1.0"
52
52
  },
53
53
  "dependencies": {
54
- "@voyantjs/react": "0.6.8"
54
+ "@voyantjs/react": "0.7.0"
55
55
  },
56
56
  "files": [
57
57
  "dist"