11import React , { useState , useEffect , useRef } from "react" ;
2- import { Button , Icon } from "webiny/admin/ui" ;
2+ import { Button , Icon , Separator , useDisclosure } from "webiny/admin/ui" ;
33import { ReactComponent as DeleteIcon } from "webiny/admin/icons/close.svg" ;
4+ import { ReactComponent as AddIcon } from "webiny/admin/icons/add.svg" ;
5+ import { ReactComponent as CheckIcon } from "webiny/admin/icons/check.svg" ;
6+ import { ReactComponent as ForkIcon } from "webiny/admin/icons/fork_right.svg" ;
47import {
58 useCreateElement ,
69 useDeleteElement ,
@@ -9,9 +12,8 @@ import {
912 Commands
1013} from "webiny/admin/website-builder/page/editor" ;
1114import { useContainer } from "../useContainer.js" ;
12-
13- const iconClasses =
14- "absolute z-10 rounded-full bg-neutral-dimmed border-solid border-sm border-neutral-muted cursor-pointer fill-neutral-strong" ;
15+ import { ConditionRulesDialog } from "../components/ConditionRulesDialog" ;
16+ import type { FunnelModelDto } from "../../models/FunnelModel" ;
1517
1618const iconPosition = {
1719 top : - 8 ,
@@ -25,6 +27,13 @@ export const Stepper = () => {
2527 const { deleteElement } = useDeleteElement ( ) ;
2628 const [ activeStepId , setActiveStepId ] = useState < string | null > ( null ) ;
2729
30+ const {
31+ open : showConditionRulesDialog ,
32+ close : hideConditionRulesDialog ,
33+ isOpen : isConditionRulesDialogOpen ,
34+ data : conditionRulesData
35+ } = useDisclosure < FunnelModelDto > ( ) ;
36+
2837 const steps = container ?. inputs . containerData ?. steps ?? [ ] ;
2938 const prevStepsRef = useRef ( steps ) ;
3039
@@ -91,6 +100,17 @@ export const Stepper = () => {
91100 deleteElement ( stepElementId ) ;
92101 } ;
93102
103+ const handleConditionalRulesClick = ( ) => {
104+ showConditionRulesDialog ( container . inputs . containerData ) ;
105+ } ;
106+
107+ const handleConditionalRulesSubmit = ( data : FunnelModelDto ) => {
108+ container . updateInputs ( current => {
109+ current . containerData = data ;
110+ } ) ;
111+ hideConditionRulesDialog ( ) ;
112+ } ;
113+
94114 const addStep = ( ) => {
95115 createElement ( {
96116 componentName : "Fub/Step" ,
@@ -101,41 +121,77 @@ export const Stepper = () => {
101121 } ;
102122
103123 return (
104- < div
105- className = { "flex flex-row p-sm bg-neutral-light justify-between" }
106- data-affects-preview = { "height" }
107- >
108- < div className = { "flex gap-md" } >
109- { steps . map ( ( step , index ) => {
110- const isFirstStep = index === 0 ;
111- const isLastStep = index === steps . length - 1 ;
112- const isSuccessStep = isLastStep ;
113- const canDelete = ! isFirstStep && ! isSuccessStep ;
114- const activeVariant = activeStepId === step . id ? "primary" : "secondary" ;
115- const elementId = slotSteps [ index ] ?. elementId ;
116-
117- return (
118- < div className = { "relative" } key = { step . id } >
119- < Button
120- variant = { activeVariant }
121- text = { step . title }
122- className = { "border-solid border-sm border-neutral-muted" }
123- onClick = { ( ) => activateStep ( step . id ) }
124- />
125- { canDelete && elementId ? (
126- < Icon
127- icon = { < DeleteIcon /> }
128- label = { "Delete step" }
129- style = { iconPosition }
130- onClick = { ( ) => deleteStep ( elementId ) }
131- className = { iconClasses }
124+ < >
125+ < div
126+ className = { "flex flex-row p-sm bg-neutral-light justify-between" }
127+ data-affects-preview = { "height" }
128+ >
129+ < div className = { "flex items-center gap-sm" } >
130+ < span className = { "uppercase font-semibold text-neutral-muted! text-sm " } >
131+ Pages
132+ </ span >
133+ { steps . map ( ( step , index ) => {
134+ const isFirstStep = index === 0 ;
135+ const isLastStep = index === steps . length - 1 ;
136+ const isSuccessStep = isLastStep ;
137+ const canDelete = ! isFirstStep && ! isSuccessStep ;
138+ const activeVariant = activeStepId === step . id ? "primary" : "secondary" ;
139+ const elementId = slotSteps [ index ] ?. elementId ;
140+
141+ return (
142+ < div className = { "flex items-center relative gap-sm" } key = { step . id } >
143+ < Button
144+ icon = { isSuccessStep && < CheckIcon /> }
145+ variant = { activeVariant }
146+ text = { step . title }
147+ onClick = { ( ) => activateStep ( step . id ) }
132148 />
133- ) : null }
134- </ div >
135- ) ;
136- } ) }
149+ { canDelete && elementId ? (
150+ < Icon
151+ icon = { < DeleteIcon /> }
152+ label = { "Delete step" }
153+ style = { iconPosition }
154+ onClick = { ( ) => deleteStep ( elementId ) }
155+ className = {
156+ "absolute z-10 rounded-full bg-neutral-dimmed border-solid border-sm border-neutral-muted cursor-pointer fill-neutral-strong h-md w-md"
157+ }
158+ />
159+ ) : null }
160+
161+ { isSuccessStep && (
162+ < div className = { "flex items-center gap-sm" } >
163+ < Separator
164+ variant = { "strong" }
165+ orientation = { "vertical" }
166+ className = { "h-lg" }
167+ />
168+ < Button
169+ icon = { < AddIcon /> }
170+ text = { "Add page" }
171+ variant = { "tertiary" }
172+ onClick = { addStep }
173+ />
174+ </ div >
175+ ) }
176+ </ div >
177+ ) ;
178+ } ) }
179+ </ div >
180+ < div className = { "flex gap-md" } >
181+ < Button
182+ variant = { "primary" }
183+ icon = { < ForkIcon /> }
184+ text = { "Conditional rules" }
185+ onClick = { handleConditionalRulesClick }
186+ />
187+ </ div >
137188 </ div >
138- < Button variant = { "primary" } text = { "+ Add step" } onClick = { addStep } />
139- </ div >
189+ < ConditionRulesDialog
190+ open = { isConditionRulesDialogOpen }
191+ data = { conditionRulesData ! }
192+ onClose = { hideConditionRulesDialog }
193+ onSubmit = { handleConditionalRulesSubmit }
194+ />
195+ </ >
140196 ) ;
141197} ;
0 commit comments