Beautiful Open-Source Form Builder
feat: polish email appearance customization
Julien Nahume0a1edfdb93b
diff --git a/api/resources/views/vendor/mail/html/layout.blade.php b/api/resources/views/vendor/mail/html/layout.blade.phpindex 190d03372..0427aa4d5 100644--- a/api/resources/views/vendor/mail/html/layout.blade.php+++ b/api/resources/views/vendor/mail/html/layout.blade.php@@ -7,12 +7,14 @@ $innerBackgroundColor = $appearance['innerBackgroundColor'] ?? null;$fontFamily = $appearance['fontFamily'] ?? null;$fontColor = $appearance['fontColor'] ?? null;-$wrapperStyle = $outerBackgroundColor ? 'background-color: ' . e($outerBackgroundColor) . ';' : '';-$bodyStyle = $outerBackgroundColor ? 'background-color: ' . e($outerBackgroundColor) . ';' : '';-$innerBodyStyle = $innerBackgroundColor ? 'background-color: ' . e($innerBackgroundColor) . ';' : '';+$pageBackgroundStyle = $outerBackgroundColor ? 'background-color: ' . e($outerBackgroundColor) . ';' : '';+$wrapperStyle = $pageBackgroundStyle;+$bodyStyle = trim(($outerBackgroundColor ? 'background-color: ' . e($outerBackgroundColor) . '; ' : '') . 'border-top: 0; border-bottom: 0;');+$innerBodyStyle = trim(($innerBackgroundColor ? 'background-color: ' . e($innerBackgroundColor) . '; ' : '') . 'border: 0; box-shadow: none;');$fontFamilyCss = $fontFamily ? 'font-family: \'' . e($fontFamily) . '\', sans-serif;' : '';$fontColorCss = $fontColor ? 'color: ' . e($fontColor) . ';' : '';$contentCellStyle = ($fontFamilyCss || $fontColorCss) ? $fontFamilyCss . ' ' . $fontColorCss : '';+$dividerColor = $innerBackgroundColor ?: ($outerBackgroundColor ?: 'transparent');@endphp<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">@@ -41,10 +43,49 @@ $contentCellStyle = ($fontFamilyCss || $fontColorCss) ? $fontFamilyCss . ' ' . $width: 100% !important;}}++ @if($fontFamily || $fontColor)+ .content-cell,+ .content-cell p,+ .content-cell div,+ .content-cell span,+ .content-cell li,+ .content-cell ul,+ .content-cell ol,+ .content-cell td,+ .content-cell th,+ .content-cell h1,+ .content-cell h2,+ .content-cell h3,+ .content-cell h4,+ .content-cell h5,+ .content-cell h6,+ .content-cell blockquote,+ .content-cell a {+ @if($fontFamily)+ font-family: '{{ e($fontFamily) }}', sans-serif !important;+ @endif+ @if($fontColor)+ color: {{ e($fontColor) }} !important;+ @endif+ }+ @endif++ .header,+ .footer .content-cell,+ .subcopy td {+ border-color: {{ e($dividerColor) }} !important;+ }++ .header,+ .footer,+ .subcopy {+ background-color: {{ e($outerBackgroundColor ?: 'transparent') }} !important;+ }</style></head>-<body>+<body @if($pageBackgroundStyle) style="{{ $pageBackgroundStyle }}" @endif><table class="wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation" @if($wrapperStyle) style="{{ $wrapperStyle }}" @endif><tr>@@ -75,4 +116,4 @@ $contentCellStyle = ($fontFamilyCss || $fontColorCss) ? $fontFamilyCss . ' ' . $</table></body>-</html>\ No newline at end of file+</html>diff --git a/api/resources/views/vendor/mail/html/message.blade.php b/api/resources/views/vendor/mail/html/message.blade.phpindex 1cfb1cb01..4eaf01b76 100644--- a/api/resources/views/vendor/mail/html/message.blade.php+++ b/api/resources/views/vendor/mail/html/message.blade.php@@ -5,16 +5,14 @@ $logoUrl = $appearance['logoUrl'] ?? null;<x-mail::layout :email-appearance="$appearance">{{-- Header --}}<x-slot:header>- @if (!(isset($noBranding) && $noBranding))@if(!empty($logoUrl))<x-mail::header :url="config('app.url')"><img src="{{ $logoUrl }}" class="logo" alt="Logo" style="max-height: 75px; height: 75px;"></x-mail::header>- @else+ @elseif (!(isset($noBranding) && $noBranding))<x-mail::header :url="config('app.url')">{{ config('app.name') }}</x-mail::header>- @endif@else<div style="margin-top:25px;" />@endif@@ -40,4 +38,4 @@ $logoUrl = $appearance['logoUrl'] ?? null;@endif</x-mail::footer></x-slot:footer>-</x-mail::layout>\ No newline at end of file+</x-mail::layout>diff --git a/api/tests/Feature/Forms/EmailAppearanceNotificationTest.php b/api/tests/Feature/Forms/EmailAppearanceNotificationTest.phpnew file mode 100644index 000000000..f0b3956d1--- /dev/null+++ b/api/tests/Feature/Forms/EmailAppearanceNotificationTest.php@@ -0,0 +1,70 @@+<?php++use App\Notifications\Forms\FormEmailNotification;+use Illuminate\Notifications\AnonymousNotifiable;++it('renders a custom logo even when opnform branding is disabled', function () {+ $user = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace, [+ 'no_branding' => true,+ ]);++ $integrationData = $this->createFormIntegration('email', $form->id, [+ 'send_to' => $user->email,+ 'sender_name' => 'Test Sender',+ 'subject' => 'Test Subject',+ 'email_content' => 'Custom content',+ 'include_submission_data' => true,+ 'logo_url' => 'https://example.com/logo.png',+ 'font_family' => 'Inter',+ 'font_color' => '#1a1a1a',+ 'outer_background_color' => '#f5f5f5',+ 'inner_background_color' => '#ffffff',+ ]);++ $formData = $this->generateFormSubmissionData($form);+ $event = new \App\Events\Forms\FormSubmitted($form, $formData);+ $mailable = new FormEmailNotification($event, $integrationData);+ $notifiable = new AnonymousNotifiable();+ $notifiable->route('mail', $user->email);++ $html = trim($mailable->toMail($notifiable)->render());++ expect($html)->toContain('https://example.com/logo.png');+ expect($html)->toContain('background-color: #f5f5f5;');+ expect($html)->toContain('background-color: #ffffff;');+ expect($html)->toContain("font-family: 'Inter', sans-serif;");+ expect($html)->toContain('color: #1a1a1a;');+ expect($html)->not->toContain('border-top: 1px solid #edf2f7;');+ expect($html)->not->toContain('border-bottom: 1px solid #edf2f7;');+ expect($html)->not->toContain('box-shadow: 0 2px 0');+ expect($html)->not->toContain('All rights reserved.');+ expect(preg_match('/<body[^>]*background-color:\s*#f5f5f5;/i', $html))->toBe(1);+});++it('inlines resize styles in generated email content html', function () {+ $user = $this->actingAsProUser();+ $workspace = $this->createUserWorkspace($user);+ $form = $this->createForm($user, $workspace);++ $integrationData = $this->createFormIntegration('email', $form->id, [+ 'send_to' => $user->email,+ 'sender_name' => 'Test Sender',+ 'subject' => 'Test Subject',+ 'email_content' => '<p><img class="ql-resize-style-left" src="https://example.com/body.png"></p>',+ 'include_submission_data' => true,+ ]);++ $formData = $this->generateFormSubmissionData($form);+ $event = new \App\Events\Forms\FormSubmitted($form, $formData);+ $mailable = new FormEmailNotification($event, $integrationData);+ $notifiable = new AnonymousNotifiable();+ $notifiable->route('mail', $user->email);++ $mailData = $mailable->toMail($notifiable)->viewData;++ expect($mailData['emailContent'])->toContain('https://example.com/body.png');+ expect($mailData['emailContent'])->toContain('float:left; margin:0 1em 1em 0;');+ expect($mailData['emailContent'])->not->toContain('ql-resize-style-left');+});diff --git a/client/components/app/Collapse.vue b/client/components/app/Collapse.vueindex 6def4b1d7..cc8194180 100644--- a/client/components/app/Collapse.vue+++ b/client/components/app/Collapse.vue@@ -8,7 +8,7 @@<slot name="title" /></div><div- class="text-neutral-400 hover:text-neutral-600 absolute -right-2 cursor-pointer p-2"+ class="text-neutral-400 hover:text-neutral-600 absolute right-4 cursor-pointer p-2"@click="trigger"><svgdiff --git a/client/components/forms/heavy/ImageInput.vue b/client/components/forms/heavy/ImageInput.vueindex 60ae4980a..66d4681b5 100644--- a/client/components/forms/heavy/ImageInput.vue+++ b/client/components/forms/heavy/ImageInput.vue@@ -13,6 +13,7 @@class="cursor-pointer relative w-full":class="ui.button({ class: props.ui?.slots?.button })":style="inputStyle"+ :disabled="disabled ? true : null"@click.prevent="showUploadModal = true"><div@@ -40,6 +41,7 @@</div><slot name="left-action" /><a+ v-if="!disabled"href="#"class="text-neutral-500 hover:text-red-500 flex items-center"@click.stop.prevent="clearUrl"@@ -221,6 +223,7 @@ export default {methods: {clearUrl() {+ if (this.disabled) returnthis.compVal = null},onUploadDragoverEvent() {@@ -239,25 +242,30 @@ export default {this.droppedFiles(e.clipboardData.files)},selectUnsplashImage(imageUrl) {+ if (this.disabled) returnthis.compVal = imageUrlthis.showUploadModal = false},insertUrl() {+ if (this.disabled) returnif (!this.urlInput || !/^https?:\/\/[^\s$.?#].[^\s]*$/i.test(this.urlInput)) returnthis.compVal = this.urlInputthis.urlInput = ''this.showUploadModal = false},droppedFiles(droppedFiles) {+ if (this.disabled) returnif (!droppedFiles) returnthis.file = droppedFiles[0]this.uploadFileToServer()},openFileUpload() {+ if (this.disabled) returnthis.$refs["actual-input"].click()},manualFileUpload(e) {+ if (this.disabled) returnthis.file = e.target.files[0]this.uploadFileToServer()},diff --git a/client/components/open/integrations/EmailIntegration.vue b/client/components/open/integrations/EmailIntegration.vueindex cde868259..927475ffb 100644--- a/client/components/open/integrations/EmailIntegration.vue+++ b/client/components/open/integrations/EmailIntegration.vue@@ -64,6 +64,7 @@<rich-text-area-input:form="integrationData":enable-mentions="true"+ :enable-image="true":mentions="form.properties"name="data.email_content"label="Email Content"@@ -71,10 +72,10 @@/><collapsev-model="showEmailAppearance"- class="mt-4 w-full border rounded-lg bg-gray-50 dark:bg-neutral-900"+ class="mt-4 w-full border rounded-lg bg-gray-50 dark:bg-neutral-900 pr-4"><template #title>- <div class="flex gap-x-3 items-start pr-8 p-4">+ <div class="flex gap-x-3 items-start pr-12 p-4"><divclass="transition-colors":class="{@@ -99,11 +100,24 @@</div></template><div class="border-t dark:border-neutral-700 p-4 space-y-4">- <TextInput+ <div+ v-if="emailAppearanceLocked"+ class="rounded-lg border border-blue-200 bg-blue-50 px-4 py-3 text-sm text-blue-900 dark:border-blue-900/60 dark:bg-blue-950/40 dark:text-blue-100"+ >+ Email appearance customisation is part of the Pro plan.+ <a+ class="underline cursor-pointer"+ @click="openSubscriptionModal"+ >+ Upgrade to Pro+ </a>+ to add your logo, custom fonts and colors.+ </div>+ <image-input:form="integrationData"+ :disabled="emailAppearanceLocked"name="data.logo_url"- label="Logo URL"- placeholder="https://example.com/logo.png"+ label="Logo"help="Display your logo in the email header (replaces app name)"/><div class="grid grid-cols-2 gap-4 mt-4">@@ -114,6 +128,7 @@blocksize="lg"variant="outline"+ :disabled="emailAppearanceLocked"@click="showGoogleFontPicker = true"><span :style="{ 'font-family': (integrationData.data.font_family ? integrationData.data.font_family + ', sans-serif' : null) }">@@ -129,6 +144,7 @@</div><ColorInput:form="integrationData"+ :disabled="emailAppearanceLocked"name="data.font_color"label="Font color"help="Color of the text in the email"@@ -137,12 +153,14 @@<div class="grid grid-cols-2 gap-4"><ColorInput:form="integrationData"+ :disabled="emailAppearanceLocked"name="data.outer_background_color"label="Outer background color"help="Background around the email content area"/><ColorInput:form="integrationData"+ :disabled="emailAppearanceLocked"name="data.inner_background_color"label="Inner background color"help="Background of the email content area"@@ -203,6 +221,7 @@ const { data: user } = useAuth().user()const showEmailAppearance = ref(false)const showGoogleFontPicker = ref(false)+const emailAppearanceLocked = computed(() => !props.form.is_pro)function onApplyFont(val) {if (props.integrationData.data) {diff --git a/client/components/pages/auth/components/QuickRegister.vue b/client/components/pages/auth/components/QuickRegister.vueindex e2c25390e..a5e96a5b6 100644--- a/client/components/pages/auth/components/QuickRegister.vue+++ b/client/components/pages/auth/components/QuickRegister.vue@@ -69,6 +69,11 @@ import LoginForm from "./LoginForm.vue"import RegisterForm from "./RegisterForm.vue"import { WindowMessageTypes } from "~/composables/useWindowMessage"+const AUTH_COOKIE_NAME = "opnform_token"+const LEGACY_AUTH_COOKIE_NAME = "token"+const ADMIN_AUTH_COOKIE_NAME = "opnform_admin_token"+const LEGACY_ADMIN_AUTH_COOKIE_NAME = "admin_token"+const appStore = useAppStore()// Define emits for component interactions@@ -115,8 +120,8 @@ onUnmounted(() => {const handleSocialLogin = () => {// This function is only called for social logins, so we refresh tokensconst authStore = useAuthStore()- const tokenValue = useCookie("token").value- const adminTokenValue = useCookie("admin_token").value+ const tokenValue = useCookie(AUTH_COOKIE_NAME).value ?? useCookie(LEGACY_AUTH_COOKIE_NAME).value+ const adminTokenValue = useCookie(ADMIN_AUTH_COOKIE_NAME).value ?? useCookie(LEGACY_ADMIN_AUTH_COOKIE_NAME).value// Re-initialize the store with the latest tokens from cookiesauthStore.initStore(tokenValue, adminTokenValue)diff --git a/client/composables/useOpnApi.js b/client/composables/useOpnApi.jsindex 72a00ad75..eb30c0597 100644--- a/client/composables/useOpnApi.js+++ b/client/composables/useOpnApi.js@@ -61,10 +61,12 @@ export function getOpnRequestsOptions(request, opts) {async onResponseError({ response }) {const { status } = responseif (status === 401) {- // Always handle 401 errors with token expiry flow- // This covers both cases: token expired AND no token present- const { handleTokenExpiry } = useAuthFlow()- await handleTokenExpiry()+ // Do not run token-expiry UX during SSR. Server-side bootstrap requests can+ // fail for context-specific reasons and should be retried client-side first.+ if (import.meta.client) {+ const { handleTokenExpiry } = useAuthFlow()+ await handleTokenExpiry()+ }} else if (status === 420) {// If invalid domain, redirect to main domainconsole.warn("Invalid response from back-end - redirecting to main domain")diff --git a/client/middleware/01.check-auth.global.js b/client/middleware/01.check-auth.global.jsindex 6bee5fe5d..e13b295f1 100644--- a/client/middleware/01.check-auth.global.js+++ b/client/middleware/01.check-auth.global.js@@ -1,14 +1,26 @@import { useQueryClient } from '@tanstack/vue-query'import { initServiceClients } from '~/composables/useAuthFlow'-export default defineNuxtRouteMiddleware(async () => {+const AUTH_COOKIE_NAME = 'opnform_token'+const LEGACY_AUTH_COOKIE_NAME = 'token'+const ADMIN_AUTH_COOKIE_NAME = 'opnform_admin_token'+const LEGACY_ADMIN_AUTH_COOKIE_NAME = 'admin_token'++export default defineNuxtRouteMiddleware(async (_to, _from) => {const authStore = useAuthStore()const queryClient = useQueryClient()+ const tokenCookie = useCookie(AUTH_COOKIE_NAME)+ const legacyTokenCookie = useCookie(LEGACY_AUTH_COOKIE_NAME)+ const adminTokenCookie = useCookie(ADMIN_AUTH_COOKIE_NAME)+ const legacyAdminTokenCookie = useCookie(LEGACY_ADMIN_AUTH_COOKIE_NAME)+ const resolvedToken = tokenCookie.value ?? legacyTokenCookie.value+ const resolvedAdminToken = adminTokenCookie.value ?? legacyAdminTokenCookie.value- // Initialize tokens from cookies first+ // Hydrate missing tokens from cookies without overwriting a fresh in-memory+ // token during the same client-side navigation cycle.authStore.initStore(- useCookie('token').value,- useCookie('admin_token').value,+ resolvedToken,+ resolvedAdminToken,)// If no token, nothing to do@@ -28,10 +40,15 @@ export default defineNuxtRouteMiddleware(async () => {userData = queryClient.getQueryData(['user'])} catch (error) {- // On 401, clear auth state+ // A server-side bootstrap request can 401 even when the browser still has a+ // valid token (for example if SSR auth validation differs from the browser+ // request context). Do not destroy auth state during SSR; let the client+ // retry before treating it as a real logout.if (error?.status === 401) {- authStore.clearToken()- queryClient.clear()+ if (import.meta.client) {+ authStore.clearToken()+ queryClient.clear()+ }}return}diff --git a/client/stores/auth.js b/client/stores/auth.jsindex 6488def26..b1be15c52 100644--- a/client/stores/auth.js+++ b/client/stores/auth.js@@ -2,6 +2,11 @@ import { defineStore } from "pinia"import { authApi } from "~/api"import { initServiceClients } from '~/composables/useAuthFlow'+const AUTH_COOKIE_NAME = "opnform_token"+const LEGACY_AUTH_COOKIE_NAME = "token"+const ADMIN_AUTH_COOKIE_NAME = "opnform_admin_token"+const LEGACY_ADMIN_AUTH_COOKIE_NAME = "admin_token"+export const useAuthStore = defineStore("auth", {state: () => {return {@@ -38,12 +43,12 @@ export const useAuthStore = defineStore("auth", {cookieOptions.maxAge = expiresIn}- this.setCookie("token", token, cookieOptions)+ this.setCookie(AUTH_COOKIE_NAME, token, cookieOptions)this.token = token},setAdminToken(token) {- this.setCookie("admin_token", token)+ this.setCookie(ADMIN_AUTH_COOKIE_NAME, token)this.admin_token = token},@@ -52,6 +57,7 @@ export const useAuthStore = defineStore("auth", {const secureDefault = (typeof window !== 'undefined') ? window.location.protocol === 'https:' : trueconst embedded = typeof window !== 'undefined' && window.top !== window.selfconst safeOptions = {+ path: options.path ?? '/',sameSite: options.sameSite ?? (embedded ? 'none' : 'lax'),secure: options.secure ?? (embedded ? true : secureDefault),...options,@@ -61,8 +67,15 @@ export const useAuthStore = defineStore("auth", {},initStore(token, adminToken) {- this.token = token- this.admin_token = adminToken+ // Prefer explicit values from cookies, but do not clobber a live in-memory+ // token during client-side navigation when cookie reactivity lags behind.+ if (token !== undefined) {+ this.token = token ?? this.token+ }++ if (adminToken !== undefined) {+ this.admin_token = adminToken ?? this.admin_token+ }},setUser(user) {@@ -90,13 +103,16 @@ export const useAuthStore = defineStore("auth", {},clearToken(){- this.setCookie("token", null, { maxAge: 0 })+ this.setCookie(AUTH_COOKIE_NAME, null, { maxAge: 0 })+ this.setCookie(LEGACY_AUTH_COOKIE_NAME, null, { maxAge: 0 })this.token = null},clearTokens(){this.clearToken()- this.setAdminToken(null)+ this.setCookie(ADMIN_AUTH_COOKIE_NAME, null, { maxAge: 0 })+ this.setCookie(LEGACY_ADMIN_AUTH_COOKIE_NAME, null, { maxAge: 0 })+ this.admin_token = null},},})