Skip to content

Commit 1858287

Browse files
committed
refactor: extract StepperBar to new component
1 parent 3fb243a commit 1858287

File tree

1 file changed

+42
-24
lines changed

1 file changed

+42
-24
lines changed

cards/02.advanced_version/RentalCars/src/app/extensions/CreateRental.jsx

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -234,30 +234,13 @@ const Extension = ({ context, runServerless, sendAlert, fetchProperties }) => {
234234

235235
return (
236236
<>
237-
<Flex
238-
direction={'row'}
239-
justify={'between'}
240-
>
241-
<StepIndicator
242-
currentStep={currentStep}
243-
stepNames={steps}
244-
variant={"default"}
245-
onClick={(step) => {
246-
//make sure that the step is valid before allowing the user to go to the next step
247-
if (step === 1) {
248-
if (selectedLocation && selectedLocation.id) {
249-
setCurrentStep(step);
250-
}
251-
else {
252-
sendAlert({ message: "Please select a location", type: "danger" });
253-
}
254-
}
255-
else {
256-
setCurrentStep(step);
257-
}
258-
}}
259-
/>
260-
Flex>
237+
<StepperBar
238+
currentStep={currentStep}
239+
setCurrentStep={setCurrentStep}
240+
selectedLocation={selectedLocation}
241+
sendAlert={sendAlert}
242+
steps={steps}
243+
/>
261244
<Divider />
262245
{currentStep === 0 && (
263246
<>
@@ -557,3 +540,38 @@ const Extension = ({ context, runServerless, sendAlert, fetchProperties }) => {
557540
>
558541
);
559542
};
543+
544+
const StepperBar = ({
545+
currentStep,
546+
setCurrentStep,
547+
selectedLocation,
548+
sendAlert,
549+
steps
550+
}) => {
551+
return(
552+
<Flex
553+
direction={'row'}
554+
justify={'between'}
555+
>
556+
<StepIndicator
557+
currentStep={currentStep}
558+
stepNames={steps}
559+
variant={"default"}
560+
onClick={(step) => {
561+
//make sure that the step is valid before allowing the user to go to the next step
562+
if (step === 1) {
563+
if (selectedLocation && selectedLocation.id) {
564+
setCurrentStep(step);
565+
}
566+
else {
567+
sendAlert({ message: "Please select a location", type: "danger" });
568+
}
569+
}
570+
else {
571+
setCurrentStep(step);
572+
}
573+
}}
574+
/>
575+
Flex>
576+
);
577+
};

0 commit comments

Comments
 (0)