Skip to content

Beautiful Open-Source Form Builder

New UI bug fixes

Julien Nahum26c40f327fd1
diff --git a/api/app/Http/Requests/Integration/FormIntegrationsRequest.php b/api/app/Http/Requests/Integration/FormIntegrationsRequest.php
index ed7069d0d..bb7b82926 100644
--- a/api/app/Http/Requests/Integration/FormIntegrationsRequest.php
+++ b/api/app/Http/Requests/Integration/FormIntegrationsRequest.php
@@ -23,15 +23,15 @@ class FormIntegrationsRequest extends FormRequest
if ($request->integration_id) {
// Load integration class, and get rules
$integration = FormIntegration::getIntegration($request->integration_id);
- if ($integration && isset($integration['file_name']) && class_exists(
+ if (! is_null($integration) && isset($integration['file_name']) && class_exists(
'App\Integrations\Handlers\\' . $integration['file_name']
)) {
$this->integrationClassName = 'App\Integrations\Handlers\\' . $integration['file_name'];
$this->loadIntegrationRules();
return;
}
- throw new \Exception('Unknown Integration!');
}
+ throw new \Exception('Unknown Integration.');
}
/**
diff --git a/client/components/open/integrations/components/IntegrationModal.vue b/client/components/open/integrations/components/IntegrationModal.vue
index bb7eb26fd..e0f641721 100644
--- a/client/components/open/integrations/components/IntegrationModal.vue
+++ b/client/components/open/integrations/components/IntegrationModal.vue
@@ -71,7 +71,7 @@
</template>
<script setup>
-import { computed } from "vue"
+import { computed, toValue } from "vue"
import { useComponentRegistry } from "~/composables/components/useComponentRegistry"
import ProTag from "~/components/app/ProTag.vue"
@@ -88,12 +88,17 @@ const emit = defineEmits(["close"])
const { createIntegration, updateIntegration } = useFormIntegrations()
-const createIntegrationMutation = createIntegration()
-const updateIntegrationMutation = updateIntegration()
+// Create mutations with reactive IDs
+const formId = computed(() => props.form.id)
+const formIntegrationId = computed(() => props.formIntegrationId)
+
+const createIntegrationMutation = createIntegration(formId)
+const updateIntegrationMutation = updateIntegration(formId, formIntegrationId)
const loading = computed(
() =>
- integrationData.value?.busy || false
+ createIntegrationMutation.isPending.value ||
+ updateIntegrationMutation.isPending.value,
)
// Computed property to handle show/hide logic for UModal
@@ -166,40 +171,23 @@ initIntegrationData()
const save = () => {
if (loading.value) return
- if (props.formIntegrationId) {
- integrationData.value.mutate(updateIntegrationMutation, {
- data: {
- formId: props.form.id,
- integrationId: props.formIntegrationId,
- }
- }).then((result) => {
+ const isUpdating = !!toValue(formIntegrationId)
+ const mutation = isUpdating ? updateIntegrationMutation : createIntegrationMutation
+
+ const promise = integrationData.value.mutate(mutation)
+
+ promise
+ .then((result) => {
alert.success(result.message)
- emit("close")
- }).catch((error) => {
- try {
- alert.error(error.data.message)
- }
- catch {
- alert.error("An error occurred while saving the integration")
- }
+ emit('close')
})
- }
- else {
- integrationData.value.mutate(createIntegrationMutation, {
- data: {
- formId: props.form.id,
- }
- }).then((result) => {
- alert.success(result.message)
- emit("close")
- }).catch((error) => {
+ .catch((error) => {
try {
alert.error(error.data.message)
}
catch {
- alert.error("An error occurred while saving the integration")
+ alert.error('An error occurred while saving the integration')
}
})
- }
}
</script>
diff --git a/client/components/open/integrations/components/WebhookIntegrationActions.vue b/client/components/open/integrations/components/WebhookIntegrationActions.vue
index 19ee92954..7bd61412c 100644
--- a/client/components/open/integrations/components/WebhookIntegrationActions.vue
+++ b/client/components/open/integrations/components/WebhookIntegrationActions.vue
@@ -4,13 +4,15 @@
v-if="integration"
class="hidden md:block space-y-1"
>
- <UBadge
- :label="integration.data.webhook_url"
- color="neutral"
- variant="subtle"
- size="sm"
- class="max-w-[300px] block truncate"
- />
+ <UTooltip :text="integration.data.webhook_url">
+ <UBadge
+ :label="integration.data.webhook_url"
+ color="neutral"
+ variant="subtle"
+ size="sm"
+ class="max-w-40 block truncate"
+ />
+ </UTooltip>
</div>
</div>
</template>
diff --git a/client/composables/query/forms/useFormIntegrations.js b/client/composables/query/forms/useFormIntegrations.js
index 88cb70dd3..cc8efacb7 100644
--- a/client/composables/query/forms/useFormIntegrations.js
+++ b/client/composables/query/forms/useFormIntegrations.js
@@ -74,37 +74,40 @@ export function useFormIntegrations() {
})
}
- const createIntegration = (options = {}) => {
+ const createIntegration = (formId, options = {}) => {
return useMutation({
- mutationFn: ({ formId, data }) => formsApi.integrations.create(formId, data),
- onSuccess: (response, { formId }) => {
+ mutationFn: (data) => formsApi.integrations.create(toValue(formId), data),
+ onSuccess: (response) => {
const newIntegration = response.form_integration
+ const currentFormId = toValue(formId)
// Add to integrations list
- queryClient.setQueryData(['forms', formId, 'integrations'], (old) => {
+ queryClient.setQueryData(['forms', currentFormId, 'integrations'], (old) => {
if (!old) return [newIntegration]
if (!Array.isArray(old)) return old
return [...old, newIntegration]
})
// Cache the individual integration
- queryClient.setQueryData(['forms', formId, 'integrations', newIntegration.id], newIntegration)
+ queryClient.setQueryData(['forms', currentFormId, 'integrations', newIntegration.id], newIntegration)
},
...options
})
}
- const updateIntegration = (options = {}) => {
+ const updateIntegration = (formId, integrationId, options = {}) => {
return useMutation({
- mutationFn: ({ formId, integrationId, data }) => formsApi.integrations.update(formId, integrationId, data),
- onSuccess: (response, { formId, integrationId }) => {
+ mutationFn: (data) => formsApi.integrations.update(toValue(formId), toValue(integrationId), data),
+ onSuccess: (response) => {
const updatedIntegration = response.form_integration
+ const currentFormId = toValue(formId)
+ const currentIntegrationId = toValue(integrationId)
// Update individual integration cache
- queryClient.setQueryData(['forms', formId, 'integrations', integrationId], updatedIntegration)
+ queryClient.setQueryData(['forms', currentFormId, 'integrations', currentIntegrationId], updatedIntegration)
// Update in integrations list
- queryClient.setQueryData(['forms', formId, 'integrations'], (old) => {
+ queryClient.setQueryData(['forms', currentFormId, 'integrations'], (old) => {
if (!Array.isArray(old)) return old
return old.map(integration =>
- integration.id === integrationId ? { ...integration, ...updatedIntegration } : integration
+ integration.id === currentIntegrationId ? { ...integration, ...updatedIntegration } : integration
)
})
},
diff --git a/client/lib/utils.js b/client/lib/utils.js
index 1e171c26f..00affe0f0 100644
--- a/client/lib/utils.js
+++ b/client/lib/utils.js
@@ -119,7 +119,13 @@ export const mentionAsText = (content) => {
(match, fieldId, fieldName, text) => {
return `${text}`
}
- ).replace(/<[^>]*>/g, '')
+ )
+ .replace(/<br\s*\/?>/gi, '\n') // Convert <br> tags to newlines
+ .replace(/<\/p>/gi, '\n') // Convert closing </p> tags to newlines
+ .replace(/<p[^>]*>/gi, '') // Remove opening <p> tags
+ .replace(/<\/div>/gi, '\n') // Convert closing </div> tags to newlines
+ .replace(/<div[^>]*>/gi, '') // Remove opening <div> tags
+ .replace(/<[^>]*>/g, '') // Remove all other HTML tags
}
export function formatNumber(num) {
diff --git a/client/pages/redirect/checkout.vue b/client/pages/redirect/checkout.vue
index eb8877c40..4ee63d227 100644
--- a/client/pages/redirect/checkout.vue
+++ b/client/pages/redirect/checkout.vue
@@ -29,10 +29,7 @@ onMounted(async () => {
// Update customer details if provided
if (name && email) {
try {
- await billingApi.updateCustomerDetails({
- method: 'PUT',
- body: { name, email }
- })
+ await billingApi.updateCustomerDetails({ name, email })
} catch {
useAlert().error('Failed to update customer details, but proceeding with checkout')
}
@@ -40,8 +37,12 @@ onMounted(async () => {
// Get checkout URL
const params = { trial_duration, currency }
+ const subscription = yearly === 'true' ? 'yearly' : 'monthly'
const { checkout_url } = await billingApi.getCheckoutUrl(
- `/subscription/new/${plan}/${yearly === 'true' ? 'yearly' : 'monthly'}/checkout/with-trial?${new URLSearchParams(params)}`
+ plan,
+ subscription,
+ 'with-trial',
+ { params }
)
if (!checkout_url) {
diff --git a/docs/front-end/data-fetching.mdx b/docs/front-end/data-fetching.mdx
index 9d6dc0e5f..cb78bb12f 100644
--- a/docs/front-end/data-fetching.mdx
+++ b/docs/front-end/data-fetching.mdx
@@ -63,6 +63,117 @@ const onSubmit = (form) => {
</script>
```
+### Mutations with URL parameters
+For endpoints that require IDs in the URL (like `/forms/{formId}/integrations/{integrationId}`), pass the required IDs when creating the mutation factory. This ensures proper cache invalidation and prevents stale closure issues:
+
+```vue
+<script setup>
+const props = defineProps({
+ formId: { type: Number, required: true },
+ integrationId: { type: Number, required: false }
+})
+
+const { createIntegration, updateIntegration } = useFormIntegrations()
+
+// ✅ Pass reactive IDs when creating mutations
+const formId = computed(() => props.formId)
+const integrationId = computed(() => props.integrationId)
+
+const createMutation = createIntegration(formId)
+const updateMutation = updateIntegration(formId, integrationId)
+
+const save = () => {
+ const mutation = props.integrationId ? updateMutation : createMutation
+
+ mutation
+ .mutateAsync(formData)
+ .then(() => useAlert().success('Integration saved!'))
+ .catch((err) => useAlert().error(err.message))
+}
+</script>
+```
+
+**Why this pattern?**
+- The mutation factory receives the IDs and can properly update query cache keys
+- No need to pass IDs in the `mutateAsync()` call
+- Reactive IDs ensure cache updates work correctly when props change
+- Cleaner separation between mutation setup and execution
+
+#### Defining mutations with URL parameters in composables
+
+In your query composable, define mutation factories that accept the required IDs as parameters:
+
+```javascript
+// client/composables/query/forms/useFormIntegrations.js
+import { useQueryClient, useMutation } from '@tanstack/vue-query'
+import { toValue } from 'vue'
+import { formsApi } from '~/api/forms'
+
+export function useFormIntegrations() {
+ const queryClient = useQueryClient()
+
+ const createIntegration = (formId, options = {}) => {
+ return useMutation({
+ mutationFn: (data) => formsApi.integrations.create(toValue(formId), data),
+ onSuccess: (response) => {
+ const newIntegration = response.form_integration
+ const currentFormId = toValue(formId)
+
+ // Update integrations list cache
+ queryClient.setQueryData(['forms', currentFormId, 'integrations'], (old) => {
+ if (!old) return [newIntegration]
+ if (!Array.isArray(old)) return old
+ return [...old, newIntegration]
+ })
+
+ // Cache the individual integration
+ queryClient.setQueryData(['forms', currentFormId, 'integrations', newIntegration.id], newIntegration)
+ },
+ ...options
+ })
+ }
+
+ const updateIntegration = (formId, integrationId, options = {}) => {
+ return useMutation({
+ mutationFn: (data) => formsApi.integrations.update(toValue(formId), toValue(integrationId), data),
+ onSuccess: (response) => {
+ const updatedIntegration = response.form_integration
+ const currentFormId = toValue(formId)
+ const currentIntegrationId = toValue(integrationId)
+
+ // Update individual integration cache
+ queryClient.setQueryData(['forms', currentFormId, 'integrations', currentIntegrationId], updatedIntegration)
+
+ // Update in integrations list
+ queryClient.setQueryData(['forms', currentFormId, 'integrations'], (old) => {
+ if (!Array.isArray(old)) return old
+ return old.map(integration =>
+ integration.id === currentIntegrationId ? { ...integration, ...updatedIntegration } : integration
+ )
+ })
+ },
+ ...options
+ })
+ }
+
+ return {
+ createIntegration,
+ updateIntegration,
+ // ... other methods
+ }
+}
+```
+
+<Note>
+Always use `toValue()` to unwrap reactive references (refs, computed) when building query keys or making API calls. This ensures the actual values are used rather than reactive objects.
+</Note>
+
+**Key patterns:**
+- **Factory functions**: Return `useMutation()` instances rather than calling them directly
+- **Reactive ID handling**: Use `toValue()` to extract values from refs/computed properties
+- **Consistent cache keys**: Match the hierarchical structure used in queries
+- **Optimistic updates**: Update cache immediately in `onSuccess` to avoid refetching
+
### Optimistic updates & cache layer
All mutations live in their composable (`client/composables/query/*`). After a successful API call they update the cache **manually** using `queryClient.setQueryData` so the UI reflects changes instantly *without* needing an extra network round-trip.