Skip to content

Commit 3f48106

Browse files
feat: Add custom CSS to response form for HITL nodes (#15807)
Co-authored-by: RomanDavydchuk <[email protected]>
1 parent 8a1cabe commit 3f48106

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/nodes-base/utils/sendAndWait/test/util.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ describe('Send and Wait utils tests', () => {
303303
responseFormTitle: 'Test title',
304304
responseFormDescription: 'Test description',
305305
responseFormButtonLabel: 'Test button',
306+
responseFormCustomCss: 'body { background-color: red; }',
306307
},
307308
};
308309
return params[parameterName];
@@ -334,6 +335,7 @@ describe('Send and Wait utils tests', () => {
334335
],
335336
appendAttribution: true,
336337
buttonLabel: 'Test button',
338+
dangerousCustomCss: 'body { background-color: red; }',
337339
});
338340
});
339341

packages/nodes-base/utils/sendAndWait/utils.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
createEmailBodyWithoutN8nAttribution,
2323
} from './email-templates';
2424
import type { IEmail } from './interfaces';
25+
import { cssVariables } from '../../nodes/Form/cssVariables';
2526
import { formFieldsProperties } from '../../nodes/Form/Form.node';
2627
import { prepareFormData, prepareFormReturnItem, resolveRawData } from '../../nodes/Form/utils';
2728
import { escapeHtml } from '../utilities';
@@ -39,6 +40,7 @@ type FormResponseTypeOptions = {
3940
responseFormTitle?: string;
4041
responseFormDescription?: string;
4142
responseFormButtonLabel?: string;
43+
responseFormCustomCss?: string;
4244
};
4345

4446
const INPUT_FIELD_IDENTIFIER = 'field-0';
@@ -283,6 +285,17 @@ export function getSendAndWaitProperties(
283285
type: 'string',
284286
default: 'Submit',
285287
},
288+
{
289+
displayName: 'Response Form Custom Styling',
290+
name: 'responseFormCustomCss',
291+
type: 'string',
292+
typeOptions: {
293+
rows: 10,
294+
editor: 'cssEditor',
295+
},
296+
default: cssVariables.trim(),
297+
description: 'Override default styling of the response form with CSS',
298+
},
286299
limitWaitTimeOption,
287300
appendAttributionOption,
288301
],
@@ -331,6 +344,7 @@ const getFormResponseCustomizations = (context: IWebhookFunctions) => {
331344
formTitle,
332345
formDescription,
333346
buttonLabel,
347+
customCss: options.responseFormCustomCss,
334348
};
335349
};
336350

@@ -351,7 +365,8 @@ export async function sendAndWaitWebhook(this: IWebhookFunctions) {
351365

352366
if (responseType === 'freeText') {
353367
if (method === 'GET') {
354-
const { formTitle, formDescription, buttonLabel } = getFormResponseCustomizations(this);
368+
const { formTitle, formDescription, buttonLabel, customCss } =
369+
getFormResponseCustomizations(this);
355370

356371
const data = prepareFormData({
357372
formTitle,
@@ -369,6 +384,7 @@ export async function sendAndWaitWebhook(this: IWebhookFunctions) {
369384
],
370385
testRun: false,
371386
query: {},
387+
customCss,
372388
});
373389

374390
res.render('form-trigger', data);
@@ -408,7 +424,8 @@ export async function sendAndWaitWebhook(this: IWebhookFunctions) {
408424
}
409425

410426
if (method === 'GET') {
411-
const { formTitle, formDescription, buttonLabel } = getFormResponseCustomizations(this);
427+
const { formTitle, formDescription, buttonLabel, customCss } =
428+
getFormResponseCustomizations(this);
412429

413430
const data = prepareFormData({
414431
formTitle,
@@ -420,6 +437,7 @@ export async function sendAndWaitWebhook(this: IWebhookFunctions) {
420437
formFields: fields,
421438
testRun: false,
422439
query: {},
440+
customCss,
423441
});
424442

425443
res.render('form-trigger', data);

0 commit comments

Comments
 (0)