@@ -3,7 +3,9 @@ import Alert from "components/Alert";
33import Button from "components/Button" ;
44import CenteredSpinner from "components/CenteredSpinner/CenteredSpinner" ;
55import { EmailIcon } from "components/Icons" ;
6+ import ProfileIncompleteDialog from "components/ProfileIncompleteDialog/ProfileIncompleteDialog" ;
67import TextBody from "components/TextBody" ;
8+ import useAccountInfo from "features/auth/useAccountInfo" ;
79import { SectionTitle } from "features/communities/CommunityPage" ;
810import { useListDiscussions } from "features/communities/hooks" ;
911import { useTranslation } from "i18n" ;
@@ -62,10 +64,13 @@ export default function DiscussionsListPage({
6264} ) {
6365 const { t } = useTranslation ( [ COMMUNITIES ] ) ;
6466
67+ const { data : accountInfo } = useAccountInfo ( ) ;
6568 const hash = typeof window !== "undefined" ? window . location . hash : "" ;
69+ // Intent to create a post, set by both the #new hash and the "New post" button.
6670 const [ isCreatingNewPost , setIsCreatingNewPost ] = useState (
6771 hash . includes ( "new" ) ,
6872 ) ;
73+
6974 const {
7075 isLoading : isDiscussionsLoading ,
7176 isFetching : isDiscussionsFetching ,
@@ -78,8 +83,22 @@ export default function DiscussionsListPage({
7883 // loading is false when refetched since there's old data in cache already
7984 const isRefetching = ! isDiscussionsLoading && isDiscussionsFetching ;
8085
86+ // Derive form/dialog visibility during render so both entry points share the
87+ // same gate: show the form only once the profile is known to be complete,
88+ // otherwise show the dialog.
89+ const profileIncomplete =
90+ accountInfo !== undefined && ! accountInfo . profileComplete ;
91+ const showCreateForm =
92+ isCreatingNewPost && accountInfo ?. profileComplete === true ;
93+ const profileDialogOpen = isCreatingNewPost && profileIncomplete ;
94+
8195 return (
8296 < >
97+ < ProfileIncompleteDialog
98+ open = { profileDialogOpen }
99+ onClose = { ( ) => setIsCreatingNewPost ( false ) }
100+ attempted_action = "create_discussion"
101+ />
83102 < StyledDiscussionsHeader >
84103 < SectionTitle icon = { < EmailIcon /> } >
85104 { t ( "communities:discussions_title" ) }
@@ -88,7 +107,7 @@ export default function DiscussionsListPage({
88107 { discussionsError && (
89108 < Alert severity = "error" > { discussionsError . message } </ Alert >
90109 ) }
91- < Collapse in = { ! isCreatingNewPost } >
110+ < Collapse in = { ! showCreateForm } >
92111 < StyledNewPostButtonContainer >
93112 < StyledCreateResourceButton
94113 onClick = { ( ) => setIsCreatingNewPost ( true ) }
@@ -98,7 +117,7 @@ export default function DiscussionsListPage({
98117 { isRefetching && < CenteredSpinner /> }
99118 </ StyledNewPostButtonContainer >
100119 </ Collapse >
101- < Collapse in = { isCreatingNewPost } >
120+ < Collapse in = { showCreateForm } >
102121 < CreateDiscussionForm
103122 communityId = { community . communityId }
104123 onCancel = { ( ) => setIsCreatingNewPost ( false ) }
0 commit comments