From cc6605168858ae819601caed0c00e2a919d9fabb Mon Sep 17 00:00:00 2001 From: theknowledgepro Date: Thu, 30 Mar 2023 03:10:16 +0100 Subject: [PATCH] Important Changes --- src/pages/Dashboard/Dashboard.js | 4 ++-- src/pages/Dashboard/history_.js | 12 ++++++----- src/pages/Dashboard/recent.js | 24 ++++++++++------------ src/store/alerts.js | 35 +++++++++++++------------------- 4 files changed, 34 insertions(+), 41 deletions(-) diff --git a/src/pages/Dashboard/Dashboard.js b/src/pages/Dashboard/Dashboard.js index 5a56067..f05d0d5 100644 --- a/src/pages/Dashboard/Dashboard.js +++ b/src/pages/Dashboard/Dashboard.js @@ -54,7 +54,7 @@ const Dashboard = () => { getData(); }, 60000); return () => clearInterval(interval); - }, [dispatch]); + }, []); return ( {/** DASHBOARD SIDEPANEL SECTION */} @@ -208,7 +208,7 @@ const Dashboard = () => { boxShadow="1px 1px 2px 0 rgba(42, 141, 0, 0.3)" > - Recent Collections + {!pathname.includes("history") ? 'Recent Collections' : 'Your Collections History'} diff --git a/src/pages/Dashboard/history_.js b/src/pages/Dashboard/history_.js index 339cbb6..d9db6cd 100644 --- a/src/pages/Dashboard/history_.js +++ b/src/pages/Dashboard/history_.js @@ -76,7 +76,7 @@ export default function Recent() { }, [data, token]); useEffect(() => { fetchAndUpdateData(); - }, [fetchAndUpdateData]); + }, [items]); return ( <> @@ -105,7 +105,7 @@ export default function Recent() { - {newData?.map((item, index) => { + {newData?.reverse()?.map((item, index) => { return ( {index + 1} @@ -117,12 +117,13 @@ export default function Recent() { onOpen(); setWastepic({ image: item.images[0], - Text: item.address, + address: item.address, + description: item.description, amount: item.quantity, }); }} > - + {item.Fullname} @@ -168,7 +169,8 @@ export default function Recent() { waste Picture - Address: {Wastepic.Text} + Address: {Wastepic.address} + Alert Description: {Wastepic.description} Amount in Kg: {Wastepic.amount}kg diff --git a/src/pages/Dashboard/recent.js b/src/pages/Dashboard/recent.js index 8065bc4..42896e9 100644 --- a/src/pages/Dashboard/recent.js +++ b/src/pages/Dashboard/recent.js @@ -41,12 +41,6 @@ export default function Recent() { }); const token = setToken(); const [newData, SetnewData] = useState([]); - const OverlayOne = () => ( - - ); const { isOpen, onOpen, onClose } = useDisclosure(); const [Wastepic, setWastepic] = useState({}); @@ -75,10 +69,12 @@ export default function Recent() { }); const newdata = await Promise.all(promises); SetnewData(newdata); - }, [data, token]); + }, [items, data, token]); + useEffect(() => { fetchAndUpdateData(); - }, [fetchAndUpdateData]); + }, [items]); + return ( <> {" "} @@ -106,7 +102,7 @@ export default function Recent() { - {newData?.map((item, index) => { + {newData?.reverse()?.map((item, index) => { return ( {index + 1} @@ -118,13 +114,14 @@ export default function Recent() { onOpen(); setWastepic({ image: item.images[0], - Text: item.address, + address: item.address, + description:item.description, amount: item.quantity, }); }} > - - {item.Fullname} + + {item.Fullname} @@ -172,7 +169,8 @@ export default function Recent() { waste Picture - Address: {Wastepic.Text} + Address: {Wastepic.address} + Alert Description: {Wastepic.description} Amount in Kg: {Wastepic.amount}kg diff --git a/src/store/alerts.js b/src/store/alerts.js index 5b1f280..446f418 100644 --- a/src/store/alerts.js +++ b/src/store/alerts.js @@ -13,16 +13,12 @@ const Alertdata = createSlice({ initialState: initialState, reducers: { AcceptingUpdate(state) { - state.Accepted = state.items - .filter((item) => { - return item.status === "accepted" && item.collectorId === state.user; - }) - .reduce((initial, item) => { - if (item.status === "accepted") { - return initial + 1; - } - return initial; - }, 0); + state.Accepted = state.items.reduce((initial, item) => { + if (item.status === "accepted" && item.collectorId === state.user) { + return initial + 1; + } + return initial; + }, 0); }, pendingUpdate(state) { state.pending = state.items.reduce((initial, item) => { @@ -33,16 +29,12 @@ const Alertdata = createSlice({ }, 0); }, completedUpdate(state) { - state.completed = state.items - .filter((item) => { - return item.status === "collected" && item.collectorId === state.user; - }) - .reduce((initial, item) => { - if (item.status === "collected") { - return initial + 1; - } - return initial; - }, 0); + state.completed = state.items.reduce((initial, item) => { + if (item.status === "collected" && item.collectorId === state.user) { + return initial + 1; + } + return initial; + }, 0); }, update(state) { Alertdata.caseReducers.completedUpdate(state); @@ -52,9 +44,9 @@ const Alertdata = createSlice({ accepted(state, action) { const actions = action.payload; const pending = state.items.find((item) => item._id === actions.id); - console.log(state.items); if (pending?.status === "pending") { pending.status = "accepted"; + pending.collectorId = state.user; Alertdata.caseReducers.update(state); } }, @@ -71,6 +63,7 @@ const Alertdata = createSlice({ const pending = state.items.find((item) => item._id === actions.id); if (pending?.status === "accepted") { pending.status = "collected"; + pending.collectorId = state.user; pending.updatedAt = new Date().toISOString(); Alertdata.caseReducers.update(state); }