@teamrepeat/card-token 1.0.7 → 1.0.8

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/README.md CHANGED
@@ -0,0 +1 @@
1
+
package/TEAM_README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Team Documentation - Card Token Widget
2
+
3
+ ## Internal Development Guide
4
+
5
+ ### How to deploy to NPM
6
+
7
+ 1. Change the version in `package.json`
8
+ 2. Run `npm run build` to build the package
9
+ 3. Run `npm publish` to publish the package to NPX
@@ -15,6 +15,8 @@ interface RepeatCardTokenWidgetProps {
15
15
  errorColor?: string;
16
16
  fontFamily?: string;
17
17
  };
18
+ onWidgetMount?: () => void;
19
+ onWidgetMountError?: (error: React.SyntheticEvent<HTMLIFrameElement, Event>) => void;
18
20
  }
19
21
  export declare const RepeatCardTokenWidget: React.FC<RepeatCardTokenWidgetProps>;
20
22
  export {};
@@ -1,12 +1,12 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useEffect } from "react";
3
- export const RepeatCardTokenWidget = ({ language, styles, isLocal, shopUUID, onTokenSuccess, onTokenError, }) => {
2
+ import { useEffect, useState } from "react";
3
+ export const RepeatCardTokenWidget = ({ language, styles, isLocal, shopUUID, onTokenSuccess, onTokenError, onWidgetMount, onWidgetMountError, }) => {
4
4
  const { borderRadius, buttonBackground, buttonColor, color, errorColor, fontFamily, } = styles || {};
5
+ const [isLoaded, setIsLoaded] = useState(false);
5
6
  useEffect(() => {
6
7
  const handleMessage = (event) => {
7
8
  const data = event.data;
8
9
  if ("repeatCardSaveSuccess" in data) {
9
- console.log("event", event);
10
10
  const success = data.repeatCardSaveSuccess;
11
11
  const token = data.cardToken;
12
12
  if (success) {
@@ -35,5 +35,16 @@ export const RepeatCardTokenWidget = ({ language, styles, isLocal, shopUUID, onT
35
35
  url += `&errorColor=${encodeURIComponent(errorColor)}`;
36
36
  if (fontFamily)
37
37
  url += `&fontFamily=${fontFamily}`;
38
- return (_jsx("div", { style: { width: "100%", height: 600 }, children: _jsx("iframe", { src: url, style: { width: "100%", height: "100%", border: "none" }, title: "Kort" }) }));
38
+ return (_jsx("div", { style: { width: "100%", height: 600 }, children: !isLoaded ? (_jsx("div", { style: {
39
+ width: "100%",
40
+ height: "100%",
41
+ display: "flex",
42
+ alignItems: "center",
43
+ justifyContent: "center",
44
+ }, children: _jsx("div", { className: "skeletonBox", style: { width: 100, height: 100 } }) })) : (_jsx("iframe", { src: url, style: { width: "100%", height: "100%", border: "none" }, title: "Kort", onLoad: () => {
45
+ setIsLoaded(true);
46
+ onWidgetMount?.();
47
+ }, onError: (error) => {
48
+ onWidgetMountError?.(error);
49
+ } })) }));
39
50
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamrepeat/card-token",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "React hook and iframe component to fetch card tokens",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",