diff --git a/src/components/Dashboard/common/WizardView.jsx b/src/components/Dashboard/common/WizardView.jsx index 31fe6c7..4367911 100644 --- a/src/components/Dashboard/common/WizardView.jsx +++ b/src/components/Dashboard/common/WizardView.jsx @@ -9,13 +9,15 @@ import { Divider, Progress, Button, - Dropdown + Dropdown, + Timeline } from 'antd' import NewObjectButtons from './NewObjectButtons' const { Title } = Typography const WizardView = ({ + sizeBarWidth = '160px', showSteps = true, steps, title = 'Wizard View', @@ -27,22 +29,76 @@ const WizardView = ({ progress = 0, actions = [], sideBarGrow = false, - disabled = false + disabled = false, + showButtons = true, + showTitle = true, + currentStep: controlledCurrentStep, + currentSubStep = 0, + onStepChange, + showSkipButton = false, + onSkip = () => {} }) => { - const [currentStep, setCurrentStep] = useState(0) + const [internalCurrentStep, setInternalCurrentStep] = useState(0) + const currentStep = controlledCurrentStep ?? internalCurrentStep const isMobile = useMediaQuery({ maxWidth: 768 }) + const setCurrentStep = (step) => { + if (controlledCurrentStep === undefined) { + setInternalCurrentStep(step) + } + onStepChange?.(step) + } + return ( {!isMobile && showSteps == true ? ( sideBar != null ? ( sideBar ) : ( -
+
({ + items={steps.map(({ subSteps, ...step }, index) => ({ ...step, + description: subSteps ? ( + { + const complete = + index < currentStep || + (index === currentStep && subStepIndex < currentSubStep) + const current = + index === currentStep && subStepIndex === currentSubStep + + const disabled = index < currentStep + return { + ...subStep, + children: subStep.title, + dot: complete ? ( +
+ +
+ ) : undefined, + color: complete ? 'blue' : current ? 'blue' : 'gray' + } + })} + /> + ) : ( + step.description + ), icon: index < currentStep ? (
@@ -76,62 +132,83 @@ const WizardView = ({ } > - - {title} - + {showTitle ? ( + + {title} + + ) : null}
{steps[currentStep].content}
- - {progress > 0 ? ( - - ) : null} - {(actions || []).map((action) => { - if (action.steps.includes(steps[currentStep].key)) { - if (action.children) { - return ( - + {showButtons || progress > 0 || actions.length > 0 ? ( + + {showSkipButton && showButtons && ( + + )} + + + {progress > 0 ? ( + + ) : null} + {(actions || []).map((action) => { + if (action.steps.includes(steps[currentStep].key)) { + if (action.children) { + return ( + + + + ) + } + return ( - - ) - } - return ( - - ) - } - return null - })} + ) + } + return null + })} - setCurrentStep((prev) => prev - 1)} - onNext={() => setCurrentStep((prev) => prev + 1)} - onSubmit={onSubmit} - formValid={formValid} - submitLoading={loading} - submitText={submitText} - /> - + {showButtons && ( + setCurrentStep(currentStep - 1)} + onNext={() => setCurrentStep(currentStep + 1)} + onSubmit={onSubmit} + formValid={formValid} + submitLoading={loading} + submitText={submitText} + /> + )} + + + ) : null} ) @@ -149,7 +226,15 @@ WizardView.propTypes = { submitText: PropTypes.string, progress: PropTypes.number, actions: PropTypes.array, - sideBarGrow: PropTypes.bool + sideBarGrow: PropTypes.bool, + showButtons: PropTypes.bool, + showTitle: PropTypes.bool, + currentStep: PropTypes.number, + currentSubStep: PropTypes.number, + onStepChange: PropTypes.func, + showSkipButton: PropTypes.bool, + onSkip: PropTypes.func, + sizeBarWidth: PropTypes.string } export default WizardView