PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / DonationForms / resources / app / form / MultiStepForm / index.tsx

index.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/DonationForms/resources/app/form/MultiStepForm/index.tsx

84 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import type {Form} from '@givewp/forms/types';
2 import {Section} from '@givewp/forms/types';
3 import {DonationFormMultiStepStateProvider} from './store';
4 import {StepObject} from '@givewp/forms/app/form/MultiStepForm/types';
5 import StepForm from '@givewp/forms/app/form/MultiStepForm/components/StepForm';
6 import getSectionFieldNames from '@givewp/forms/app/form/MultiStepForm/utilities/getSectionFieldNames';
7 import DonationFormErrorBoundary from '@givewp/forms/app/errors/boundaries/DonationFormErrorBoundary';
8 import {withTemplateWrapper} from '@givewp/forms/app/templates';
9 import SectionNode from '@givewp/forms/app/fields/SectionNode';
10 import Steps from '@givewp/forms/app/form/MultiStepForm/components/Steps';
11 import HeaderStep from '@givewp/forms/app/form/MultiStepForm/components/HeaderStep';
12 import {DonationSummaryProvider} from '@givewp/forms/app/store/donation-summary';
13
14 const FormSectionTemplate = withTemplateWrapper(window.givewp.form.templates.layouts.section, 'section');
15
16 /**
17 * @since 3.0.0
18 */
19 const convertSectionsToSteps = (sections: Section[], hasFirstStep: boolean) => {
20 const totalSteps = hasFirstStep ? sections.length + 1 : sections.length;
21
22 return sections.map((section, index) => {
23 const currentStep = hasFirstStep ? index + 1 : index;
24 const isFirstStep = currentStep === 0;
25 const isLastStep = currentStep === totalSteps - 1;
26 const fields = getSectionFieldNames(section);
27 const title = section?.label;
28 const description = section?.description;
29
30 const element = (
31 <StepForm key={currentStep} currentStep={currentStep} isFirstStep={isFirstStep} isLastStep={isLastStep}>
32 <DonationFormErrorBoundary key={section.name}>
33 <FormSectionTemplate key={section.name} section={section} hideLabel>
34 {section.nodes.map((node) => (
35 <DonationFormErrorBoundary key={node.name}>
36 <SectionNode key={node.name} node={node} />
37 </DonationFormErrorBoundary>
38 ))}
39 </FormSectionTemplate>
40 </DonationFormErrorBoundary>
41 </StepForm>
42 );
43
44 return {
45 id: currentStep,
46 title,
47 description,
48 element,
49 fields,
50 visibilityConditions: section.visibilityConditions,
51 isVisible: !section.visibilityConditions.length,
52 } as StepObject;
53 });
54 };
55
56 /**
57 * @since 3.6.0 updated to use includeHeaderInMultiStep
58 * @since 3.0.0
59 */
60 export default function MultiStepForm({form}: {form: Form}) {
61 const shouldIncludeHeaderInSteps = form.design?.includeHeaderInMultiStep && form.settings?.showHeader;
62 const steps = convertSectionsToSteps(form.nodes, shouldIncludeHeaderInSteps);
63
64 if (shouldIncludeHeaderInSteps) {
65 steps.unshift({
66 id: 0,
67 title: null,
68 description: null,
69 element: <HeaderStep form={form} />,
70 fields: [],
71 visibilityConditions: [],
72 isVisible: true,
73 });
74 }
75
76 return (
77 <DonationFormMultiStepStateProvider initialState={{steps, currentStep: 0}}>
78 <DonationSummaryProvider>
79 <Steps steps={steps} />
80 </DonationSummaryProvider>
81 </DonationFormMultiStepStateProvider>
82 );
83 }
84