@@ -24,6 +24,7 @@ import PlanPanelLeft from '@/components/content/PlanPanelLeft';
2424import ContentToolbar from '@/coral/components/Content/ContentToolbar' ;
2525import { TaskService } from '../services/TaskService' ;
2626import { TeamConfig } from '../models/Team' ;
27+ import { TeamService } from '../services/TeamService' ;
2728
2829/**
2930 * HomePage component - displays task lists and provides navigation
@@ -33,6 +34,39 @@ const HomePage: React.FC = () => {
3334 const navigate = useNavigate ( ) ;
3435 const { dispatchToast } = useToastController ( "toast" ) ;
3536 const [ selectedTeam , setSelectedTeam ] = useState < TeamConfig | null > ( null ) ;
37+ const [ isLoadingTeam , setIsLoadingTeam ] = useState ( true ) ;
38+
39+ /**
40+ * Load teams and set default team on component mount
41+ */
42+ useEffect ( ( ) => {
43+ const loadDefaultTeam = async ( ) => {
44+ setIsLoadingTeam ( true ) ;
45+ try {
46+ const teams = await TeamService . getUserTeams ( ) ;
47+ console . log ( 'All teams loaded:' , teams ) ;
48+ if ( teams . length > 0 ) {
49+ // Always prioritize "Business Operations Team" as default
50+ const businessOpsTeam = teams . find ( team => team . name === "Business Operations Team" ) ;
51+ const defaultTeam = businessOpsTeam || teams [ 0 ] ;
52+ setSelectedTeam ( defaultTeam ) ;
53+ console . log ( 'Default team loaded:' , defaultTeam . name , 'with' , defaultTeam . starting_tasks ?. length || 0 , 'starting tasks' ) ;
54+ console . log ( 'Team logo:' , defaultTeam . logo ) ;
55+ console . log ( 'Team description:' , defaultTeam . description ) ;
56+ console . log ( 'Is Business Operations Team:' , defaultTeam . name === "Business Operations Team" ) ;
57+ } else {
58+ console . log ( 'No teams found - user needs to upload a team configuration' ) ;
59+ // Even if no teams are found, we clear the loading state to show the "no team" message
60+ }
61+ } catch ( error ) {
62+ console . error ( 'Error loading default team:' , error ) ;
63+ } finally {
64+ setIsLoadingTeam ( false ) ;
65+ }
66+ } ;
67+
68+ loadDefaultTeam ( ) ;
69+ } , [ ] ) ;
3670
3771 /**
3872 * Handle new task creation from the "New task" button
@@ -58,6 +92,38 @@ const HomePage: React.FC = () => {
5892 ) ;
5993 } , [ dispatchToast ] ) ;
6094
95+ /**
96+ * Handle team upload completion - refresh team list and keep Business Operations Team as default
97+ */
98+ const handleTeamUpload = useCallback ( async ( ) => {
99+ try {
100+ const teams = await TeamService . getUserTeams ( ) ;
101+ console . log ( 'Teams refreshed after upload:' , teams . length ) ;
102+
103+ if ( teams . length > 0 ) {
104+ // Always keep "Business Operations Team" as default, even after new uploads
105+ const businessOpsTeam = teams . find ( team => team . name === "Business Operations Team" ) ;
106+ const defaultTeam = businessOpsTeam || teams [ 0 ] ;
107+ setSelectedTeam ( defaultTeam ) ;
108+ console . log ( 'Default team after upload:' , defaultTeam . name ) ;
109+ console . log ( 'Business Operations Team remains default' ) ;
110+
111+ // Show a toast notification about the upload success
112+ dispatchToast (
113+ < Toast >
114+ < ToastTitle > Team Uploaded Successfully!</ ToastTitle >
115+ < ToastBody >
116+ Team uploaded. { defaultTeam . name } remains your default team.
117+ </ ToastBody >
118+ </ Toast > ,
119+ { intent : "success" }
120+ ) ;
121+ }
122+ } catch ( error ) {
123+ console . error ( 'Error refreshing teams after upload:' , error ) ;
124+ }
125+ } , [ dispatchToast ] ) ;
126+
61127 /**
62128 * Handle new task creation from input submission
63129 * Creates a plan and navigates to the create plan page
@@ -78,7 +144,13 @@ const HomePage: React.FC = () => {
78144 </ Toast > ,
79145 { intent : "success" }
80146 ) ;
81- navigate ( `/plan/${ response . plan_id } /create` ) ;
147+
148+ // Navigate with team ID if a team is selected
149+ const navPath = selectedTeam
150+ ? `/plan/${ response . plan_id } /create/${ selectedTeam . team_id } `
151+ : `/plan/${ response . plan_id } /create` ;
152+ console . log ( 'Navigating to:' , navPath , 'with team:' , selectedTeam ?. name ) ;
153+ navigate ( navPath ) ;
82154 } else {
83155 dispatchToast (
84156 < Toast >
@@ -115,17 +187,29 @@ const HomePage: React.FC = () => {
115187 < PlanPanelLeft
116188 onNewTaskButton = { handleNewTaskButton }
117189 onTeamSelect = { handleTeamSelect }
190+ onTeamUpload = { handleTeamUpload }
118191 selectedTeam = { selectedTeam }
119192 />
120193 < Content >
121194 < ContentToolbar
122195 panelTitle = { "Multi-Agent Planner" }
123196 > </ ContentToolbar >
124- < HomeInput
125- onInputSubmit = { handleNewTask }
126- onQuickTaskSelect = { handleNewTask }
127- selectedTeam = { selectedTeam }
128- />
197+ { ! isLoadingTeam ? (
198+ < HomeInput
199+ onInputSubmit = { handleNewTask }
200+ onQuickTaskSelect = { handleNewTask }
201+ selectedTeam = { selectedTeam }
202+ />
203+ ) : (
204+ < div style = { {
205+ display : 'flex' ,
206+ justifyContent : 'center' ,
207+ alignItems : 'center' ,
208+ height : '200px'
209+ } } >
210+ < Spinner label = "Loading team configuration..." />
211+ </ div >
212+ ) }
129213 </ Content >
130214
131215 </ CoralShellRow >
0 commit comments