Files
parcer/src/components/robot/pages/RobotConfigPage.tsx

202 lines
5.4 KiB
TypeScript
Raw Normal View History

2025-08-04 22:54:51 +05:30
import React from 'react';
2025-08-25 19:37:49 +05:30
import {
Box,
Typography,
Button,
2025-08-04 22:54:51 +05:30
IconButton,
Divider,
useTheme
} from '@mui/material';
import { ArrowBack } from '@mui/icons-material';
import { useNavigate, useLocation } from 'react-router-dom';
2025-08-25 19:37:49 +05:30
import { useTranslation } from 'react-i18next';
2025-08-04 22:54:51 +05:30
interface RobotConfigPageProps {
title: string;
children: React.ReactNode;
onSave?: () => void;
onCancel?: () => void;
saveButtonText?: string;
cancelButtonText?: string;
showSaveButton?: boolean;
showCancelButton?: boolean;
isLoading?: boolean;
icon?: React.ReactNode;
onBackToSelection?: () => void;
backToSelectionText?: string;
2025-08-25 19:37:49 +05:30
onArrowBack?: () => void; // Optional prop for custom back action
2025-08-04 22:54:51 +05:30
}
export const RobotConfigPage: React.FC<RobotConfigPageProps> = ({
title,
children,
onSave,
onCancel,
2025-08-25 19:37:49 +05:30
saveButtonText,
cancelButtonText,
2025-08-04 22:54:51 +05:30
showSaveButton = true,
showCancelButton = true,
isLoading = false,
icon,
onBackToSelection,
2025-08-25 19:37:49 +05:30
backToSelectionText,
onArrowBack,
2025-08-04 22:54:51 +05:30
}) => {
2025-08-25 19:37:49 +05:30
const navigate = useNavigate();
const location = useLocation();
2025-08-04 22:54:51 +05:30
const theme = useTheme();
2025-08-25 19:37:49 +05:30
const { t } = useTranslation();
2025-08-04 22:54:51 +05:30
const handleBack = () => {
if (onCancel) {
onCancel();
2025-08-25 19:37:49 +05:30
} else {
// Try to determine the correct path based on current URL
const currentPath = location.pathname;
const basePath = currentPath.includes('/prebuilt-robots') ? '/prebuilt-robots' : '/robots';
navigate(basePath);
2025-08-04 22:54:51 +05:30
}
};
return (
2025-08-25 19:37:49 +05:30
<Box sx={{
maxWidth: 1000,
margin: '50px auto',
maxHeight: '100vh',
2025-08-04 22:54:51 +05:30
display: 'flex',
flexDirection: 'column',
width: '1000px',
2025-08-25 19:37:49 +05:30
height: '100%',
overflowY: 'auto', // Allow scrolling if content exceeds height
2025-08-04 22:54:51 +05:30
}}>
2025-08-25 19:37:49 +05:30
{/* Header Section - Fixed Position */}
<Box sx={{
display: 'flex',
alignItems: 'center',
maxHeight: '64px',
2025-08-04 22:54:51 +05:30
mb: 2,
flexShrink: 0
}}>
<IconButton
2025-08-25 19:37:49 +05:30
onClick={onArrowBack ? onArrowBack : handleBack}
2025-08-04 22:54:51 +05:30
sx={{
2025-08-25 19:37:49 +05:30
ml: -1,
mr: 1,
2025-08-04 22:54:51 +05:30
color: theme.palette.text.primary,
2025-08-25 19:37:49 +05:30
backgroundColor: 'transparent !important',
2025-08-04 22:54:51 +05:30
'&:hover': {
2025-08-25 19:37:49 +05:30
backgroundColor: 'transparent !important',
},
'&:active': {
backgroundColor: 'transparent !important',
},
'&:focus': {
backgroundColor: 'transparent !important',
},
'&:focus-visible': {
backgroundColor: 'transparent !important',
},
2025-08-04 22:54:51 +05:30
}}
2025-08-25 19:37:49 +05:30
disableRipple
2025-08-04 22:54:51 +05:30
>
<ArrowBack />
</IconButton>
{icon && (
<Box sx={{ mr: 2, color: theme.palette.text.primary }}>
{icon}
</Box>
)}
2025-08-25 19:37:49 +05:30
<Typography
variant="h4"
sx={{
2025-08-04 22:54:51 +05:30
fontWeight: 600,
color: theme.palette.text.primary,
lineHeight: 1.2
}}
>
{title}
</Typography>
</Box>
<Divider sx={{ mb: 4, flexShrink: 0 }} />
2025-08-25 19:37:49 +05:30
{/* Content Section */}
<Box sx={{
2025-08-04 22:54:51 +05:30
flex: 1,
display: 'flex',
flexDirection: 'column',
2025-08-25 19:37:49 +05:30
minHeight: 0,
mt: 2,
mb: 3,
2025-08-04 22:54:51 +05:30
}}>
{children}
</Box>
2025-08-25 19:37:49 +05:30
{/* Action Buttons */}
2025-08-04 22:54:51 +05:30
{(showSaveButton || showCancelButton || onBackToSelection) && (
<Box
sx={{
display: 'flex',
2025-08-25 19:37:49 +05:30
justifyContent: onBackToSelection ? 'space-between' : 'flex-start',
2025-08-04 22:54:51 +05:30
gap: 2,
2025-08-25 19:37:49 +05:30
pt: 3, // Reduce padding top to minimize space above
2025-08-04 22:54:51 +05:30
borderTop: `1px solid ${theme.palette.divider}`,
flexShrink: 0,
width: '100%',
}}
>
2025-08-25 19:37:49 +05:30
{/* Left side - Back to Selection button */}
2025-08-04 22:54:51 +05:30
{onBackToSelection && (
<Button
variant="outlined"
onClick={onBackToSelection}
disabled={isLoading}
sx={{
2025-08-04 23:43:36 +05:30
color: '#ff00c3 !important',
borderColor: '#ff00c3 !important',
backgroundColor: 'white !important',
}} >
2025-08-25 19:37:49 +05:30
{backToSelectionText || t("buttons.back_arrow")}
2025-08-04 22:54:51 +05:30
</Button>
)}
2025-08-25 19:37:49 +05:30
{/* Right side - Save/Cancel buttons */}
2025-08-04 22:54:51 +05:30
<Box sx={{ display: 'flex', gap: 2 }}>
2025-08-25 19:37:49 +05:30
{showCancelButton && (
<Button
variant="outlined"
onClick={handleBack}
disabled={isLoading}
sx={{
color: '#ff00c3 !important',
borderColor: '#ff00c3 !important',
backgroundColor: 'white !important',
}} >
{cancelButtonText || t("buttons.cancel")}
</Button>
)}
{showSaveButton && onSave && (
<Button
variant="contained"
onClick={onSave}
disabled={isLoading}
sx={{
bgcolor: '#ff00c3',
'&:hover': {
bgcolor: '#cc0099',
boxShadow: 'none',
},
textTransform: 'none',
fontWeight: 500,
px: 3,
2025-08-04 22:54:51 +05:30
boxShadow: 'none',
2025-08-25 19:37:49 +05:30
}}
>
{isLoading ? t("buttons.saving") : (saveButtonText || t("buttons.save"))}
</Button>
)}
2025-08-04 22:54:51 +05:30
</Box>
</Box>
)}
</Box>
);
};