Files
parcer/src/components/dashboard/MainMenu.tsx
2026-01-19 14:13:36 +05:30

194 lines
7.2 KiB
TypeScript

import React, { useState } from 'react';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Box from '@mui/material/Box';
import { useNavigate, useLocation } from 'react-router-dom';
import { Paper, Button, useTheme, Modal, Typography, Stack, Divider } from "@mui/material";
import { AutoAwesome, VpnKey, Usb, CloudQueue, Description, Favorite, SlowMotionVideo, PlayArrow, ArrowForwardIos } from "@mui/icons-material";
import { useTranslation } from 'react-i18next';
import { useGlobalInfoStore } from "../../context/globalInfo";
interface MainMenuProps {
value: string;
handleChangeContent: (newValue: string) => void;
}
export const MainMenu = ({ value = 'robots', handleChangeContent }: MainMenuProps) => {
const theme = useTheme();
const { t } = useTranslation();
const navigate = useNavigate();
const location = useLocation();
const { notify } = useGlobalInfoStore();
const [sponsorModalOpen, setSponsorModalOpen] = useState(false);
const [docModalOpen, setDocModalOpen] = useState(false);
const ossDiscountCode = "MAXUNOSS8";
const handleChange = (event: React.SyntheticEvent, newValue: string) => {
navigate(`/${newValue}`);
handleChangeContent(newValue);
};
const handleRobotsClick = () => {
if (location.pathname !== '/robots') {
navigate('/robots');
handleChangeContent('robots');
}
};
const copyDiscountCode = () => {
navigator.clipboard.writeText(ossDiscountCode).then(() => {
notify("success", "Discount code copied to clipboard!");
}).catch(err => {
console.error('Failed to copy text: ', err);
notify("error", "Failed to copy discount code.");
});
};
const defaultcolor = theme.palette.mode === 'light' ? 'black' : 'white';
const buttonStyles = {
justifyContent: 'flex-start',
textAlign: 'left',
fontSize: '15px',
letterSpacing: '0.02857em',
padding: '20px 20px 20px 22px',
minHeight: '48px',
minWidth: '100%',
display: 'flex',
alignItems: 'center',
textTransform: 'none',
color: theme.palette.mode === 'light' ? '#6C6C6C' : 'inherit',
'&:hover': {
color: theme.palette.mode === 'light' ? '#6C6C6C' : 'inherit',
backgroundColor: theme.palette.mode === 'light' ? '#f5f5f5' : 'inherit',
},
};
return (
<>
<Paper
sx={{
height: '100%',
width: '230px',
backgroundColor: theme.palette.background.paper,
paddingTop: '0.5rem',
color: defaultcolor,
}}
variant="outlined"
square
>
<Box sx={{ width: '100%', paddingBottom: '1rem' }}>
<Tabs
value={value}
onChange={handleChange}
textColor="primary"
indicatorColor="primary"
orientation="vertical"
sx={{ alignItems: 'flex-start', '& .MuiTabs-indicator': { display: 'none' }}}
>
<Tab
value="robots"
label={t('mainmenu.recordings')}
icon={<AutoAwesome sx={{ fontSize: 20 }} />}
iconPosition="start"
disableRipple={true}
sx={{ justifyContent: 'flex-start', textAlign: 'left', fontSize: '16px' }}
onClick={handleRobotsClick} />
<Tab value="runs"
label={t('mainmenu.runs')}
icon={<PlayArrow sx={{ fontSize: 20 }} />}
iconPosition="start"
disableRipple={true}
sx={{ justifyContent: 'flex-start', textAlign: 'left', fontSize: '16px' }} />
<Tab value="proxy"
label={t('mainmenu.proxy')}
icon={<Usb sx={{ fontSize: 20 }} />}
iconPosition="start"
disableRipple={true}
sx={{ justifyContent: 'flex-start', textAlign: 'left', fontSize: '16px' }} />
<Tab value="apikey"
label={t('mainmenu.apikey')}
icon={<VpnKey sx={{ fontSize: 20 }}/>}
iconPosition="start"
disableRipple={true}
sx={{ justifyContent: 'flex-start', textAlign: 'left', fontSize: '16px' }} />
</Tabs>
<Divider sx={{ borderColor: theme.palette.mode === 'dark' ? "#080808ff" : "" }} />
<Box sx={{ display: 'flex', flexDirection: 'column', textAlign: 'left' }}>
<Button
href='https://docs.maxun.dev/sdk/sdk-overview'
target="_blank"
rel="noopener noreferrer"
sx={buttonStyles} startIcon={<ArrowForwardIos sx={{ fontSize: 20 }} />}>
SDK
</Button>
<Button
onClick={() => setDocModalOpen(true)}
sx={buttonStyles}
startIcon={<Description sx={{ fontSize: 20 }} />}
>
Documentation
</Button>
<Modal open={docModalOpen ?? false} onClose={() => setDocModalOpen(false)}>
<Box sx={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', bgcolor: 'background.paper', borderRadius: 2, p: 4, width: 400 }}>
<Stack spacing={2}>
<Button
href="https://docs.maxun.dev"
target="_blank"
rel="noopener noreferrer"
variant="outlined"
startIcon={<Description />}
fullWidth
>
Documentation
</Button>
<Button
href="https://www.youtube.com/@MaxunOSS/videos"
target="_blank"
rel="noopener noreferrer"
variant="outlined"
startIcon={<SlowMotionVideo />}
fullWidth
>
Video Tutorials
</Button>
</Stack>
</Box>
</Modal>
<Button
href='https://app.maxun.dev/'
target="_blank"
rel="noopener noreferrer"
sx={buttonStyles} startIcon={<CloudQueue sx={{ fontSize: 16 }} />}>
Join Maxun Cloud
</Button>
<Button onClick={() => setSponsorModalOpen(true)} sx={buttonStyles} startIcon={<Favorite sx={{ fontSize: 16 }} />}>
Sponsor Us
</Button>
</Box>
</Box>
</Paper>
<Modal open={sponsorModalOpen} onClose={() => setSponsorModalOpen(false)}>
<Box sx={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', bgcolor: 'rgba(13, 13, 13, 1)', borderRadius: 2, p: 4, width: 600 }}>
<Typography variant="h6" marginBottom={4}>
Support Maxun Open Source
</Typography>
<Typography variant="body1" gutterBottom>
Maxun is built by a small, full-time team. Your donations directly contribute to making it better.
<br />
Thank you for your support! 🩷
</Typography>
<Stack direction="row" spacing={2} mt={4}>
<Button href="https://github.com/sponsors/amhsirak" target="_blank" rel="noopener noreferrer" variant="outlined" fullWidth>
Sponsor Maxun on GitHub Sponsors
</Button>
</Stack>
</Box>
</Modal>
</>
);
};