Skip to content

Commit

Permalink
106a6 integration performance issues (#581)
Browse files Browse the repository at this point in the history
* apply performance fixes

* fix integration

* Update client/components/open/forms/components/FirstSubmissionModal.vue

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix unique cache for forms

---------

Co-authored-by: Julien Nahum <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 1, 2024
1 parent 5346054 commit dea8fe5
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ public function poll(PollSubmissionRequest $request)
$this->authorize('view', $form);

$lastSubmission = $form->submissions()->latest()->first();
$submissionData = null;
if (!$lastSubmission) {
// Generate fake data when no previous submissions
$submissionData = (new FormSubmissionDataFactory($form))->asFormSubmissionData()->createSubmissionData();
}
$cacheKey = "zapier-poll-submissions-{$form->id}";
return (array) \Cache::remember($cacheKey, 60 * 5, function () use ($form, $submissionData, $lastSubmission) {
return [ZapierIntegration::formatWebhookData($form, $submissionData ?? $lastSubmission->data)];
});

return [ZapierIntegration::formatWebhookData($form, $submissionData ?? $lastSubmission->data)];
}
}
11 changes: 5 additions & 6 deletions api/app/Integrations/Handlers/AbstractIntegrationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,12 @@ public static function formatWebhookData(Form $form, array $submissionData): arr

// Old format - kept for retro-compatibility
$oldFormatData = [];
foreach ($formatter->getFieldsWithValue() as $field) {
$oldFormatData[$field['name']] = $field['value'];
}

// New format using ID
$formattedData = [];
foreach ($formatter->getFieldsWithValue() as $field) {
$fieldsWithValue = $formatter->getFieldsWithValue();

foreach ($fieldsWithValue as $field) {
$oldFormatData[$field['name']] = $field['value'];
// New format using ID
$formattedData[$field['id']] = [
'value' => $field['value'],
'name' => $field['name'],
Expand Down
108 changes: 108 additions & 0 deletions client/components/open/forms/components/FirstSubmissionModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<template>
<modal
:show="show"
compact-header
backdrop-blur="sm"
@close="$emit('close')"
>
<template #title>
<h2 class="text-xl font-medium">
🎉 Your first submission! Congratulations!
</h2>
</template>
<div class="">
<div class="text-sm text-gray-500">
Congratulations on creating your form and receiving your first submission! Your form is now live and ready for action. You can now <span class="font-semibold">share your form</span> with others, or <span class="font-semibold">open your Notion database</span> to view the submitted data.
</div>

<div class="flex gap-2 items-center max-w-full">
<ShareFormUrl
class="flex-grow my-4"
:form="form"
/>
<UButton
v-track.form_first_submission_modal_open_db_click
color="white"
icon="i-logos-notion-icon"
:to="form.notion_database_url"
target="_blank"
>
See Notion database
</UButton>
</div>

<p class="text-gray-500 font-medium text-sm text-center my-4">
What's next?
</p>
<div class="grid grid-cols-2 gap-2">
<div
v-for="(item, i) in helpLinks"
:key="i"
role="button"
class="bg-white shadow border border-gray-200 rounded-lg p-4 pb-2 items-center justify-center flex flex-col relative hover:bg-gray-50 group transition-colors"
@click="item.action"
>
<div class="flex justify-center">
<div class="h-8 w-8 text-gray-600 group-hover:text-gray-800 transition-colors flex items-center">
<Icon
:name="item.icon"
class=""
size="40px"
/>
</div>
</div>

<p class="text-gray-500 font-medium text-xs text-center my-2">
{{ item.label }}
</p>
</div>
</div>
</div>
</modal>
</template>

<script setup>
import ShareFormUrl from '~/components/notion/forms/components/ShareFormUrl.vue'
const props = defineProps({
show: { type: Boolean, required: true },
form: { type: Object, required: true }
})
const emit = defineEmits(['close'])
const confetti = useConfetti()
const crisp = useCrisp()
watch(() => props.show, () => {
if (props.show) {
confetti.play()
useAmplitude().logEvent('form_first_submission_modal_viewed')
}
})
const helpLinks = computed(() => {
return [
{
'label': 'Embed form on your website',
'icon': 'heroicons:code-bracket',
'action': () => crisp.openHelpdeskArticle('how-to-embed-your-form-on-your-website-yqa6i')
},
{
'label': 'Embed form in Notion',
'icon': 'ri:notion-fill',
'action': () => crisp.openHelpdeskArticle('can-i-embed-my-form-in-a-notion-page-or-site-11iroj9')
},
{
'label': 'Help Center',
'icon': 'heroicons:book-open',
'action': () => crisp.openHelpdesk()
},
{
'label': 'Contact Us',
'icon': 'heroicons:chat-bubble-left-right',
'action': () => { crisp.openAndShowChat() }
},
]
})
</script>

0 comments on commit dea8fe5

Please sign in to comment.