Skip to content

Commit

Permalink
fix: fix multiple api requests
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinan029 committed Sep 17, 2024
1 parent df46942 commit 34ebc58
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ const CustomerPlanContainer = ({
slug,
activePolicies,
activeSubscriptions,
countOfActivePlans,
countOfAllPlans,
inactivePolicies,
inactiveSubscriptions,
isLoading,
Expand All @@ -33,6 +31,10 @@ const CustomerPlanContainer = ({
<SubscriptionPlanCard key={subscription.uuid} isActive={false} slug={slug} subscription={subscription} />
));

const countOfActivePlans = activeSubscriptions.length + activePolicies.length;
const countOfInactivePlans = inactiveSubscriptions.length + inactivePolicies.length;
const countOfAllPlans = countOfActivePlans + countOfInactivePlans;

return (
<div>
{!isLoading ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const CustomerViewContainer = () => {

useEffect(() => {
fetchData();
}, []);
}, [fetchData]);

const renderPlanContainer = () => {
if (!isLoading && !associatedPlans.isLoading && associatedPlans.countOfAllPlans) {
Expand Down
12 changes: 1 addition & 11 deletions src/Configuration/Customers/data/hooks/useAllAssociatedPlans.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const useAllAssociatedPlans = (enterpriseId) => {
const [activeSubscriptions, setActiveSubscriptions] = useState([]);
const [activePolicies, setActivePolicies] = useState([]);
const [inactivePolicies, setInactivePolicies] = useState([]);
const [countOfActivePlans, setCountOfActivePlans] = useState(0);
const [countOfAllPlans, setCountOfAllPlans] = useState(0);

const fetchData = useCallback(
async () => {
Expand All @@ -39,19 +37,11 @@ const useAllAssociatedPlans = (enterpriseId) => {

useEffect(() => {
fetchData();
if (!isLoading) {
const activePlanCount = activeSubscriptions.length + activePolicies.length;
const inactivePlanCount = inactiveSubscriptions.length + inactivePolicies.length;
setCountOfActivePlans(prev => prev + activePlanCount);
setCountOfAllPlans(prev => prev + activePlanCount + inactivePlanCount);
}
}, [fetchData, isLoading]);
}, [fetchData]);

return {
activePolicies,
activeSubscriptions,
countOfActivePlans,
countOfAllPlans,
inactivePolicies,
inactiveSubscriptions,
isLoading,
Expand Down

0 comments on commit 34ebc58

Please sign in to comment.