@thecb/components 11.3.2-beta.1 → 11.3.3-beta.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thecb/components",
3
- "version": "11.3.2-beta.1",
3
+ "version": "11.3.3-beta.0",
4
4
  "description": "Common lib for CityBase react components",
5
5
  "main": "dist/index.cjs.js",
6
6
  "typings": "dist/index.d.ts",
package/src/.DS_Store ADDED
Binary file
Binary file
Binary file
@@ -1,6 +1,9 @@
1
1
  import React from "react";
2
+ import { MATISSE_BLUE } from "../../../constants/colors";
2
3
 
3
- const CustomerSearchIcon = () => {
4
+ const CustomerSearchIcon = ({
5
+ fillPrimary = MATISSE_BLUE
6
+ }) => {
4
7
  return (
5
8
  <svg
6
9
  xmlns="http://www.w3.org/2000/svg"
@@ -75,7 +78,7 @@ const CustomerSearchIcon = () => {
75
78
  d="M185 185c28.719 0 52 5.373 52 12s-23.281 12-52 12c-28.718 0-52-5.373-52-12s23.282-12 52-12zM97 44a2 2 0 012 2v52a2 2 0 01-2 2H45a2 2 0 01-2-2V46a2 2 0 012-2h52zM80 70c-3.535 0-6.145 1.941-7.827 5.824C70.192 73.274 67.633 72 64.5 72c-5.912 0-9.773 4.536-11.585 13.608a2 2 0 001.83 2.388l.13.004h19.25l.148-.005a2 2 0 001.812-2.387 37.807 37.807 0 00-.733-3.045L75.184 82h11.893l.15-.005a2 2 0 001.797-2.451C87.534 73.18 84.526 70 80 70zm136-26c10.493 0 19 8.507 19 19s-8.507 19-19 19-19-8.507-19-19 8.507-19 19-19zM64.5 56a7 7 0 100 14 7 7 0 000-14zM216 58c-4.206 0-7.903 2.689-9.348 6.641a2.5 2.5 0 004.635 1.87l.061-.152.083-.214c.786-1.896 2.575-3.145 4.57-3.145 1.994 0 3.782 1.249 4.568 3.145l.083.214.061.152a2.5 2.5 0 004.635-1.87C223.903 60.69 220.207 58 216.001 58zM80 57a5.5 5.5 0 100 11 5.5 5.5 0 000-11z"
76
79
  ></path>
77
80
  <path
78
- fill="#15749D"
81
+ fill={fillPrimary}
79
82
  fillRule="nonzero"
80
83
  d="M182 176v20a4 4 0 01-3.8 3.995l-.2.005h-14a4 4 0 01-.2-7.995l.2-.005h10v-16h8zm14 0v16h10a4 4 0 013.995 3.8l.005.2a4 4 0 01-3.8 3.995l-.2.005h-14a4 4 0 01-3.995-3.8L188 196v-20h8zM69 128.5v9l-7.875 4.429 32.876 6.953c1.81-4.055 5.877-6.882 10.604-6.882a4 4 0 01.2 7.995l-.2.005a3.605 3.605 0 00-3.605 3.593v.035-.023a3.606 3.606 0 003.414 3.601l.191.005h6.644a4 4 0 01.2 7.995l-.2.005h-6.644c-5.246 0-9.679-3.48-11.115-8.259l-44.708-9.457c-3.58-.757-4.322-5.493-1.242-7.336l.175-.1L69 128.5zM263.644 96c6.184 0 11.24 4.838 11.586 10.936l38.713 7.13c3.304.609 4.407 4.749 1.927 6.93l-.15.125L301 133v-10.5l2.891-2.151-31.014-5.712a11.586 11.586 0 01-8.881 4.569l-.352.005H257l-.2-.005a4 4 0 010-7.99l.2-.005h6.644l.191-.005a3.606 3.606 0 003.414-3.601c0-1.99-.358-3.259-2.403-5.238a361.04 361.04 0 00-4.65-4.395A3.998 3.998 0 01263.644 96zM97 40a6 6 0 016 6v52a6 6 0 01-6 6H45a6 6 0 01-6-6V46a6 6 0 016-6h52zm0 4H45a2 2 0 00-1.995 1.85L43 46v52a2 2 0 001.85 1.995L45 100h52a2 2 0 001.995-1.85L99 98V46a2 2 0 00-1.85-1.995L97 44zM80 70c4.526 0 7.534 3.181 9.024 9.544a2 2 0 01-1.798 2.45l-.149.006H75.184c.342 1.11.643 2.313.901 3.608a2 2 0 01-1.812 2.387l-.149.005H54.876a2 2 0 01-1.961-2.392C54.727 76.536 58.588 72 64.5 72c3.134 0 5.692 1.275 7.673 3.824C73.855 71.941 76.465 70 80 70zM64.5 56a7 7 0 110 14 7 7 0 010-14zM80 57a5.5 5.5 0 110 11 5.5 5.5 0 010-11z"
81
84
  ></path>
@@ -1,6 +1,10 @@
1
1
  import React from "react";
2
+ import { SEA_GREEN, HINT_GREEN } from "../../../constants/colors";
2
3
 
3
- const PaymentSearchIcon = () => {
4
+ const PaymentSearchIcon = ({
5
+ fillPrimary = SEA_GREEN,
6
+ fillSecondary = HINT_GREEN
7
+ }) => {
4
8
  return (
5
9
  <svg
6
10
  xmlns="http://www.w3.org/2000/svg"
@@ -75,11 +79,11 @@ const PaymentSearchIcon = () => {
75
79
  xlinkHref="#payment-search-path-1"
76
80
  ></use>
77
81
  <path
78
- fill="#E8FFEF"
82
+ fill={fillSecondary}
79
83
  d="M185 185c28.719 0 52 5.373 52 12s-23.281 12-52 12c-28.718 0-52-5.373-52-12s23.282-12 52-12zM97 44a2 2 0 012 2v52a2 2 0 01-2 2H45a2 2 0 01-2-2V46a2 2 0 012-2h52zM74.134 56h-5.268c-.441 0-.806.304-.86.696l-.006.1v2.456c-4.391.845-7.029 3.74-7.144 7.532l-.004.26v.072c0 5.135 4.208 6.644 9.66 7.865 3.408.801 4.302 1.333 4.351 2.348l.002.093v.073c0 1.077-1.025 1.723-2.963 1.723-2.717 0-5.28-.875-7.66-2.542a.896.896 0 00-1.112.082l-.078.081-2.845 3.336a.84.84 0 00.11 1.21c2.061 1.596 4.522 2.668 7.182 3.207l.5.095.001 2.581c0 .37.3.677.688.725l.108.007h5.407c.403 0 .737-.275.79-.632l.007-.1v-2.602c4.212-.902 6.88-3.587 6.996-7.58l.004-.273v-.072c0-4.705-3.659-6.572-9.513-7.83-3.483-.767-4.411-1.263-4.462-2.344l-.002-.097v-.072c0-.934.842-1.616 2.562-1.616 2.041 0 4.32.669 6.462 2.007a.9.9 0 001.13-.126l.073-.089 2.566-3.556a.841.841 0 00-.185-1.18 14.999 14.999 0 00-5.178-2.318l-.451-.103-.002-2.62c0-.44-.388-.797-.866-.797z"
80
84
  ></path>
81
85
  <path
82
- fill="#317D4F"
86
+ fill={fillPrimary}
83
87
  fillRule="nonzero"
84
88
  d="M182 176v20a4 4 0 01-3.8 3.995l-.2.005h-14a4 4 0 01-.2-7.995l.2-.005h10v-16h8zm14 0v16h10a4 4 0 013.995 3.8l.005.2a4 4 0 01-3.8 3.995l-.2.005h-14a4 4 0 01-3.995-3.8L188 196v-20h8zM69 128.5v9l-7.875 4.429 32.876 6.953c1.81-4.055 5.877-6.882 10.604-6.882a4 4 0 01.2 7.995l-.2.005a3.605 3.605 0 00-3.605 3.593v.035-.023a3.606 3.606 0 003.414 3.601l.191.005h6.644a4 4 0 01.2 7.995l-.2.005h-6.644c-5.246 0-9.679-3.48-11.115-8.259l-44.708-9.457c-3.58-.757-4.322-5.493-1.242-7.336l.175-.1L69 128.5zM263.644 96c6.184 0 11.24 4.838 11.586 10.936l38.713 7.13c3.304.609 4.407 4.749 1.927 6.93l-.15.125L301 133v-10.5l2.891-2.151-31.014-5.712a11.586 11.586 0 01-8.881 4.569l-.352.005H257l-.2-.005a4 4 0 010-7.99l.2-.005h6.644l.191-.005a3.606 3.606 0 003.414-3.601c0-1.99-.358-3.259-2.403-5.238a361.04 361.04 0 00-4.65-4.395A3.998 3.998 0 01263.644 96zM97 40a6 6 0 016 6v52a6 6 0 01-6 6H45a6 6 0 01-6-6V46a6 6 0 016-6h52zm0 4H45a2 2 0 00-1.995 1.85L43 46v52a2 2 0 001.85 1.995L45 100h52a2 2 0 001.995-1.85L99 98V46a2 2 0 00-1.85-1.995L97 44zM74.134 56c.478 0 .866.356.866.796l.002 2.621c2.128.452 3.983 1.265 5.629 2.42.383.27.457.804.185 1.181l-2.566 3.556c-.275.382-.801.466-1.203.215-2.142-1.338-4.42-2.007-6.462-2.007-1.72 0-2.562.682-2.562 1.616v.072c0 1.15.879 1.652 4.464 2.442C78.341 70.169 82 72.036 82 76.742v.07c0 4.144-2.692 6.932-7 7.854v2.602c0 .404-.357.732-.797.732h-5.407c-.44 0-.796-.328-.796-.732v-2.581c-2.852-.502-5.493-1.606-7.684-3.302a.84.84 0 01-.11-1.21l2.846-3.336a.898.898 0 011.19-.163c2.38 1.667 4.943 2.542 7.66 2.542 1.938 0 2.963-.646 2.963-1.723v-.073c0-1.076-.841-1.615-4.353-2.44-5.452-1.222-9.66-2.73-9.66-7.866v-.072c0-3.92 2.657-6.928 7.148-7.792v-2.456c0-.44.388-.796.866-.796h5.268z"
85
89
  ></path>
@@ -3,46 +3,20 @@ import React, {
3
3
  useEffect,
4
4
  useRef,
5
5
  forwardRef,
6
- useImperativeHandle,
7
- useCallback
6
+ useImperativeHandle
8
7
  } from "react";
9
8
  import { Box } from "../../atoms/layouts";
10
- import Text from "../../atoms/text";
11
9
  import styled from "styled-components";
12
10
  import { useTurnstileScript } from "../../../hooks";
13
11
  import { noop } from "../../../util/general";
14
- import { ERROR_COLOR } from "../../../constants/colors";
15
12
 
16
13
  const TurnstileWidgetContainer = styled(Box)`
17
14
  display: flex;
18
- flex-direction: column;
19
15
  padding: ${({ padding }) => padding};
20
16
  justify-content: ${({ justify }) => justify};
21
- align-items: ${({ align }) => align};
22
17
  width: 100%;
23
18
  `;
24
19
 
25
- const FATAL_ERROR_CODES = [
26
- // Configuration errors
27
- /^100/,
28
- /^105/,
29
- /^110100$/,
30
- /^110110$/,
31
- /^110200$/,
32
- /^110420$/,
33
- /^110430$/,
34
- /^400020$/,
35
- /^400030$/,
36
- /^400040$/,
37
- // Browser/environment errors
38
- /^110500$/,
39
- /^110510$/,
40
- /^200010$/,
41
- /^200100$/,
42
- // Internal errors
43
- /^120/
44
- ];
45
-
46
20
  const TurnstileWidget = forwardRef(
47
21
  (
48
22
  {
@@ -53,150 +27,64 @@ const TurnstileWidget = forwardRef(
53
27
  onExpired = noop,
54
28
  padding = "1rem",
55
29
  justify = "flex-end",
56
- align = "flex-end",
57
30
  size = "normal",
58
31
  tabindex = 0,
59
- retry = "never",
60
- theme = "light",
61
- extraStyles = "",
62
- maxErrorRetries = 3
32
+ retry = "auto",
33
+ theme = "auto",
34
+ extraStyles = ""
63
35
  },
64
36
  ref
65
37
  ) => {
66
38
  if (!verifyURL || !siteKey) return null;
67
39
 
68
40
  const widgetRef = useRef(null);
69
- const widgetIdRef = useRef(null);
70
- const retryCountRef = useRef(0);
71
- const [error, setError] = useState(null);
72
-
73
- const { scriptLoaded, scriptError } = useTurnstileScript(verifyURL);
74
-
75
- // Clear the error state and reset retry count
76
- const clearError = () => {
77
- setError(null);
78
- retryCountRef.current = 0;
79
- };
80
-
81
- // Handle errors based on the retry strategy
82
- const handleError = errorCode => {
83
- retryCountRef.current += 1;
84
- const currentRetryCount = retryCountRef.current;
85
-
86
- // If we haven't exceeded max retries, reset and try again
87
- if (currentRetryCount <= maxErrorRetries) {
88
- window.turnstile.reset(widgetIdRef.current);
89
- setError(null);
90
- return;
91
- }
92
-
93
- // Max retries exceeded - show appropriate error message
94
- if (errorCode) {
95
- const errorMessage = getErrorMessage(errorCode);
96
- setError(errorMessage);
97
- }
98
- };
99
-
100
- const getErrorMessage = errorCode => {
101
- const isFatalError = FATAL_ERROR_CODES.some(pattern =>
102
- pattern.test(errorCode)
103
- );
104
-
105
- if (isFatalError) {
106
- return "Browser or system error. Please refresh the page or update your browser.";
107
- }
108
- return "Something went wrong. Please refresh and try again.";
109
- };
110
-
111
- // Reset the Turnstile widget when requested
112
- const resetWidget = useCallback(() => {
113
- if (widgetIdRef.current && window.turnstile) {
114
- window.turnstile.reset(widgetIdRef.current);
115
- clearError();
116
- }
117
- }, [clearError]);
41
+ const [widgetId, setWidgetId] = useState(null);
42
+ const isTurnstileLoaded = useTurnstileScript(verifyURL);
118
43
 
119
44
  // Allow the parent component to reset the Turnstile widget
120
45
  useImperativeHandle(
121
46
  ref,
122
47
  () => ({
123
- reset: resetWidget
48
+ reset: () => {
49
+ if (widgetId && window.turnstile) {
50
+ window.turnstile.reset(widgetId);
51
+ }
52
+ }
124
53
  }),
125
- [resetWidget]
54
+ [widgetId]
126
55
  );
127
56
 
128
57
  useEffect(() => {
129
- if (scriptError) {
130
- setError(
131
- "Unable to load security verification. Please refresh the page."
132
- );
133
- onError?.({ type: "script_load_failed", error: scriptError });
134
- return;
135
- }
136
-
137
- if (widgetIdRef.current || !window.turnstile || !scriptLoaded) return;
138
-
139
- try {
140
- widgetIdRef.current = window.turnstile.render(widgetRef.current, {
58
+ if (!widgetRef.current || !window.turnstile) return;
59
+ if (!widgetId) {
60
+ const newWidgetId = window.turnstile.render(widgetRef.current, {
141
61
  sitekey: siteKey,
142
62
  size: size,
143
63
  retry: retry,
144
64
  tabindex: tabindex,
145
65
  theme: theme,
146
- callback: token => {
147
- clearError();
148
- onSuccess(token);
149
- },
150
- "error-callback": errorCode => {
151
- if (retry === "never") {
152
- handleError(errorCode);
153
- }
154
- onError?.(errorCode);
155
- },
156
- "expired-callback": () => {
157
- clearError();
158
- onExpired?.();
159
- }
66
+ callback: token => onSuccess(token),
67
+ "error-callback": () => onError(),
68
+ "expired-callback": () => onExpired()
160
69
  });
161
- } catch (error) {
162
- setError(
163
- "Unable to load security verification. Please refresh the page."
164
- );
165
- onError?.({ type: "render_failed", error });
70
+ setWidgetId(newWidgetId);
166
71
  }
167
-
168
72
  return () => {
169
- if (widgetIdRef.current && window.turnstile) {
170
- window.turnstile.remove(widgetIdRef.current);
171
- widgetIdRef.current = null;
172
- clearError();
73
+ if (widgetId && window.turnstile) {
74
+ window.turnstile.remove(widgetId);
75
+ setWidgetId(null);
173
76
  }
174
77
  };
175
- }, [scriptLoaded, siteKey]);
78
+ }, [isTurnstileLoaded, siteKey, widgetId]);
176
79
 
177
80
  return (
178
- <>
179
- <TurnstileWidgetContainer
180
- padding={padding}
181
- justify={justify}
182
- align={align}
183
- extraStyles={extraStyles}
184
- >
185
- <div ref={widgetRef} />
186
- {error && (
187
- <Text
188
- color={ERROR_COLOR}
189
- variant="pXS"
190
- extraStyles={`
191
- word-break: break-word;
192
- text-align: end;
193
- `}
194
- >
195
- {error}
196
- </Text>
197
- )}
198
- </TurnstileWidgetContainer>
199
- </>
81
+ <TurnstileWidgetContainer
82
+ padding={padding}
83
+ justify={justify}
84
+ extraStyles={extraStyles}
85
+ >
86
+ <div ref={widgetRef} />
87
+ </TurnstileWidgetContainer>
200
88
  );
201
89
  }
202
90
  );
@@ -6,44 +6,31 @@ import { useEffect, useState } from "react";
6
6
  * @param {string} verifyURL - The URL of the Turnstile verification script.
7
7
  */
8
8
  const useTurnstileScript = verifyURL => {
9
- const [scriptLoaded, setScriptLoaded] = useState(false);
10
- const [scriptError, setScriptError] = useState(false);
11
-
12
- const handleScriptError = () => {
13
- setScriptError(true);
14
- setScriptLoaded(false);
15
- };
9
+ const [isLoaded, setIsLoaded] = useState(false);
16
10
 
17
11
  useEffect(() => {
18
12
  if (typeof window === "undefined") {
19
- setScriptLoaded(false);
13
+ setIsLoaded(false);
20
14
  return;
21
15
  }
22
16
  if (window.turnstile && window.turnstile.render) {
23
- setScriptLoaded(true);
17
+ setIsLoaded(true);
24
18
  return;
25
19
  }
26
20
 
27
21
  const script = document.createElement("script");
28
22
  script.src = `${verifyURL}?render=explicit`;
29
23
  script.onload = () => {
30
- setScriptLoaded(true);
31
- };
32
- script.onerror = () => {
33
- handleScriptError();
34
- };
35
- script.onabort = () => {
36
- handleScriptError();
24
+ setIsLoaded(true);
37
25
  };
38
26
  script.defer = true;
39
27
  document.getElementsByTagName("head")[0].appendChild(script);
40
28
 
41
29
  return () => {
42
- setScriptLoaded(false);
43
- setScriptError(false);
30
+ setIsLoaded(false);
44
31
  };
45
32
  }, [verifyURL]);
46
33
 
47
- return { scriptLoaded, scriptError };
34
+ return isLoaded;
48
35
  };
49
36
  export default useTurnstileScript;