@medusajs/loyalty-plugin 2.21.2-snapshot-20260928075521 → 2.21.2

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.
@@ -41979,158 +41979,6 @@ const GiftCardProductEdit = () => {
41979
41979
  !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(GiftCardProductEditForm, { product })
41980
41980
  ] });
41981
41981
  };
41982
- const VariantPricingForm = ({ form }) => {
41983
- const { store } = useStore$2();
41984
- const { regions } = useRegions({ limit: 9999 });
41985
- const { price_preferences: pricePreferences } = usePricePreferences({});
41986
- const { setCloseOnEscape } = useRouteModal();
41987
- const columns = useVariantPriceGridColumns({
41988
- currencies: store?.supported_currencies,
41989
- regions,
41990
- pricePreferences
41991
- });
41992
- const variants = useWatch({
41993
- control: form.control,
41994
- name: "variants"
41995
- });
41996
- return /* @__PURE__ */ jsxRuntime.jsx(
41997
- DataGrid,
41998
- {
41999
- columns,
42000
- data: variants,
42001
- state: form,
42002
- onEditingChange: (editing) => setCloseOnEscape(!editing)
42003
- }
42004
- );
42005
- };
42006
- const columnHelper$1 = createDataGridHelper();
42007
- const useVariantPriceGridColumns = ({
42008
- currencies: currencies2 = [],
42009
- regions = [],
42010
- pricePreferences = []
42011
- }) => {
42012
- return React.useMemo(() => {
42013
- return [
42014
- columnHelper$1.column({
42015
- id: "Title",
42016
- header: "Title",
42017
- cell: (context) => {
42018
- const entity = context.row.original;
42019
- return /* @__PURE__ */ jsxRuntime.jsx(DataGrid.ReadonlyCell, { context, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-full w-full items-center gap-x-2 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: entity.title }) }) });
42020
- },
42021
- disableHiding: true
42022
- }),
42023
- ...createDataGridPriceColumns({
42024
- currencies: currencies2.map((c) => c.currency_code),
42025
- regions,
42026
- pricePreferences,
42027
- getFieldName: (context, value) => {
42028
- return `variants.${context.row.index}.prices.${value}`;
42029
- }
42030
- })
42031
- ];
42032
- }, [currencies2, regions, pricePreferences]);
42033
- };
42034
- const UpdateDenominationPricesSchema = zod__namespace.object({
42035
- variants: zod__namespace.array(
42036
- zod__namespace.object({
42037
- prices: zod__namespace.record(zod__namespace.string(), zod__namespace.string().or(zod__namespace.number()).optional()).optional()
42038
- })
42039
- )
42040
- });
42041
- const PricingEdit = ({
42042
- product,
42043
- variantId
42044
- }) => {
42045
- const { handleSuccess } = useRouteModal();
42046
- const { mutateAsync, isPending } = useUpdateProductVariantsBatch(product.id);
42047
- const { regions } = useRegions({ limit: 9999 });
42048
- const regionsCurrencyMap = React.useMemo(() => {
42049
- if (!regions?.length) {
42050
- return {};
42051
- }
42052
- return regions.reduce((acc, reg) => {
42053
- acc[reg.id] = reg.currency_code;
42054
- return acc;
42055
- }, {});
42056
- }, [regions]);
42057
- const variants = variantId ? product.variants?.filter((v) => v.id === variantId) : product.variants;
42058
- const form = useForm({
42059
- defaultValues: {
42060
- variants: variants?.map((variant) => ({
42061
- title: variant.title,
42062
- prices: variant.prices.reduce((acc, price) => {
42063
- if (price.rules?.region_id) {
42064
- acc[price.rules.region_id] = price.amount;
42065
- } else {
42066
- acc[price.currency_code] = price.amount;
42067
- }
42068
- return acc;
42069
- }, {})
42070
- }))
42071
- },
42072
- resolver: u(UpdateDenominationPricesSchema, {})
42073
- });
42074
- const handleSubmit = form.handleSubmit(async (values) => {
42075
- const reqData = values.variants.map((variant, ind) => ({
42076
- id: variants?.[ind]?.id,
42077
- prices: Object.entries(variant.prices || {}).filter(
42078
- ([_, value]) => value !== "" && typeof value !== "undefined"
42079
- // deleted cells
42080
- ).map(([currencyCodeOrRegionId, value]) => {
42081
- const regionId = currencyCodeOrRegionId.startsWith("reg_") ? currencyCodeOrRegionId : void 0;
42082
- const currencyCode = currencyCodeOrRegionId.startsWith("reg_") ? regionsCurrencyMap[regionId] : currencyCodeOrRegionId;
42083
- let existingId = void 0;
42084
- if (regionId) {
42085
- existingId = variants?.[ind]?.prices?.find(
42086
- (p) => p.rules["region_id"] === regionId
42087
- )?.id;
42088
- } else {
42089
- existingId = variants?.[ind]?.prices?.find(
42090
- (p) => p.currency_code === currencyCode && Object.keys(p.rules ?? {}).length === 0
42091
- )?.id;
42092
- }
42093
- const amount = castNumber(value);
42094
- return {
42095
- id: existingId,
42096
- currency_code: currencyCode,
42097
- amount,
42098
- ...regionId ? { rules: { region_id: regionId } } : {}
42099
- };
42100
- })
42101
- }));
42102
- await mutateAsync(reqData, {
42103
- onSuccess: () => {
42104
- handleSuccess("..");
42105
- }
42106
- });
42107
- });
42108
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { onSubmit: handleSubmit, className: "flex size-full flex-col", children: [
42109
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
42110
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(VariantPricingForm, { form }) }),
42111
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center justify-end gap-x-2", children: [
42112
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
42113
- /* @__PURE__ */ jsxRuntime.jsx(
42114
- ui.Button,
42115
- {
42116
- type: "submit",
42117
- variant: "primary",
42118
- size: "small",
42119
- isLoading: isPending,
42120
- children: "Save"
42121
- }
42122
- )
42123
- ] }) })
42124
- ] }) });
42125
- };
42126
- const ProductPrices = () => {
42127
- const { id, variant_id } = reactRouterDom.useParams();
42128
- const { product, isLoading, isError, error } = useProduct(id);
42129
- if (isError) {
42130
- throw error;
42131
- }
42132
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { children: !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(PricingEdit, { product, variantId: variant_id }) });
42133
- };
42134
41982
  const EditProductMediaForm = ({ product }) => {
42135
41983
  const [selection, setSelection] = React.useState({});
42136
41984
  const { handleSuccess } = useRouteModal();
@@ -42741,6 +42589,158 @@ const ProductMedia = () => {
42741
42589
  ready && /* @__PURE__ */ jsxRuntime.jsx(ProductMediaView, { product })
42742
42590
  ] });
42743
42591
  };
42592
+ const VariantPricingForm = ({ form }) => {
42593
+ const { store } = useStore$2();
42594
+ const { regions } = useRegions({ limit: 9999 });
42595
+ const { price_preferences: pricePreferences } = usePricePreferences({});
42596
+ const { setCloseOnEscape } = useRouteModal();
42597
+ const columns = useVariantPriceGridColumns({
42598
+ currencies: store?.supported_currencies,
42599
+ regions,
42600
+ pricePreferences
42601
+ });
42602
+ const variants = useWatch({
42603
+ control: form.control,
42604
+ name: "variants"
42605
+ });
42606
+ return /* @__PURE__ */ jsxRuntime.jsx(
42607
+ DataGrid,
42608
+ {
42609
+ columns,
42610
+ data: variants,
42611
+ state: form,
42612
+ onEditingChange: (editing) => setCloseOnEscape(!editing)
42613
+ }
42614
+ );
42615
+ };
42616
+ const columnHelper$1 = createDataGridHelper();
42617
+ const useVariantPriceGridColumns = ({
42618
+ currencies: currencies2 = [],
42619
+ regions = [],
42620
+ pricePreferences = []
42621
+ }) => {
42622
+ return React.useMemo(() => {
42623
+ return [
42624
+ columnHelper$1.column({
42625
+ id: "Title",
42626
+ header: "Title",
42627
+ cell: (context) => {
42628
+ const entity = context.row.original;
42629
+ return /* @__PURE__ */ jsxRuntime.jsx(DataGrid.ReadonlyCell, { context, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-full w-full items-center gap-x-2 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: entity.title }) }) });
42630
+ },
42631
+ disableHiding: true
42632
+ }),
42633
+ ...createDataGridPriceColumns({
42634
+ currencies: currencies2.map((c) => c.currency_code),
42635
+ regions,
42636
+ pricePreferences,
42637
+ getFieldName: (context, value) => {
42638
+ return `variants.${context.row.index}.prices.${value}`;
42639
+ }
42640
+ })
42641
+ ];
42642
+ }, [currencies2, regions, pricePreferences]);
42643
+ };
42644
+ const UpdateDenominationPricesSchema = zod__namespace.object({
42645
+ variants: zod__namespace.array(
42646
+ zod__namespace.object({
42647
+ prices: zod__namespace.record(zod__namespace.string(), zod__namespace.string().or(zod__namespace.number()).optional()).optional()
42648
+ })
42649
+ )
42650
+ });
42651
+ const PricingEdit = ({
42652
+ product,
42653
+ variantId
42654
+ }) => {
42655
+ const { handleSuccess } = useRouteModal();
42656
+ const { mutateAsync, isPending } = useUpdateProductVariantsBatch(product.id);
42657
+ const { regions } = useRegions({ limit: 9999 });
42658
+ const regionsCurrencyMap = React.useMemo(() => {
42659
+ if (!regions?.length) {
42660
+ return {};
42661
+ }
42662
+ return regions.reduce((acc, reg) => {
42663
+ acc[reg.id] = reg.currency_code;
42664
+ return acc;
42665
+ }, {});
42666
+ }, [regions]);
42667
+ const variants = variantId ? product.variants?.filter((v) => v.id === variantId) : product.variants;
42668
+ const form = useForm({
42669
+ defaultValues: {
42670
+ variants: variants?.map((variant) => ({
42671
+ title: variant.title,
42672
+ prices: variant.prices.reduce((acc, price) => {
42673
+ if (price.rules?.region_id) {
42674
+ acc[price.rules.region_id] = price.amount;
42675
+ } else {
42676
+ acc[price.currency_code] = price.amount;
42677
+ }
42678
+ return acc;
42679
+ }, {})
42680
+ }))
42681
+ },
42682
+ resolver: u(UpdateDenominationPricesSchema, {})
42683
+ });
42684
+ const handleSubmit = form.handleSubmit(async (values) => {
42685
+ const reqData = values.variants.map((variant, ind) => ({
42686
+ id: variants?.[ind]?.id,
42687
+ prices: Object.entries(variant.prices || {}).filter(
42688
+ ([_, value]) => value !== "" && typeof value !== "undefined"
42689
+ // deleted cells
42690
+ ).map(([currencyCodeOrRegionId, value]) => {
42691
+ const regionId = currencyCodeOrRegionId.startsWith("reg_") ? currencyCodeOrRegionId : void 0;
42692
+ const currencyCode = currencyCodeOrRegionId.startsWith("reg_") ? regionsCurrencyMap[regionId] : currencyCodeOrRegionId;
42693
+ let existingId = void 0;
42694
+ if (regionId) {
42695
+ existingId = variants?.[ind]?.prices?.find(
42696
+ (p) => p.rules["region_id"] === regionId
42697
+ )?.id;
42698
+ } else {
42699
+ existingId = variants?.[ind]?.prices?.find(
42700
+ (p) => p.currency_code === currencyCode && Object.keys(p.rules ?? {}).length === 0
42701
+ )?.id;
42702
+ }
42703
+ const amount = castNumber(value);
42704
+ return {
42705
+ id: existingId,
42706
+ currency_code: currencyCode,
42707
+ amount,
42708
+ ...regionId ? { rules: { region_id: regionId } } : {}
42709
+ };
42710
+ })
42711
+ }));
42712
+ await mutateAsync(reqData, {
42713
+ onSuccess: () => {
42714
+ handleSuccess("..");
42715
+ }
42716
+ });
42717
+ });
42718
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { onSubmit: handleSubmit, className: "flex size-full flex-col", children: [
42719
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
42720
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(VariantPricingForm, { form }) }),
42721
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center justify-end gap-x-2", children: [
42722
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
42723
+ /* @__PURE__ */ jsxRuntime.jsx(
42724
+ ui.Button,
42725
+ {
42726
+ type: "submit",
42727
+ variant: "primary",
42728
+ size: "small",
42729
+ isLoading: isPending,
42730
+ children: "Save"
42731
+ }
42732
+ )
42733
+ ] }) })
42734
+ ] }) });
42735
+ };
42736
+ const ProductPrices = () => {
42737
+ const { id, variant_id } = reactRouterDom.useParams();
42738
+ const { product, isLoading, isError, error } = useProduct(id);
42739
+ if (isError) {
42740
+ throw error;
42741
+ }
42742
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { children: !isLoading && product && /* @__PURE__ */ jsxRuntime.jsx(PricingEdit, { product, variantId: variant_id }) });
42743
+ };
42744
42744
  const EditSalesChannelsSchema = zod__namespace.object({
42745
42745
  sales_channels: zod__namespace.array(zod__namespace.string()).optional()
42746
42746
  });
@@ -42940,14 +42940,14 @@ const routeModule = {
42940
42940
  }
42941
42941
  ]
42942
42942
  },
42943
- {
42944
- Component: ProductPrices,
42945
- path: "/gift-cards/gift-card-products/:id/prices"
42946
- },
42947
42943
  {
42948
42944
  Component: ProductMedia,
42949
42945
  path: "/gift-cards/gift-card-products/:id/media"
42950
42946
  },
42947
+ {
42948
+ Component: ProductPrices,
42949
+ path: "/gift-cards/gift-card-products/:id/prices"
42950
+ },
42951
42951
  {
42952
42952
  Component: ProductSalesChannels,
42953
42953
  path: "/gift-cards/gift-card-products/:id/sales-channels"
@@ -41959,158 +41959,6 @@ const GiftCardProductEdit = () => {
41959
41959
  !isLoading && product && /* @__PURE__ */ jsx(GiftCardProductEditForm, { product })
41960
41960
  ] });
41961
41961
  };
41962
- const VariantPricingForm = ({ form }) => {
41963
- const { store } = useStore$2();
41964
- const { regions } = useRegions({ limit: 9999 });
41965
- const { price_preferences: pricePreferences } = usePricePreferences({});
41966
- const { setCloseOnEscape } = useRouteModal();
41967
- const columns = useVariantPriceGridColumns({
41968
- currencies: store?.supported_currencies,
41969
- regions,
41970
- pricePreferences
41971
- });
41972
- const variants = useWatch({
41973
- control: form.control,
41974
- name: "variants"
41975
- });
41976
- return /* @__PURE__ */ jsx(
41977
- DataGrid,
41978
- {
41979
- columns,
41980
- data: variants,
41981
- state: form,
41982
- onEditingChange: (editing) => setCloseOnEscape(!editing)
41983
- }
41984
- );
41985
- };
41986
- const columnHelper$1 = createDataGridHelper();
41987
- const useVariantPriceGridColumns = ({
41988
- currencies: currencies2 = [],
41989
- regions = [],
41990
- pricePreferences = []
41991
- }) => {
41992
- return useMemo(() => {
41993
- return [
41994
- columnHelper$1.column({
41995
- id: "Title",
41996
- header: "Title",
41997
- cell: (context) => {
41998
- const entity = context.row.original;
41999
- return /* @__PURE__ */ jsx(DataGrid.ReadonlyCell, { context, children: /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center gap-x-2 overflow-hidden", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: entity.title }) }) });
42000
- },
42001
- disableHiding: true
42002
- }),
42003
- ...createDataGridPriceColumns({
42004
- currencies: currencies2.map((c) => c.currency_code),
42005
- regions,
42006
- pricePreferences,
42007
- getFieldName: (context, value) => {
42008
- return `variants.${context.row.index}.prices.${value}`;
42009
- }
42010
- })
42011
- ];
42012
- }, [currencies2, regions, pricePreferences]);
42013
- };
42014
- const UpdateDenominationPricesSchema = zod.object({
42015
- variants: zod.array(
42016
- zod.object({
42017
- prices: zod.record(zod.string(), zod.string().or(zod.number()).optional()).optional()
42018
- })
42019
- )
42020
- });
42021
- const PricingEdit = ({
42022
- product,
42023
- variantId
42024
- }) => {
42025
- const { handleSuccess } = useRouteModal();
42026
- const { mutateAsync, isPending } = useUpdateProductVariantsBatch(product.id);
42027
- const { regions } = useRegions({ limit: 9999 });
42028
- const regionsCurrencyMap = useMemo(() => {
42029
- if (!regions?.length) {
42030
- return {};
42031
- }
42032
- return regions.reduce((acc, reg) => {
42033
- acc[reg.id] = reg.currency_code;
42034
- return acc;
42035
- }, {});
42036
- }, [regions]);
42037
- const variants = variantId ? product.variants?.filter((v) => v.id === variantId) : product.variants;
42038
- const form = useForm({
42039
- defaultValues: {
42040
- variants: variants?.map((variant) => ({
42041
- title: variant.title,
42042
- prices: variant.prices.reduce((acc, price) => {
42043
- if (price.rules?.region_id) {
42044
- acc[price.rules.region_id] = price.amount;
42045
- } else {
42046
- acc[price.currency_code] = price.amount;
42047
- }
42048
- return acc;
42049
- }, {})
42050
- }))
42051
- },
42052
- resolver: u(UpdateDenominationPricesSchema, {})
42053
- });
42054
- const handleSubmit = form.handleSubmit(async (values) => {
42055
- const reqData = values.variants.map((variant, ind) => ({
42056
- id: variants?.[ind]?.id,
42057
- prices: Object.entries(variant.prices || {}).filter(
42058
- ([_, value]) => value !== "" && typeof value !== "undefined"
42059
- // deleted cells
42060
- ).map(([currencyCodeOrRegionId, value]) => {
42061
- const regionId = currencyCodeOrRegionId.startsWith("reg_") ? currencyCodeOrRegionId : void 0;
42062
- const currencyCode = currencyCodeOrRegionId.startsWith("reg_") ? regionsCurrencyMap[regionId] : currencyCodeOrRegionId;
42063
- let existingId = void 0;
42064
- if (regionId) {
42065
- existingId = variants?.[ind]?.prices?.find(
42066
- (p) => p.rules["region_id"] === regionId
42067
- )?.id;
42068
- } else {
42069
- existingId = variants?.[ind]?.prices?.find(
42070
- (p) => p.currency_code === currencyCode && Object.keys(p.rules ?? {}).length === 0
42071
- )?.id;
42072
- }
42073
- const amount = castNumber(value);
42074
- return {
42075
- id: existingId,
42076
- currency_code: currencyCode,
42077
- amount,
42078
- ...regionId ? { rules: { region_id: regionId } } : {}
42079
- };
42080
- })
42081
- }));
42082
- await mutateAsync(reqData, {
42083
- onSuccess: () => {
42084
- handleSuccess("..");
42085
- }
42086
- });
42087
- });
42088
- return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { onSubmit: handleSubmit, className: "flex size-full flex-col", children: [
42089
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
42090
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-col overflow-hidden", children: /* @__PURE__ */ jsx(VariantPricingForm, { form }) }),
42091
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center justify-end gap-x-2", children: [
42092
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
42093
- /* @__PURE__ */ jsx(
42094
- Button,
42095
- {
42096
- type: "submit",
42097
- variant: "primary",
42098
- size: "small",
42099
- isLoading: isPending,
42100
- children: "Save"
42101
- }
42102
- )
42103
- ] }) })
42104
- ] }) });
42105
- };
42106
- const ProductPrices = () => {
42107
- const { id, variant_id } = useParams();
42108
- const { product, isLoading, isError, error } = useProduct(id);
42109
- if (isError) {
42110
- throw error;
42111
- }
42112
- return /* @__PURE__ */ jsx(RouteFocusModal, { children: !isLoading && product && /* @__PURE__ */ jsx(PricingEdit, { product, variantId: variant_id }) });
42113
- };
42114
41962
  const EditProductMediaForm = ({ product }) => {
42115
41963
  const [selection, setSelection] = useState({});
42116
41964
  const { handleSuccess } = useRouteModal();
@@ -42721,6 +42569,158 @@ const ProductMedia = () => {
42721
42569
  ready && /* @__PURE__ */ jsx(ProductMediaView, { product })
42722
42570
  ] });
42723
42571
  };
42572
+ const VariantPricingForm = ({ form }) => {
42573
+ const { store } = useStore$2();
42574
+ const { regions } = useRegions({ limit: 9999 });
42575
+ const { price_preferences: pricePreferences } = usePricePreferences({});
42576
+ const { setCloseOnEscape } = useRouteModal();
42577
+ const columns = useVariantPriceGridColumns({
42578
+ currencies: store?.supported_currencies,
42579
+ regions,
42580
+ pricePreferences
42581
+ });
42582
+ const variants = useWatch({
42583
+ control: form.control,
42584
+ name: "variants"
42585
+ });
42586
+ return /* @__PURE__ */ jsx(
42587
+ DataGrid,
42588
+ {
42589
+ columns,
42590
+ data: variants,
42591
+ state: form,
42592
+ onEditingChange: (editing) => setCloseOnEscape(!editing)
42593
+ }
42594
+ );
42595
+ };
42596
+ const columnHelper$1 = createDataGridHelper();
42597
+ const useVariantPriceGridColumns = ({
42598
+ currencies: currencies2 = [],
42599
+ regions = [],
42600
+ pricePreferences = []
42601
+ }) => {
42602
+ return useMemo(() => {
42603
+ return [
42604
+ columnHelper$1.column({
42605
+ id: "Title",
42606
+ header: "Title",
42607
+ cell: (context) => {
42608
+ const entity = context.row.original;
42609
+ return /* @__PURE__ */ jsx(DataGrid.ReadonlyCell, { context, children: /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center gap-x-2 overflow-hidden", children: /* @__PURE__ */ jsx("span", { className: "truncate", children: entity.title }) }) });
42610
+ },
42611
+ disableHiding: true
42612
+ }),
42613
+ ...createDataGridPriceColumns({
42614
+ currencies: currencies2.map((c) => c.currency_code),
42615
+ regions,
42616
+ pricePreferences,
42617
+ getFieldName: (context, value) => {
42618
+ return `variants.${context.row.index}.prices.${value}`;
42619
+ }
42620
+ })
42621
+ ];
42622
+ }, [currencies2, regions, pricePreferences]);
42623
+ };
42624
+ const UpdateDenominationPricesSchema = zod.object({
42625
+ variants: zod.array(
42626
+ zod.object({
42627
+ prices: zod.record(zod.string(), zod.string().or(zod.number()).optional()).optional()
42628
+ })
42629
+ )
42630
+ });
42631
+ const PricingEdit = ({
42632
+ product,
42633
+ variantId
42634
+ }) => {
42635
+ const { handleSuccess } = useRouteModal();
42636
+ const { mutateAsync, isPending } = useUpdateProductVariantsBatch(product.id);
42637
+ const { regions } = useRegions({ limit: 9999 });
42638
+ const regionsCurrencyMap = useMemo(() => {
42639
+ if (!regions?.length) {
42640
+ return {};
42641
+ }
42642
+ return regions.reduce((acc, reg) => {
42643
+ acc[reg.id] = reg.currency_code;
42644
+ return acc;
42645
+ }, {});
42646
+ }, [regions]);
42647
+ const variants = variantId ? product.variants?.filter((v) => v.id === variantId) : product.variants;
42648
+ const form = useForm({
42649
+ defaultValues: {
42650
+ variants: variants?.map((variant) => ({
42651
+ title: variant.title,
42652
+ prices: variant.prices.reduce((acc, price) => {
42653
+ if (price.rules?.region_id) {
42654
+ acc[price.rules.region_id] = price.amount;
42655
+ } else {
42656
+ acc[price.currency_code] = price.amount;
42657
+ }
42658
+ return acc;
42659
+ }, {})
42660
+ }))
42661
+ },
42662
+ resolver: u(UpdateDenominationPricesSchema, {})
42663
+ });
42664
+ const handleSubmit = form.handleSubmit(async (values) => {
42665
+ const reqData = values.variants.map((variant, ind) => ({
42666
+ id: variants?.[ind]?.id,
42667
+ prices: Object.entries(variant.prices || {}).filter(
42668
+ ([_, value]) => value !== "" && typeof value !== "undefined"
42669
+ // deleted cells
42670
+ ).map(([currencyCodeOrRegionId, value]) => {
42671
+ const regionId = currencyCodeOrRegionId.startsWith("reg_") ? currencyCodeOrRegionId : void 0;
42672
+ const currencyCode = currencyCodeOrRegionId.startsWith("reg_") ? regionsCurrencyMap[regionId] : currencyCodeOrRegionId;
42673
+ let existingId = void 0;
42674
+ if (regionId) {
42675
+ existingId = variants?.[ind]?.prices?.find(
42676
+ (p) => p.rules["region_id"] === regionId
42677
+ )?.id;
42678
+ } else {
42679
+ existingId = variants?.[ind]?.prices?.find(
42680
+ (p) => p.currency_code === currencyCode && Object.keys(p.rules ?? {}).length === 0
42681
+ )?.id;
42682
+ }
42683
+ const amount = castNumber(value);
42684
+ return {
42685
+ id: existingId,
42686
+ currency_code: currencyCode,
42687
+ amount,
42688
+ ...regionId ? { rules: { region_id: regionId } } : {}
42689
+ };
42690
+ })
42691
+ }));
42692
+ await mutateAsync(reqData, {
42693
+ onSuccess: () => {
42694
+ handleSuccess("..");
42695
+ }
42696
+ });
42697
+ });
42698
+ return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { onSubmit: handleSubmit, className: "flex size-full flex-col", children: [
42699
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
42700
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-col overflow-hidden", children: /* @__PURE__ */ jsx(VariantPricingForm, { form }) }),
42701
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center justify-end gap-x-2", children: [
42702
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
42703
+ /* @__PURE__ */ jsx(
42704
+ Button,
42705
+ {
42706
+ type: "submit",
42707
+ variant: "primary",
42708
+ size: "small",
42709
+ isLoading: isPending,
42710
+ children: "Save"
42711
+ }
42712
+ )
42713
+ ] }) })
42714
+ ] }) });
42715
+ };
42716
+ const ProductPrices = () => {
42717
+ const { id, variant_id } = useParams();
42718
+ const { product, isLoading, isError, error } = useProduct(id);
42719
+ if (isError) {
42720
+ throw error;
42721
+ }
42722
+ return /* @__PURE__ */ jsx(RouteFocusModal, { children: !isLoading && product && /* @__PURE__ */ jsx(PricingEdit, { product, variantId: variant_id }) });
42723
+ };
42724
42724
  const EditSalesChannelsSchema = zod.object({
42725
42725
  sales_channels: zod.array(zod.string()).optional()
42726
42726
  });
@@ -42920,14 +42920,14 @@ const routeModule = {
42920
42920
  }
42921
42921
  ]
42922
42922
  },
42923
- {
42924
- Component: ProductPrices,
42925
- path: "/gift-cards/gift-card-products/:id/prices"
42926
- },
42927
42923
  {
42928
42924
  Component: ProductMedia,
42929
42925
  path: "/gift-cards/gift-card-products/:id/media"
42930
42926
  },
42927
+ {
42928
+ Component: ProductPrices,
42929
+ path: "/gift-cards/gift-card-products/:id/prices"
42930
+ },
42931
42931
  {
42932
42932
  Component: ProductSalesChannels,
42933
42933
  path: "/gift-cards/gift-card-products/:id/sales-channels"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/loyalty-plugin",
3
- "version": "2.21.2-snapshot-20260928075521",
3
+ "version": "2.21.2",
4
4
  "description": "Medusa Plugin: Loyalty - Gift Cards",
5
5
  "author": "Medusa (https://medusajs.com)",
6
6
  "license": "MIT",
@@ -55,16 +55,16 @@
55
55
  "watch": "medusa plugin:develop"
56
56
  },
57
57
  "devDependencies": {
58
- "@medusajs/admin-sdk": "2.21.2-snapshot-20260928075521",
59
- "@medusajs/cli": "2.21.2-snapshot-20260928075521",
60
- "@medusajs/dashboard": "2.21.2-snapshot-20260928075521",
61
- "@medusajs/framework": "2.21.2-snapshot-20260928075521",
62
- "@medusajs/icons": "2.21.2-snapshot-20260928075521",
63
- "@medusajs/medusa": "2.21.2-snapshot-20260928075521",
64
- "@medusajs/test-utils": "2.21.2-snapshot-20260928075521",
65
- "@medusajs/types": "2.21.2-snapshot-20260928075521",
66
- "@medusajs/ui": "4.2.6-snapshot-20260928075521",
67
- "@medusajs/ui-preset": "2.21.2-snapshot-20260928075521",
58
+ "@medusajs/admin-sdk": "2.21.2",
59
+ "@medusajs/cli": "2.21.2",
60
+ "@medusajs/dashboard": "2.21.2",
61
+ "@medusajs/framework": "2.21.2",
62
+ "@medusajs/icons": "2.21.2",
63
+ "@medusajs/medusa": "2.21.2",
64
+ "@medusajs/test-utils": "2.21.2",
65
+ "@medusajs/types": "2.21.2",
66
+ "@medusajs/ui": "4.2.6",
67
+ "@medusajs/ui-preset": "2.21.2",
68
68
  "@swc/core": "1.5.7",
69
69
  "@types/node": "^20.0.0",
70
70
  "cross-env": "^7.0.3",
@@ -72,14 +72,14 @@
72
72
  "typescript": "^5.7.3"
73
73
  },
74
74
  "peerDependencies": {
75
- "@medusajs/admin-sdk": "2.21.2-snapshot-20260928075521",
76
- "@medusajs/cli": "2.21.2-snapshot-20260928075521",
77
- "@medusajs/dashboard": "2.21.2-snapshot-20260928075521",
78
- "@medusajs/framework": "2.21.2-snapshot-20260928075521",
79
- "@medusajs/icons": "2.21.2-snapshot-20260928075521",
80
- "@medusajs/medusa": "2.21.2-snapshot-20260928075521",
81
- "@medusajs/test-utils": "2.21.2-snapshot-20260928075521",
82
- "@medusajs/ui": "4.2.6-snapshot-20260928075521",
75
+ "@medusajs/admin-sdk": "2.21.2",
76
+ "@medusajs/cli": "2.21.2",
77
+ "@medusajs/dashboard": "2.21.2",
78
+ "@medusajs/framework": "2.21.2",
79
+ "@medusajs/icons": "2.21.2",
80
+ "@medusajs/medusa": "2.21.2",
81
+ "@medusajs/test-utils": "2.21.2",
82
+ "@medusajs/ui": "4.2.6",
83
83
  "react": "^18.3.1",
84
84
  "react-dom": "^18.3.1",
85
85
  "react-router-dom": "^6.30.4 || ^7.0.0"