diff --git a/apps/admin-x-settings/src/components/settings/growth/embedSignup/EmbedSignupFormModal.tsx b/apps/admin-x-settings/src/components/settings/growth/embedSignup/EmbedSignupFormModal.tsx index 006b5fb60a..9e017eb8a5 100644 --- a/apps/admin-x-settings/src/components/settings/growth/embedSignup/EmbedSignupFormModal.tsx +++ b/apps/admin-x-settings/src/components/settings/growth/embedSignup/EmbedSignupFormModal.tsx @@ -16,7 +16,8 @@ const EmbedSignupFormModal = NiceModal.create(() => { const [selectedColor, setSelectedColor] = useState('#08090c'); const [selectedLabels, setSelectedLabels] = useState([]); const [selectedLayout, setSelectedLayout] = useState('all-in-one'); - const [embedScript, setEmbedScript] = useState(''); + const [previewScript, setPreviewScript] = useState(''); + const [generatedScript, setGeneratedScript] = useState(''); const [isCopied, setIsCopied] = useState(false); const {updateRoute} = useRouting(); @@ -33,8 +34,8 @@ const EmbedSignupFormModal = NiceModal.create(() => { if (!siteData) { return; } - const code = generateCode({ - preview: true, + + const defaultConfig = { config: { blogUrl: siteData.url, signupForm: { @@ -53,14 +54,24 @@ const EmbedSignupFormModal = NiceModal.create(() => { backgroundColor: selectedColor || '#08090c', layout: selectedLayout, i18nEnabled - }); + }; - setEmbedScript(code); + const previewCode = generateCode({ + preview: true, + ...defaultConfig + }); + setPreviewScript(previewCode); + + const generatedCode = generateCode({ + preview: false, + ...defaultConfig + }); + setGeneratedScript(generatedCode); }, [siteData, accentColor, selectedLabels, config, title, selectedColor, selectedLayout, locale, i18nEnabled, icon, description]); const handleCopyClick = async () => { try { - await navigator.clipboard.writeText(embedScript); + await navigator.clipboard.writeText(generatedScript); setIsCopied(true); setTimeout(() => setIsCopied(false), 2000); // reset after 2 seconds } catch (err) { @@ -98,13 +109,13 @@ const EmbedSignupFormModal = NiceModal.create(() => { >
`; - if (preview && style === 'minimal') { + if (preview && layout === 'minimal') { return `
${code}`; } diff --git a/apps/admin-x-settings/test/unit/utils/generateEmbedCode.test.ts b/apps/admin-x-settings/test/unit/utils/generateEmbedCode.test.ts index 98a2e80572..4ee376ae63 100644 --- a/apps/admin-x-settings/test/unit/utils/generateEmbedCode.test.ts +++ b/apps/admin-x-settings/test/unit/utils/generateEmbedCode.test.ts @@ -54,7 +54,7 @@ describe('generateCode', function () { it('renders a preview with a minimal layout', function () { genOptions.preview = true; genOptions.layout = 'minimal'; - assert.equal(generateCode(genOptions), '
'); + assert.equal(generateCode(genOptions), '
'); }); it('generates text color based on background color - light background, black text', function () {