Skip to content

Commit 84ddce7

Browse files
authored
Merge pull request #754 from getmaxun/new-ui-fix
feat: pages ui revamp
2 parents af8ddaf + 5d8fe40 commit 84ddce7

File tree

5 files changed

+226
-123
lines changed

5 files changed

+226
-123
lines changed

src/components/robot/pages/RobotConfigPage.tsx

Lines changed: 91 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import 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';
1010
import { ArrowBack } from '@mui/icons-material';
1111
import { useNavigate, useLocation } from 'react-router-dom';
12+
import { useTranslation } from 'react-i18next';
1213

1314
interface 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

2830
export 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
)}

src/components/robot/pages/RobotDuplicatePage.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ import { useNavigate, useLocation } from "react-router-dom";
1919
interface RobotMeta {
2020
name: string;
2121
id: string;
22+
prebuiltId?: string;
2223
createdAt: string;
2324
pairs: number;
2425
updatedAt: string;
2526
params: any[];
27+
type?: string;
28+
description?: string;
29+
usedByUsers?: number[];
30+
subscriptionLevel?: number;
31+
access?: string;
32+
sample?: any[];
2633
url?: string;
2734
}
2835

@@ -73,7 +80,7 @@ export const RobotDuplicatePage = ({ handleStart }: RobotSettingsProps) => {
7380
const [targetUrl, setTargetUrl] = useState<string | undefined>("");
7481
const [robot, setRobot] = useState<RobotSettings | null>(null);
7582
const [isLoading, setIsLoading] = useState(false);
76-
const { recordingId, notify, setRerenderRobots } =
83+
const { recordingId, notify, setRerenderRobots} =
7784
useGlobalInfoStore();
7885

7986
useEffect(() => {
@@ -132,7 +139,10 @@ export const RobotDuplicatePage = ({ handleStart }: RobotSettingsProps) => {
132139
t("robot_duplication.notifications.duplicate_success")
133140
);
134141
handleStart(robot);
135-
navigate("/robots");
142+
const basePath = location.pathname.includes("/prebuilt-robots")
143+
? "/prebuilt-robots"
144+
: "/robots";
145+
navigate(basePath);
136146
} else {
137147
notify("error", t("robot_duplication.notifications.duplicate_error"));
138148
}
@@ -145,7 +155,10 @@ export const RobotDuplicatePage = ({ handleStart }: RobotSettingsProps) => {
145155
};
146156

147157
const handleCancel = () => {
148-
navigate("/robots");
158+
const basePath = location.pathname.includes("/prebuilt-robots")
159+
? "/prebuilt-robots"
160+
: "/robots";
161+
navigate(basePath);
149162
};
150163

151164
return (
@@ -156,6 +169,7 @@ export const RobotDuplicatePage = ({ handleStart }: RobotSettingsProps) => {
156169
saveButtonText={t("robot_duplication.buttons.duplicate")}
157170
cancelButtonText={t("robot_duplication.buttons.cancel")}
158171
isLoading={isLoading}
172+
showCancelButton={false}
159173
>
160174
<>
161175
<Box style={{ display: "flex", flexDirection: "column" }}>
@@ -188,4 +202,4 @@ export const RobotDuplicatePage = ({ handleStart }: RobotSettingsProps) => {
188202
</>
189203
</RobotConfigPage>
190204
);
191-
};
205+
};

0 commit comments

Comments
 (0)