Browse Source

fix(issues): Share modal group could be undefined (#40657)

Scott Cooper 2 years ago
parent
commit
43e5feb548
1 changed files with 12 additions and 12 deletions
  1. 12 12
      static/app/views/organizationGroupDetails/actions/shareModal.tsx

+ 12 - 12
static/app/views/organizationGroupDetails/actions/shareModal.tsx

@@ -40,16 +40,8 @@ function ShareIssueModal({
   const [loading, setLoading] = useState(false);
   const urlRef = useRef<UrlRef>(null);
   const groups = useLegacyStore(GroupStore);
-  const group = (groups as Group[]).find(item => item.id === groupId)!;
-  const isShared = group.isPublic;
-
-  function getShareUrl() {
-    const path = `/share/issue/${group.shareId}/`;
-    const {host, protocol} = window.location;
-    return `${protocol}//${host}${path}`;
-  }
-
-  const shareUrl = group.shareId ? getShareUrl() : null;
+  const group = (groups as Group[]).find(item => item.id === groupId);
+  const isShared = group?.isPublic;
 
   const handleShare = useCallback(
     (e: React.MouseEvent<HTMLButtonElement> | null, reshare?: boolean) => {
@@ -92,6 +84,14 @@ function ShareIssueModal({
     // eslint-disable-next-line react-hooks/exhaustive-deps -- we only want to run this on open
   }, []);
 
+  function getShareUrl() {
+    const path = `/share/issue/${group!.shareId}/`;
+    const {host, protocol} = window.location;
+    return `${protocol}//${host}${path}`;
+  }
+
+  const shareUrl = group?.shareId ? getShareUrl() : null;
+
   return (
     <Fragment>
       <Header closeButton>
@@ -112,13 +112,13 @@ function ShareIssueModal({
             />
           </SwitchWrapper>
 
-          {loading && (
+          {(!group || loading) && (
             <LoadingContainer>
               <LoadingIndicator mini />
             </LoadingContainer>
           )}
 
-          {!loading && isShared && shareUrl && (
+          {group && !loading && isShared && shareUrl && (
             <UrlContainer>
               <TextContainer>
                 <StyledAutoSelectText ref={urlRef}>{shareUrl}</StyledAutoSelectText>