@marvalt/madapter 2.3.2 → 2.3.3
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/index.cjs +24 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +25 -22
- package/dist/index.esm.js.map +1 -1
- package/dist/react/components/MauticForm.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useRef, useEffect, useState,
|
|
1
|
+
import React, { useRef, useEffect, useState, useMemo, useCallback, createContext, useContext } from 'react';
|
|
2
2
|
import { useQueryClient, useMutation, useQuery } from '@tanstack/react-query';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -2168,8 +2168,8 @@ const MauticForm = ({ formId, title, description, className = '', form, onSubmit
|
|
|
2168
2168
|
const [showSuccessMessage, setShowSuccessMessage] = useState(false);
|
|
2169
2169
|
const [turnstileToken, setTurnstileToken] = useState(null);
|
|
2170
2170
|
const submitMutation = useMauticFormSubmission();
|
|
2171
|
-
// Get Turnstile site key from environment
|
|
2172
|
-
const
|
|
2171
|
+
// Get Turnstile site key from environment - memoized to prevent re-renders
|
|
2172
|
+
const turnstilesiteKey = useMemo(() => {
|
|
2173
2173
|
try {
|
|
2174
2174
|
// @ts-ignore - import.meta is a Vite-specific global
|
|
2175
2175
|
if (typeof import.meta !== 'undefined' && import.meta.env) {
|
|
@@ -2183,8 +2183,27 @@ const MauticForm = ({ formId, title, description, className = '', form, onSubmit
|
|
|
2183
2183
|
// import.meta not available
|
|
2184
2184
|
}
|
|
2185
2185
|
return undefined;
|
|
2186
|
-
};
|
|
2187
|
-
|
|
2186
|
+
}, []); // Empty deps - site key doesn't change during runtime
|
|
2187
|
+
// Memoize Turnstile callbacks to prevent widget re-renders
|
|
2188
|
+
const handleTurnstileSuccess = useCallback((token) => {
|
|
2189
|
+
setTurnstileToken(token);
|
|
2190
|
+
// Clear any turnstile error
|
|
2191
|
+
setErrors(prev => {
|
|
2192
|
+
if (!prev._turnstile)
|
|
2193
|
+
return prev;
|
|
2194
|
+
const next = { ...prev };
|
|
2195
|
+
delete next._turnstile;
|
|
2196
|
+
return next;
|
|
2197
|
+
});
|
|
2198
|
+
}, []);
|
|
2199
|
+
const handleTurnstileError = useCallback(() => {
|
|
2200
|
+
setTurnstileToken(null);
|
|
2201
|
+
setErrors(prev => ({ ...prev, _turnstile: 'Verification failed. Please try again.' }));
|
|
2202
|
+
}, []);
|
|
2203
|
+
const handleTurnstileExpire = useCallback(() => {
|
|
2204
|
+
setTurnstileToken(null);
|
|
2205
|
+
setErrors(prev => ({ ...prev, _turnstile: 'Verification expired. Please verify again.' }));
|
|
2206
|
+
}, []);
|
|
2188
2207
|
useEffect(() => {
|
|
2189
2208
|
if (!form) {
|
|
2190
2209
|
console.warn(`Form ${formId} not found`);
|
|
@@ -2357,23 +2376,7 @@ const MauticForm = ({ formId, title, description, className = '', form, onSubmit
|
|
|
2357
2376
|
return (jsxRuntimeExports.jsxs("form", { className: `mautic-form ${className}`, onSubmit: handleSubmit, children: [(title || form.name) && (jsxRuntimeExports.jsxs("div", { className: "form-header", children: [jsxRuntimeExports.jsx("h3", { children: title || form.name }), (description || form.description) && (jsxRuntimeExports.jsx("p", { className: "form-description", children: description || form.description }))] })), jsxRuntimeExports.jsx("div", { className: "form-fields", children: form.fields
|
|
2358
2377
|
// Filter out button/submit from field group; render them in actions
|
|
2359
2378
|
.filter((field) => field.type !== 'button' && field.alias !== 'submit')
|
|
2360
|
-
.map((field) => (jsxRuntimeExports.jsxs("div", { className: `form-field form-field-${field.type}`, children: [field.showLabel !== false && (jsxRuntimeExports.jsxs("label", { htmlFor: field.alias, className: "field-label", children: [field.label, field.isRequired && jsxRuntimeExports.jsx("span", { className: "required", children: "*" })] })), renderField(field), field.properties?.helpText && (jsxRuntimeExports.jsx("p", { className: "field-help", children: field.properties.helpText })), errors[field.alias] && (jsxRuntimeExports.jsx("p", { className: "field-error", children: errors[field.alias] }))] }, field.id))) }), turnstilesiteKey && (jsxRuntimeExports.jsxs("div", { className: "form-turnstile", children: [jsxRuntimeExports.jsx(TurnstileWidget, { siteKey: turnstilesiteKey, onSuccess: (
|
|
2361
|
-
setTurnstileToken(token);
|
|
2362
|
-
// Clear any turnstile error
|
|
2363
|
-
if (errors._turnstile) {
|
|
2364
|
-
setErrors(prev => {
|
|
2365
|
-
const next = { ...prev };
|
|
2366
|
-
delete next._turnstile;
|
|
2367
|
-
return next;
|
|
2368
|
-
});
|
|
2369
|
-
}
|
|
2370
|
-
}, onError: () => {
|
|
2371
|
-
setTurnstileToken(null);
|
|
2372
|
-
setErrors(prev => ({ ...prev, _turnstile: 'Verification failed. Please try again.' }));
|
|
2373
|
-
}, onExpire: () => {
|
|
2374
|
-
setTurnstileToken(null);
|
|
2375
|
-
setErrors(prev => ({ ...prev, _turnstile: 'Verification expired. Please verify again.' }));
|
|
2376
|
-
}, theme: "auto", size: "normal" }), errors._turnstile && (jsxRuntimeExports.jsx("p", { className: "field-error turnstile-error", children: errors._turnstile }))] })), jsxRuntimeExports.jsx("div", { className: "form-actions", children: jsxRuntimeExports.jsx("button", { type: "submit", disabled: isSubmitting || (!!turnstilesiteKey && !turnstileToken), className: "submit-button", children: isSubmitting ? 'Submitting...' : 'Submit' }) }), submitMutation.error && (jsxRuntimeExports.jsx("div", { className: "form-error", children: jsxRuntimeExports.jsx("p", { children: "There was an error submitting the form. Please try again." }) }))] }));
|
|
2379
|
+
.map((field) => (jsxRuntimeExports.jsxs("div", { className: `form-field form-field-${field.type}`, children: [field.showLabel !== false && (jsxRuntimeExports.jsxs("label", { htmlFor: field.alias, className: "field-label", children: [field.label, field.isRequired && jsxRuntimeExports.jsx("span", { className: "required", children: "*" })] })), renderField(field), field.properties?.helpText && (jsxRuntimeExports.jsx("p", { className: "field-help", children: field.properties.helpText })), errors[field.alias] && (jsxRuntimeExports.jsx("p", { className: "field-error", children: errors[field.alias] }))] }, field.id))) }), turnstilesiteKey && (jsxRuntimeExports.jsxs("div", { className: "form-turnstile", children: [jsxRuntimeExports.jsx(TurnstileWidget, { siteKey: turnstilesiteKey, onSuccess: handleTurnstileSuccess, onError: handleTurnstileError, onExpire: handleTurnstileExpire, theme: "auto", size: "normal" }), errors._turnstile && (jsxRuntimeExports.jsx("p", { className: "field-error turnstile-error", children: errors._turnstile }))] })), jsxRuntimeExports.jsx("div", { className: "form-actions", children: jsxRuntimeExports.jsx("button", { type: "submit", disabled: isSubmitting || (!!turnstilesiteKey && !turnstileToken), className: "submit-button", children: isSubmitting ? 'Submitting...' : 'Submit' }) }), submitMutation.error && (jsxRuntimeExports.jsx("div", { className: "form-error", children: jsxRuntimeExports.jsx("p", { children: "There was an error submitting the form. Please try again." }) }))] }));
|
|
2377
2380
|
};
|
|
2378
2381
|
|
|
2379
2382
|
const MauticTracking = ({ enabled, mauticUrl, proxyUrl, children }) => {
|