@tapcart/mobile-components 0.8.7 → 0.8.9

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.
@@ -69,7 +69,11 @@ export declare const useMockCart: ({ apiUrl, appId, enabled, limit, }: UseMockCa
69
69
  amount: string;
70
70
  currencyCode: string;
71
71
  };
72
- };
72
+ compareAtPrice: {
73
+ amount: string;
74
+ currencyCode: string;
75
+ };
76
+ }[];
73
77
  sellingPlan: {
74
78
  id: string;
75
79
  name: string;
@@ -1 +1 @@
1
- {"version":3,"file":"use-mock-cart.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-mock-cart.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAA;AAgLhF,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,WAAW,uCAKrB,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCnB,CAAA"}
1
+ {"version":3,"file":"use-mock-cart.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-mock-cart.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAA;AAsLhF,KAAK,iBAAiB,GAAG;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,WAAW,uCAKrB,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCnB,CAAA"}
@@ -60,16 +60,22 @@ const transformCart = ({ products, cartOrigin = cartMock, }) => {
60
60
  }
61
61
  const sellingPlanAllocation = i === 0
62
62
  ? {
63
- priceAdjustments: {
64
- perDeliveryPrice: {
65
- amount: price.toString(),
66
- currencyCode: "USD",
63
+ priceAdjustments: [
64
+ {
65
+ perDeliveryPrice: {
66
+ amount: price.toString(),
67
+ currencyCode: "USD",
68
+ },
69
+ price: {
70
+ amount: price.toString(),
71
+ currencyCode: "USD",
72
+ },
73
+ compareAtPrice: {
74
+ amount: (price * 1.2).toString(),
75
+ currencyCode: "USD",
76
+ },
67
77
  },
68
- price: {
69
- amount: price.toString(),
70
- currencyCode: "USD",
71
- },
72
- },
78
+ ],
73
79
  sellingPlan: {
74
80
  id: "gid://shopify/SellingPlan/123",
75
81
  name: "Delivery every 30 Days",
@@ -1,5 +1,5 @@
1
1
  import { KMP } from "./kmp";
2
- import { FilterCategory } from "@/components/libs/sort-filter/search-integration";
2
+ import { FilterCategory } from "../../../components/libs/sort-filter/search-integration";
3
3
  import { ReadonlyURLSearchParams } from "next/navigation";
4
4
  import { Integration } from "app-studio-types";
5
5
  export declare class CustomSearch extends KMP {
@@ -1,4 +1,4 @@
1
- import { InputProps } from "@/components/ui/Input/types";
1
+ import { InputProps } from "../../../components/ui/Input/types";
2
2
  import * as React from "react";
3
3
  declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
4
4
  export { Input };
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import type { VariantProps } from "class-variance-authority";
3
- import { inputVariants } from "@/components/ui/Input/useInput";
4
- import { Color, TextStyle } from "@/lib/utils";
3
+ import { inputVariants } from "../../../components/ui/Input/useInput";
4
+ import { Color, TextStyle } from "../../../lib/utils";
5
5
  export type BorderSides = ("all" | "bottom" | "left" | "right" | "top")[];
6
6
  export interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange">, VariantProps<typeof inputVariants> {
7
7
  id: string;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { InputProps } from "@/components/ui/Input/types";
2
+ import { InputProps } from "../../../components/ui/Input/types";
3
3
  export declare const DEFAULT_ICON_SIZE = 20;
4
4
  export declare const DEFAULT_X_PADDING = 12;
5
5
  export declare const DEFAULT_Y_PADDING = 8;
@@ -1,4 +1,29 @@
1
- import { EnrichedCart, CartCalculatedDiscount, CartCalculatedAppliedGiftCard } from "app-studio-types";
1
+ import { EnrichedCart, CartCalculatedDiscount, CartCalculatedAppliedGiftCard, ProductVariant } from "app-studio-types";
2
+ export declare const getVariantPrice: ({ quantity, variant, sellingPlanAllocation, }: {
3
+ quantity: number;
4
+ variant: ProductVariant;
5
+ sellingPlanAllocation?: {
6
+ priceAdjustments: {
7
+ perDeliveryPrice?: {
8
+ amount: string;
9
+ currencyCode: string;
10
+ };
11
+ price: {
12
+ amount: string;
13
+ currencyCode: string;
14
+ };
15
+ compareAtPrice?: {
16
+ amount: string;
17
+ currencyCode: string;
18
+ };
19
+ }[];
20
+ } | undefined;
21
+ }) => {
22
+ price: number;
23
+ compareAtPrice: number;
24
+ currency: string;
25
+ isSale: boolean;
26
+ };
2
27
  export declare const isOrderLevelDiscount: (code: string, cart: EnrichedCart) => boolean;
3
28
  export declare const isLineItemDiscount: (code: string, cart: EnrichedCart) => boolean;
4
29
  export type CalculatedData = {
@@ -10,11 +35,14 @@ export type CalculatedData = {
10
35
  salesAmount: number;
11
36
  totalCompareAtPrice: number;
12
37
  totalDiscountedPrice: number;
38
+ totalSavedAmount: number;
13
39
  };
14
40
  export declare const DEFAULT_CALCULATED_DATA: CalculatedData;
15
41
  export declare const getCalculatedCartData: (cart: EnrichedCart) => CalculatedData;
16
42
  export declare const getCartItemKey: (variantId: string, sellingPlanId?: string, attributes?: {
43
+ [key: string]: string;
44
+ } | {
17
45
  key: string;
18
46
  value: string;
19
- }[]) => string;
47
+ }[] | undefined) => string;
20
48
  //# sourceMappingURL=cart.util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cart.util.d.ts","sourceRoot":"","sources":["../../lib/cart.util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,6BAA6B,EAC9B,MAAM,kBAAkB,CAAA;AA4CzB,eAAO,MAAM,oBAAoB,SAAU,MAAM,QAAQ,YAAY,YAMpE,CAAA;AAED,eAAO,MAAM,kBAAkB,SAAU,MAAM,QAAQ,YAAY,YAMlE,CAAA;AAqGD,MAAM,MAAM,cAAc,GAAG;IAC3B,yBAAyB,EAAE,sBAAsB,EAAE,CAAA;IACnD,gBAAgB,EAAE,6BAA6B,EAAE,CAAA;IACjD,cAAc,EAAE,OAAO,CAAA;IACvB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,oBAAoB,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,cASrC,CAAA;AAED,eAAO,MAAM,qBAAqB,SAAU,YAAY,KAAG,cA4B1D,CAAA;AAED,eAAO,MAAM,cAAc,cACd,MAAM,kBACD,MAAM,eACT;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAAE,WAO9C,CAAA"}
1
+ {"version":3,"file":"cart.util.d.ts","sourceRoot":"","sources":["../../lib/cart.util.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,6BAA6B,EAE7B,cAAc,EACf,MAAM,kBAAkB,CAAA;AAGzB,eAAO,MAAM,eAAe;cAKhB,MAAM;aACP,cAAc;;0BAEH;YAChB,gBAAgB,CAAC,EAAE;gBACjB,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;YACD,KAAK,EAAE;gBACL,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;YACD,cAAc,CAAC,EAAE;gBACf,MAAM,EAAE,MAAM,CAAA;gBACd,YAAY,EAAE,MAAM,CAAA;aACrB,CAAA;SACF,EAAE;;;;;;;CAgCN,CAAA;AA2CD,eAAO,MAAM,oBAAoB,SAAU,MAAM,QAAQ,YAAY,YAMpE,CAAA;AAED,eAAO,MAAM,kBAAkB,SAAU,MAAM,QAAQ,YAAY,YAMlE,CAAA;AAoHD,MAAM,MAAM,cAAc,GAAG;IAC3B,yBAAyB,EAAE,sBAAsB,EAAE,CAAA;IACnD,gBAAgB,EAAE,6BAA6B,EAAE,CAAA;IACjD,cAAc,EAAE,OAAO,CAAA;IACvB,oBAAoB,EAAE,MAAM,CAAA;IAC5B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,oBAAoB,EAAE,MAAM,CAAA;IAC5B,gBAAgB,EAAE,MAAM,CAAA;CACzB,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,cAUrC,CAAA;AAED,eAAO,MAAM,qBAAqB,SAAU,YAAY,KAAG,cA8B1D,CAAA;AAED,eAAO,MAAM,cAAc,cACd,MAAM,kBACD,MAAM;;;SACF,MAAM;WAAS,MAAM;0BAW1C,CAAA"}
@@ -1,4 +1,30 @@
1
1
  import { getIdFromGid } from "./utils";
2
+ export const getVariantPrice = ({ quantity, variant, sellingPlanAllocation = { priceAdjustments: [] }, }) => {
3
+ var _a, _b, _c, _d;
4
+ const isSubscription = ((_a = sellingPlanAllocation === null || sellingPlanAllocation === void 0 ? void 0 : sellingPlanAllocation.priceAdjustments) === null || _a === void 0 ? void 0 : _a.length) > 0;
5
+ if (isSubscription) {
6
+ const { perDeliveryPrice, price, compareAtPrice } = sellingPlanAllocation.priceAdjustments[0];
7
+ const effectivePrice = perDeliveryPrice || price;
8
+ const subscriptionUnitPrice = parseFloat((perDeliveryPrice === null || perDeliveryPrice === void 0 ? void 0 : perDeliveryPrice.amount) || "0") || 0;
9
+ const effectiveCompareAtPrice = parseFloat((compareAtPrice === null || compareAtPrice === void 0 ? void 0 : compareAtPrice.amount) || "0") ||
10
+ parseFloat((price === null || price === void 0 ? void 0 : price.amount) || "0") ||
11
+ 0;
12
+ return {
13
+ price: subscriptionUnitPrice * quantity,
14
+ compareAtPrice: effectiveCompareAtPrice * quantity,
15
+ currency: effectivePrice === null || effectivePrice === void 0 ? void 0 : effectivePrice.currencyCode,
16
+ isSale: subscriptionUnitPrice < effectiveCompareAtPrice,
17
+ };
18
+ }
19
+ const variantUnitPrice = parseFloat((_b = variant === null || variant === void 0 ? void 0 : variant.price) === null || _b === void 0 ? void 0 : _b.amount) || 0;
20
+ const variantComparePrice = parseFloat((_c = variant === null || variant === void 0 ? void 0 : variant.compareAtPrice) === null || _c === void 0 ? void 0 : _c.amount) || 0;
21
+ return {
22
+ price: variantUnitPrice * quantity,
23
+ compareAtPrice: variantComparePrice * quantity,
24
+ currency: (_d = variant === null || variant === void 0 ? void 0 : variant.price) === null || _d === void 0 ? void 0 : _d.currencyCode,
25
+ isSale: variantUnitPrice < variantComparePrice,
26
+ };
27
+ };
2
28
  const getOrderLevelDiscounts = (cart) => {
3
29
  var _a;
4
30
  const discountMap = (_a = cart.discountAllocations) === null || _a === void 0 ? void 0 : _a.filter((discount) => discount.targetType !== "SHIPPING_LINE").reduce((acc, discount) => {
@@ -52,12 +78,13 @@ const getAppliedGiftCards = (cart) => {
52
78
  const getSalesAmount = (cart) => {
53
79
  var _a;
54
80
  return (_a = cart.items) === null || _a === void 0 ? void 0 : _a.reduce((acc, item) => {
55
- var _a, _b, _c, _d;
56
- const compareAtPrice = +(((_b = (_a = item.variantDetails) === null || _a === void 0 ? void 0 : _a.compareAtPrice) === null || _b === void 0 ? void 0 : _b.amount) || 0);
57
- const price = +(((_d = (_c = item.variantDetails) === null || _c === void 0 ? void 0 : _c.price) === null || _d === void 0 ? void 0 : _d.amount) || 0);
58
- const quantity = item.quantity || 1;
81
+ const { compareAtPrice, price } = getVariantPrice({
82
+ quantity: item.quantity || 1,
83
+ variant: item.variantDetails,
84
+ sellingPlanAllocation: item.sellingPlanAllocation,
85
+ });
59
86
  if (compareAtPrice && compareAtPrice > price) {
60
- return acc + (compareAtPrice - price) * quantity;
87
+ return acc + (compareAtPrice - price);
61
88
  }
62
89
  return acc;
63
90
  }, 0);
@@ -120,6 +147,13 @@ const getTotalDiscountedPrice = (totalCompareAtPrice, discountsTotalAmount, sale
120
147
  : giftCardsTotalAmount);
121
148
  return isNaN(total) ? 0 : total;
122
149
  };
150
+ const getTotalSavedAmount = (cart) => {
151
+ const salesAmount = getSalesAmount(cart);
152
+ const totalDiscountsAmount = getDiscountsTotalAmount(getOrderLevelDiscounts(cart).concat(getLineItemDiscounts(cart)));
153
+ const totalGiftCardsAmount = getGiftCardsTotalAmount(getAppliedGiftCards(cart));
154
+ const totalSavedAmount = salesAmount + totalDiscountsAmount + totalGiftCardsAmount;
155
+ return totalSavedAmount;
156
+ };
123
157
  export const DEFAULT_CALCULATED_DATA = {
124
158
  orderAndLineItemDiscounts: [],
125
159
  appliedGiftCards: [],
@@ -129,6 +163,7 @@ export const DEFAULT_CALCULATED_DATA = {
129
163
  giftCardsTotalAmount: 0,
130
164
  totalCompareAtPrice: 0,
131
165
  totalDiscountedPrice: 0,
166
+ totalSavedAmount: 0,
132
167
  };
133
168
  export const getCalculatedCartData = (cart) => {
134
169
  const orderAndLineItemDiscounts = getOrderLevelDiscounts(cart).concat(getLineItemDiscounts(cart));
@@ -139,6 +174,7 @@ export const getCalculatedCartData = (cart) => {
139
174
  const salesAmount = getSalesAmount(cart);
140
175
  const totalCompareAtPrice = getTotalCompareAtPrice(cart);
141
176
  const totalDiscountedPrice = getTotalDiscountedPrice(totalCompareAtPrice, discountsTotalAmount, salesAmount, giftCardsTotalAmount);
177
+ const totalSavedAmount = getTotalSavedAmount(cart);
142
178
  return {
143
179
  orderAndLineItemDiscounts,
144
180
  appliedGiftCards,
@@ -148,9 +184,14 @@ export const getCalculatedCartData = (cart) => {
148
184
  salesAmount,
149
185
  totalCompareAtPrice,
150
186
  totalDiscountedPrice,
187
+ totalSavedAmount,
151
188
  };
152
189
  };
153
190
  export const getCartItemKey = (variantId, sellingPlanId, attributes) => {
154
- const key = `${getIdFromGid(variantId)}:${sellingPlanId || "no-plan"}:${attributes === null || attributes === void 0 ? void 0 : attributes.map((attr) => `${attr.key}-${attr.value}`).join("-")}`;
191
+ const key = `${getIdFromGid(variantId)}:${sellingPlanId || "no-plan"}:${Array.isArray(attributes)
192
+ ? attributes === null || attributes === void 0 ? void 0 : attributes.map((attr) => `${attr.key}-${attr.value}`).join("-")
193
+ : Object.entries(attributes || {})
194
+ .map(([key, value]) => `${key}-${value}`)
195
+ .join("-")}`;
155
196
  return key;
156
197
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapcart/mobile-components",
3
- "version": "0.8.7",
3
+ "version": "0.8.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "style": "dist/styles.css",
@@ -1,15 +0,0 @@
1
- import AppStudioCache from "./AppStudioCache";
2
- type CartCache = {
3
- [key: string]: any;
4
- };
5
- export default class CartLocalStorage extends AppStudioCache {
6
- adapter: string;
7
- cachePrefix: string;
8
- getCacheKey(): string;
9
- constructor();
10
- getCache(): CartCache | null;
11
- setCacheItem(cart: CartCache): CartCache | null;
12
- clearCache(): void;
13
- }
14
- export {};
15
- //# sourceMappingURL=CartLocalStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CartLocalStorage.d.ts","sourceRoot":"","sources":["../../../../components/libs/cache/CartLocalStorage.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAE7C,KAAK,SAAS,GAAG;IAEf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB,CAAA;AAED,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,cAAc;IAC1D,OAAO,EAAE,MAAM,CAAuB;IACtC,WAAW,EAAE,MAAM,CAAY;IAE/B,WAAW;;IASX,QAAQ,IAAI,SAAS,GAAG,IAAI;IAa5B,YAAY,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI;IAM/C,UAAU;CAGX"}
@@ -1,34 +0,0 @@
1
- import AppStudioCache from "./AppStudioCache";
2
- export default class CartLocalStorage extends AppStudioCache {
3
- getCacheKey() {
4
- return `${this.cachePrefix}`;
5
- }
6
- constructor() {
7
- super();
8
- this.adapter = "local-storage-cart";
9
- this.cachePrefix = "as-cart";
10
- console.log(this.adapter, this.cachePrefix);
11
- }
12
- getCache() {
13
- const value = localStorage.getItem(this.getCacheKey());
14
- try {
15
- if (value) {
16
- const parsedValue = JSON.parse(value);
17
- return parsedValue;
18
- }
19
- }
20
- catch (error) {
21
- // ignore invalid JSON error and return null
22
- }
23
- return null;
24
- }
25
- setCacheItem(cart) {
26
- if (!cart)
27
- return this.getCache();
28
- localStorage.setItem(this.getCacheKey(), JSON.stringify(cart));
29
- return cart;
30
- }
31
- clearCache() {
32
- localStorage.removeItem(this.getCacheKey());
33
- }
34
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/libs/cache/index.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,4 +0,0 @@
1
- import { LeadingActions, SwipeableList, SwipeableListItem, SwipeAction, TrailingActions, Type as ListType } from "react-swipeable-list";
2
- import "react-swipeable-list/dist/styles.css";
3
- export { LeadingActions, SwipeableList, SwipeableListItem, SwipeAction, TrailingActions, ListType, };
4
- //# sourceMappingURL=swipeable-list.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"swipeable-list.d.ts","sourceRoot":"","sources":["../../../components/ui/swipeable-list.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,IAAI,IAAI,QAAQ,EACjB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,sCAAsC,CAAA;AAE7C,OAAO,EACL,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,eAAe,EACf,QAAQ,GACT,CAAA"}
@@ -1,4 +0,0 @@
1
- "use client";
2
- import { LeadingActions, SwipeableList, SwipeableListItem, SwipeAction, TrailingActions, Type as ListType, } from "react-swipeable-list";
3
- import "react-swipeable-list/dist/styles.css";
4
- export { LeadingActions, SwipeableList, SwipeableListItem, SwipeAction, TrailingActions, ListType, };