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

feat: add allowance modal #36

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

alangsto
Copy link
Member

@alangsto alangsto commented Jul 31, 2024

COSMO-393

This PR adds a modal component that users may interact with to add allowances for specified users.

Default view:
Screenshot 2024-08-01 at 8 07 34 AM

Error view:
Screenshot 2024-08-01 at 8 07 47 AM

setForm(prev => ({ ...prev, 'exam-type': defaultExamType }));
handleExamTypeChange();
}
}, [examsList]); // eslint-disable-line react-hooks/exhaustive-deps
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm struggling to test this component because it seems like the useEffect isn't running when I render the component in a test. If I take this code out of the useEffect, it causes too many renders. Any suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

Nothing stands out to me about the hook that would cause it not to run. Have you confirmed that it's not running, or is it running and not doing anything? Maybe there's an issue with your set up (e.g. examsList is empty)?

However, my initial thought is that this doesn't need to be in a useEffect hook, based on You Might Not Need an Effect. When you say "it causes too many renders" when you move it out of the useEffect hook, what do you mean by that?

If necessary, you could use the useMemo hook to memoize the results of the computation to avoid recomputing it unless examsList changes, but you'd have to refactor your hook a little to return something that can be memoized (e.g. the proctoredExams and timedExams variables).

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

If I run tests when this code is outside of a hook, the tests fail because of too many re-renders. The line that's specifically causing too many rerenders is setForm(prev => ({ ...prev, 'exam-type': defaultExamType }));. If I comment that line out, the tests pass.

Copy link
Member

Choose a reason for hiding this comment

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

I'll pull down your code and take a look. I'll follow up soon.

additionalTime = form['additional-time-minutes'];
}

const userKey = user.includes('@') ? 'email' : 'username';
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if I should include a more strict check for email vs username.

Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why we need to differentiate email or username here? Only for display purposes?

Copy link
Member

Choose a reason for hiding this comment

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

Seems practical enough for me.

Copy link
Member Author

Choose a reason for hiding this comment

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

The backend accepts either email or username for the user identifier, so we need to specify which identifier we are sending from the frontend.

@alangsto alangsto force-pushed the alangsto/add_allowances_modal branch 3 times, most recently from df8808e to b5c4a9e Compare July 31, 2024 20:22
@alangsto alangsto marked this pull request as ready for review July 31, 2024 20:27
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 84.37500% with 15 lines in your changes missing coverage. Please review.

Please upload report for BASE (feature/add_allowances@2a35900). Learn more about missing BASE report.

Files Patch % Lines
...c/pages/ExamsPage/components/AddAllowanceModal.jsx 89.85% 5 Missing and 2 partials ⚠️
src/pages/ExamsPage/data/api.js 0.00% 5 Missing ⚠️
src/pages/ExamsPage/utils.js 85.71% 2 Missing ⚠️
src/pages/ExamsPage/hooks.js 85.71% 1 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##             feature/add_allowances      #36   +/-   ##
=========================================================
  Coverage                          ?   80.47%           
=========================================================
  Files                             ?       24           
  Lines                             ?      466           
  Branches                          ?       76           
=========================================================
  Hits                              ?      375           
  Misses                            ?       86           
  Partials                          ?        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/pages/ExamsPage/hooks.js Outdated Show resolved Hide resolved
@alangsto alangsto force-pushed the alangsto/add_allowances_modal branch 4 times, most recently from e8b9a1c to 1aa8132 Compare August 1, 2024 17:43
Copy link
Member

@schenedx schenedx left a comment

Choose a reason for hiding this comment

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

👍

@alangsto alangsto force-pushed the alangsto/add_allowances_modal branch 2 times, most recently from e3dd98b to ef04d23 Compare August 1, 2024 18:14
Copy link
Member

@rijuma rijuma left a comment

Choose a reason for hiding this comment

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

LGTM. Nice work!

@alangsto alangsto force-pushed the alangsto/add_allowances_modal branch from ef04d23 to 0fedd80 Compare August 1, 2024 18:20
@alangsto alangsto merged commit 090e4af into feature/add_allowances Aug 1, 2024
5 checks passed
@alangsto alangsto deleted the alangsto/add_allowances_modal branch August 1, 2024 18:23
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.

5 participants