2024-06-16 01:32:46 -04:00
import PropTypes from "prop-types" ;
import { useState } from "react" ;
import {
Box ,
Typography ,
Tab ,
useTheme ,
TextField ,
Avatar ,
Stack ,
Divider ,
2024-06-16 18:12:15 -04:00
Modal ,
2024-06-16 20:32:42 -04:00
FormControl ,
OutlinedInput ,
InputAdornment ,
IconButton ,
2024-06-17 22:30:35 -04:00
Container ,
Table ,
TableHead ,
TableRow ,
TableCell ,
TableBody ,
Checkbox ,
Select ,
MenuItem ,
2024-06-16 01:32:46 -04:00
} from "@mui/material" ;
import TabPanel from "@mui/lab/TabPanel" ;
import TabContext from "@mui/lab/TabContext" ;
import TabList from "@mui/lab/TabList" ;
2024-06-16 20:32:42 -04:00
import Visibility from "@mui/icons-material/Visibility" ;
import VisibilityOff from "@mui/icons-material/VisibilityOff" ;
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined" ;
import WarningAmberOutlinedIcon from "@mui/icons-material/WarningAmberOutlined" ;
2024-06-16 01:32:46 -04:00
import ButtonSpinner from "../../Components/ButtonSpinner" ;
import Button from "../../Components/Button" ;
2024-06-16 20:32:42 -04:00
import "./index.css" ;
import AnnouncementsDualButtonWithIcon from "../../Components/Announcements/AnnouncementsDualButtonWithIcon/AnnouncementsDualButtonWithIcon" ;
2024-06-16 01:32:46 -04:00
const tabList = [ "Profile" , "Password" , "Team" ];
2024-06-16 18:45:21 -04:00
const profileConfig = {
firstName : {
id : "edit-first-name" ,
label : "First name" ,
type : "input" ,
},
lastName : {
id : "edit-last-name" ,
label : "Last name" ,
type : "input" ,
},
email : {
id : "edit-email" ,
label : "Email" ,
description : "After updating, you'll receive a confirmation email." ,
type : "input" ,
},
photo : {
id : "edit-photo" ,
label : "Your photo" ,
description : "This photo will be displayed in your profile page." ,
type : "photo" ,
},
};
2024-06-16 20:32:42 -04:00
const passwordConfig = {
current_password : {
id : "edit-current-password" ,
label : "Current password" ,
type : "input" ,
},
password : {
id : "edit-password" ,
label : "Password" ,
type : "input" ,
},
confirm_password : {
id : "notice-confirm-password" ,
label : "Confirm new password" ,
type : "notice" ,
},
};
2024-06-17 14:26:09 -04:00
const orgConfig = {
name : "Bluewave Labs" ,
isLoading : false ,
isOpen : false ,
newName : "" ,
};
2024-06-17 22:30:35 -04:00
const teamColumns = [
{
id : "checkbox" ,
label : "" ,
sx : { minWidth : "20px" , width : "40px" },
},
{
id : "name" ,
label : "NAME" ,
sx : { fontSize : "12px" },
},
{ id : "email" , label : "EMAIL" , sx : { fontSize : "12px" } },
{ id : "role" , label : "ROLE" , sx : { fontSize : "12px" } },
];
const teamConfig = [
{
id : 0 ,
isChecked : false ,
name : "John Connor" ,
email : "john@domain.com" ,
type : "admin" ,
role : "Administrator" ,
createdAt : "10/4/2022" ,
},
{
id : 1 ,
isChecked : false ,
name : "Adam McFadden" ,
email : "adam@domain.com" ,
type : "member" ,
role : "Member" ,
createdAt : "10/4/2022" ,
},
{
id : 2 ,
isChecked : false ,
name : "Cris Cross" ,
email : "cris@domain.com" ,
type : "member" ,
role : "Member" ,
createdAt : "10/4/2022" ,
},
{
id : 3 ,
isChecked : false ,
name : "Prince" ,
email : "prince@domain.com" ,
type : "member" ,
role : "Member" ,
createdAt : "10/4/2022" ,
},
];
const actionsConfig = [
{
value : "bulk" ,
label : "Bulk actions" ,
},
];
const roleConfig = [
{
value : "role" ,
label : "Change role to" ,
},
];
2024-05-22 17:14:34 -04:00
const Settings = () => {
2024-06-16 01:32:46 -04:00
//(tab) 0 - Profile
//(tab) 1 - Password
//(tab) 2 - Team
const [ tab , setTab ] = useState ( "0" );
const handleTabChange = ( event , newTab ) => {
setTab ( newTab );
};
const theme = useTheme ();
const [ isLoading , setIsLoading ] = useState ( false );
//TODO - implement delete profile picture function
const handleDeletePicture = () => {
setIsLoading ( true );
setTimeout (() => {
setIsLoading ( false );
}, 2000 );
};
2024-06-16 18:12:15 -04:00
//TODO - implement delete profile update function
2024-06-16 01:32:46 -04:00
const handleUpdatePicture = () => {};
2024-06-16 18:12:15 -04:00
const [ isOpen , setIsOpen ] = useState ( false );
//TODO - implement delete account function
2024-06-16 01:32:46 -04:00
const handleDeleteAccount = () => {
setIsLoading ( true );
setTimeout (() => {
setIsLoading ( false );
2024-06-16 18:12:15 -04:00
setIsOpen ( false );
2024-06-16 01:32:46 -04:00
}, 2000 );
};
2024-06-16 20:32:42 -04:00
const handleSaveProfile = () => {
setIsLoading ( true );
setTimeout (() => {
setIsLoading ( false );
setIsOpen ( false );
}, 2000 );
};
const [ showPassword , setShowPassword ] = useState ( false );
2024-06-17 14:26:09 -04:00
const [ orgStates , setOrgStates ] = useState ( orgConfig );
const toggleOrgModal = ( state ) => {
setOrgStates (( prev ) => ({
... prev ,
isOpen : state ,
}));
};
const toggleOrgLoading = ( state ) => {
setOrgStates (( prev ) => ({
... prev ,
isLoading : state ,
}));
};
const handleRenameOrg = () => {
toggleOrgLoading ( true );
setTimeout (() => {
setOrgStates (( prev ) => ({
... prev ,
name : prev . newName !== "" ? prev . newName : prev . name ,
isLoading : false ,
isOpen : false ,
newName : "" ,
}));
}, 2000 );
};
2024-06-17 22:30:35 -04:00
const [ teamStates , setTeamStates ] = useState ( teamConfig );
const handleCellChecked = ( id ) => {
const updatedTeamStates = [... teamStates ];
updatedTeamStates [ id ] = {
... updatedTeamStates [ id ],
isChecked : ! updatedTeamStates [ id ]. isChecked ,
};
setTeamStates ( updatedTeamStates );
};
const handleApplyActionSelect = () => {
setIsLoading ( true );
setTimeout (() => {
setIsLoading ( false );
setIsOpen ( false );
}, 2000 );
};
const handleApplyRoleSelect = () => {
setIsLoading ( true );
setTimeout (() => {
setIsLoading ( false );
setIsOpen ( false );
}, 2000 );
};
2024-06-16 01:32:46 -04:00
return (
< Box
// TODO - need to figure out document sizing
// TODO - breakpoints for responsive design
height = "calc(100vh - 104px)"
minWidth = { theme . spacing ( 55 )}
width = "100vw"
2024-06-16 20:32:42 -04:00
maxWidth = "calc(100vw - 800px)"
2024-06-16 01:32:46 -04:00
mt = { theme . spacing ( 8 )}
pt = { theme . spacing ( 5 )}
px = { theme . spacing ( 10 )}
>
< TabContext value = { tab }>
< Box width = "100%" sx = {{ borderBottom : 1 , borderColor : "divider" }}>
2024-06-16 18:12:15 -04:00
< TabList onChange = { handleTabChange } aria - label = "settings tabs" >
2024-06-16 01:32:46 -04:00
{ tabList . map (( label , index ) => (
< Tab
label = { label }
key = { index }
value = { index . toString ()}
sx = {{
fontSize : "13px" ,
color : theme . palette . secondary . main ,
textTransform : "none" ,
minWidth : "fit-content" ,
paddingLeft : "0" ,
paddingY : "8px" ,
marginRight : "20px" ,
"&:focus" : {
outline : "none" ,
},
}}
/>
))}
</ TabList >
</ Box >
< TabPanel
value = "0"
sx = {{ padding : "0" , marginTop : theme . spacing ( 6.25 ), width : "100%" }}
>
< form className = "edit-profile-form" noValidate spellCheck = "false" >
2024-06-16 18:45:21 -04:00
{ Object . entries ( profileConfig ). map (([ key , field ]) => (
< div className = "edit-profile-form__wrapper" key = { key }>
< Stack
direction = "column"
gap = "8px"
sx = {{ flex : 1 , marginRight : "10px" }}
2024-06-16 01:32:46 -04:00
>
2024-06-17 14:26:09 -04:00
< Typography variant = "h4" component = "h1" >
2024-06-16 18:45:21 -04:00
{ field . label }
</ Typography >
{ field ? (
2024-06-17 14:26:09 -04:00
< Typography variant = "h5" component = "p" >
2024-06-16 18:45:21 -04:00
{ field . description }
</ Typography >
) : (
""
)}
</ Stack >
{ field . type === "input" ? (
< TextField
id = { field . id }
placeholder = { `Enter your ${ field . label . toLowerCase () } ` }
sx = {{
flex : 1 ,
minWidth : theme . spacing ( 30 ),
}}
></ TextField >
) : field . type === "photo" ? (
< Stack direction = "row" alignItems = "center" sx = {{ flex : 1 }}>
{ /* TODO - Use Avatar component instead of @mui */ }
< Avatar
alt = "Remy Sharp"
src = "/static/images/avatar/2.jpg"
className = "icon-button-avatar"
style = {{ width : "64px" , height : "64px" }}
/>
< ButtonSpinner
level = "tertiary"
label = "Delete"
onClick = { handleDeletePicture }
isLoading = { isLoading }
sx = {{
height : "fit-content" ,
fontSize : "13px" ,
"&:focus" : {
outline : "none" ,
},
}}
/>
{ /* TODO - modal popup for update pfp? */ }
< Button
level = "tertiary"
label = "Update"
onClick = { handleUpdatePicture }
sx = {{
height : "fit-content" ,
color : theme . palette . primary . main ,
fontSize : "13px" ,
"&:focus" : {
outline : "none" ,
},
}}
/>
</ Stack >
) : (
""
)}
</ div >
))}
2024-06-16 01:32:46 -04:00
</ form >
2024-06-16 20:32:42 -04:00
< Divider aria - hidden = "true" sx = {{ marginY : theme . spacing ( 6.25 ) }} />
2024-06-16 01:32:46 -04:00
< form className = "delete-profile-form" noValidate spellCheck = "false" >
< div className = "delete-profile-form__wrapper" >
< Stack direction = "column" gap = "15px" >
2024-06-17 14:26:09 -04:00
< Typography variant = "h4" component = "h1" >
2024-06-16 18:12:15 -04:00
Delete account
2024-06-16 01:32:46 -04:00
</ Typography >
2024-06-17 14:26:09 -04:00
< Typography variant = "h5" component = "p" >
2024-06-16 01:32:46 -04:00
Note that deleting your account will remove all data from our
system . This is permanent and non - recoverable .
</ Typography >
< Box sx = {{ mt : theme . spacing ( 1 ) }}>
< Button
level = "error"
2024-06-16 18:12:15 -04:00
label = "Delete account"
onClick = {() => setIsOpen ( true )}
2024-06-16 01:32:46 -04:00
sx = {{
fontSize : "13px" ,
"&:focus" : {
outline : "none" ,
},
}}
/>
</ Box >
</ Stack >
</ div >
</ form >
2024-06-16 20:32:42 -04:00
< Divider
aria - hidden = "true"
width = "0"
sx = {{ marginY : theme . spacing ( 6.25 ) }}
/>
{ /* !!! - All save buttons are tied to the same state */ }
{ /* TODO - Implement Save Profile function */ }
< Stack direction = "row" justifyContent = "flex-end" >
< Box width = "fit-content" >
< ButtonSpinner
level = "primary"
label = "Save"
onClick = { handleSaveProfile }
isLoading = { isLoading }
loadingText = "Saving..."
sx = {{
paddingX : "40px" ,
height : "fit-content" ,
fontSize : "13px" ,
"&:focus" : {
outline : "none" ,
},
}}
/>
</ Box >
</ Stack >
2024-06-16 01:32:46 -04:00
</ TabPanel >
2024-06-16 18:45:21 -04:00
< TabPanel
value = "1"
sx = {{ padding : "0" , marginTop : theme . spacing ( 6.25 ), width : "100%" }}
2024-06-16 20:32:42 -04:00
>
< form className = "edit-password-form" noValidate spellCheck = "false" >
< div className = "edit-password-form__wrapper" >
< AnnouncementsDualButtonWithIcon
icon = {< InfoOutlinedIcon style = {{ fill : "#344054" }} />}
subject = "SSO login"
body = "Since you logged in via SSO, you cannot reset or modify your password."
/>
</ div >
{ Object . entries ( passwordConfig ). map (([ key , field ]) => (
< div className = "edit-password-form__wrapper" key = { key }>
< Stack
direction = "column"
gap = "8px"
sx = {{ flex : 1 , marginRight : "10px" }}
>
2024-06-17 14:26:09 -04:00
< Typography variant = "h4" component = "h1" >
2024-06-16 20:32:42 -04:00
{ field . label }
</ Typography >
</ Stack >
{ /* TODO - Refactor Password Input Component */ }
{ field . type === "input" ? (
< FormControl sx = {{ flex : 1 , minWidth : theme . spacing ( 30 ) }}>
< OutlinedInput
id = { field . id }
value = "RandomPasswordLol"
type = { showPassword ? "text" : "password" }
endAdornment = {
< InputAdornment position = "end" >
< IconButton
aria - label = "toggle password visibility"
onClick = {() => setShowPassword (( show ) => ! show )}
sx = {{
width : "30px" ,
height : "30px" ,
"&:focus" : {
outline : "none" ,
},
}}
>
{ ! showPassword ? (
< VisibilityOff sx = {{ fill : "#98A2B3" }} />
) : (
< Visibility sx = {{ fill : "#98A2B3" }} />
)}
</ IconButton >
</ InputAdornment >
}
></ OutlinedInput >
</ FormControl >
) : field . type === "notice" ? (
< Box sx = {{ flex : 1 , minWidth : theme . spacing ( 30 ) }}>
< AnnouncementsDualButtonWithIcon
icon = {
< WarningAmberOutlinedIcon style = {{ fill : "#f79009" }} />
}
body = "New password must contain at least 8 characters and must have at least one uppercase letter, one number and one symbol."
/>
</ Box >
) : (
""
)}
</ div >
))}
2024-06-17 14:26:09 -04:00
< Divider
aria - hidden = "true"
width = "0"
sx = {{ marginY : theme . spacing ( 6.25 ) }}
/>
{ /* !!! - All save buttons are tied to the same state */ }
{ /* TODO - Implement Save Password function */ }
< Stack direction = "row" justifyContent = "flex-end" >
< Box width = "fit-content" >
< ButtonSpinner
level = "primary"
label = "Save"
onClick = { handleSaveProfile }
isLoading = { isLoading }
loadingText = "Saving..."
sx = {{
paddingX : "40px" ,
height : "fit-content" ,
fontSize : "13px" ,
"&:focus" : {
outline : "none" ,
},
}}
/>
</ Box >
</ Stack >
</ form >
</ TabPanel >
< TabPanel
value = "2"
sx = {{ padding : "0" , marginTop : theme . spacing ( 6.25 ), width : "100%" }}
>
< form className = "edit-team-form" noValidate spellCheck = "false" >
< div className = "edit-team-form__wrapper" >
< Stack
direction = "column"
gap = "8px"
sx = {{ flex : 1 , marginRight : "10px" }}
>
< Typography variant = "h4" component = "h1" >
Organization name
</ Typography >
</ Stack >
< Stack
direction = "row"
justifyContent = "flex-end"
gap = "8px"
sx = {{ flex : 1 }}
>
< ButtonSpinner
level = "tertiary"
label = { ! orgStates . isLoading && orgStates . name }
disabled
onClick = {() => toggleOrgModal ( true )}
isLoading = { orgStates . isLoading }
2024-06-17 22:30:35 -04:00
sx = {{ fontSize : "13px" }}
2024-06-17 14:26:09 -04:00
/>
< Button
level = "primary"
label = "Rename"
2024-06-17 22:30:35 -04:00
sx = {{ paddingX : "30px" , fontSize : "13px" }}
2024-06-17 14:26:09 -04:00
onClick = {() => toggleOrgModal ( true )}
/>
</ Stack >
</ div >
< div className = "edit-team-form__wrapper" >
< Typography variant = "h4" component = "h1" >
Team members
</ Typography >
</ div >
2024-06-17 22:30:35 -04:00
< div className = "edit-team-form__wrapper" >
< Container
disableGutters
sx = {{
border : `1px solid ${ theme . palette . section . borderColor } ` ,
borderRadius : ` ${ theme . shape . borderRadius } px` ,
borderBottom : "none" ,
}}
>
< Stack direction = "row" gap = "40px" p = "20px" >
< Stack direction = "row" gap = "10px" alignItems = "center" >
< Select
id = "select-actions"
value = "bulk"
sx = {{
fontSize : "13px" ,
color : theme . palette . secondary . main ,
}}
inputProps = {{ id : "select-actions-input" }}
>
{ actionsConfig . map (( action ) => (
< MenuItem
value = { action . value }
key = { action . value }
sx = {{ fontSize : "13px" }}
>
{ action . label }
</ MenuItem >
))}
</ Select >
< ButtonSpinner
level = "secondary"
label = "Apply"
onClick = { handleApplyActionSelect }
isLoading = { isLoading }
sx = {{
height : "fit-content" ,
fontSize : "13px" ,
fontWeight : 500 ,
bgcolor : "#fafafa" ,
}}
/>
</ Stack >
< Stack direction = "row" gap = "10px" alignItems = "center" >
< Select
id = "select-role"
value = "role"
sx = {{
fontSize : "13px" ,
color : theme . palette . secondary . main ,
}}
inputProps = {{ id : "select-role-input" }}
>
{ roleConfig . map (( role ) => (
< MenuItem
value = { role . value }
key = { role . value }
sx = {{ fontSize : "13px" }}
>
{ role . label }
</ MenuItem >
))}
</ Select >
< ButtonSpinner
level = "secondary"
label = "Apply"
onClick = { handleApplyRoleSelect }
isLoading = { isLoading }
sx = {{
height : "fit-content" ,
fontSize : "13px" ,
fontWeight : 500 ,
bgcolor : "#fafafa" ,
}}
/>
</ Stack >
</ Stack >
< Table
sx = {{
borderTop : `1px solid ${ theme . palette . section . borderColor } ` ,
}}
>
< TableHead >
< TableRow
sx = {{
bgcolor : "#fafafa" ,
}}
>
{ teamColumns . map (( cell ) => (
< TableCell
key = { cell . id }
sx = {{
... cell . sx ,
color : theme . palette . otherColors . slateGray ,
}}
>
{ cell . label }
</ TableCell >
))}
</ TableRow >
</ TableHead >
< TableBody >
{ teamStates . map (( cell ) => (
< TableRow key = { cell . id }>
< TableCell align = "center" >
< Checkbox
id = { ` ${ cell . id } - ${ cell . name } ` }
checked = { cell . isChecked }
onChange = {() => handleCellChecked ( cell . id )}
inputProps = {{ "aria-label" : "controlled" }}
/>
</ TableCell >
< TableCell >
< Stack direction = "column" >
< Box
sx = {{
color : theme . palette . otherColors . blackish ,
verticalAlign : "top" ,
}}
>
{ cell . name }
</ Box >
< Box > Created at { cell . createdAt }</ Box >
</ Stack >
</ TableCell >
< TableCell >{ cell . email }</ TableCell >
< TableCell >{ cell . role }</ TableCell >
</ TableRow >
))}
</ TableBody >
</ Table >
</ Container >
</ div >
2024-06-17 14:26:09 -04:00
< Divider
aria - hidden = "true"
width = "0"
sx = {{ marginY : theme . spacing ( 6.25 ) }}
/>
{ /* !!! - All save buttons are tied to the same state */ }
{ /* TODO - Implement Save Team function */ }
< Stack direction = "row" justifyContent = "flex-end" >
< Box width = "fit-content" >
< ButtonSpinner
level = "primary"
label = "Save"
onClick = { handleSaveProfile }
isLoading = { isLoading }
loadingText = "Saving..."
sx = {{
paddingX : "40px" ,
height : "fit-content" ,
fontSize : "13px" ,
"&:focus" : {
outline : "none" ,
},
}}
/>
</ Box >
</ Stack >
2024-06-16 20:32:42 -04:00
</ form >
</ TabPanel >
2024-06-16 01:32:46 -04:00
</ TabContext >
2024-06-16 18:12:15 -04:00
{ /* TODO - Update ModalPopup Component with @mui for reusability */ }
{ /* <DualButtonPopupModal
subject="Really delete this account?"
description="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."
esc="Cancel"
save="Delete account"
/> */ }
< Modal
aria - labelledby = "modal-delete-account"
aria - describedby = "delete-account-confirmation"
open = { isOpen }
onClose = {() => setIsOpen ( false )}
disablePortal
>
< Stack
gap = "10px"
sx = {{
position : "absolute" ,
top : "50%" ,
left : "50%" ,
transform : "translate(-50%, -50%)" ,
width : 400 ,
bgcolor : "white" ,
border : "solid 1px #f2f2f2" ,
borderRadius : "4px" ,
boxShadow : 24 ,
p : "30px" ,
"&:focus" : {
outline : "none" ,
},
}}
>
2024-06-17 14:26:09 -04:00
< Typography id = "modal-delete-account" variant = "h4" component = "h1" >
2024-06-16 18:12:15 -04:00
Really delete this account ?
</ Typography >
< Typography
id = "delete-account-confirmation"
2024-06-17 14:26:09 -04:00
variant = "h5"
2024-06-16 18:12:15 -04:00
component = "p"
sx = {{
color : theme . palette . secondary . main ,
fontSize : "13px" ,
}}
>
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 direction = "row" gap = "10px" mt = "10px" justifyContent = "flex-end" >
< Button
level = "tertiary"
label = "Cancel"
onClick = {() => setIsOpen ( false )}
sx = {{ fontSize : "13px" }}
/>
< ButtonSpinner
level = "error"
label = "Delete account"
onClick = { handleDeleteAccount }
isLoading = { isLoading }
sx = {{ fontSize : "13px" }}
/>
</ Stack >
</ Stack >
</ Modal >
2024-06-17 14:26:09 -04:00
< Modal
aria - labelledby = "modal-edit-org-name"
aria - describedby = "edit-organization-name"
open = { orgStates . isOpen }
onClose = {() => toggleOrgModal ( false )}
disablePortal
>
< Stack
gap = "20px"
sx = {{
position : "absolute" ,
top : "50%" ,
left : "50%" ,
transform : "translate(-50%, -50%)" ,
width : 400 ,
bgcolor : "white" ,
border : "solid 1px #f2f2f2" ,
borderRadius : "4px" ,
boxShadow : 24 ,
p : "30px" ,
"&:focus" : {
outline : "none" ,
},
}}
>
< Typography id = "modal-edit-org-name" variant = "h4" component = "h1" >
Rename this organization ?
</ Typography >
< TextField
id = "edit-organization-name"
placeholder = { orgStates . name }
spellCheck = "false"
value = { orgStates . newName }
onChange = {( event ) =>
setOrgStates (( prev ) => ({
... prev ,
newName : event . target . value ,
}))
}
></ TextField >
< Stack direction = "row" gap = "10px" mt = "10px" justifyContent = "flex-end" >
< Button
level = "tertiary"
label = "Cancel"
onClick = {() => toggleOrgModal ( false )}
sx = {{ fontSize : "13px" }}
/>
< ButtonSpinner
level = "primary"
label = "Rename"
onClick = { handleRenameOrg }
isLoading = { orgStates . isLoading }
sx = {{ fontSize : "13px" , paddingX : "30px" }}
/>
</ Stack >
</ Stack >
</ Modal >
2024-06-16 01:32:46 -04:00
</ Box >
);
};
2024-05-22 17:14:34 -04:00
2024-06-16 01:32:46 -04:00
export default Settings ;