opnform-host-nginx/client/components/global/Modal.vue

242 lines
5.2 KiB
Vue
Raw Normal View History

2023-12-09 15:47:03 +01:00
<template>
2023-12-14 16:53:05 +01:00
<Teleport to="body">
2023-12-20 13:51:39 +01:00
<transition @leave="onLeave">
<div
v-if="show"
ref="backdrop"
:class="[{ 'backdrop-blur-sm': backdropBlur }, twMerge('fixed z-40 top-0 inset-0 px-2 sm:px-4 flex items-top justify-center bg-gray-700/75 w-full h-screen overflow-y-scroll', $attrs.class)]"
@click.self="close"
2023-12-09 15:47:03 +01:00
>
<div
ref="content"
class="self-start bg-white dark:bg-notion-dark w-full relative my-2 sm:my-6 rounded-xl shadow-xl"
:class="maxWidthClass"
2023-12-09 15:47:03 +01:00
>
<div
v-if="closeable"
class="absolute top-4 right-4"
>
<button
class="text-gray-500 hover:text-gray-900 cursor-pointer"
@click="close()"
>
<svg
class="h-6 w-6"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M18 6L6 18M6 6L18 18"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
2023-12-09 15:47:03 +01:00
/>
</svg>
</button>
</div>
<div
v-if="_has($slots, 'icon') || _has($slots, 'title')"
class="flex border-b pb-4"
:class="[
{
'flex-col sm:items-start': !compactHeader,
'items-center justify-center py-6 gap-x-4': compactHeader,
},
headerInnerPadding,
]"
>
<div
v-if="_has($slots, 'icon')"
:class="{ 'w-full mb-4 flex justify-center': !compactHeader }"
>
<div
class="w-14 h-14 rounded-full flex justify-center items-center"
:class="'bg-' + iconColor + '-100 text-' + iconColor + '-600'"
2023-12-09 15:47:03 +01:00
>
<slot name="icon" />
2023-12-09 15:47:03 +01:00
</div>
</div>
<div
class="mt-3 text-center sm:mt-0"
:class="{ 'w-full': !compactHeader }"
>
<h2
v-if="_has($slots, 'title')"
class="text-2xl font-semibold text-center text-gray-900"
2023-12-09 15:47:03 +01:00
>
<slot name="title" />
2023-12-09 15:47:03 +01:00
</h2>
</div>
</div>
<div
class="w-full"
:class="innerPadding"
>
<slot />
2023-12-09 15:47:03 +01:00
</div>
<div
v-if="_has($slots, 'footer')"
class="bg-gray-50 border-t rounded-b-xl text-right"
:class="footerInnerPadding"
>
<slot name="footer" />
2023-12-09 15:47:03 +01:00
</div>
</div>
</div>
</transition>
2023-12-14 16:53:05 +01:00
</Teleport>
2023-12-09 15:47:03 +01:00
</template>
2023-12-19 19:42:02 +01:00
<script setup>
import { watch } from 'vue'
import { default as _has } from 'lodash/has'
import {twMerge} from 'tailwind-merge'
2023-12-09 15:47:03 +01:00
2023-12-19 19:42:02 +01:00
const props = defineProps({
show: {
type: Boolean,
default: false
2023-12-19 19:42:02 +01:00
},
backdropBlur: {
type: Boolean,
default: false
2023-12-19 19:42:02 +01:00
},
iconColor: {
type: String,
default: 'blue'
2023-12-09 15:47:03 +01:00
},
2023-12-19 19:42:02 +01:00
maxWidth: {
type: String,
default: '2xl'
2023-12-19 19:42:02 +01:00
},
Notification & Integrations refactoring (#346) * Integrations Refactoring - WIP * integrations list & edit - WIP * Fix integration store binding issue * integrations refactor - WIP * Form integration - WIP * Form integration Edit - WIP * Integration Refactor - Slack - WIP * Integration Refactor - Discord - WIP * Integration Refactor - Webhook - WIP * Integration Refactor - Send Submission Confirmation - WIP * Integration Refactor - Backend handler - WIP * Form Integration Status field * Integration Refactor - Backend SubmissionConfirmation - WIP * IntegrationMigration Command * skip confirmation email test case * Small refactoring * FormIntegration status active/inactive * formIntegrationData to integrationData * Rename file name with Integration suffix for integration realted files * Loader on form integrations * WIP * form integration test case * WIP * Added Integration card - working on refactoring * change location for IntegrationCard and update package file * Form Integration Create/Edit in single Modal * Remove integration extra pages * crisp_help_page_slug for integration json * integration logic as collapse * UI improvements * WIP * Trying to debug vue devtools * WIP for integrations * getIntegrationHandler change namespace name * useForm for integration fields + validation structure * Integration Test case & apply validation rules * Apply useform changes to integration other files * validation rules for FormNotificationsMessageActions fields * Zapier integration as coming soon * Update FormCleaner * set default settings for confirmation integration * WIP * Finish validation for all integrations * Updated purify, added integration formatData * Fix testcase * Ran pint; working on integration errors * Handle integration events * command for Delete Old Integration Events * Display Past Events in Modal * on Integration event create with status error send email to form creator * Polish styling * Minor improvements * Finish badge and integration status * Fix tests and add an integration event test * Lint --------- Co-authored-by: Julien Nahum <julien@nahum.net>
2024-03-28 18:14:30 +01:00
innerPadding: {
type: String,
default: 'p-6'
Notification & Integrations refactoring (#346) * Integrations Refactoring - WIP * integrations list & edit - WIP * Fix integration store binding issue * integrations refactor - WIP * Form integration - WIP * Form integration Edit - WIP * Integration Refactor - Slack - WIP * Integration Refactor - Discord - WIP * Integration Refactor - Webhook - WIP * Integration Refactor - Send Submission Confirmation - WIP * Integration Refactor - Backend handler - WIP * Form Integration Status field * Integration Refactor - Backend SubmissionConfirmation - WIP * IntegrationMigration Command * skip confirmation email test case * Small refactoring * FormIntegration status active/inactive * formIntegrationData to integrationData * Rename file name with Integration suffix for integration realted files * Loader on form integrations * WIP * form integration test case * WIP * Added Integration card - working on refactoring * change location for IntegrationCard and update package file * Form Integration Create/Edit in single Modal * Remove integration extra pages * crisp_help_page_slug for integration json * integration logic as collapse * UI improvements * WIP * Trying to debug vue devtools * WIP for integrations * getIntegrationHandler change namespace name * useForm for integration fields + validation structure * Integration Test case & apply validation rules * Apply useform changes to integration other files * validation rules for FormNotificationsMessageActions fields * Zapier integration as coming soon * Update FormCleaner * set default settings for confirmation integration * WIP * Finish validation for all integrations * Updated purify, added integration formatData * Fix testcase * Ran pint; working on integration errors * Handle integration events * command for Delete Old Integration Events * Display Past Events in Modal * on Integration event create with status error send email to form creator * Polish styling * Minor improvements * Finish badge and integration status * Fix tests and add an integration event test * Lint --------- Co-authored-by: Julien Nahum <julien@nahum.net>
2024-03-28 18:14:30 +01:00
},
headerInnerPadding: {
type: String,
default: 'p-6'
Notification & Integrations refactoring (#346) * Integrations Refactoring - WIP * integrations list & edit - WIP * Fix integration store binding issue * integrations refactor - WIP * Form integration - WIP * Form integration Edit - WIP * Integration Refactor - Slack - WIP * Integration Refactor - Discord - WIP * Integration Refactor - Webhook - WIP * Integration Refactor - Send Submission Confirmation - WIP * Integration Refactor - Backend handler - WIP * Form Integration Status field * Integration Refactor - Backend SubmissionConfirmation - WIP * IntegrationMigration Command * skip confirmation email test case * Small refactoring * FormIntegration status active/inactive * formIntegrationData to integrationData * Rename file name with Integration suffix for integration realted files * Loader on form integrations * WIP * form integration test case * WIP * Added Integration card - working on refactoring * change location for IntegrationCard and update package file * Form Integration Create/Edit in single Modal * Remove integration extra pages * crisp_help_page_slug for integration json * integration logic as collapse * UI improvements * WIP * Trying to debug vue devtools * WIP for integrations * getIntegrationHandler change namespace name * useForm for integration fields + validation structure * Integration Test case & apply validation rules * Apply useform changes to integration other files * validation rules for FormNotificationsMessageActions fields * Zapier integration as coming soon * Update FormCleaner * set default settings for confirmation integration * WIP * Finish validation for all integrations * Updated purify, added integration formatData * Fix testcase * Ran pint; working on integration errors * Handle integration events * command for Delete Old Integration Events * Display Past Events in Modal * on Integration event create with status error send email to form creator * Polish styling * Minor improvements * Finish badge and integration status * Fix tests and add an integration event test * Lint --------- Co-authored-by: Julien Nahum <julien@nahum.net>
2024-03-28 18:14:30 +01:00
},
footerInnerPadding: {
type: String,
default: 'p-6'
Notification & Integrations refactoring (#346) * Integrations Refactoring - WIP * integrations list & edit - WIP * Fix integration store binding issue * integrations refactor - WIP * Form integration - WIP * Form integration Edit - WIP * Integration Refactor - Slack - WIP * Integration Refactor - Discord - WIP * Integration Refactor - Webhook - WIP * Integration Refactor - Send Submission Confirmation - WIP * Integration Refactor - Backend handler - WIP * Form Integration Status field * Integration Refactor - Backend SubmissionConfirmation - WIP * IntegrationMigration Command * skip confirmation email test case * Small refactoring * FormIntegration status active/inactive * formIntegrationData to integrationData * Rename file name with Integration suffix for integration realted files * Loader on form integrations * WIP * form integration test case * WIP * Added Integration card - working on refactoring * change location for IntegrationCard and update package file * Form Integration Create/Edit in single Modal * Remove integration extra pages * crisp_help_page_slug for integration json * integration logic as collapse * UI improvements * WIP * Trying to debug vue devtools * WIP for integrations * getIntegrationHandler change namespace name * useForm for integration fields + validation structure * Integration Test case & apply validation rules * Apply useform changes to integration other files * validation rules for FormNotificationsMessageActions fields * Zapier integration as coming soon * Update FormCleaner * set default settings for confirmation integration * WIP * Finish validation for all integrations * Updated purify, added integration formatData * Fix testcase * Ran pint; working on integration errors * Handle integration events * command for Delete Old Integration Events * Display Past Events in Modal * on Integration event create with status error send email to form creator * Polish styling * Minor improvements * Finish badge and integration status * Fix tests and add an integration event test * Lint --------- Co-authored-by: Julien Nahum <julien@nahum.net>
2024-03-28 18:14:30 +01:00
},
2023-12-19 19:42:02 +01:00
closeable: {
type: Boolean,
default: true
Notification & Integrations refactoring (#346) * Integrations Refactoring - WIP * integrations list & edit - WIP * Fix integration store binding issue * integrations refactor - WIP * Form integration - WIP * Form integration Edit - WIP * Integration Refactor - Slack - WIP * Integration Refactor - Discord - WIP * Integration Refactor - Webhook - WIP * Integration Refactor - Send Submission Confirmation - WIP * Integration Refactor - Backend handler - WIP * Form Integration Status field * Integration Refactor - Backend SubmissionConfirmation - WIP * IntegrationMigration Command * skip confirmation email test case * Small refactoring * FormIntegration status active/inactive * formIntegrationData to integrationData * Rename file name with Integration suffix for integration realted files * Loader on form integrations * WIP * form integration test case * WIP * Added Integration card - working on refactoring * change location for IntegrationCard and update package file * Form Integration Create/Edit in single Modal * Remove integration extra pages * crisp_help_page_slug for integration json * integration logic as collapse * UI improvements * WIP * Trying to debug vue devtools * WIP for integrations * getIntegrationHandler change namespace name * useForm for integration fields + validation structure * Integration Test case & apply validation rules * Apply useform changes to integration other files * validation rules for FormNotificationsMessageActions fields * Zapier integration as coming soon * Update FormCleaner * set default settings for confirmation integration * WIP * Finish validation for all integrations * Updated purify, added integration formatData * Fix testcase * Ran pint; working on integration errors * Handle integration events * command for Delete Old Integration Events * Display Past Events in Modal * on Integration event create with status error send email to form creator * Polish styling * Minor improvements * Finish badge and integration status * Fix tests and add an integration event test * Lint --------- Co-authored-by: Julien Nahum <julien@nahum.net>
2024-03-28 18:14:30 +01:00
},
compactHeader: {
default: false,
type: Boolean
}
2023-12-19 19:42:02 +01:00
})
2023-12-09 15:47:03 +01:00
const emit = defineEmits(['close'])
2023-12-09 15:47:03 +01:00
2023-12-19 19:42:02 +01:00
useHead({
Notification & Integrations refactoring (#346) * Integrations Refactoring - WIP * integrations list & edit - WIP * Fix integration store binding issue * integrations refactor - WIP * Form integration - WIP * Form integration Edit - WIP * Integration Refactor - Slack - WIP * Integration Refactor - Discord - WIP * Integration Refactor - Webhook - WIP * Integration Refactor - Send Submission Confirmation - WIP * Integration Refactor - Backend handler - WIP * Form Integration Status field * Integration Refactor - Backend SubmissionConfirmation - WIP * IntegrationMigration Command * skip confirmation email test case * Small refactoring * FormIntegration status active/inactive * formIntegrationData to integrationData * Rename file name with Integration suffix for integration realted files * Loader on form integrations * WIP * form integration test case * WIP * Added Integration card - working on refactoring * change location for IntegrationCard and update package file * Form Integration Create/Edit in single Modal * Remove integration extra pages * crisp_help_page_slug for integration json * integration logic as collapse * UI improvements * WIP * Trying to debug vue devtools * WIP for integrations * getIntegrationHandler change namespace name * useForm for integration fields + validation structure * Integration Test case & apply validation rules * Apply useform changes to integration other files * validation rules for FormNotificationsMessageActions fields * Zapier integration as coming soon * Update FormCleaner * set default settings for confirmation integration * WIP * Finish validation for all integrations * Updated purify, added integration formatData * Fix testcase * Ran pint; working on integration errors * Handle integration events * command for Delete Old Integration Events * Display Past Events in Modal * on Integration event create with status error send email to form creator * Polish styling * Minor improvements * Finish badge and integration status * Fix tests and add an integration event test * Lint --------- Co-authored-by: Julien Nahum <julien@nahum.net>
2024-03-28 18:14:30 +01:00
bodyAttrs: computed(() => {
return {
class: {
'overflow-hidden': props.show
}
2023-12-09 15:47:03 +01:00
}
})
2023-12-19 19:42:02 +01:00
})
2023-12-09 15:47:03 +01:00
2023-12-19 19:42:02 +01:00
const closeOnEscape = (e) => {
if (e.key === 'Escape' && props.show) {
2024-01-18 12:58:12 +01:00
close()
2023-12-19 19:42:02 +01:00
}
}
2023-12-09 15:47:03 +01:00
2023-12-19 19:42:02 +01:00
onMounted(() => {
if (import.meta.server) return
document.addEventListener('keydown', closeOnEscape)
initMotions()
2023-12-19 19:42:02 +01:00
})
2023-12-09 15:47:03 +01:00
2023-12-19 19:42:02 +01:00
onBeforeUnmount(() => {
if (import.meta.server) return
document.removeEventListener('keydown', closeOnEscape)
2023-12-19 19:42:02 +01:00
})
2023-12-09 15:47:03 +01:00
2023-12-19 19:42:02 +01:00
const maxWidthClass = computed(() => {
return {
sm: 'sm:max-w-sm',
md: 'sm:max-w-md',
lg: 'sm:max-w-lg',
xl: 'sm:max-w-xl',
'2xl': 'max-w-2xl',
'screen-lg': 'max-w-screen-lg'
2023-12-19 19:42:02 +01:00
}[props.maxWidth]
})
2023-12-20 13:51:39 +01:00
const motionFadeIn = {
initial: {
opacity: 0,
transition: {
delay: 100,
duration: 200,
ease: 'easeIn'
}
2023-12-20 13:51:39 +01:00
},
enter: {
opacity: 1,
transition: {
duration: 200
}
}
2023-12-20 13:51:39 +01:00
}
2023-12-09 15:47:03 +01:00
2023-12-20 13:51:39 +01:00
const motionSlideBottom = {
initial: {
y: 150,
opacity: 0,
transition: {
ease: 'easeIn',
duration: 200
}
2023-12-20 13:51:39 +01:00
},
enter: {
y: 0,
opacity: 1,
transition: {
duration: 250,
ease: 'easeOut',
delay: 100
}
}
2023-12-20 13:51:39 +01:00
}
const onLeave = (el, done) => {
contentMotion.value.leave(() => {})
2023-12-20 13:51:39 +01:00
backdropMotion.value.leave(done)
}
2023-12-19 19:42:02 +01:00
const close = () => {
if (props.closeable) {
emit('close')
2023-12-19 19:42:02 +01:00
}
2023-12-09 15:47:03 +01:00
}
2023-12-20 13:51:39 +01:00
const backdrop = ref(null)
const content = ref(null)
const backdropMotion = ref(null)
const contentMotion = ref(null)
const initMotions = () => {
if (props.show) {
2023-12-20 13:51:39 +01:00
nextTick(() => {
backdropMotion.value = useMotion(backdrop.value, motionFadeIn)
contentMotion.value = useMotion(content.value, motionSlideBottom)
})
}
}
watch(() => props.show, initMotions)
2023-12-09 15:47:03 +01:00
</script>