Alina-Khmilevska / UPSA-React

This repository contains the source code for the UPSA Pharmaceutical Organization's website, developed using the React library.
1 stars 0 forks source link

Setting up API Service via Redux for Data Retrieval from Backend #3

Closed Alina-Khmilevska closed 10 months ago

Alina-Khmilevska commented 10 months ago

We need to implement an API service that will execute requests to the backend to retrieve data. Ensure this service's integration with Redux to manage the app state.

Steps:

Acceptance Criteria:

Notes:

Alina-Khmilevska commented 10 months ago

The Redux setup for API service integration is now complete, providing a robust and maintainable solution for data retrieval from the Drupal backend. This structure ensures scalability and ease of maintenance as the application grows and evolves.

Actions Taken:

  1. Redux Store Setup: Initialized a Redux store with middleware and DevTools integration for an enhanced development experience.
  2. Action Creators: Created asynchronous actions to handle API calls, with separate actions for request initiation, success, and failure to cleanly manage the different states of an API call.
  3. Redux Thunk: Utilized Redux Thunk to write action creators that return a function instead of an action, allowing for delayed actions and conditional dispatching.
  4. Custom Hook (useDataFetcher): Developed a reusable custom hook to abstract the data fetching logic, making it easier to reuse this functionality across different components.
  5. Environment Variables: Configured the use of environment variables to manage the API URLs, ensuring that the API base path can be easily changed without code modifications.
  6. Error and Loading UI: Implemented a common component to display loading and error states, improving the user experience and reducing repetitive code.
  7. Separation of Concerns: Encapsulated API endpoints into a separate file for better maintainability and to avoid hardcoding URLs in action creators.
  8. Documentation: Added comprehensive inline comments throughout the codebase to explain the functionality and usage of various parts of the Redux setup.