From 917288f8e739ee3347026671bca62319df5b313a Mon Sep 17 00:00:00 2001 From: Temi Akinsoto Date: Mon, 25 Nov 2024 09:51:38 +0000 Subject: [PATCH 01/31] add mocked data for new fields --- .../cms/pages/fixtures/page/feedback.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts b/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts index 90194b34..916feb61 100644 --- a/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts +++ b/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts @@ -82,6 +82,32 @@ export const feedbackMock: PageResponse = { choices: '', default_value: '', }, + { + id: 5, + meta: { + type: 'forms.FormField', + }, + clean_name: 'what_would_you_like_to_see_on_the_dashboard_in_the_future', + label: 'Select all the options you would you like to see on the dashboard in the future?', + field_type: 'checkboxes', + help_text: 'Select all that apply', + required: false, + choices: '', + default_value: 'Improve\r\nModify', + }, + { + id: 6, + meta: { + type: 'forms.FormField', + }, + clean_name: 'what_would_you_like_to_see_on_the_dashboard_in_the_future', + label: 'Choose some options you would like to see on the dashboard in the future?', + field_type: 'dropdown', + help_text: '', + required: false, + choices: 'Option One\r\nOption Two', + default_value: '', + }, ], confirmation_slug: 'confirmation', confirmation_panel_title: 'Form submitted', From 70f5af419ca705f5cc76930124b96d1146b322bd Mon Sep 17 00:00:00 2001 From: Temi Akinsoto Date: Mon, 25 Nov 2024 11:39:17 +0000 Subject: [PATCH 02/31] add mock data for number field --- .../handlers/cms/pages/fixtures/page/feedback.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts b/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts index 916feb61..7b030030 100644 --- a/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts +++ b/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts @@ -108,6 +108,19 @@ export const feedbackMock: PageResponse = { choices: 'Option One\r\nOption Two', default_value: '', }, + { + id: 7, + meta: { + type: 'forms.FormField', + }, + clean_name: 'enter-any-number', + label: 'Enter any number', + field_type: 'number', + help_text: '', + required: false, + choices: '', + default_value: '', + }, ], confirmation_slug: 'confirmation', confirmation_panel_title: 'Form submitted', From d6f5cc33db7844417cc8a65ab7a6d2c55e877b82 Mon Sep 17 00:00:00 2001 From: Temi Akinsoto Date: Mon, 25 Nov 2024 12:05:15 +0000 Subject: [PATCH 03/31] add mock data for field type --- .../handlers/cms/pages/fixtures/page/feedback.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts b/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts index 7b030030..916feb61 100644 --- a/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts +++ b/src/mock-server/handlers/cms/pages/fixtures/page/feedback.ts @@ -108,19 +108,6 @@ export const feedbackMock: PageResponse = { choices: 'Option One\r\nOption Two', default_value: '', }, - { - id: 7, - meta: { - type: 'forms.FormField', - }, - clean_name: 'enter-any-number', - label: 'Enter any number', - field_type: 'number', - help_text: '', - required: false, - choices: '', - default_value: '', - }, ], confirmation_slug: 'confirmation', confirmation_panel_title: 'Form submitted', From e8d1935ed06c524275e5d629998f0a8864fc8436 Mon Sep 17 00:00:00 2001 From: Temi Akinsoto Date: Mon, 25 Nov 2024 12:20:20 +0000 Subject: [PATCH 04/31] no unused vars --- src/app/components/cms/Feedback/EmailField.tsx | 18 ++++++++++++++++++ src/app/components/cms/Feedback/Feedback.tsx | 16 +++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 src/app/components/cms/Feedback/EmailField.tsx diff --git a/src/app/components/cms/Feedback/EmailField.tsx b/src/app/components/cms/Feedback/EmailField.tsx new file mode 100644 index 00000000..5e88bc66 --- /dev/null +++ b/src/app/components/cms/Feedback/EmailField.tsx @@ -0,0 +1,18 @@ +'use client' + +import { Fieldtype } from './Feedback' + +export default function EmailField({ label, helpText, cleanName }: Fieldtype) { + return ( +
+

+ +

+ {helpText.length > 0 ?
{helpText}
: null} + + +
+ ) +} diff --git a/src/app/components/cms/Feedback/Feedback.tsx b/src/app/components/cms/Feedback/Feedback.tsx index 619fcaa8..08f5c2be 100644 --- a/src/app/components/cms/Feedback/Feedback.tsx +++ b/src/app/components/cms/Feedback/Feedback.tsx @@ -6,6 +6,7 @@ import { useFormState } from 'react-dom' import { z } from 'zod' import { FormField } from '@/api/models/cms/Page/FormFields' +import EmailField from '@/app/components/cms/Feedback/EmailField' import { handler } from '../utils/handler' @@ -14,6 +15,14 @@ const initialState = { errors: {}, } +export interface Fieldtype { + label: string + helpText: string + cleanName: string + choices?: string + defaultValue?: string +} + interface FeedbackProps { formFields: { id: number @@ -44,7 +53,7 @@ export default function Feedback({ formFields }: FeedbackProps) {
{formFields.map(renderFormFields)} - + {state.message}
)} + + {fieldType === 'email' && } ) } From aa4dfb8ac32df410ca311c6ff0f011bd65481059 Mon Sep 17 00:00:00 2001 From: Temi Akinsoto Date: Mon, 25 Nov 2024 12:45:18 +0000 Subject: [PATCH 05/31] add Checkboxes form field --- .../cms/Feedback/CheckboxesField.tsx | 42 +++++++++++++++++++ src/app/components/cms/Feedback/Feedback.tsx | 12 ++++-- 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/app/components/cms/Feedback/CheckboxesField.tsx diff --git a/src/app/components/cms/Feedback/CheckboxesField.tsx b/src/app/components/cms/Feedback/CheckboxesField.tsx new file mode 100644 index 00000000..644a33d3 --- /dev/null +++ b/src/app/components/cms/Feedback/CheckboxesField.tsx @@ -0,0 +1,42 @@ +import { Fieldtype } from './Feedback' + +export default function CheckboxesField({ label, helpText, cleanName, defaultValue = '' }: Fieldtype) { + const defaultValuesList = defaultValue.includes('\r\n') ? defaultValue.split('\r\n') : defaultValue.split(',') + const trimmedValuesList = defaultValuesList.map((value) => value.trim()) + + return ( +
+
+ +

+ +

+
+ + {helpText.length > 0 ?
{helpText}
: null} + +
+ {trimmedValuesList.map((defaultVal, key) => { + const uniqueId = `${cleanName}-${key}` // Generate a unique ID for each checkbox + return ( +
+ + +
+ ) + })} +
+
+
+ ) +} diff --git a/src/app/components/cms/Feedback/Feedback.tsx b/src/app/components/cms/Feedback/Feedback.tsx index 08f5c2be..acb67b96 100644 --- a/src/app/components/cms/Feedback/Feedback.tsx +++ b/src/app/components/cms/Feedback/Feedback.tsx @@ -6,9 +6,10 @@ import { useFormState } from 'react-dom' import { z } from 'zod' import { FormField } from '@/api/models/cms/Page/FormFields' -import EmailField from '@/app/components/cms/Feedback/EmailField' import { handler } from '../utils/handler' +import CheckboxesField from './CheckboxesField' +import EmailField from './EmailField' const initialState = { message: '', @@ -53,7 +54,7 @@ export default function Feedback({ formFields }: FeedbackProps) {
{formFields.map(renderFormFields)} - {state.message} +