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

Added pagination and add/edit/delete item #51

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

kaitlinnleung
Copy link
Contributor

closes #42

getData();
}, [backend, category]);
loadData();
}, [backend, category, currentPageNum, data]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] <react-hooks/exhaustive-deps> reported by reviewdog 🐶
React Hook useEffect has a missing dependency: 'loadInfo'. Either include it or remove the dependency array.

}
};
getData();
}, [isOpen]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] <react-hooks/exhaustive-deps> reported by reviewdog 🐶
React Hook useEffect has a missing dependency: 'data'. Either include it or remove the dependency array. If 'setCategoryData' needs the current value of 'data', you can also switch to useReducer instead of useState and read 'data' in the reducer.

Copy link
Contributor

@srukelman srukelman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work jits. take a look at the requested changes. try to get them done by monday noon.

Comment on lines 60 to 72
// useEffect(() => {
// const getData = async () => {
// try {
// const response = await backend.get(`/value/filter/${category}`);
// setData(response.data);
// console.log(response.data);
// } catch (error) {
// console.error('Error getting donation items:', error);
// setData([]);
// }
// };
// getData();
// }, [backend]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete if unnecessary


return (
<>
<Button onClick={onOpen}>Add Item<AddIcon/></Button>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remember to yarn format

Comment on lines 125 to 126
{/* TODO */}
{/* When we onClick EditIcon, setData(item), and then set isOpen to True to open the modal */}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete comments if you're done with this

);
};

DonationItems.propTypes = {
category: PropTypes.string.isRequired,
category: PropTypes.string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

category should be required unless there is a reason you got rid of this

Comment on lines 40 to 45
await backend.put(`/value/${data["item_id"]}`, {
'itemName': typeData,
'quantityType': weightData,
'price': priceData,
'category': categoryData,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add validation to see if any of these values are empty and don't pass any empty values

});
}
const dataResponse = backend.get(
`/value/?itemsLimit=10&pageNum=${currentPageNum}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this do the get all GET request also. otherwise we have a problem where when you add the 11th item (or like if you have a full page and add another item), it won't be loaded into the tab until the page is reloaded.

Comment on lines +17 to +22
if (isOpen && data) {
setCategoryData(data['category']);
setTypeData(data['item_name']);
setWeightData(data['quantity_type']);
setPriceData(data['price']);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure that the data present isn't the data that was just passed to the post request. otherwise we get a little bug where when you create an item and then click add item, it populates the modal with the data from the last item you made.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe when you call the post request what you can do is call all the set useStates to make the data empty

Comment on lines 92 to 97
const changePage = async () => {
const formResponse = await backend.get(
`/value/?itemsLimit=10&pageNum=${currentPageNum}`,
);
setData(formResponse.data);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure to pass the category to the route (a comment is left on the backend to change the route accordingly) so that it only grabs the corresponding data for the filter

getData();
}, [backend, category]);
loadInfo();
}, [currentPageNum, category]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [eslint] <react-hooks/exhaustive-deps> reported by reviewdog 🐶
React Hook useEffect has a missing dependency: 'loadInfo'. Either include it or remove the dependency array.

@Madhu2244 Madhu2244 merged commit 9d275c8 into main Mar 4, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Donation Items Table - Add Pagination + Add/Edit/Delete Item
5 participants