-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added a modal for sending invitation #406
Merged
MuhammadKhalilzadeh
merged 2 commits into
bluewave-labs:master
from
melpsh:38-Dec-31-inviting-a-new-user
Jan 6, 2025
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
164 changes: 164 additions & 0 deletions
164
Clients/src/presentation/components/Modals/InviteUser/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/** | ||
* A modal component that displays a form for inviting a user. | ||
* | ||
* @component | ||
* @param {InviteUserModalProps} props - The properties for the InviteUserModal component. | ||
* @param {boolean} props.isOpen - A boolean indicating whether the modal is open. | ||
* @param {function} props.setIsOpen - A function to set the modal's open state. | ||
* @param {function} props.onSendInvite - A function to handle sending the invite. | ||
* | ||
* @returns {JSX.Element} The rendered modal component. | ||
* | ||
* @example | ||
* <InviteUserModal isOpen={isOpen} setIsOpen={setIsOpen} onSendInvite={handleSendInvite} /> | ||
*/ | ||
|
||
import { | ||
Button, | ||
MenuItem, | ||
Modal, | ||
Select, | ||
Stack, | ||
TextField, | ||
Typography, | ||
useTheme, | ||
} from "@mui/material"; | ||
import React, { useState } from "react"; | ||
|
||
interface InviteUserModalProps { | ||
isOpen: boolean; | ||
setIsOpen: (isOpen: boolean) => void; | ||
onSendInvite: (email: string, role: string) => void; | ||
} | ||
|
||
const InviteUserModal: React.FC<InviteUserModalProps> = ({ | ||
isOpen, | ||
setIsOpen, | ||
onSendInvite, | ||
}) => { | ||
const theme = useTheme(); | ||
|
||
const [email, setEmail] = useState<string>(""); | ||
const [role, setRole] = useState<string>(""); | ||
|
||
const handleSendInvite = () => { | ||
onSendInvite(email, role); | ||
setIsOpen(false); | ||
}; | ||
|
||
return ( | ||
<Modal open={isOpen} onClose={() => setIsOpen(false)}> | ||
<Stack | ||
gap={theme.spacing(2)} | ||
color={theme.palette.text.secondary} | ||
sx={{ | ||
position: "absolute", | ||
top: "50%", | ||
left: "50%", | ||
transform: "translate(-50%, -50%)", | ||
width: 450, | ||
bgcolor: theme.palette.background.paper, | ||
border: 1, | ||
borderColor: theme.palette.border.dark, | ||
borderRadius: theme.shape.borderRadius, | ||
boxShadow: 24, | ||
p: theme.spacing(4), | ||
padding: theme.spacing(12), | ||
"&:focus": { | ||
outline: "none", | ||
}, | ||
}} | ||
> | ||
<Typography id="modal-invite-user" fontSize={16} fontWeight={600}> | ||
Invite new team member | ||
</Typography> | ||
<Typography | ||
id="invite-user-instructions" | ||
fontSize={13} | ||
textAlign={"justify"} | ||
paddingBottom={theme.spacing(8)} | ||
> | ||
When you add a new team member, they will get access to all monitors. | ||
</Typography> | ||
<TextField | ||
label="Email" | ||
type="email" | ||
fullWidth | ||
variant="outlined" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
required | ||
sx={{ | ||
marginBottom: theme.spacing(4), | ||
}} | ||
/> | ||
<Select | ||
fullWidth | ||
value={role} | ||
onChange={(e) => setRole(e.target.value)} | ||
displayEmpty | ||
sx={{ mt: theme.spacing(2) }} | ||
> | ||
<MenuItem value="" disabled> | ||
Select Role | ||
</MenuItem> | ||
<MenuItem value="administrator">Administrator</MenuItem> | ||
<MenuItem value="reviewer">Reviewer</MenuItem> | ||
<MenuItem value="editor">Editor</MenuItem> | ||
</Select> | ||
<Stack | ||
direction="row" | ||
gap={theme.spacing(4)} | ||
mt={theme.spacing(4)} | ||
justifyContent="flex-end" | ||
paddingBottom={theme.spacing(4)} | ||
> | ||
<Button | ||
disableRipple | ||
disableFocusRipple | ||
disableTouchRipple | ||
variant="text" | ||
color="inherit" | ||
onClick={() => setIsOpen(false)} | ||
sx={{ | ||
width: 100, | ||
textTransform: "capitalize", | ||
fontSize: 13, | ||
borderRadius: "4px", | ||
"&:hover": { | ||
boxShadow: "none", | ||
backgroundColor: "transparent", | ||
}, | ||
}} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
disableRipple | ||
disableFocusRipple | ||
disableTouchRipple | ||
variant="contained" | ||
color="primary" | ||
disabled={!email || !role} | ||
sx={{ | ||
width: 140, | ||
textTransform: "capitalize", | ||
fontSize: 13, | ||
boxShadow: "none", | ||
borderRadius: "4px", | ||
"&:hover": { | ||
boxShadow: "none", | ||
}, | ||
}} | ||
onClick={handleSendInvite} | ||
> | ||
Send Invite | ||
</Button> | ||
</Stack> | ||
</Stack> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default InviteUserModal; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Encapsulate inviteTeamMember logic if it grows.
Right now, logging and setting the modal open is straightforward. If you need more comprehensive logic for error handling or backend calls, consider moving it to a separate function or hooking into a context or service for maintainability.