11import  React  from  'react' ; 
2- import  {   
3-   Box ,   
4-   Typography ,   
5-   Button ,   
2+ import  { 
3+   Box , 
4+   Typography , 
5+   Button , 
66  IconButton , 
77  Divider , 
88  useTheme 
99}  from  '@mui/material' ; 
1010import  {  ArrowBack  }  from  '@mui/icons-material' ; 
1111import  {  useNavigate ,  useLocation  }  from  'react-router-dom' ; 
12+ import  {  useTranslation  }  from  'react-i18next' ; 
1213
1314interface  RobotConfigPageProps  { 
1415  title : string ; 
@@ -23,57 +24,80 @@ interface RobotConfigPageProps {
2324  icon ?: React . ReactNode ; 
2425  onBackToSelection ?: ( )  =>  void ; 
2526  backToSelectionText ?: string ; 
27+   onArrowBack ?: ( )  =>  void ;  // Optional prop for custom back action 
2628} 
2729
2830export  const  RobotConfigPage : React . FC < RobotConfigPageProps >  =  ( { 
2931  title, 
3032  children, 
3133  onSave, 
3234  onCancel, 
33-   saveButtonText  =   "Save" , 
34-   cancelButtonText  =   "Cancel" , 
35+   saveButtonText, 
36+   cancelButtonText, 
3537  showSaveButton =  true , 
3638  showCancelButton =  true , 
3739  isLoading =  false , 
3840  icon, 
3941  onBackToSelection, 
40-   backToSelectionText =  "← Back" 
42+   backToSelectionText, 
43+   onArrowBack, 
4144} )  =>  { 
45+   const  navigate  =  useNavigate ( ) ; 
46+   const  location  =  useLocation ( ) ; 
4247  const  theme  =  useTheme ( ) ; 
48+   const  {  t }  =  useTranslation ( ) ; 
4349
4450  const  handleBack  =  ( )  =>  { 
4551    if  ( onCancel )  { 
4652      onCancel ( ) ; 
53+     }  else  { 
54+       // Try to determine the correct path based on current URL 
55+       const  currentPath  =  location . pathname ; 
56+       const  basePath  =  currentPath . includes ( '/prebuilt-robots' )  ? '/prebuilt-robots'  : '/robots' ; 
57+       navigate ( basePath ) ; 
4758    } 
4859  } ; 
4960
5061  return  ( 
51-     < Box  sx = { {  
52-       maxWidth : 1000 ,  
53-       margin : 'auto' ,  
54-       px : 4 , 
55-       py : 3 , 
56-       minHeight : '80vh' , 
62+     < Box  sx = { { 
63+       maxWidth : 1000 , 
64+       margin : '50px auto' , 
65+       maxHeight : '100vh' , 
5766      display : 'flex' , 
5867      flexDirection : 'column' , 
5968      width : '1000px' , 
69+       height : '100%' , 
70+       overflowY : 'auto' ,  // Allow scrolling if content exceeds height 
6071    } } > 
61-       < Box  sx = { {  
62-         display : 'flex' ,  
63-         alignItems : 'center' ,  
64-         minHeight : '64px' , 
72+       { /* Header Section - Fixed Position */ } 
73+       < Box  sx = { { 
74+         display : 'flex' , 
75+         alignItems : 'center' , 
76+         maxHeight : '64px' , 
6577        mb : 2 , 
6678        flexShrink : 0 
6779      } } > 
6880        < IconButton 
69-           onClick = { handleBack } 
81+           onClick = { onArrowBack  ?  onArrowBack  :  handleBack } 
7082          sx = { { 
71-             mr : 2 , 
83+             ml : - 1 , 
84+             mr : 1 , 
7285            color : theme . palette . text . primary , 
86+             backgroundColor : 'transparent !important' , 
7387            '&:hover' : { 
74-               bgcolor : theme . palette . action . hover 
75-             } 
88+               backgroundColor : 'transparent !important' , 
89+             } , 
90+             '&:active' : { 
91+               backgroundColor : 'transparent !important' , 
92+             } , 
93+             '&:focus' : { 
94+               backgroundColor : 'transparent !important' , 
95+             } , 
96+             '&:focus-visible' : { 
97+               backgroundColor : 'transparent !important' , 
98+             } , 
7699          } } 
100+           disableRipple 
77101        > 
78102          < ArrowBack  /> 
79103        </ IconButton > 
@@ -82,9 +106,9 @@ export const RobotConfigPage: React.FC<RobotConfigPageProps> = ({
82106            { icon } 
83107          </ Box > 
84108        ) } 
85-         < Typography   
86-           variant = "h4"   
87-           sx = { {   
109+         < Typography 
110+           variant = "h4" 
111+           sx = { { 
88112            fontWeight : 600 , 
89113            color : theme . palette . text . primary , 
90114            lineHeight : 1.2 
@@ -95,29 +119,32 @@ export const RobotConfigPage: React.FC<RobotConfigPageProps> = ({
95119      </ Box > 
96120      < Divider  sx = { {  mb : 4 ,  flexShrink : 0  } }  /> 
97121
98-       < Box  sx = { {  
122+       { /* Content Section */ } 
123+       < Box  sx = { { 
99124        flex : 1 , 
100125        display : 'flex' , 
101126        flexDirection : 'column' , 
102-         minHeight : 0 
127+         minHeight : 0 , 
128+         mt : 2 , 
129+         mb : 3 , 
103130      } } > 
104131        { children } 
105132      </ Box > 
106133
134+       { /* Action Buttons */ } 
107135      { ( showSaveButton  ||  showCancelButton  ||  onBackToSelection )  &&  ( 
108136        < Box 
109137          sx = { { 
110138            display : 'flex' , 
111-             justifyContent : onBackToSelection  ? 'space-between'  : 'flex-end ' , 
139+             justifyContent : onBackToSelection  ? 'space-between'  : 'flex-start ' , 
112140            gap : 2 , 
113-             pt : 3 , 
114-             mt : 2 , 
141+             pt : 3 ,  // Reduce padding top to minimize space above 
115142            borderTop : `1px solid ${ theme . palette . divider }  , 
116143            flexShrink : 0 , 
117144            width : '100%' , 
118-             px : 3 
119145          } } 
120146        > 
147+           { /* Left side - Back to Selection button */ } 
121148          { onBackToSelection  &&  ( 
122149            < Button 
123150              variant = "outlined" 
@@ -128,44 +155,45 @@ export const RobotConfigPage: React.FC<RobotConfigPageProps> = ({
128155                borderColor : '#ff00c3 !important' , 
129156                backgroundColor : 'white !important' , 
130157              } }  > 
131-               { backToSelectionText } 
158+               { backToSelectionText   ||   t ( "buttons.back_arrow" ) } 
132159            </ Button > 
133160          ) } 
134161
162+           { /* Right side - Save/Cancel buttons */ } 
135163          < Box  sx = { {  display : 'flex' ,  gap : 2  } } > 
136-           { showCancelButton  &&  ( 
137-             < Button 
138-               variant = "outlined" 
139-               onClick = { handleBack } 
140-               disabled = { isLoading } 
141-               sx = { { 
142-                 color : '#ff00c3 !important' , 
143-                 borderColor : '#ff00c3 !important' , 
144-                 backgroundColor : 'white !important' , 
145-               } }  > 
146-               { cancelButtonText } 
147-             </ Button > 
148-           ) } 
149-           { showSaveButton  &&  onSave  &&  ( 
150-             < Button 
151-               variant = "contained" 
152-               onClick = { onSave } 
153-               disabled = { isLoading } 
154-               sx = { { 
155-                 bgcolor : '#ff00c3' , 
156-                 '&:hover' : { 
157-                   bgcolor : '#cc0099' , 
164+             { showCancelButton  &&  ( 
165+               < Button 
166+                 variant = "outlined" 
167+                 onClick = { handleBack } 
168+                 disabled = { isLoading } 
169+                 sx = { { 
170+                   color : '#ff00c3 !important' , 
171+                   borderColor : '#ff00c3 !important' , 
172+                   backgroundColor : 'white !important' , 
173+                 } }  > 
174+                 { cancelButtonText  ||  t ( "buttons.cancel" ) } 
175+               </ Button > 
176+             ) } 
177+             { showSaveButton  &&  onSave  &&  ( 
178+               < Button 
179+                 variant = "contained" 
180+                 onClick = { onSave } 
181+                 disabled = { isLoading } 
182+                 sx = { { 
183+                   bgcolor : '#ff00c3' , 
184+                   '&:hover' : { 
185+                     bgcolor : '#cc0099' , 
186+                     boxShadow : 'none' , 
187+                   } , 
188+                   textTransform : 'none' , 
189+                   fontWeight : 500 , 
190+                   px : 3 , 
158191                  boxShadow : 'none' , 
159-                 } , 
160-                 textTransform : 'none' , 
161-                 fontWeight : 500 , 
162-                 px : 3 , 
163-                 boxShadow : 'none' , 
164-               } } 
165-             > 
166-               { isLoading  ? 'Saving...'  : saveButtonText } 
167-             </ Button > 
168-           ) } 
192+                 } } 
193+               > 
194+                 { isLoading  ? t ( "buttons.saving" )  : ( saveButtonText  ||  t ( "buttons.save" ) ) } 
195+               </ Button > 
196+             ) } 
169197          </ Box > 
170198        </ Box > 
171199      ) } 
0 commit comments