-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Group details page and integrated with the hosted veda-auth-central
- Loading branch information
1 parent
567ea07
commit 009734a
Showing
17 changed files
with
988 additions
and
164 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
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
122 changes: 122 additions & 0 deletions
122
veda-auth-portal/src/components/Groups/AddGroupMemberModal.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,122 @@ | ||
import { | ||
useToast, | ||
Button, Input, Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalFooter, | ||
ModalBody, | ||
ModalCloseButton, FormControl, | ||
FormLabel, | ||
Stack, | ||
Select | ||
} from "@chakra-ui/react"; | ||
import { BACKEND_URL } from "../../lib/constants"; | ||
import axios, { AxiosResponse } from "axios"; | ||
import React from "react"; | ||
import { useAuth } from "react-oidc-context"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
export const AddGroupMemberModal = ({ | ||
groupId, | ||
isOpen, | ||
onClose, | ||
}: { | ||
groupId: string | undefined; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
}) => { | ||
const toast = useToast(); | ||
const [newEmail, setNewEmail] = React.useState(""); | ||
const [newRole, setNewRole] = React.useState("MEMBER"); | ||
const auth = useAuth(); | ||
const navigate = useNavigate(); | ||
|
||
const handleAddMember = async () => { | ||
const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/; | ||
|
||
if (!emailRegex.test(newEmail)) { | ||
toast({ | ||
title: "Invalid email", | ||
status: "error", | ||
duration: 2000, | ||
isClosable: true, | ||
}); | ||
return; | ||
} | ||
|
||
const resp = await axios | ||
.post( | ||
`${BACKEND_URL}/api/v1/group-management/groups/${groupId}/members`, | ||
{ | ||
username: newEmail, | ||
type: newRole, | ||
}, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${auth.user?.access_token}`, | ||
}, | ||
} | ||
) | ||
.catch((error) => { | ||
toast({ | ||
title: "Error adding member", | ||
description: error.response.data.error, | ||
status: "error", | ||
duration: 2000, | ||
isClosable: true, | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
}) as AxiosResponse<any, any>; | ||
|
||
if (resp.status > 199 && resp.status < 300) { | ||
onClose(); | ||
navigate(0); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>Add Member</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<Stack spacing={4}> | ||
<FormControl> | ||
<FormLabel>Email</FormLabel> | ||
<Input | ||
type="email" | ||
placeholder="[email protected]" | ||
value={newEmail} | ||
onChange={(e) => setNewEmail(e.target.value)} | ||
/> | ||
</FormControl> | ||
|
||
<FormControl> | ||
<FormLabel>Role</FormLabel> | ||
<Select | ||
value={newRole} | ||
onChange={(e) => setNewRole(e.target.value)} | ||
> | ||
<option value="MEMBER">Member</option> | ||
<option value="OWNER">Owner</option> | ||
<option value="ADMIN">ADMIN</option> | ||
</Select> | ||
</FormControl> | ||
|
||
<Button colorScheme="blue" onClick={handleAddMember}> | ||
Add | ||
{newEmail && newRole ? ` ${newEmail} as ${newRole}` : ""} | ||
</Button> | ||
</Stack> | ||
</ModalBody> | ||
|
||
<ModalFooter /> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
Oops, something went wrong.