1- // Conservamos tu estructura original con tu animación y componentes
2- import React , { useState , useContext , useEffect } from "react" ;
1+ import React , { useState , useContext , useEffect , useCallback } from "react" ;
32import { motion , AnimatePresence } from "framer-motion" ;
43import { useNavigate } from "react-router" ;
54import { AuthContext } from "../../context/authContext" ;
@@ -68,6 +67,12 @@ export const Onboarding = () => {
6867
6968 const steps = stepConfigs [ role ] || [ ] ;
7069 const currentStep = steps [ currentStepIndex ] ;
70+ // Al principio, justo después de `const steps = stepConfigs[role] || [];`
71+ const visibleSteps = steps . filter ( ( step ) => step . id !== "complete" ) ;
72+ const displayedStepIndex = Math . min (
73+ currentStepIndex ,
74+ visibleSteps . length - 1
75+ ) ;
7176
7277 useEffect ( ( ) => {
7378 if ( profile ?. hasCompletedOnboarding ) {
@@ -88,15 +93,24 @@ export const Onboarding = () => {
8893 }
8994 } , [ profile , navigate ] ) ;
9095
91- const handleStepDataChange = ( stepId , data ) => {
92- setFormData ( ( prev ) => ( {
93- ...prev ,
94- [ stepId ] : {
95- ...prev [ stepId ] ,
96- ...data ,
97- } ,
98- } ) ) ;
99- } ;
96+ const handleStepDataChange = useCallback ( ( stepId , data ) => {
97+ setFormData ( ( prev ) => {
98+ const currentStepData = prev [ stepId ] ;
99+ const mergedData = { ...currentStepData , ...data } ;
100+
101+ if (
102+ stepId === "roletype2" &&
103+ JSON . stringify ( currentStepData ) === JSON . stringify ( mergedData )
104+ ) {
105+ return prev ;
106+ }
107+
108+ return {
109+ ...prev ,
110+ [ stepId ] : mergedData ,
111+ } ;
112+ } ) ;
113+ } , [ ] ) ;
100114
101115 const handleStart = ( ) => {
102116 setShowStarting ( false ) ;
@@ -201,43 +215,46 @@ export const Onboarding = () => {
201215 animate = { { opacity : 1 , x : 0 } }
202216 exit = { { opacity : 0 , x : 50 } }
203217 transition = { { duration : 0.5 } }
204- className = "flex justify-between items-center px-20 pt-12"
218+ className = "flex justify-between items-center px-4 pt-6 sm:px- 20 sm: pt-12"
205219 >
206- < div className = "flex items-center justify-between w-full" >
207- < h2
208- className = { `${ colorSet . text } text-lg font-medium whitespace-nowrap` }
209- >
210- { currentStep . title }
211- </ h2 >
212- < div className = "flex items-center gap-4 flex-1 max-w-md min-w-0 justify-end" >
213- < nav
214- aria-label = "Steps"
215- className = "flex flex-1 h-1 items-center gap-[18px] min-w-0"
216- >
217- { steps . map ( ( step , index ) => (
218- < div
219- key = { step . id }
220- className = { `flex-1 h-full rounded transition-colors duration-300 ${
221- index < currentStepIndex
222- ? colorSet . stepActive
223- : index === currentStepIndex
224- ? colorSet . stepper
225- : "bg-neutral-55"
226- } `}
227- />
228- ) ) }
229- </ nav >
230- < div
220+ < div className = "flex items-center justify-between w-full gap-8" >
221+ { currentStep . id !== "complete" && (
222+ < h2
231223 className = { `${ colorSet . text } text-lg font-medium whitespace-nowrap` }
232224 >
233- { currentStep . id !== "complete" &&
234- `${ currentStepIndex + 1 } / ${ steps . length } ` }
225+ { currentStep . title }
226+ </ h2 >
227+ ) } { " " }
228+ { currentStep . id !== "complete" && (
229+ < div className = "flex items-center gap-4 flex-1 max-w-md min-w-0 justify-end" >
230+ < nav
231+ aria-label = "Steps"
232+ className = "flex flex-1 h-1 items-center gap-[18px] min-w-0"
233+ >
234+ { visibleSteps . map ( ( step , index ) => (
235+ < div
236+ key = { step . id }
237+ className = { `flex-1 h-full rounded transition-colors duration-300 ${
238+ index < displayedStepIndex
239+ ? colorSet . stepActive
240+ : index === displayedStepIndex
241+ ? colorSet . stepper
242+ : "bg-neutral-55"
243+ } `}
244+ />
245+ ) ) }
246+ </ nav >
247+ < div
248+ className = { `${ colorSet . text } text-lg font-medium whitespace-nowrap` }
249+ >
250+ { `${ displayedStepIndex + 1 } / ${ visibleSteps . length } ` }
251+ </ div >
235252 </ div >
236- </ div >
253+ ) }
237254 </ div >
238255 </ motion . div >
239256
240- < div className = "relative h-full" >
257+ < div className = "relative flex-1 flex flex-col h-full" >
241258 < AnimatePresence mode = "wait" >
242259 < motion . div
243260 key = { currentStep . id }
@@ -246,14 +263,14 @@ export const Onboarding = () => {
246263 animate = "center"
247264 exit = "exit"
248265 transition = { { duration : 0.5 } }
249- className = "absolute inset-0 overflow-y-auto"
266+ className = "absolute inset-0 overflow-y-auto h-full flex flex-col "
250267 >
251268 { renderStepComponent ( ) }
252269 </ motion . div >
253270 </ AnimatePresence >
254271 </ div >
255272
256- < div className = "absolute bottom-6 right-5 w-full max-w-5xl flex justify-end gap-4 md: px-10 md :py-2" >
273+ < div className = "absolute bottom-6 right-0 w-full max-w-5xl flex justify-center gap-4 px-4 py-2 sm:justify-end sm:right-5 sm: px-10 sm :py-2" >
257274 { currentStepIndex < steps . length - 1 ? (
258275 < >
259276 { steps [ currentStepIndex ] . id === "userinfo1" ? (
@@ -285,7 +302,7 @@ export const Onboarding = () => {
285302 </ >
286303 ) : (
287304 < button
288- className = { `px-4 py-2 rounded ${ colorSet . bg } text-neutral-0 ${ colorSet . hoverBg } transition` }
305+ className = { `px-10 py-2 rounded ${ colorSet . bg } text-neutral-0 ${ colorSet . hoverBg } transition` }
289306 onClick = { handleSubmit }
290307 >
291308 Finish
0 commit comments