refactor team panel to get rid of error of unused code, and add generic modals
This commit is contained in:
1 parent
effc6dac3a
commit
7752e52fcd
2 files changed
+185
-238
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import TabPanel from "@mui/lab/TabPanel";
|
import TabPanel from "@mui/lab/TabPanel";
|
||||||
import { Box, Button, Divider, Modal, Stack, Typography } from "@mui/material";
|
import { Box, Button, Divider, Stack, Typography } from "@mui/material";
|
||||||
import Avatar from "../../Avatar";
|
import Avatar from "../../Avatar";
|
||||||
import Field from "../../Inputs/Field";
|
import Field from "../../Inputs/Field";
|
||||||
import ImageField from "../../Inputs/Image";
|
import ImageField from "../../Inputs/Image";
|
||||||
@@ -15,6 +15,7 @@ import { clearUptimeMonitorState } from "../../../Features/UptimeMonitors/uptime
|
|||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { logger } from "../../../Utils/Logger";
|
import { logger } from "../../../Utils/Logger";
|
||||||
import LoadingButton from "@mui/lab/LoadingButton";
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
|
import { GenericDialog } from "../../Dialog/genericDialog";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProfilePanel component displays a form for editing user profile information
|
* ProfilePanel component displays a form for editing user profile information
|
||||||
@@ -369,158 +370,121 @@ const ProfilePanel = () => {
|
|||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
{/* TODO - Update ModalPopup Component with @mui for reusability */}
|
{/* TODO - Update ModalPopup Component with @mui for reusability */}
|
||||||
<Modal
|
<GenericDialog
|
||||||
aria-labelledby="modal-delete-account"
|
title={"modal-delete-account"}
|
||||||
aria-describedby="delete-account-confirmation"
|
description={"delete-account-confirmation"}
|
||||||
open={isModalOpen("delete")}
|
open={isModalOpen("delete")}
|
||||||
onClose={() => setIsOpen("")}
|
close={() => setIsOpen("")}
|
||||||
disablePortal
|
theme={theme}
|
||||||
|
/* disablePortal ? */
|
||||||
>
|
>
|
||||||
|
<Typography
|
||||||
|
id="modal-delete-account"
|
||||||
|
component="h1"
|
||||||
|
>
|
||||||
|
Really delete this account?
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
id="delete-account-confirmation"
|
||||||
|
component="p"
|
||||||
|
>
|
||||||
|
If you delete your account, you will no longer be able to sign in, and all of
|
||||||
|
your data will be deleted. Deleting your account is permanent and
|
||||||
|
non-recoverable action.
|
||||||
|
</Typography>
|
||||||
<Stack
|
<Stack
|
||||||
|
direction="row"
|
||||||
gap={theme.spacing(5)}
|
gap={theme.spacing(5)}
|
||||||
sx={{
|
mt={theme.spacing(5)}
|
||||||
position: "absolute",
|
justifyContent="flex-end"
|
||||||
top: "50%",
|
|
||||||
left: "50%",
|
|
||||||
transform: "translate(-50%, -50%)",
|
|
||||||
width: 500,
|
|
||||||
bgcolor: theme.palette.background.main,
|
|
||||||
border: 1,
|
|
||||||
borderColor: theme.palette.border.light,
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
boxShadow: 24,
|
|
||||||
p: theme.spacing(15),
|
|
||||||
"&:focus": {
|
|
||||||
outline: "none",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Typography
|
<Button
|
||||||
id="modal-delete-account"
|
variant="text"
|
||||||
component="h1"
|
color="info"
|
||||||
|
onClick={() => setIsOpen("")}
|
||||||
>
|
>
|
||||||
Really delete this account?
|
Cancel
|
||||||
</Typography>
|
</Button>
|
||||||
<Typography
|
<LoadingButton
|
||||||
id="delete-account-confirmation"
|
variant="contained"
|
||||||
component="p"
|
color="error"
|
||||||
|
onClick={handleDeleteAccount}
|
||||||
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
If you delete your account, you will no longer be able to sign in, and all of
|
Delete account
|
||||||
your data will be deleted. Deleting your account is permanent and
|
</LoadingButton>
|
||||||
non-recoverable action.
|
|
||||||
</Typography>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(5)}
|
|
||||||
mt={theme.spacing(5)}
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
variant="text"
|
|
||||||
color="info"
|
|
||||||
onClick={() => setIsOpen("")}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<LoadingButton
|
|
||||||
variant="contained"
|
|
||||||
color="error"
|
|
||||||
onClick={handleDeleteAccount}
|
|
||||||
loading={isLoading}
|
|
||||||
>
|
|
||||||
Delete account
|
|
||||||
</LoadingButton>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</Modal>
|
</GenericDialog>
|
||||||
<Modal
|
<GenericDialog
|
||||||
aria-labelledby="modal-update-picture"
|
title={"modal-update-picture"}
|
||||||
aria-describedby="update-profile-picture"
|
description={"update-profile-picture"}
|
||||||
open={isModalOpen("picture")}
|
open={isModalOpen("picture")}
|
||||||
onClose={closePictureModal}
|
close={closePictureModal}
|
||||||
|
theme={theme}
|
||||||
>
|
>
|
||||||
<Stack
|
<Typography
|
||||||
sx={{
|
id="modal-update-picture"
|
||||||
position: "absolute",
|
component="h1"
|
||||||
top: "50%",
|
color={theme.palette.text.secondary}
|
||||||
left: "50%",
|
|
||||||
transform: "translate(-50%, -50%)",
|
|
||||||
width: 475,
|
|
||||||
bgcolor: theme.palette.background.main,
|
|
||||||
border: 1,
|
|
||||||
borderColor: theme.palette.border.light,
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
boxShadow: theme.shape.boxShadow,
|
|
||||||
p: theme.spacing(15),
|
|
||||||
"&:focus": {
|
|
||||||
outline: "none",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Typography
|
Upload Image
|
||||||
id="modal-update-picture"
|
</Typography>
|
||||||
component="h1"
|
<ImageField
|
||||||
color={theme.palette.text.secondary}
|
id="update-profile-picture"
|
||||||
>
|
src={
|
||||||
Upload Image
|
file?.delete
|
||||||
</Typography>
|
? ""
|
||||||
<ImageField
|
: file?.src
|
||||||
id="update-profile-picture"
|
? file.src
|
||||||
src={
|
: localData?.file
|
||||||
file?.delete
|
? localData.file
|
||||||
? ""
|
: user?.avatarImage
|
||||||
: file?.src
|
? `data:image/png;base64,${user.avatarImage}`
|
||||||
? file.src
|
: ""
|
||||||
: localData?.file
|
}
|
||||||
? localData.file
|
loading={progress.isLoading && progress.value !== 100}
|
||||||
: user?.avatarImage
|
onChange={handlePicture}
|
||||||
? `data:image/png;base64,${user.avatarImage}`
|
/>
|
||||||
: ""
|
{progress.isLoading || progress.value !== 0 || errors["picture"] ? (
|
||||||
}
|
<ProgressUpload
|
||||||
loading={progress.isLoading && progress.value !== 100}
|
icon={<ImageIcon />}
|
||||||
onChange={handlePicture}
|
label={file?.name}
|
||||||
|
size={file?.size}
|
||||||
|
progress={progress.value}
|
||||||
|
onClick={removePicture}
|
||||||
|
error={errors["picture"]}
|
||||||
/>
|
/>
|
||||||
{progress.isLoading || progress.value !== 0 || errors["picture"] ? (
|
) : (
|
||||||
<ProgressUpload
|
""
|
||||||
icon={<ImageIcon />}
|
)}
|
||||||
label={file?.name}
|
<Stack
|
||||||
size={file?.size}
|
direction="row"
|
||||||
progress={progress.value}
|
mt={theme.spacing(10)}
|
||||||
onClick={removePicture}
|
gap={theme.spacing(5)}
|
||||||
error={errors["picture"]}
|
justifyContent="flex-end"
|
||||||
/>
|
>
|
||||||
) : (
|
<Button
|
||||||
""
|
variant="text"
|
||||||
)}
|
color="info"
|
||||||
<Stack
|
onClick={removePicture}
|
||||||
direction="row"
|
|
||||||
mt={theme.spacing(10)}
|
|
||||||
gap={theme.spacing(5)}
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
>
|
||||||
<Button
|
Remove
|
||||||
variant="text"
|
</Button>
|
||||||
color="info"
|
<Button
|
||||||
onClick={removePicture}
|
variant="contained"
|
||||||
>
|
color="primary"
|
||||||
Remove
|
onClick={handleUpdatePicture}
|
||||||
</Button>
|
disabled={
|
||||||
<Button
|
(Object.keys(errors).length !== 0 && errors?.picture) ||
|
||||||
variant="contained"
|
progress.value !== 100
|
||||||
color="primary"
|
? true
|
||||||
onClick={handleUpdatePicture}
|
: false
|
||||||
disabled={
|
}
|
||||||
(Object.keys(errors).length !== 0 && errors?.picture) ||
|
>
|
||||||
progress.value !== 100
|
Update
|
||||||
? true
|
</Button>
|
||||||
: false
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Update
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</Modal>
|
</GenericDialog>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import TabPanel from "@mui/lab/TabPanel";
|
import TabPanel from "@mui/lab/TabPanel";
|
||||||
import { Box, Button, ButtonGroup, Modal, Stack, Typography } from "@mui/material";
|
import { Box, Button, ButtonGroup, Stack, Typography } from "@mui/material";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import Field from "../../Inputs/Field";
|
import Field from "../../Inputs/Field";
|
||||||
import { credentials } from "../../../Validation/validation";
|
import { credentials } from "../../../Validation/validation";
|
||||||
@@ -10,6 +10,7 @@ import { useSelector } from "react-redux";
|
|||||||
import BasicTable from "../../BasicTable";
|
import BasicTable from "../../BasicTable";
|
||||||
import Select from "../../Inputs/Select";
|
import Select from "../../Inputs/Select";
|
||||||
import LoadingButton from "@mui/lab/LoadingButton";
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
|
import { GenericDialog } from "../../Dialog/genericDialog";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TeamPanel component manages the organization and team members,
|
* TeamPanel component manages the organization and team members,
|
||||||
@@ -31,10 +32,10 @@ const TeamPanel = () => {
|
|||||||
|
|
||||||
const { authToken, user } = useSelector((state) => state.auth);
|
const { authToken, user } = useSelector((state) => state.auth);
|
||||||
//TODO
|
//TODO
|
||||||
const [orgStates, setOrgStates] = useState({
|
// const [orgStates, setOrgStates] = useState({
|
||||||
name: "Bluewave Labs",
|
// name: "Bluewave Labs",
|
||||||
isEdit: false,
|
// isEdit: false,
|
||||||
});
|
// });
|
||||||
const [toInvite, setToInvite] = useState({
|
const [toInvite, setToInvite] = useState({
|
||||||
email: "",
|
email: "",
|
||||||
role: ["0"],
|
role: ["0"],
|
||||||
@@ -134,10 +135,10 @@ const TeamPanel = () => {
|
|||||||
}, [errors, toInvite.email]);
|
}, [errors, toInvite.email]);
|
||||||
|
|
||||||
// RENAME ORGANIZATION
|
// RENAME ORGANIZATION
|
||||||
const toggleEdit = () => {
|
// const toggleEdit = () => {
|
||||||
setOrgStates((prev) => ({ ...prev, isEdit: !prev.isEdit }));
|
// setOrgStates((prev) => ({ ...prev, isEdit: !prev.isEdit }));
|
||||||
};
|
// };
|
||||||
const handleRename = () => {};
|
// const handleRename = () => {};
|
||||||
|
|
||||||
// INVITE MEMBER
|
// INVITE MEMBER
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
@@ -327,100 +328,82 @@ const TeamPanel = () => {
|
|||||||
table={"team"}
|
table={"team"}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Modal
|
|
||||||
aria-labelledby="modal-invite-member"
|
<GenericDialog
|
||||||
aria-describedby="invite-member-to-team"
|
title={"modal-invite-member"}
|
||||||
|
description={"invite-member-to-team"}
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onClose={closeInviteModal}
|
close={closeInviteModal}
|
||||||
|
theme={theme}
|
||||||
>
|
>
|
||||||
<Stack
|
<Box>
|
||||||
gap={theme.spacing(5)}
|
<Typography
|
||||||
sx={{
|
id="modal-invite-member"
|
||||||
position: "absolute",
|
component="h1"
|
||||||
top: "50%",
|
fontWeight={600}
|
||||||
left: "50%",
|
fontColor={theme.palette.text.secondary}
|
||||||
transform: "translate(-50%, -50%)",
|
|
||||||
width: 450,
|
|
||||||
bgcolor: theme.palette.background.main,
|
|
||||||
border: 1,
|
|
||||||
borderColor: theme.palette.border.light,
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
boxShadow: theme.shape.boxShadow,
|
|
||||||
p: theme.spacing(15),
|
|
||||||
"&:focus": {
|
|
||||||
outline: "none",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
id="modal-invite-member"
|
|
||||||
component="h1"
|
|
||||||
fontWeight={600}
|
|
||||||
fontColor={theme.palette.text.secondary}
|
|
||||||
>
|
|
||||||
Invite new team member
|
|
||||||
</Typography>
|
|
||||||
<Typography
|
|
||||||
id="invite-member-to-team"
|
|
||||||
component="p"
|
|
||||||
fontSize={13}
|
|
||||||
color={theme.palette.text.accent}
|
|
||||||
sx={{ mt: theme.spacing(1), mb: theme.spacing(4) }}
|
|
||||||
>
|
|
||||||
When you add a new team member, they will get access to all monitors.
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Field
|
|
||||||
type="email"
|
|
||||||
id="input-team-member"
|
|
||||||
placeholder="Email"
|
|
||||||
value={toInvite.email}
|
|
||||||
onChange={handleChange}
|
|
||||||
error={errors.email}
|
|
||||||
/>
|
|
||||||
<Select
|
|
||||||
id="team-member-role"
|
|
||||||
placeholder="Select role"
|
|
||||||
isHidden={true}
|
|
||||||
value={toInvite.role[0]}
|
|
||||||
onChange={(event) =>
|
|
||||||
setToInvite((prev) => ({
|
|
||||||
...prev,
|
|
||||||
role: [event.target.value],
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
items={[
|
|
||||||
{ _id: "admin", name: "Admin" },
|
|
||||||
{ _id: "user", name: "User" },
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
mt={theme.spacing(8)}
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
>
|
||||||
<LoadingButton
|
Invite new team member
|
||||||
loading={isSendingInvite}
|
</Typography>
|
||||||
variant="text"
|
<Typography
|
||||||
color="info"
|
id="invite-member-to-team"
|
||||||
onClick={closeInviteModal}
|
component="p"
|
||||||
>
|
fontSize={13}
|
||||||
Cancel
|
color={theme.palette.text.accent}
|
||||||
</LoadingButton>
|
sx={{ mt: theme.spacing(1), mb: theme.spacing(4) }}
|
||||||
<LoadingButton
|
>
|
||||||
variant="contained"
|
When you add a new team member, they will get access to all monitors.
|
||||||
color="primary"
|
</Typography>
|
||||||
onClick={handleInviteMember}
|
</Box>
|
||||||
loading={isSendingInvite}
|
<Field
|
||||||
disabled={isDisabled}
|
type="email"
|
||||||
>
|
id="input-team-member"
|
||||||
Send invite
|
placeholder="Email"
|
||||||
</LoadingButton>
|
value={toInvite.email}
|
||||||
</Stack>
|
onChange={handleChange}
|
||||||
|
error={errors.email}
|
||||||
|
/>
|
||||||
|
<Select
|
||||||
|
id="team-member-role"
|
||||||
|
placeholder="Select role"
|
||||||
|
isHidden={true}
|
||||||
|
value={toInvite.role[0]}
|
||||||
|
onChange={(event) =>
|
||||||
|
setToInvite((prev) => ({
|
||||||
|
...prev,
|
||||||
|
role: [event.target.value],
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
items={[
|
||||||
|
{ _id: "admin", name: "Admin" },
|
||||||
|
{ _id: "user", name: "User" },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
mt={theme.spacing(8)}
|
||||||
|
justifyContent="flex-end"
|
||||||
|
>
|
||||||
|
<LoadingButton
|
||||||
|
loading={isSendingInvite}
|
||||||
|
variant="text"
|
||||||
|
color="info"
|
||||||
|
onClick={closeInviteModal}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</LoadingButton>
|
||||||
|
<LoadingButton
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={handleInviteMember}
|
||||||
|
loading={isSendingInvite}
|
||||||
|
disabled={isDisabled}
|
||||||
|
>
|
||||||
|
Send invite
|
||||||
|
</LoadingButton>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Modal>
|
</GenericDialog>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user