@tapcart/mobile-components 0.7.28 → 0.7.29
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/components/hooks/use-customer.d.ts +10 -0
- package/dist/components/hooks/use-customer.d.ts.map +1 -0
- package/dist/components/hooks/use-customer.js +24 -0
- package/dist/components/hooks/use-tap.d.ts +8 -0
- package/dist/components/hooks/use-tap.d.ts.map +1 -0
- package/dist/components/hooks/use-tap.js +100 -0
- package/dist/components/ui/apple-pay-button.d.ts +24 -0
- package/dist/components/ui/apple-pay-button.d.ts.map +1 -0
- package/dist/components/ui/apple-pay-button.js +121 -0
- package/dist/components/ui/price.js +1 -1
- package/dist/styles.css +3 -0
- package/package.json +1 -1
- package/dist/components/hooks/use-debug-dependencies.d.ts +0 -10
- package/dist/components/hooks/use-debug-dependencies.d.ts.map +0 -1
- package/dist/components/hooks/use-debug-dependencies.js +0 -17
- package/dist/components/hooks/use-layout.d.ts +0 -13
- package/dist/components/hooks/use-layout.d.ts.map +0 -1
- package/dist/components/hooks/use-layout.js +0 -23
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Customer = {
|
|
2
|
+
isAuthenticated: boolean;
|
|
3
|
+
};
|
|
4
|
+
type UseCustomerProps = {};
|
|
5
|
+
type UseCustomerReturn = {
|
|
6
|
+
customer: Customer;
|
|
7
|
+
};
|
|
8
|
+
export declare const useCustomer: (props: UseCustomerProps | null) => UseCustomerReturn;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=use-customer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-customer.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-customer.ts"],"names":[],"mappings":"AAWA,KAAK,QAAQ,GAAG;IACd,eAAe,EAAE,OAAO,CAAA;CACzB,CAAA;AAGD,KAAK,gBAAgB,GAAG,EAAE,CAAA;AAE1B,KAAK,iBAAiB,GAAG;IACvB,QAAQ,EAAE,QAAQ,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,WAAW,UACf,gBAAgB,GAAG,IAAI,KAC7B,iBAuBF,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
// @ts-ignore -- webbridge-react is not typed (yet)
|
|
4
|
+
import { useActions } from "@tapcart/webbridge-react";
|
|
5
|
+
export const useCustomer = (props) => {
|
|
6
|
+
const [isAuthenticated, setIsAuthenticated] = useState(false);
|
|
7
|
+
const [customer, setCustomer] = useState({});
|
|
8
|
+
const actions = useActions();
|
|
9
|
+
// verify customer
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
try {
|
|
12
|
+
// webbridge method to get customerIdentity
|
|
13
|
+
actions.getCustomerIdentity(null, {
|
|
14
|
+
onSuccess: (user) => setIsAuthenticated(!!(user === null || user === void 0 ? void 0 : user.email)),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
console.log("unable to get customer identity ", e);
|
|
19
|
+
}
|
|
20
|
+
}, [actions]);
|
|
21
|
+
return {
|
|
22
|
+
customer: Object.assign({ isAuthenticated }, customer),
|
|
23
|
+
};
|
|
24
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
declare const useTap: (tapThreshold?: number) => {
|
|
3
|
+
onTap: (handler: (event: any) => void) => (event: any) => void;
|
|
4
|
+
isPressed: boolean;
|
|
5
|
+
ref: React.MutableRefObject<null>;
|
|
6
|
+
};
|
|
7
|
+
export { useTap };
|
|
8
|
+
//# sourceMappingURL=use-tap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tap.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-tap.ts"],"names":[],"mappings":"AACA,OAAO,KAAmD,MAAM,OAAO,CAAA;AAuFvE,QAAA,MAAM,MAAM;6BAuBkC,GAAG,KAAK,IAAI,aACvC,GAAG;;;CAerB,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useEffect, useCallback, useRef } from "react";
|
|
3
|
+
// Shared manager for all instances of the hook
|
|
4
|
+
const tapManager = (() => {
|
|
5
|
+
const elements = new Map();
|
|
6
|
+
let isListening = false;
|
|
7
|
+
const startListening = () => {
|
|
8
|
+
if (isListening)
|
|
9
|
+
return;
|
|
10
|
+
const handleTouchStart = (e) => {
|
|
11
|
+
const touch = e.touches[0];
|
|
12
|
+
elements.forEach((data, el) => {
|
|
13
|
+
if (el.contains(touch.target)) {
|
|
14
|
+
data.touchStarted = true;
|
|
15
|
+
data.touchMoved = false;
|
|
16
|
+
data.startPosition = { x: touch.clientX, y: touch.clientY };
|
|
17
|
+
// Don't set isPressed here, wait to determine if it's a tap or drag
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const handleTouchMove = (e) => {
|
|
22
|
+
const touch = e.touches[0];
|
|
23
|
+
elements.forEach((data, el) => {
|
|
24
|
+
if (data.touchStarted) {
|
|
25
|
+
const deltaX = Math.abs(touch.clientX - data.startPosition.x);
|
|
26
|
+
const deltaY = Math.abs(touch.clientY - data.startPosition.y);
|
|
27
|
+
if (deltaX > data.tapThreshold || deltaY > data.tapThreshold) {
|
|
28
|
+
data.touchMoved = true;
|
|
29
|
+
data.setIsPressed(false);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const handleTouchEnd = () => {
|
|
35
|
+
elements.forEach((data) => {
|
|
36
|
+
if (data.touchStarted) {
|
|
37
|
+
data.touchStarted = false;
|
|
38
|
+
if (!data.touchMoved) {
|
|
39
|
+
// It's a tap, set isPressed briefly
|
|
40
|
+
data.setIsPressed(true);
|
|
41
|
+
setTimeout(() => data.setIsPressed(false), 100);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
document.addEventListener("touchstart", (e) => handleTouchStart(e), { passive: true });
|
|
47
|
+
document.addEventListener("touchmove", (e) => handleTouchMove(e), { passive: true });
|
|
48
|
+
document.addEventListener("touchend", () => handleTouchEnd(), {
|
|
49
|
+
passive: true,
|
|
50
|
+
});
|
|
51
|
+
isListening = true;
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
register: (el, data) => {
|
|
55
|
+
elements.set(el, data);
|
|
56
|
+
startListening();
|
|
57
|
+
},
|
|
58
|
+
unregister: (el) => {
|
|
59
|
+
elements.delete(el);
|
|
60
|
+
},
|
|
61
|
+
elements,
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
const useTap = (tapThreshold = 10) => {
|
|
65
|
+
const [isPressed, setIsPressed] = useState(false);
|
|
66
|
+
const elementRef = useRef(null);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const element = elementRef.current;
|
|
69
|
+
if (!element)
|
|
70
|
+
return;
|
|
71
|
+
const data = {
|
|
72
|
+
touchStarted: false,
|
|
73
|
+
touchMoved: false,
|
|
74
|
+
startPosition: { x: 0, y: 0 },
|
|
75
|
+
setIsPressed,
|
|
76
|
+
tapThreshold,
|
|
77
|
+
};
|
|
78
|
+
tapManager.register(element, data);
|
|
79
|
+
return () => {
|
|
80
|
+
tapManager.unregister(element);
|
|
81
|
+
};
|
|
82
|
+
}, [tapThreshold]);
|
|
83
|
+
const onTap = useCallback((handler) => {
|
|
84
|
+
return (event) => {
|
|
85
|
+
const data = tapManager.elements.get(elementRef.current);
|
|
86
|
+
if (!data)
|
|
87
|
+
return;
|
|
88
|
+
if (event.type === "touchend" && !data.touchMoved) {
|
|
89
|
+
handler(event);
|
|
90
|
+
}
|
|
91
|
+
else if (event.type === "click" && !data.touchStarted) {
|
|
92
|
+
handler(event);
|
|
93
|
+
setIsPressed(true);
|
|
94
|
+
setTimeout(() => setIsPressed(false), 100);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}, []);
|
|
98
|
+
return { onTap, isPressed, ref: elementRef };
|
|
99
|
+
};
|
|
100
|
+
export { useTap };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="applepayjs" />
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
export type ApplePayButtonType = 'plain' | 'add-money' | 'book' | 'buy' | 'check-out' | 'continue' | 'contribute' | 'donate' | 'order' | 'pay' | 'reload' | 'rent' | 'set-up' | 'subscribe' | 'support' | 'tip' | 'top-up';
|
|
4
|
+
export type ApplePayButtonStyle = 'black' | 'white' | 'white-outline';
|
|
5
|
+
export interface ApplePayButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
6
|
+
displayName: string;
|
|
7
|
+
amount: number;
|
|
8
|
+
startSessionURL: string;
|
|
9
|
+
appId: string;
|
|
10
|
+
domainName: string;
|
|
11
|
+
countryCode?: string;
|
|
12
|
+
currencyCode?: string;
|
|
13
|
+
merchantCapabilities?: ApplePayJS.ApplePayMerchantCapability[];
|
|
14
|
+
supportedNetworks?: string[];
|
|
15
|
+
buttonType?: ApplePayButtonType;
|
|
16
|
+
buttonStyle?: ApplePayButtonStyle;
|
|
17
|
+
onPaymentAuthorized?: (paymentData: ApplePayJS.ApplePayPayment) => void;
|
|
18
|
+
}
|
|
19
|
+
declare const ApplePayButton: {
|
|
20
|
+
({ displayName, amount, startSessionURL, appId, domainName, countryCode, currencyCode, merchantCapabilities, supportedNetworks, buttonType, buttonStyle, onPaymentAuthorized, }: ApplePayButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
displayName: string;
|
|
22
|
+
};
|
|
23
|
+
export { ApplePayButton };
|
|
24
|
+
//# sourceMappingURL=apple-pay-button.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apple-pay-button.d.ts","sourceRoot":"","sources":["../../../components/ui/apple-pay-button.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,WAAW,GAAG,MAAM,GAAG,KAAK,GAAG,WAAW,GAAG,UAAU,GAAG,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE3N,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,OAAO,GAAG,eAAe,CAAA;AAErE,MAAM,WAAW,mBACf,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,UAAU,CAAC,0BAA0B,EAAE,CAAC;IAC/D,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,mBAAmB,CAAC,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC,eAAe,KAAK,IAAI,CAAC;CACzE;AAED,QAAA,MAAM,cAAc;qLAcf,mBAAmB;;CA2IvB,CAAA;AAID,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import * as React from "react";
|
|
12
|
+
import ApplePayButtonComponent from 'apple-pay-button';
|
|
13
|
+
const ApplePayButton = ({ displayName, amount, startSessionURL, appId, domainName, countryCode = 'US', currencyCode = 'USD', merchantCapabilities = ["supports3DS"], supportedNetworks = ["visa", "masterCard", "amex", "discover"], buttonType = 'plain', buttonStyle = 'white-outline', onPaymentAuthorized, }) => {
|
|
14
|
+
const [paymentDataResult, setPaymentDataResult] = React.useState("");
|
|
15
|
+
const onClick = () => {
|
|
16
|
+
const applePayRequest = {
|
|
17
|
+
countryCode,
|
|
18
|
+
currencyCode,
|
|
19
|
+
merchantCapabilities,
|
|
20
|
+
supportedNetworks,
|
|
21
|
+
total: {
|
|
22
|
+
label: displayName,
|
|
23
|
+
type: "final",
|
|
24
|
+
amount: amount.toString(),
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const session = new ApplePaySession(3, applePayRequest);
|
|
28
|
+
handleEventsForApplePay(session);
|
|
29
|
+
session.begin();
|
|
30
|
+
};
|
|
31
|
+
const defaultFetcher = (url, body) => fetch(url, {
|
|
32
|
+
method: body ? "POST" : "GET",
|
|
33
|
+
headers: {
|
|
34
|
+
"Content-Type": "application/json",
|
|
35
|
+
},
|
|
36
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
37
|
+
}).then((res) => res.json());
|
|
38
|
+
const validateMerchant = (validationURL, appId, domainName, displayName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
let url = startSessionURL;
|
|
40
|
+
let body = {
|
|
41
|
+
validationURL,
|
|
42
|
+
appId,
|
|
43
|
+
domainName,
|
|
44
|
+
displayName
|
|
45
|
+
};
|
|
46
|
+
console.log("request body", body);
|
|
47
|
+
const response = yield defaultFetcher(url, body);
|
|
48
|
+
return response.data;
|
|
49
|
+
});
|
|
50
|
+
const handleEventsForApplePay = (session) => {
|
|
51
|
+
session.onvalidatemerchant = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
const response = yield validateMerchant(event.validationURL, appId, domainName, displayName);
|
|
53
|
+
if (response) {
|
|
54
|
+
session.completeMerchantValidation(response);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.error("Error during validating merchant");
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
session.onpaymentmethodselected = (event) => {
|
|
61
|
+
const update = {
|
|
62
|
+
newTotal: {
|
|
63
|
+
label: displayName,
|
|
64
|
+
type: "final",
|
|
65
|
+
amount: amount.toString(),
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
session.completePaymentMethodSelection(update);
|
|
69
|
+
};
|
|
70
|
+
session.onshippingmethodselected = (event) => {
|
|
71
|
+
const update = {
|
|
72
|
+
newTotal: {
|
|
73
|
+
label: displayName,
|
|
74
|
+
type: "final",
|
|
75
|
+
amount: amount.toString(),
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
session.completeShippingMethodSelection(update);
|
|
79
|
+
};
|
|
80
|
+
session.onshippingcontactselected = (event) => {
|
|
81
|
+
const update = {
|
|
82
|
+
newTotal: {
|
|
83
|
+
label: displayName,
|
|
84
|
+
type: "final",
|
|
85
|
+
amount: amount.toString(),
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
session.completeShippingContactSelection(update);
|
|
89
|
+
};
|
|
90
|
+
session.onpaymentauthorized = (event) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
const paymentData = event.payment;
|
|
92
|
+
if (onPaymentAuthorized) { // Call the callback if provided
|
|
93
|
+
onPaymentAuthorized(paymentData);
|
|
94
|
+
}
|
|
95
|
+
if (paymentData.token) {
|
|
96
|
+
const paymentDataJson = JSON.stringify(paymentData.token, null, 2);
|
|
97
|
+
console.log("paymentData", paymentDataJson);
|
|
98
|
+
setPaymentDataResult(paymentDataJson);
|
|
99
|
+
const result = {
|
|
100
|
+
status: ApplePaySession.STATUS_SUCCESS,
|
|
101
|
+
};
|
|
102
|
+
session.completePayment(result);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const result = {
|
|
106
|
+
status: ApplePaySession.STATUS_FAILURE,
|
|
107
|
+
};
|
|
108
|
+
session.completePayment(result);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
session.oncancel = (event) => {
|
|
112
|
+
console.log("Session Cancelled.");
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
return (_jsxs("div", { children: [_jsx("div", Object.assign({ className: "flex flex-row justify-center items-center pt-40" }, { children: _jsx(ApplePayButtonComponent, { onClick: onClick, style: {
|
|
116
|
+
height: "48px",
|
|
117
|
+
borderRadius: '4px',
|
|
118
|
+
}, type: buttonType, buttonStyle: buttonStyle }) })), _jsx("div", Object.assign({ className: "w-100 overflow-auto" }, { children: _jsx("pre", Object.assign({ className: "whitespace-pre-wrap break-words" }, { children: paymentDataResult })) }))] }));
|
|
119
|
+
};
|
|
120
|
+
ApplePayButton.displayName = "ApplePayButton";
|
|
121
|
+
export { ApplePayButton };
|
|
@@ -7,7 +7,7 @@ function Price({ price, priceHigh, priceRanges = false, isSale = false, compareA
|
|
|
7
7
|
const ProductPrice = () => {
|
|
8
8
|
const priceStyles = (!isSale || !compareAtPrice) ? standardStyles : saleStyles;
|
|
9
9
|
const colorClass = isSale ? 'text-textColors-salePriceText' : 'text-textColors-priceText';
|
|
10
|
-
return (_jsx(Text, Object.assign({ className: `${colorClass} flex-shrink-0`, style: { fontSize: `${fontSize}px` } }, { children: _jsxs("span", Object.assign({ className: "flex-grow min-w-[fit-content]" }, { children: [_jsx(Money, { price: price, currency: currency, locale: locale, styles: priceStyles, hideZeroCents: hideZeroCents }), priceRanges && priceHigh !== undefined && _jsx(Spacer, {}), priceRanges && priceHigh !== undefined && (_jsx(Money, { price: priceHigh, currency: currency, locale: locale, styles: priceStyles, hideZeroCents: hideZeroCents }))] })) })));
|
|
10
|
+
return (_jsx(Text, Object.assign({ className: `${colorClass} flex-shrink-0 w-full`, style: { fontSize: `${fontSize}px` } }, { children: _jsxs("span", Object.assign({ className: "flex-grow min-w-[fit-content] break-all" }, { children: [_jsx(Money, { price: price, currency: currency, locale: locale, styles: priceStyles, hideZeroCents: hideZeroCents }), priceRanges && priceHigh !== undefined && _jsx(Spacer, {}), priceRanges && priceHigh !== undefined && (_jsx(Money, { price: priceHigh, currency: currency, locale: locale, styles: priceStyles, hideZeroCents: hideZeroCents }))] })) })));
|
|
11
11
|
};
|
|
12
12
|
const StrikeThroughPrice = () => {
|
|
13
13
|
if (!isSale || !compareAtPrice)
|
package/dist/styles.css
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom hook to debug dependency changes.
|
|
3
|
-
*
|
|
4
|
-
* Usage:
|
|
5
|
-
* useDebugDependencies([dependencyA, dependencyB]);
|
|
6
|
-
*
|
|
7
|
-
* @param {Array} deps - Array of dependencies to monitor for changes.
|
|
8
|
-
*/
|
|
9
|
-
export declare const useDebugDependencies: (deps: any[]) => void;
|
|
10
|
-
//# sourceMappingURL=use-debug-dependencies.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-debug-dependencies.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-debug-dependencies.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,SAAU,GAAG,EAAE,SAU/C,CAAA"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useRef, useEffect } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* Custom hook to debug dependency changes.
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* useDebugDependencies([dependencyA, dependencyB]);
|
|
7
|
-
*
|
|
8
|
-
* @param {Array} deps - Array of dependencies to monitor for changes.
|
|
9
|
-
*/
|
|
10
|
-
export const useDebugDependencies = (deps) => {
|
|
11
|
-
const prevDeps = useRef(deps);
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
const changedDeps = deps.map((dep, i) => dep !== prevDeps.current[i] ? dep : null);
|
|
14
|
-
console.log("Changed dependencies:", changedDeps);
|
|
15
|
-
prevDeps.current = deps;
|
|
16
|
-
}, [deps]);
|
|
17
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { PhoenixLayout } from "lib/tapcart/types";
|
|
2
|
-
type UseLayoutProps = {
|
|
3
|
-
appId: string;
|
|
4
|
-
layoutId: string;
|
|
5
|
-
};
|
|
6
|
-
type UseLayoutReturn = {
|
|
7
|
-
layout: PhoenixLayout | null;
|
|
8
|
-
error: any;
|
|
9
|
-
isLoading: boolean;
|
|
10
|
-
};
|
|
11
|
-
export declare function useLayout({ appId, layoutId, }: UseLayoutProps): UseLayoutReturn;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=use-layout.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-layout.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-layout.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGjD,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,KAAK,eAAe,GAAG;IACrB,MAAM,EAAE,aAAa,GAAG,IAAI,CAAA;IAC5B,KAAK,EAAE,GAAG,CAAA;IACV,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,QAAQ,GACT,EAAE,cAAc,GAAG,eAAe,CAYlC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
import useSWR from "swr";
|
|
12
|
-
import { fetchLayoutById } from "apps/tapcart-ssr-app/lib/tapcart/index";
|
|
13
|
-
export function useLayout({ appId, layoutId, }) {
|
|
14
|
-
const fetcher = (appId, layoutId) => __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
return fetchLayoutById(appId, layoutId);
|
|
16
|
-
});
|
|
17
|
-
const { data, error } = useSWR([appId, layoutId], fetcher);
|
|
18
|
-
return {
|
|
19
|
-
layout: data || null,
|
|
20
|
-
error,
|
|
21
|
-
isLoading: !data && !error,
|
|
22
|
-
};
|
|
23
|
-
}
|