feat(project-drawer): enhance project data fetching and error handling

- Updated project data fetching logic in the project drawer and related components to ensure the drawer opens only after successful data retrieval.
- Added detailed logging for successful and failed fetch attempts to improve debugging and user feedback.
- Introduced error handling to maintain user experience by allowing the drawer to open even if data fetching fails, displaying an error state.
- Refactored project list and project view components to optimize search functionality and improve loading states.
- Removed deprecated components related to task management to streamline the project view.
This commit is contained in:
chamikaJ
2025-07-07 17:07:45 +05:30
parent 978d9158c0
commit b0253135e5
12 changed files with 450 additions and 984 deletions

View File

@@ -20,10 +20,31 @@ export const fetchProjectData = createAsyncThunk(
'project/fetchProjectData',
async (projectId: string, { rejectWithValue, dispatch }) => {
try {
if (!projectId) {
throw new Error('Project ID is required');
}
console.log(`Fetching project data for ID: ${projectId}`);
const response = await projectsApiService.getProject(projectId);
if (!response) {
throw new Error('No response received from API');
}
if (!response.done) {
throw new Error(response.message || 'API request failed');
}
if (!response.body) {
throw new Error('No project data in response body');
}
console.log(`Successfully fetched project data:`, response.body);
return response.body;
} catch (error) {
return rejectWithValue(error instanceof Error ? error.message : 'Failed to fetch project');
const errorMessage = error instanceof Error ? error.message : 'Failed to fetch project';
console.error(`Error fetching project data for ID ${projectId}:`, error);
return rejectWithValue(errorMessage);
}
}
);
@@ -44,16 +65,21 @@ const projectDrawerSlice = createSlice({
},
extraReducers: builder => {
builder
.addCase(fetchProjectData.pending, state => {
console.log('Starting project data fetch...');
state.projectLoading = true;
state.project = null; // Clear existing data while loading
})
.addCase(fetchProjectData.fulfilled, (state, action) => {
console.log('Project data fetch completed successfully:', action.payload);
state.project = action.payload;
state.projectLoading = false;
})
.addCase(fetchProjectData.rejected, state => {
.addCase(fetchProjectData.rejected, (state, action) => {
console.error('Project data fetch failed:', action.payload);
state.projectLoading = false;
state.project = null;
// You could add an error field to the state if needed for UI feedback
});
},
});