From e4f6481e6d78408baed9856c2b1457b663ef9161 Mon Sep 17 00:00:00 2001 From: "Vytautas A." Date: Wed, 11 Dec 2024 18:46:00 -0600 Subject: [PATCH] Fixes --- src/containers/CustomerDashboard.js | 42 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/containers/CustomerDashboard.js b/src/containers/CustomerDashboard.js index e9e2b4a..b088576 100644 --- a/src/containers/CustomerDashboard.js +++ b/src/containers/CustomerDashboard.js @@ -1,4 +1,4 @@ -import React, { useEffect } from "react"; +import React, {useCallback, useEffect} from "react"; import FetchService from "../service/FetchService"; import formatMoney from "../util/formatMoney"; import { Link, Navigate } from "react-router-dom"; @@ -7,45 +7,45 @@ function CustomerDashboard({ currentUser }) { const [offersState, setOffersState] = React.useState([]); const [savedPropertiesState, setSavedPropertiesState] = React.useState([]); - const fetchOffers = () => { + const fetchOffers = useCallback(() => { FetchService.getCustomersOffers(currentUser.accessToken).then((response) => - setOffersState(response.data) + setOffersState(response.data) ); - }; + }, [currentUser.accessToken]); - useEffect(() => { - fetchOffers(); - fetchSavedProperties(); - }, []); + const fetchSavedProperties = useCallback(() => { + FetchService.getSavedProperties(currentUser.accessToken).then((response) => + setSavedPropertiesState(response.data) + ); + }, [currentUser.accessToken]); const cancelOffer = (offerId) => { FetchService.cancelOffer(currentUser.accessToken, offerId).then( - (response) => fetchOffers() - ); - }; - - const fetchSavedProperties = () => { - FetchService.getSavedProperties(currentUser.accessToken).then((response) => - setSavedPropertiesState(response.data) + (response) => fetchOffers() ); }; const turnOnContingent = (offerId) => { FetchService.turnPropertyContingentForCustomer( - currentUser.accessToken, - offerId + currentUser.accessToken, + offerId ) - .then((response) => fetchOffers()) - .catch((error) => console.log(error)); + .then((response) => fetchOffers()) + .catch((error) => console.log(error)); }; const removePropertyFromSavedList = (propertyId) => { FetchService.removePropertyFromSavedList( - currentUser.accessToken, - propertyId + currentUser.accessToken, + propertyId ).then((response) => fetchSavedProperties()); }; + useEffect(() => { + fetchOffers(); + fetchSavedProperties(); + }, [fetchOffers, fetchSavedProperties]); + return (

My Offers