@lookiero/checkout 0.3.10 → 0.3.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -1,4 +1,3 @@
1
- import { Button } from "@lookiero/aurora-next/build/components/atoms/Button/Button";
2
1
  import { Text } from "@lookiero/aurora-next/build/components/primitives/Text/Text";
3
2
  import { useI18nMessage } from "@lookiero/i18n-react";
4
3
  import { CommandStatus, QueryStatus } from "@lookiero/messaging-react";
@@ -13,19 +12,21 @@ import { Spinner } from "../../../../shared/ui/components/atoms/spinner/Spinner"
13
12
  import { useMarkCheckoutAsPaid } from "../../../domain/checkout/react/useMarkCheckoutAsPaid";
14
13
  import { useViewFirstAvailableCheckoutByCustomerId } from "../../../projection/checkout/react/useViewFirstAvailableCheckoutByCustomerId";
15
14
  import { useViewPaymentFlowPayloadByCheckoutId } from "../../../projection/payment/react/useViewPaymentFlowPayloadByCheckoutId";
15
+ import { useViewPricingByCheckoutId } from "../../../projection/pricing/react/useViewPricingByCheckoutId";
16
16
  import { Body } from "../../components/layouts/body/Body";
17
17
  import { SafeAreaScrollView } from "../../components/templates/SafeAreaScrollView";
18
18
  import { I18nMessages } from "../../i18n/i18n";
19
19
  import { Routes } from "../../routing/routes";
20
20
  import { useBasePath } from "../../routing/useBasePath";
21
21
  import { ProductVariant } from "../item/components/productVariant/ProductVariant";
22
+ import { Pricing } from "../summary/components/pricing/Pricing";
22
23
  import { style } from "./Checkout.style";
23
24
  import { CheckoutSuccessModal } from "./components/CheckoutSuccessModal";
24
25
  const Checkout = ({ customerId, authToken }) => {
25
26
  const titleText = useI18nMessage({ id: I18nMessages.CHECKOUT_TITLE });
26
- const payButtonText = useI18nMessage({ id: I18nMessages.CHECKOUT_PAY_BUTTON });
27
27
  const paymentFlowRef = useRef(null);
28
28
  const [checkout, checkoutStatus] = useViewFirstAvailableCheckoutByCustomerId({ customerId });
29
+ const [pricing, pricingStatus] = useViewPricingByCheckoutId({ checkoutId: checkout?.id });
29
30
  const [paymentFlowPayload] = useViewPaymentFlowPayloadByCheckoutId({
30
31
  checkoutId: checkout?.id,
31
32
  });
@@ -34,7 +35,8 @@ const Checkout = ({ customerId, authToken }) => {
34
35
  const [processingCheckout, setProcessingCheckout] = useState(false);
35
36
  const navigate = useNavigate();
36
37
  const basePath = useBasePath();
37
- const onSubmitCheckout = useCallback(() => {
38
+ const handleOnSubmitCheckout = useCallback(() => {
39
+ console.log("onSubmit checkout");
38
40
  if (!paymentFlowRef.current) {
39
41
  return;
40
42
  }
@@ -64,7 +66,7 @@ const Checkout = ({ customerId, authToken }) => {
64
66
  const handleOnSuccessModalDismiss = useCallback(() => navigate(`${basePath}/${Routes.FEEDBACK}`), [basePath, navigate]);
65
67
  const checkoutItemsKept = useMemo(() => checkout?.items.filter((checkoutItem) => checkoutItem.status === CheckoutItemStatus.KEPT || checkoutItem.status === CheckoutItemStatus.REPLACED), [checkout?.items]);
66
68
  const dependenciesLoadedStatuses = [QueryStatus.ERROR, QueryStatus.SUCCESS];
67
- const dependenciesLoaded = dependenciesLoadedStatuses.includes(checkoutStatus);
69
+ const dependenciesLoaded = dependenciesLoadedStatuses.includes(checkoutStatus) && dependenciesLoadedStatuses.includes(pricingStatus);
68
70
  if (!dependenciesLoaded)
69
71
  return React.createElement(Spinner, null);
70
72
  return (React.createElement(React.Fragment, null,
@@ -74,7 +76,8 @@ const Checkout = ({ customerId, authToken }) => {
74
76
  React.createElement(Text, { level: 3, style: style.title, heading: true }, titleText),
75
77
  checkoutItemsKept?.map((checkoutItem) => (React.createElement(View, { key: checkoutItem.id, style: style.checkoutItemKept, testID: "checkout-items-kept" },
76
78
  React.createElement(ProductVariant, { brand: checkoutItem.productVariant.brand, color: checkoutItem.productVariant.color, media: checkoutItem.productVariant.media, name: checkoutItem.productVariant.name, price: checkoutItem.price, size: checkoutItem.productVariant.size, status: checkoutItem.status })))),
77
- React.createElement(Button, { busy: processingCheckout || markAsPaidStatus === CommandStatus.LOADING, onPress: onSubmitCheckout }, payButtonText))),
79
+ pricing && (React.createElement(View, { style: style.pricingContainer },
80
+ React.createElement(Pricing, { balanceDiscount: pricing.balanceDiscount, busy: processingCheckout || markAsPaidStatus === CommandStatus.LOADING, collapsible: false, discount: pricing.discount, discountPercentage: pricing.discountPercentage, orderTotal: pricing.orderTotal, service: pricing.service, subtotal: pricing.subtotal, totalCheckoutItemsKept: checkoutItemsKept?.length || 0, onSubmit: handleOnSubmitCheckout }))))),
78
81
  React.createElement(PaymentFlow, { ref: paymentFlowRef, token: authToken })));
79
82
  };
80
83
  export { Checkout };
@@ -5,8 +5,12 @@ declare const style: {
5
5
  checkoutItemKept: {
6
6
  paddingVertical: number;
7
7
  };
8
+ pricingContainer: {
9
+ marginTop: number;
10
+ };
8
11
  title: {
9
12
  marginBottom: number;
13
+ marginTop: number;
10
14
  textAlign: "center";
11
15
  };
12
16
  };
@@ -1,6 +1,6 @@
1
1
  import { StyleSheet } from "react-native";
2
2
  import { theme } from "../../theme/theme";
3
- const { spaceM, spaceXL } = theme();
3
+ const { spaceM, spaceXL, spaceXXL } = theme();
4
4
  const style = StyleSheet.create({
5
5
  bodyColumn: {
6
6
  paddingHorizontal: spaceXL,
@@ -8,8 +8,12 @@ const style = StyleSheet.create({
8
8
  checkoutItemKept: {
9
9
  paddingVertical: spaceM,
10
10
  },
11
+ pricingContainer: {
12
+ marginTop: spaceXL,
13
+ },
11
14
  title: {
12
15
  marginBottom: spaceM,
16
+ marginTop: spaceXXL,
13
17
  textAlign: "center",
14
18
  },
15
19
  });
@@ -11,6 +11,7 @@ interface PricingProps {
11
11
  readonly service: ServiceProjection;
12
12
  readonly collapsible?: boolean;
13
13
  readonly collapsed?: boolean;
14
+ readonly busy?: boolean;
14
15
  readonly onPress?: () => void;
15
16
  readonly onSubmit: () => void;
16
17
  }
@@ -13,7 +13,7 @@ const PS_SERVICE_FREE_INDICATOR = 100;
13
13
  const Row = ({ text, level = 3, children }) => (React.createElement(View, { style: style.row },
14
14
  React.createElement(Text, { level: level, style: style.uppercase, action: true }, text),
15
15
  children));
16
- const Pricing = ({ orderTotal, subtotal, balanceDiscount, discount, discountPercentage = 0, totalCheckoutItemsKept, service, collapsible = true, collapsed = false, onPress = () => void 0, onSubmit, }) => {
16
+ const Pricing = ({ orderTotal, subtotal, balanceDiscount, discount, discountPercentage = 0, totalCheckoutItemsKept, service, collapsible = true, collapsed = false, busy = false, onPress = () => void 0, onSubmit, }) => {
17
17
  const totalText = useI18nMessage({ id: I18nMessages.SUMMARY_TOTAL }) || "";
18
18
  const totalCheckoutItemsKeptText = useI18nMessage({
19
19
  id: I18nMessages.SUMMARY_TOTAL_ITEMS_KEPT,
@@ -31,7 +31,7 @@ const Pricing = ({ orderTotal, subtotal, balanceDiscount, discount, discountPerc
31
31
  const isPSServiceFree = service.discount.amount === PS_SERVICE_FREE_INDICATOR;
32
32
  const collapsedStyle = useSpring({ opacitiy: collapsed ? 1 : 0 });
33
33
  const notCollapsedStyle = useSpring({ opacitiy: collapsed ? 0 : 1 });
34
- return (React.createElement(Pressable, { disabled: !collapsible, testID: "pricing", onPress: onPress },
34
+ return (React.createElement(Pressable, { testID: "pricing", onPress: collapsible ? onPress : null },
35
35
  collapsible && (React.createElement(View, { style: style.iconContainer }, collapsed ? (React.createElement(ArrowUp, { style: style.icon, testID: "arrow-up" })) : (React.createElement(ArrowDown, { style: style.icon, testID: "arrow-down" })))),
36
36
  collapsed && collapsible ? (React.createElement(animated.View, { style: [style.collapsed, { opacity: collapsedStyle.opacitiy }] },
37
37
  React.createElement(View, null,
@@ -41,7 +41,7 @@ const Pricing = ({ orderTotal, subtotal, balanceDiscount, discount, discountPerc
41
41
  totalCheckoutItemsKeptText),
42
42
  React.createElement(Price, { price: orderTotal, variant: "detail" })),
43
43
  React.createElement(View, null,
44
- React.createElement(Button, { small: true, onPress: onSubmit }, submitButtonText)))) : (React.createElement(animated.View, { style: { opacity: notCollapsedStyle.opacitiy } },
44
+ React.createElement(Button, { busy: busy, small: true, onPress: onSubmit }, submitButtonText)))) : (React.createElement(animated.View, { style: { opacity: notCollapsedStyle.opacitiy } },
45
45
  React.createElement(Row, { text: `${subtotalText} ${totalCheckoutItemsKeptText}` },
46
46
  React.createElement(Price, { price: subtotal, variant: "subtotal" })),
47
47
  discount && (React.createElement(Row, { text: discountText },
@@ -52,6 +52,6 @@ const Pricing = ({ orderTotal, subtotal, balanceDiscount, discount, discountPerc
52
52
  React.createElement(View, { style: style.divider }),
53
53
  React.createElement(Row, { level: 2, text: totalText },
54
54
  React.createElement(Price, { price: orderTotal, variant: "total" })),
55
- React.createElement(Button, { onPress: onSubmit }, submitButtonText)))));
55
+ React.createElement(Button, { busy: busy, onPress: onSubmit }, submitButtonText)))));
56
56
  };
57
57
  export { Pricing };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.3.10",
3
+ "version": "0.3.11",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [