@@ -170,23 +170,21 @@ export const Reports: React.FC = () => {
170170 const [ sendJobEmail , { isLoading : sendingEmail } ] = useSendJobEmailMutation ( ) ;
171171 const [ createAsset , { isLoading : isCreating } ] = useCreateAssetMutation ( ) ;
172172
173- // Get admin teams (or all teams for godmode users)
173+ // Get teams where user can create reports
174174 const isGodMode = userCompanies . some ( c => c . role === 'godmode_access' ) ;
175- const adminCompanySlugs = isGodMode
176- ? userCompanies . map ( c => c . slug ) // Godmode can access all companies
177- : userCompanies . filter ( c => c . role === 'admin' ) . map ( c => c . slug ) ;
178- const adminTeams = userTeams . filter ( t => adminCompanySlugs . includes ( t . company_slug ) ) ;
179- const canCreateReport = adminTeams . length > 0 ; // Only show button if there are teams available
175+
176+ // Team members can create reports in their teams (backend allows this)
177+ const creatableTeams = userTeams ;
178+ const canCreateReport = creatableTeams . length > 0 ; // Show button if user is in any team
180179
181180 // Debug logging
182181 React . useEffect ( ( ) => {
183182 console . log ( '[Reports] Is god mode:' , isGodMode ) ;
184183 console . log ( '[Reports] User companies:' , userCompanies ) ;
185184 console . log ( '[Reports] User teams:' , userTeams ) ;
186- console . log ( '[Reports] Admin company slugs:' , adminCompanySlugs ) ;
187- console . log ( '[Reports] Admin teams:' , adminTeams ) ;
185+ console . log ( '[Reports] Creatable teams:' , creatableTeams ) ;
188186 console . log ( '[Reports] Can create report:' , canCreateReport ) ;
189- } , [ isGodMode , userCompanies , userTeams , adminCompanySlugs , adminTeams , canCreateReport ] ) ;
187+ } , [ isGodMode , userCompanies , userTeams , creatableTeams , canCreateReport ] ) ;
190188
191189 // Helper to create unique asset ID
192190 const getAssetId = ( asset : typeof availableAssets [ 0 ] ) =>
@@ -350,6 +348,17 @@ export const Reports: React.FC = () => {
350348 } ;
351349
352350 const handleCreateReport = async ( ) => {
351+ // Check if teams exist
352+ if ( creatableTeams . length === 0 ) {
353+ toast ( {
354+ title : 'No teams available' ,
355+ description : 'Please join a team first before creating reports' ,
356+ status : 'error' ,
357+ duration : 5000
358+ } ) ;
359+ return ;
360+ }
361+
353362 // Validation
354363 if ( ! newReport . teamSlug ) {
355364 toast ( {
@@ -395,7 +404,7 @@ export const Reports: React.FC = () => {
395404 }
396405
397406 try {
398- const selectedTeam = adminTeams . find ( t => t . slug === newReport . teamSlug ) ;
407+ const selectedTeam = creatableTeams . find ( ( t ) => t . slug === newReport . teamSlug ) ;
399408 if ( ! selectedTeam ) throw new Error ( 'Team not found' ) ;
400409
401410 await createAsset ( {
@@ -1016,7 +1025,7 @@ export const Reports: React.FC = () => {
10161025 onChange = { ( e ) => setNewReport ( { ...newReport , teamSlug : e . target . value } ) }
10171026 placeholder = "Select team"
10181027 >
1019- { adminTeams . map ( ( team ) => (
1028+ { creatableTeams . map ( ( team ) => (
10201029 < option key = { team . slug } value = { team . slug } >
10211030 { team . name } ({ team . company_name } )
10221031 </ option >
@@ -1034,7 +1043,7 @@ export const Reports: React.FC = () => {
10341043 placeholder = "Use your godmode identity"
10351044 >
10361045 { ( ( ) => {
1037- const selectedTeam = adminTeams . find ( t => t . slug === newReport . teamSlug ) ;
1046+ const selectedTeam = creatableTeams . find ( t => t . slug === newReport . teamSlug ) ;
10381047 const company = userCompanies . find ( c => c . slug === selectedTeam ?. company_slug ) ;
10391048 return company ?. admins ?. map ( ( adminEmail ) => (
10401049 < option key = { adminEmail } value = { adminEmail } >
0 commit comments