1- import React , { useEffect } from 'react'
1+ import React , { ReactNode , useEffect } from 'react'
22import PageTitle from 'components/PageTitle'
33import Tabs from 'components/navigation/TabMenu/Tabs'
44import TabItem from 'components/navigation/TabMenu/TabItem'
@@ -16,10 +16,19 @@ import { PermissionsTab } from './tabs/PermissionsTab'
1616import { CustomFieldsTab } from './tabs/CustomFieldsTab'
1717import { ImportTab } from './tabs/ImportTab'
1818
19+ type ProjectSettingsTab = {
20+ component : ReactNode
21+ isVisible : boolean
22+ key : string
23+ label : ReactNode
24+ labelString ?: string
25+ }
26+
1927const ProjectSettingsPage = ( ) => {
2028 const { environmentId, projectId } = useRouteContext ( )
2129 const {
2230 data : project ,
31+ error,
2332 isLoading,
2433 isUninitialized,
2534 } = useGetProjectQuery ( { id : String ( projectId ) } , { skip : ! projectId } )
@@ -28,7 +37,6 @@ const ProjectSettingsPage = () => {
2837 API . trackPage ( Constants . pages . PROJECT_SETTINGS )
2938 } , [ ] )
3039
31- // Show loader only on initial load (not during refetches from mutations)
3240 const isInitialLoading = isUninitialized || ( isLoading && ! project )
3341
3442 if ( isInitialLoading ) {
@@ -42,24 +50,23 @@ const ProjectSettingsPage = () => {
4250 )
4351 }
4452
45- const hasEnvironments = ! ! project ?. environments ?. length
46- const hasFeatureHealth = Utils . getFlagsmithHasFeature ( 'feature_health' )
47-
48- // Derive organisationId from project data (not available in route params)
49- const organisationId = project ?. organisation
50-
51- if ( ! project || ! projectId || ! organisationId ) {
53+ if ( error || ! project || ! projectId || ! project ?. organisation ) {
5254 return (
5355 < div className = 'app-container container' >
5456 < PageTitle title = 'Project Settings' />
55- < div className = 'text-center' >
56- < Loader />
57+ < div className = 'alert alert-danger mt-4 text-center' >
58+ Failed to load project settings. Please try again.
5759 </ div >
5860 </ div >
5961 )
6062 }
6163
62- const tabs = [
64+ // Derive data from project after all early returns
65+ const hasEnvironments = ! ! project . environments ?. length
66+ const hasFeatureHealth = Utils . getFlagsmithHasFeature ( 'feature_health' )
67+ const organisationId = project . organisation
68+
69+ const tabs : ProjectSettingsTab [ ] = [
6370 {
6471 component : < GeneralTab project = { project } environmentId = { environmentId } /> ,
6572 isVisible : true ,
@@ -122,25 +129,22 @@ const ProjectSettingsPage = () => {
122129 key : 'export' ,
123130 label : 'Export' ,
124131 } ,
125- ]
132+ ] . filter ( ( { isVisible } ) => isVisible )
126133
127134 return (
128135 < div className = 'app-container container' >
129136 < PageTitle title = 'Project Settings' />
130137 < Tabs urlParam = 'tab' className = 'mt-0' uncontrolled >
131- { tabs . map (
132- ( { component, isVisible, key, label, labelString } ) =>
133- isVisible && (
134- < TabItem
135- key = { key }
136- tabLabel = { label }
137- data-test = { key }
138- tabLabelString = { labelString }
139- >
140- { component }
141- </ TabItem >
142- ) ,
143- ) }
138+ { tabs . map ( ( { component, key, label, labelString } ) => (
139+ < TabItem
140+ key = { key }
141+ tabLabel = { label }
142+ data-test = { key }
143+ tabLabelString = { labelString }
144+ >
145+ { component }
146+ </ TabItem >
147+ ) ) }
144148 </ Tabs >
145149 </ div >
146150 )
0 commit comments