opnform-host-nginx/client/components/pages/forms/show/EmbedFormAsPopupModal.vue

244 lines
6.9 KiB
Vue
Raw Normal View History

2023-12-09 15:47:03 +01:00
<template>
<div>
<v-button
v-track.share_embed_form_popup_click="{
form_id: form.id,
form_slug: form.slug,
}"
2023-12-09 15:47:03 +01:00
class="w-full"
color="light-gray"
@click="showEmbedFormAsPopupModal = true"
2023-12-09 15:47:03 +01:00
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6 mr-2 text-blue-600 inline"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M2.25 12.76c0 1.6 1.123 2.994 2.707 3.227 1.068.157 2.148.279 3.238.364.466.037.893.281 1.153.671L12 21l2.652-3.978c.26-.39.687-.634 1.153-.67 1.09-.086 2.17-.208 3.238-.365 1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.123-2.995-2.707-3.228A48.394 48.394 0 0012 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018z"
2023-12-09 15:47:03 +01:00
/>
</svg>
2023-12-24 09:51:22 +01:00
Embed as popup
2023-12-09 15:47:03 +01:00
</v-button>
<modal
:show="showEmbedFormAsPopupModal"
@close="onClose"
>
2023-12-09 15:47:03 +01:00
<template #icon>
<svg
xmlns="http://www.w3.org/2000/svg"
class="w-10 h-10 text-blue"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M2.25 12.76c0 1.6 1.123 2.994 2.707 3.227 1.068.157 2.148.279 3.238.364.466.037.893.281 1.153.671L12 21l2.652-3.978c.26-.39.687-.634 1.153-.67 1.09-.086 2.17-.208 3.238-.365 1.584-.233 2.707-1.626 2.707-3.228V6.741c0-1.602-1.123-2.995-2.707-3.228A48.394 48.394 0 0012 3c-2.392 0-4.744.175-7.043.513C3.373 3.746 2.25 5.14 2.25 6.741v6.018z"
2023-12-09 15:47:03 +01:00
/>
</svg>
</template>
<template #title>
<span>Add the popup to your website</span>
</template>
<div class="p-4">
<h3 class="border-t text-xl font-semibold mb-2 pt-6">
Demo
</h3>
<p class="pb-6">
A live preview of your form popup was just added to this page.
<span class="font-semibold text-blue-800">Click on the button on the bottom
2023-12-09 15:47:03 +01:00
{{ advancedOptions.position }} corner to try it</span>.
</p>
<h3 class="border-t text-xl font-semibold mb-2 pt-6">
How does it work?
</h3>
<p>
Paste the following code snippet in the <b>&lt;head&gt;</b> section of
your website.
</p>
2023-12-09 15:47:03 +01:00
<div
class="border border-nt-blue-light bg-blue-50 dark:bg-notion-dark-light rounded-md p-4 mb-5 w-full mx-auto mt-4 select-all"
>
<div class="flex items-center">
<p class="select-all text-nt-blue flex-grow break-all">
{{ embedPopupCode }}
</p>
<div
class="hover:bg-nt-blue-lighter rounded transition-colors cursor-pointer"
@click="copyToClipboard"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6 text-nt-blue"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
2023-12-09 15:47:03 +01:00
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"
2023-12-09 15:47:03 +01:00
/>
</svg>
</div>
</div>
</div>
<collapse
class="py-5 w-full border rounded-md px-4"
:model-value="true"
>
2023-12-09 15:47:03 +01:00
<template #title>
<div class="flex">
<h3 class="font-semibold block text-lg">
Advanced options
</h3>
</div>
</template>
<div class="border-t mt-4 -mx-4" />
<color-input
v-model="advancedOptions.bgcolor"
name="bgcolor"
class="mt-4"
label="Circle Background Color"
2023-12-09 15:47:03 +01:00
/>
<text-input
v-model="advancedOptions.emoji"
name="emoji"
class="mt-4"
label="Emoji"
:max-char-limit="2"
2023-12-09 15:47:03 +01:00
/>
<flat-select-input
v-model="advancedOptions.position"
name="position"
class="mt-4"
label="Position"
:options="[
{ name: 'Bottom Right', value: 'right' },
{ name: 'Bottom Left', value: 'left' },
]"
2023-12-09 15:47:03 +01:00
/>
<text-input
v-model="advancedOptions.width"
name="width"
class="mt-4"
label="Form pop max width (px)"
native-type="number"
2023-12-09 15:47:03 +01:00
/>
</collapse>
<div class="flex justify-end mt-4">
<v-button
color="gray"
shade="light"
@click="onClose"
>
2023-12-09 15:47:03 +01:00
Close
</v-button>
</div>
</div>
</modal>
</div>
</template>
2024-01-05 09:59:53 +01:00
<script setup>
import { ref, defineProps, computed } from "vue"
import { appUrl } from "~/lib/utils.js"
2024-01-05 09:59:53 +01:00
const { copy } = useClipboard()
const crisp = useCrisp()
const props = defineProps({
form: { type: Object, required: true },
2024-01-05 09:59:53 +01:00
})
const embedScriptUrl = "/widgets/embed-min.js"
const showEmbedFormAsPopupModal = ref(false)
const advancedOptions = ref({
emoji: "💬",
position: "right",
bgcolor: "#3B82F6",
width: "500",
2024-01-05 09:59:53 +01:00
})
const shareUrl = computed(() => {
Decouple title from title block (#696) * Decouple title from title block * fix lint * remove dry run for FormTitleMigration * Skip form title migration for forms with hidden titles * Refactor AI Form Generation with Dedicated Prompt Services - Extract AI form generation logic from GenerateTemplate command into dedicated prompt service classes - Update GenerateAiForm job to use new prompt generation services - Improve GptCompleter with more robust error handling and token tracking - Add error field to AiFormCompletion model for better error logging - Simplify command signature from 'ai:make-form-template' to 'form:generate' * Consolidate Template Metadata Generation with Unified Prompt Service - Create GenerateTemplateMetadataPrompt to centralize template metadata generation - Update GenerateTemplate command to use new consolidated metadata generation approach - Enhance GptCompleter to support strict JSON schema validation - Increase form prompt max length to support more complex form descriptions - Refactor form generation to simplify metadata extraction and processing * Implement Form Mode Strategy for Flexible Form Rendering - Introduce FormModeStrategy to centralize form rendering logic - Add support for different form modes: LIVE, PREVIEW, TEST, EDIT, PREFILL - Refactor components to use mode-based rendering strategy - Remove legacy boolean props like adminPreview and creating - Enhance form component flexibility and reusability * Refine Form Mode Strategy Display Behavior - Update FormModeStrategy to hide hidden fields in PREVIEW mode - Add FormMode getter in UrlFormPrefill component for mode-specific rendering - Clarify mode-specific validation and display logic in form strategies * Enhance Form Template Generation with Advanced Field Options - Update GenerateTemplate command to use front_url for template URL output - Expand GenerateFormPrompt with comprehensive field configuration options - Add support for advanced field types: date with time, toggle switches, radio/checkbox selections - Introduce field width configuration and HTML formatting for text elements - Re-enable select, multi-select, and matrix field type definitions with enhanced configurations * Remove Deprecated Template Metadata Generation Services - Delete multiple AI prompt services related to template metadata generation - Simplify GenerateTemplate command to use default values instead of complex metadata generation - Remove GenerateTemplateMetadataPrompt and related classes like GenerateTemplateDescriptionPrompt, GenerateTemplateImageKeywordsPrompt, etc. - Update form template generation to use basic fallback metadata generation approach * Restore GenerateTemplateMetadataPrompt for Comprehensive Template Generation - Reintroduce GenerateTemplateMetadataPrompt to replace default metadata generation - Update GenerateTemplate command to use consolidated metadata generation approach - Extract detailed metadata components including title, description, industries, and image search query - Improve template generation with more dynamic and AI-generated metadata * Refactor Template Preview Section Layout - Remove unnecessary nested div in template preview section - Simplify HTML structure for the template preview component - Maintain existing styling and functionality while improving code readability * Refactor Constructor and Code Formatting in AI Form Generation and Prompt Classes - Updated the constructor in GenerateAiForm.php to use a block structure for improved readability and consistency. - Added a blank line in the Prompt.php file to enhance code formatting and maintain consistency with PHP coding standards. - Modified the migration file to use a more concise class declaration syntax, improving clarity. These changes aim to enhance code readability and maintainability across the affected files. --------- Co-authored-by: Julien Nahum <julien@nahum.net>
2025-03-21 16:59:18 +01:00
return props.form.share_url
2024-01-05 09:59:53 +01:00
})
const embedPopupCode = computed(() => {
2024-01-05 09:59:53 +01:00
const nfData = {
formurl: shareUrl.value,
emoji: advancedOptions.value.emoji,
position: advancedOptions.value.position,
bgcolor: advancedOptions.value.bgcolor,
width: advancedOptions.value.width,
2023-12-09 15:47:03 +01:00
}
2024-01-05 09:59:53 +01:00
previewPopup(nfData)
return (
"<script async data-nf='" +
JSON.stringify(nfData) +
"' src='" +
appUrl(embedScriptUrl) +
"'></scrip" +
"t>"
)
2024-01-05 09:59:53 +01:00
})
onMounted(() => {
advancedOptions.value.bgcolor = props.form.color
})
const onClose = () => {
removePreview()
crisp.showChat()
showEmbedFormAsPopupModal.value = false
}
const copyToClipboard = () => {
if (import.meta.server) return
2024-01-05 09:59:53 +01:00
copy(embedPopupCode.value)
useAlert().success("Copied!")
2024-01-05 09:59:53 +01:00
}
const removePreview = () => {
if (import.meta.server) return
const oldP = document.head.querySelector("#nf-popup-preview")
2024-01-05 09:59:53 +01:00
if (oldP) {
oldP.remove()
}
const oldM = document.body.querySelector(".nf-main")
2024-01-05 09:59:53 +01:00
if (oldM) {
oldM.remove()
}
}
const previewPopup = (nfData) => {
if (import.meta.server) return
2024-01-05 09:59:53 +01:00
if (!showEmbedFormAsPopupModal.value) {
return
}
// Remove old preview, if there
removePreview()
// Hide crisp
crisp.hideChat()
// Add new preview
const el = document.createElement("script")
el.id = "nf-popup-preview"
2024-01-05 09:59:53 +01:00
el.async = true
el.src = embedScriptUrl
el.setAttribute("data-nf", JSON.stringify(nfData))
2024-01-05 09:59:53 +01:00
document.head.appendChild(el)
2023-12-09 15:47:03 +01:00
}
</script>