Modified Integrations component to include props.

This commit is contained in:
M M committed 2024-06-10 12:44:10 -07:00
commit aa8a9a33c8
9 files changed
+254 -550

No files matched your search

+91 -496
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -27,7 +27,7 @@
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-redux": "9.1.2", "react-redux": "9.1.2",
"react-router": "^6.23.0", "react-router": "^6.23.0",
"react-router-dom": "^6.23.0" "react-router-dom": "^6.23.1"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^18.2.66", "@types/react": "^18.2.66",
+51 -5
View File
@@ -6,6 +6,9 @@ import Incidents from "../../assets/Images/Icon-warning-gray.png";
import SensorsIcon from "../../assets/Images/Icon-signal-gray.png"; import SensorsIcon from "../../assets/Images/Icon-signal-gray.png";
import AllInclusiveIcon from "../../assets/Images/Icon-link-gray.png"; import AllInclusiveIcon from "../../assets/Images/Icon-link-gray.png";
import SettingsIcon from "../../assets/Images/Icon-setting-gray.png"; import SettingsIcon from "../../assets/Images/Icon-setting-gray.png";
import React, { useState, useEffect } from "react";
import { useNavigate, useLocation } from "react-router-dom";
import pathMap from "../../Utils/PathMap";
/** /**
* @component * @component
@@ -16,13 +19,56 @@ import SettingsIcon from "../../assets/Images/Icon-setting-gray.png";
*/ */
function DashboardMenu() { function DashboardMenu() {
const [activeButton, setActiveButton] = useState(null);
const navigate = useNavigate();
const location = useLocation();
useEffect(() => {
setActiveButton(location.pathname);
}, [location]);
const handleClick = (title, path) => {
setActiveButton(title);
navigate(path);
};
return ( return (
<div className="dashboard-menu-container"> <div className="dashboard-menu-container">
{DashboardMenuButton(Monitors, "Monitors", "/monitors")} {DashboardMenuButton(
{DashboardMenuButton(Incidents, "Incidents", "/incidents")} Monitors,
{DashboardMenuButton(SensorsIcon, "Status Pages", "/status")} "Monitors",
{DashboardMenuButton(AllInclusiveIcon, "Integrations", "/integrations")} "/monitors",
{DashboardMenuButton(SettingsIcon, "Settings", "/settings")} activeButton === "/monitors",
() => handleClick(pathMap["/monitors"], "/monitors")
)}
{DashboardMenuButton(
Incidents,
"Incidents",
"/incidents",
activeButton === "/incidents",
() => handleClick(pathMap["/incidents"], "/incidents")
)}
{DashboardMenuButton(
SensorsIcon,
"Status Pages",
"/status",
activeButton === "/status",
() => handleClick(pathMap["/status"], "/status")
)}
{DashboardMenuButton(
AllInclusiveIcon,
"Integrations",
"/integrations",
activeButton === "/integrations",
() => handleClick(pathMap["/integrations"], "/integrations")
)}
{DashboardMenuButton(
SettingsIcon,
"Settings",
"/settings",
activeButton === "/settings",
() => handleClick(pathMap["/settings"], "/settings")
)}
</div> </div>
); );
} }
@@ -11,13 +11,9 @@ import { useNavigate } from "react-router-dom";
* @returns {React.ReactElement} The rendered menu button component. * @returns {React.ReactElement} The rendered menu button component.
*/ */
const DashboardMenuButton = (icon, title, to) => { const DashboardMenuButton = (icon, title, to, isActive, onClick) => {
const [isActive, setIsActive] = useState(false);
const navigate = useNavigate();
const handleClick = () => { const handleClick = () => {
setIsActive(!isActive); onClick();
navigate(to);
}; };
return ( return (
+23 -8
View File
@@ -1,11 +1,17 @@
import { Box, Typography, useTheme } from '@mui/material'; import { Box, Typography, useTheme } from '@mui/material';
import Button from '../Button'; import Button from '../Button';
import PropTypes from 'prop-types';
/** /**
* Integrations component * Integrations component
* @returns {JSX.Element} * @param {Object} props - Props for the IntegrationsComponent.
* @param {string} props.url - The URL for the integration image.
* @param {string} props.header - The header for the integration.
* @param {string} props.info - Information about the integration.
* @param {Function} props.onClick - The onClick handler for the integration button.
* @returns {JSX.Element} The JSX representation of the IntegrationsComponent.
*/ */
const IntegrationsComponent = () => { const IntegrationsComponent = ({ url, header, info, onClick }) => {
const theme = useTheme(); const theme = useTheme();
return ( return (
@@ -19,8 +25,8 @@ const IntegrationsComponent = () => {
> >
<Box <Box
component="img" component="img"
src="https://via.placeholder.com/100" src={url}
alt="Placeholder" alt="Integration"
width={100} width={100}
height={100} height={100}
/> />
@@ -32,8 +38,8 @@ const IntegrationsComponent = () => {
flexDirection="column" flexDirection="column"
alignItems="flex-start" alignItems="flex-start"
> >
<Typography variant="h6" component="div"> <Typography variant="h6" component="div" style={{ fontSize: '16px' }}>
Header {header}
</Typography> </Typography>
<Typography <Typography
variant="body1" variant="body1"
@@ -43,14 +49,23 @@ const IntegrationsComponent = () => {
wordWrap: 'break-word', wordWrap: 'break-word',
textAlign: 'left' textAlign: 'left'
}} }}
style={{ fontSize: '13px' }}
> >
This is a paragraph that provides more detail about the header. {info}
</Typography> </Typography>
</Box> </Box>
<Button label="Click Me" level="primary" /> <Button label="Click Me" level="primary" onClick={onClick} />
</Box> </Box>
); );
}; };
// PropTypes for IntegrationsComponent
IntegrationsComponent.propTypes = {
url: PropTypes.string.isRequired,
header: PropTypes.string.isRequired,
info: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired
};
export default IntegrationsComponent; export default IntegrationsComponent;
+61 -31
View File
@@ -1,40 +1,70 @@
import IntegrationsComponent from '../../Components/Integrations';
import { Box, Typography, useTheme } from '@mui/material'; import { Box, Typography, useTheme } from '@mui/material';
import IntegrationsComponent from '../../Components/Integrations';
/** /**
* Integrations Page Component * Integrations Page Component
* @returns {JSX.Element} * @returns {JSX.Element} The JSX representation of the Integrations page.
*/ */
const Integrations = () => { const Integrations = () => {
const theme = useTheme(); const theme = useTheme();
return (
const integrations = [
{
url: 'https://via.placeholder.com/100',
header: 'Integration 1',
info: 'Info about Integration 1',
onClick: () => {}
},
{
url: 'https://via.placeholder.com/100',
header: 'Integration 2',
info: 'Info about Integration 2',
onClick: () => {}
},
{
url: 'https://via.placeholder.com/100',
header: 'Integration 2',
info: 'Info about Integration 2',
onClick: () => {}
}
// Add more integrations as needed
];
return (
<Box
display="flex"
flexDirection="column"
alignItems="flex-start"
justifyContent="flex-start"
height="100vh"
p={theme.spacing(4)}
mt={theme.spacing(8)}
>
<Typography variant="h4" component="h1" gutterBottom style={{ fontSize: '16px' }}>
Integrations
</Typography>
<Typography variant="h6" component="h2" gutterBottom style={{ fontSize: '13px' }}>
Connect Uptime Genie to your favorite service
</Typography>
<Box <Box
display="flex" display="flex"
flexDirection="column" flexWrap="wrap"
alignItems="flex-start" gap={theme.spacing(4)}
justifyContent="flex-start"
height="100vh"
p={theme.spacing(4)}
mt={theme.spacing(8)}
> >
<Typography variant="h4" component="h1" gutterBottom> {integrations.map((integration, index) => (
Integrations <IntegrationsComponent
</Typography> key={index}
<Typography variant="h6" component="h2" gutterBottom> url={integration.url}
Connect Uptime Genie to your favorite service header={integration.header}
</Typography> info={integration.info}
<Box onClick={integration.onClick}
display="flex" />
flexWrap="wrap" ))}
gap={theme.spacing(4)}
>
<IntegrationsComponent />
<IntegrationsComponent />
<IntegrationsComponent />
</Box>
</Box> </Box>
); </Box>
}; );
};
export default Integrations;
export default Integrations;
+12 -2
View File
@@ -50,10 +50,21 @@ const Register = () => {
return { ...acc, [err.path[0]]: err.message }; return { ...acc, [err.path[0]]: err.message };
}, {}); }, {});
setErrors(validationErrors); setErrors(validationErrors);
} else {
setErrors({});
} }
}, []); }, []);
const handleInput = (e) => { const handleInput = (e) => {
const fieldName = idMap[e.target.id];
// Extract and validate individual fields as input changes
const fieldSchema = registerValidation.extract(fieldName);
const { error } = fieldSchema.validate(e.target.value);
let errMsg = "";
if (error) {
errMsg = error.message;
}
setErrors({ ...errors, [fieldName]: errMsg });
const newForm = { ...form, [idMap[e.target.id]]: e.target.value }; const newForm = { ...form, [idMap[e.target.id]]: e.target.value };
setForm(newForm); setForm(newForm);
}; };
@@ -77,8 +88,7 @@ const Register = () => {
} catch (error) { } catch (error) {
if (error.name === "ValidationError") { if (error.name === "ValidationError") {
// TODO Handle validation errors // TODO Handle validation errors
console.log(error); alert(error);
alert("Invalid input");
} else if (error.response) { } else if (error.response) {
// TODO handle dispatch errors // TODO handle dispatch errors
alert(error.response.msg); alert(error.response.msg);
+9
View File
@@ -0,0 +1,9 @@
const pathMap = {
"/monitors": "Monitors",
"/incidents": "Incidents",
"/status" : "Status Pages",
"/integrations": "Integrations",
"/settings" : "Settings"
}
export default pathMap;
+4 -1
View File
@@ -4,4 +4,7 @@ import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
}) optimizeDeps: {
include: ['@mui/material/Tooltip', '@emotion/styled'],
},
})