|
|
@@ -44,7 +44,7 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
|
|
|
|
|
|
useEffect(() => {
|
|
|
api
|
|
|
- .getAvailableRoles("<token>", {}, { project_id: currentProject.id })
|
|
|
+ .getAvailableRoles("<token>", {}, { project_id: currentProject?.id })
|
|
|
.then(({ data }: { data: string[] }) => {
|
|
|
const availableRoleList = data?.map((role) => ({
|
|
|
value: role,
|
|
|
@@ -69,7 +69,7 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
|
|
|
"<token>",
|
|
|
{},
|
|
|
{
|
|
|
- id: currentProject.id,
|
|
|
+ id: currentProject?.id,
|
|
|
}
|
|
|
);
|
|
|
invites = response.data.filter((i: InviteType) => !i.accepted);
|
|
|
@@ -82,7 +82,7 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
|
|
|
"<token>",
|
|
|
{},
|
|
|
{
|
|
|
- project_id: currentProject.id,
|
|
|
+ project_id: currentProject?.id,
|
|
|
}
|
|
|
);
|
|
|
collaborators = parseCollaboratorsResponse(response.data);
|
|
|
@@ -96,24 +96,25 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
|
|
|
const parseCollaboratorsResponse = (
|
|
|
collaborators: Array<Collaborator>
|
|
|
): Array<InviteType> => {
|
|
|
- return (
|
|
|
- collaborators
|
|
|
- // Parse role id to number
|
|
|
- .map((c) => ({ ...c, id: Number(c.id) }))
|
|
|
- // Sort them so the owner will be first allways
|
|
|
- .sort((curr, prev) => curr.id - prev.id)
|
|
|
- // Remove the owner from list
|
|
|
- .slice(1)
|
|
|
- // Parse the remainings to InviteType
|
|
|
- .map((c) => ({
|
|
|
- email: c.email,
|
|
|
- expired: false,
|
|
|
- id: Number(c.user_id),
|
|
|
- kind: c.kind,
|
|
|
- accepted: true,
|
|
|
- token: "",
|
|
|
- }))
|
|
|
- );
|
|
|
+ const admins = collaborators
|
|
|
+ .filter((c) => c.kind === "admin")
|
|
|
+ .map((c) => ({ ...c, id: Number(c.id) }))
|
|
|
+ .sort((curr, prev) => curr.id - prev.id)
|
|
|
+ .slice(1);
|
|
|
+
|
|
|
+ const nonAdmins = collaborators
|
|
|
+ .filter((c) => c.kind !== "admin")
|
|
|
+ .map((c) => ({ ...c, id: Number(c.id) }))
|
|
|
+ .sort((curr, prev) => curr.id - prev.id);
|
|
|
+
|
|
|
+ return [...admins, ...nonAdmins].map((c) => ({
|
|
|
+ email: c.email,
|
|
|
+ expired: false,
|
|
|
+ id: Number(c.user_id),
|
|
|
+ kind: c.kind,
|
|
|
+ accepted: true,
|
|
|
+ token: "",
|
|
|
+ }));
|
|
|
};
|
|
|
|
|
|
const createInvite = () => {
|
|
|
@@ -333,6 +334,10 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
|
|
|
}/invites/${token}
|
|
|
`;
|
|
|
|
|
|
+ if (!user) {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
const mappedInviteList = inviteList.map(
|
|
|
({ accepted, expired, token, ...rest }) => {
|
|
|
const currentUser: boolean = user.email === rest.email;
|