Skip to content

Commit fc938cd

Browse files
Fix: Update team restoration logic to use backend-fresh object and improve error handling for team uploads
1 parent 6a1e779 commit fc938cd

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/App/src/pages/HomePage.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ const HomePage: React.FC = () => {
4141
// Check if we have a stored team and if it still exists in the backend
4242
const storedTeam = TeamService.getStoredTeam();
4343
if (storedTeam) {
44-
const existsInBackend = teams.some(t => t.team_id === storedTeam.team_id);
45-
if (existsInBackend) {
46-
// Stored team still exists, use it
47-
dispatch(setSelectedTeam(storedTeam));
48-
showToast(`${storedTeam.name} team restored from storage`, 'success');
44+
const backendTeam = teams.find(t => t.team_id === storedTeam.team_id);
45+
if (backendTeam) {
46+
// Stored team still exists, use backend-fresh object
47+
dispatch(setSelectedTeam(backendTeam));
48+
showToast(`${backendTeam.name} team restored from storage`, 'success');
4949
dispatch(setIsLoadingTeam(false));
5050
return;
5151
} else {
5252
// Stored team was deleted, clear localStorage
5353
console.warn(`Stored team ${storedTeam.team_id} no longer exists, clearing storage`);
54-
// Don't call storageTeam with null, just let init response guide us
54+
TeamService.clearStoredTeam();
5555
}
5656
}
5757

@@ -143,7 +143,7 @@ const HomePage: React.FC = () => {
143143
[dispatch, showToast],
144144
);
145145

146-
const handleTeamUpload = useCallback(async (uploadedTeam?: any) => {
146+
const handleTeamUpload = useCallback(async (uploadedTeam?: TeamConfig) => {
147147
try {
148148
console.log('handleTeamUpload called with:', uploadedTeam);
149149
if (uploadedTeam) {
@@ -167,7 +167,7 @@ const HomePage: React.FC = () => {
167167
}
168168
} catch (error) {
169169
console.error('Team upload failed:', error);
170-
showToast('Team upload completed', 'success');
170+
showToast('Team upload failed. Please try again.', 'warning');
171171
}
172172
}, [dispatch, showToast]);
173173

src/App/src/store/TeamService.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ export class TeamService {
7373
}
7474
}
7575

76+
static clearStoredTeam(): boolean {
77+
// Remove persisted team from localStorage
78+
if (typeof window === 'undefined' || !window.localStorage) return false;
79+
try {
80+
window.localStorage.removeItem(TeamService.STORAGE_KEY);
81+
return true;
82+
} catch {
83+
return false;
84+
}
85+
}
86+
7687
static async uploadCustomTeam(teamFile: File): Promise<{
7788
modelError?: any; success: boolean; team?: TeamConfig; error?: string; raiError?: any; searchError?: any
7889
}> {

0 commit comments

Comments
 (0)