Przeglądaj źródła

Added null safe conditions to prevent crash on Invite list

jnfrati 4 lat temu
rodzic
commit
c8a4957bec

+ 7 - 3
dashboard/src/main/home/project-settings/InviteList.tsx

@@ -44,7 +44,7 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
 
 
   useEffect(() => {
   useEffect(() => {
     api
     api
-      .getAvailableRoles("<token>", {}, { project_id: currentProject.id })
+      .getAvailableRoles("<token>", {}, { project_id: currentProject?.id })
       .then(({ data }: { data: string[] }) => {
       .then(({ data }: { data: string[] }) => {
         const availableRoleList = data?.map((role) => ({
         const availableRoleList = data?.map((role) => ({
           value: role,
           value: role,
@@ -69,7 +69,7 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
         "<token>",
         "<token>",
         {},
         {},
         {
         {
-          id: currentProject.id,
+          id: currentProject?.id,
         }
         }
       );
       );
       invites = response.data.filter((i: InviteType) => !i.accepted);
       invites = response.data.filter((i: InviteType) => !i.accepted);
@@ -82,7 +82,7 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
         "<token>",
         "<token>",
         {},
         {},
         {
         {
-          project_id: currentProject.id,
+          project_id: currentProject?.id,
         }
         }
       );
       );
       collaborators = parseCollaboratorsResponse(response.data);
       collaborators = parseCollaboratorsResponse(response.data);
@@ -334,6 +334,10 @@ const InvitePage: React.FunctionComponent<Props> = ({}) => {
     }/invites/${token}
     }/invites/${token}
     `;
     `;
 
 
+    if (!user) {
+      return [];
+    }
+
     const mappedInviteList = inviteList.map(
     const mappedInviteList = inviteList.map(
       ({ accepted, expired, token, ...rest }) => {
       ({ accepted, expired, token, ...rest }) => {
         const currentUser: boolean = user.email === rest.email;
         const currentUser: boolean = user.email === rest.email;