To maintain consistency across the codebase, follow these import path conventions:
-
Types: Use
#types/...for all type importsimport { SheetMetaData } from "#types/sheet"; import { ApiResponse } from "#types/api";
-
Components: Use
@components/...for component imports (without the leading slash)import AlbumCard from "@components/basic/AlbumCard";
-
Pages: Use
@pages/...for page imports (without the leading slash)import HomePage from "@pages/Home";
-
Stores/Redux: Use
@stores/...for store imports (without the leading slash)import { RootState } from "@stores/store"; import { setToken } from "@stores/authSlice";
-
Utilities: Use
@utils/...for utility imports (without the leading slash)import { fetchApi } from "@utils/api";
The backend API now returns responses with a standardized structure that includes a .data property. All API responses follow this format:
interface ApiResponse<T> {
success: boolean;
data?: T;
error?: string;
message?: string;
}We've added utility functions to handle this new structure. Use the fetchApi function for all API calls:
import { fetchApi } from "@utils/api";
// Example usage:
const data = await fetchApi<YourDataType>("your-api-endpoint");The fetchApi function will:
- Make the API request
- Check if the response was successful
- Extract the data from the
.dataproperty - Handle errors appropriately
- All direct
fetchcalls to backend API endpoints should be replaced withfetchApi - The response data is now accessed directly without needing to check
.datain your components - Error handling is built into the utility function
For any questions or issues, please contact the development team.