Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Hardcoded Branch ID in UseBranchService with Dynamic Data from Manager #47

Open
TheTharz opened this issue May 30, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@TheTharz
Copy link
Member

Title: Replace Hardcoded Branch ID in UseBranchService with Dynamic Data from Manager

Description:
The UseBranchService currently uses a hardcoded branchID value of 3. To improve flexibility and maintainability, we need to replace this hardcoded value with dynamic data fetched from the manager's details.

File:
src/path/to/UseBranchService.ts

Current Code:

import { useState } from 'react';
import useAxiosInstance from '../../login/services/useAxiosInstance';
import { IBranchData } from '../interfaces/IBranchData';
import { useUserContext } from '../../../context/UserContext';
import { toast } from 'react-toastify';

const UseBranchService = () => {
  const http = useAxiosInstance();
  const [branchData, setBranchData] = useState<IBranchData>();
  const { user } = useUserContext(); //dont remove this from code because this is for the branch id
  const branchID = 3; //replace this with actual id
  const [loading, setLoading] = useState<boolean>(false);

  const fetchBranchData = async () => {
    try {
      setLoading(true);
      const res = await http.get(`/branch-summary/sales-summary/${branchID}`);
      console.log(res);
      const { data } = res;
      setBranchData(data.data);
    } catch (error) {
      toast.error('Unable to fetch details');
      console.log(error);
    } finally {
      setLoading(false);
    }
  };

  return {
    fetchBranchData,
    branchData,
  };
};

export default UseBranchService;

Proposed Change:

  • Fetch the branch ID dynamically from the manager's data and use it in the API call.

Steps:

  1. Retrieve the branch ID from the manager's details available in the useUserContext.
  2. Replace the hardcoded branchID with the dynamically fetched value.

Expected Behavior:
The UseBranchService should use the branch ID associated with the logged-in manager, making the service more flexible and aligned with actual data.

Additional Context:
If there are any changes required in the context or other parts of the application to support this dynamic fetching, please include them in this issue.

Labels:

  • enhancement
  • backend
  • frontend
@TheTharz TheTharz added the bug Something isn't working label May 30, 2024
@TheTharz TheTharz self-assigned this May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

1 participant