-
Notifications
You must be signed in to change notification settings - Fork 0
Frontend fix #97
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
Frontend fix #97
Changes from all commits
f7b4283
2170ada
0e10250
4177fb9
ee458ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ export default function ExpansesDashboard({ trip }: { trip: Group }) { | |
|
|
||
| useEffect(() => { | ||
| fetchGroupExpenses(); | ||
| }, []); | ||
| }, [trip]); | ||
|
Comment on lines
35
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To fully align with React best practices, wrap const fetchGroupExpenses = useCallback(async () => {
// ... function body
}, [trip]);
useEffect(() => {
fetchGroupExpenses();
}, [fetchGroupExpenses]);Style Guide ReferencesFootnotes |
||
|
|
||
| if (error) { | ||
| return ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,4 +20,19 @@ axiosInstance.interceptors.request.use( | |||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| axiosInstance.interceptors.response.use( | ||||||||||||||||||||||||||||
| (response) => response, | ||||||||||||||||||||||||||||
| (error) => { | ||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||
| error.response && | ||||||||||||||||||||||||||||
| (error.response.status === 403 || error.response.status === 409) | ||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||
| if (typeof window !== 'undefined') { | ||||||||||||||||||||||||||||
| window.location.href = '/trips'; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+26
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code-quality): Merge nested if conditions (
Suggested change
ExplanationReading deeply nested conditional code is confusing, since you have to keep track of whichconditions relate to which levels. We therefore strive to reduce nesting where possible, and the situation where two if conditions can be combined usingand is an easy win.
|
||||||||||||||||||||||||||||
| return Promise.reject(error); | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The global response interceptor redirects users to axiosInstance.interceptors.response.use(
(response) => response,
(error) => {
if (error.response && error.response.status === 403) {
if (typeof window !== 'undefined') {
window.location.href = '/trips';
}
}
return Promise.reject(error);
},
);Style Guide ReferencesFootnotes |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| export default axiosInstance; | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To adhere to React best practices and prevent potential issues with stale closures, wrap the
fetchDatafunction inuseCallbackand include it in the dependency array.1Style Guide References
Footnotes
Using useCallback ensures that the function instance is stable across renders unless its dependencies change, preventing unnecessary re-renders and potential issues with stale closures. (link) ↩