Server IP : 192.158.238.246 / Your IP : 3.133.59.209 Web Server : LiteSpeed System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64 User : jenniferflocom ( 1321) PHP Version : 8.1.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/7779/cwd/plugins/give/src/DonationForms/resources/app/form/MultiStepForm/store/ |
Upload File : |
import {MultiStepFormContextState} from '@givewp/forms/app/form/MultiStepForm/store/index'; import {visibliityConditionsPass} from '@givewp/forms/app/hooks/useVisibilityCondition'; const SET_CURRENT_STEP = 'set_current_step'; const SET_NEXT_STEP = 'set_next_step'; type Action<T> = {type: typeof SET_CURRENT_STEP; step: T} | {type: typeof SET_NEXT_STEP; formValues: T}; /** * @since 3.0.0 */ export default function reducer<T>(state: MultiStepFormContextState, action: Action<T>) { switch (action.type) { case SET_CURRENT_STEP: return { ...state, currentStep: action.step, }; case SET_NEXT_STEP: const visibleSteps = state.steps.map((step) => { const isVisible = step.visibilityConditions.length ? visibliityConditionsPass(step.visibilityConditions, new Map(Object.entries(action.formValues))) : true; return { ...step, isVisible, }; }); return { ...state, steps: visibleSteps, currentStep: visibleSteps.findIndex((step, index) => step.isVisible && index > state.currentStep), }; default: return state; } } /** * @since 3.0.0 */ export function setCurrentStep(step: number) { return { type: SET_CURRENT_STEP, step, }; } export function setNextStep(formValues) { return { type: SET_NEXT_STEP, formValues, }; }