feat: add popups for import and add users on sponsors global#963
feat: add popups for import and add users on sponsors global#963tomrndom wants to merge 4 commits into
Conversation
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
📝 WalkthroughWalkthroughAdds two global sponsor-user popups (invite and import), updates sendSponsorUserInvite to accept an optional sponsorId override, enriches sponsor query results with companyId, integrates the popups into SponsorUsersListPage, and adds tests for both popups. ChangesSponsor User Management Popups
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Suggested Reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/actions/sponsor-users-actions.js`:
- Around line 535-547: The current promise chain swallows errors with
catch(console.log) and calls dispatch(stopLoading()) twice; remove the
catch(console.log) so rejections propagate to callers (or replace it with a
catch that logs and rethrows), and remove the stopLoading() call inside the
.then handler so stopLoading is invoked only from .finally; update the chain
around dispatch, stopLoading, snackbarSuccessHandler, and
T.translate("sponsor_users.new_user.success") accordingly so success still shows
the snackbar but loading is stopped exactly once in .finally.
In
`@src/pages/sponsors/sponsor-users-list-page/components/sponsor-global-import-users-popup.js`:
- Around line 86-95: The handleImport handler currently calls
importSponsorUsers(...).then(() => onClose()) which will close the dialog even
on failure; change it to await the thunk result from importSponsorUsers in
handleImport (or handle its returned promise) and only call onClose() when the
thunk returns an explicit success flag (e.g., { success: true }) or resolves
truthy; update importSponsorUsers so it resolves/rejects or returns an explicit
success value on completion, and gate onClose() on that success result (and
handle or surface errors when it fails instead of closing).
- Around line 49-50: The code reads the selected sponsor's id from
formik.values.sponsor?.value but the select stores {id, name, companyId}, so
sponsorId becomes undefined; update both occurrences (the sponsorId assignment
and the other similar block around lines where companyId is used) to use
formik.values.sponsor?.id instead of .value, and ensure any downstream uses
(e.g., the import target and candidate list loader) reference this corrected
sponsorId and continue to use formik.values.sponsor?.companyId for companyId.
In
`@src/pages/sponsors/sponsor-users-list-page/components/sponsor-global-new-user-popup.js`:
- Around line 37-41: The handler handleOnSave currently closes the popup in a
finally block so failures also dismiss the form; change it to call
sendSponsorUserInvite(values.email, values.sponsor.id).then(() => {
getSponsorUsers(); handleClose(); }).catch((err) => { /* keep popup open and
surface error to user */ }); and ensure the sendSponsorUserInvite thunk returns
a rejected Promise on failure so the catch runs; reference handleOnSave,
sendSponsorUserInvite, getSponsorUsers, and handleClose when making the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 67165833-76a2-4a0f-91a7-33147faa7006
📒 Files selected for processing (5)
src/actions/sponsor-actions.jssrc/actions/sponsor-users-actions.jssrc/pages/sponsors/sponsor-users-list-page/components/sponsor-global-import-users-popup.jssrc/pages/sponsors/sponsor-users-list-page/components/sponsor-global-new-user-popup.jssrc/pages/sponsors/sponsor-users-list-page/index.js
| .then(() => { | ||
| dispatch(stopLoading()); | ||
| dispatch( | ||
| snackbarSuccessHandler({ | ||
| title: T.translate("general.success"), | ||
| html: T.translate("sponsor_users.new_user.success") | ||
| }) | ||
| ); | ||
| }) | ||
| .catch(console.log) // need to catch promise reject | ||
| .finally(() => { | ||
| dispatch(stopLoading()); | ||
| }); |
There was a problem hiding this comment.
Preserve invite failures for callers and stop loading once.
catch(console.log) turns failed invites into fulfilled promises, so popup callers cannot tell failure from success. The extra stopLoading() in the success path also double-decrements the loader.
Proposed fix
)(params)(dispatch)
.then(() => {
- dispatch(stopLoading());
dispatch(
snackbarSuccessHandler({
title: T.translate("general.success"),
html: T.translate("sponsor_users.new_user.success")
})
);
})
- .catch(console.log) // need to catch promise reject
+ .catch((err) => {
+ console.log(err);
+ throw err;
+ })
.finally(() => {
dispatch(stopLoading());
});🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/actions/sponsor-users-actions.js` around lines 535 - 547, The current
promise chain swallows errors with catch(console.log) and calls
dispatch(stopLoading()) twice; remove the catch(console.log) so rejections
propagate to callers (or replace it with a catch that logs and rethrows), and
remove the stopLoading() call inside the .then handler so stopLoading is invoked
only from .finally; update the chain around dispatch, stopLoading,
snackbarSuccessHandler, and T.translate("sponsor_users.new_user.success")
accordingly so success still shows the snackbar but loading is stopped exactly
once in .finally.
| const sponsorId = formik.values.sponsor?.value; | ||
| const companyId = formik.values.sponsor?.companyId; |
There was a problem hiding this comment.
Use the selected sponsor's id, not value.
formatSelectedValue stores { id, name, companyId }, so formik.values.sponsor?.value stays undefined. That prevents the candidate list from loading and sends an empty target sponsor on import.
Proposed fix
- const sponsorId = formik.values.sponsor?.value;
+ const sponsorId = formik.values.sponsor?.id;Also applies to: 143-147
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@src/pages/sponsors/sponsor-users-list-page/components/sponsor-global-import-users-popup.js`
around lines 49 - 50, The code reads the selected sponsor's id from
formik.values.sponsor?.value but the select stores {id, name, companyId}, so
sponsorId becomes undefined; update both occurrences (the sponsorId assignment
and the other similar block around lines where companyId is used) to use
formik.values.sponsor?.id instead of .value, and ensure any downstream uses
(e.g., the import target and candidate list loader) reference this corrected
sponsorId and continue to use formik.values.sponsor?.companyId for companyId.
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
Signed-off-by: Tomás Castillo <tcastilloboireau@gmail.com>
There was a problem hiding this comment.
♻️ Duplicate comments (3)
src/pages/sponsors/sponsor-users-list-page/components/sponsor-global-new-user-popup.js (1)
43-49:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftSuccess path is still triggered on failed invites.
Line 43 chains
.then(...), but the thunk currently swallows errors insrc/actions/sponsor-users-actions.js(.catch(console.log)), so this block can still run after a failed API call and close/refresh the dialog incorrectly. Gate close/refresh on an explicit success result (or make the thunk reject on failure).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pages/sponsors/sponsor-users-list-page/components/sponsor-global-new-user-popup.js` around lines 43 - 49, The success path currently runs even when the invite fails because sendSponsorUserInvite swallows errors; update the flow so sendSponsorUserInvite (the thunk in src/actions/sponsor-users-actions.js) returns a rejected promise on failure (remove the terminal .catch(console.log) or re-throw the error) or have the caller inspect an explicit success result before proceeding; then in sponsor-global-new-user-popup.js, only call getSponsorUsers() and handleClose() when sendSponsorUserInvite resolves successfully (or when the resolved payload indicates success) and ensure setIsSaving(false) still runs in finally.src/pages/sponsors/sponsor-users-list-page/components/sponsor-global-import-users-popup.js (2)
94-96:⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftImport dialog can close even when import fails.
Line 95 closes in
.then(...), but the current thunk contract insrc/actions/sponsor-users-actions.jsswallows failures, so this can still execute on failed imports. Only close after a verifiable success result (or make thunk reject on failure).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pages/sponsors/sponsor-users-list-page/components/sponsor-global-import-users-popup.js` around lines 94 - 96, The import dialog is closed unconditionally in the then() callback of importSponsorUsers even though the import thunk in sponsor-users-actions.js swallows failures; change the flow so onClose is only called after a verifiable success: either update the thunk importSponsorUsers to reject the promise on failure, or change the caller to inspect the resolved value (e.g., check a success flag or returned result) before calling onClose; keep setIsSaving(false) in finally() but move onClose into the branch that confirms success so failures do not close the dialog.
51-52:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winUse sponsor
id, notvalue, for selected sponsor state.Line 51 reads
formik.values.sponsor?.value, but Line 156-160 stores{ id, name, companyId }. This leavessponsorIdundefined and breaks candidate loading/import targeting.Proposed fix
- const sponsorId = formik.values.sponsor?.value; + const sponsorId = formik.values.sponsor?.id;Also applies to: 156-160
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pages/sponsors/sponsor-users-list-page/components/sponsor-global-import-users-popup.js` around lines 51 - 52, The selected sponsor was read from formik.values.sponsor?.value but the stored object uses { id, name, companyId }, so sponsorId becomes undefined; update the code to read formik.values.sponsor?.id (leave companyId as formik.values.sponsor?.companyId) wherever sponsorId is derived (e.g., the sponsorId and companyId consts and any import/targeting logic) so it matches the stored { id, name, companyId } shape and restores correct candidate loading/import targeting.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In
`@src/pages/sponsors/sponsor-users-list-page/components/sponsor-global-import-users-popup.js`:
- Around line 94-96: The import dialog is closed unconditionally in the then()
callback of importSponsorUsers even though the import thunk in
sponsor-users-actions.js swallows failures; change the flow so onClose is only
called after a verifiable success: either update the thunk importSponsorUsers to
reject the promise on failure, or change the caller to inspect the resolved
value (e.g., check a success flag or returned result) before calling onClose;
keep setIsSaving(false) in finally() but move onClose into the branch that
confirms success so failures do not close the dialog.
- Around line 51-52: The selected sponsor was read from
formik.values.sponsor?.value but the stored object uses { id, name, companyId },
so sponsorId becomes undefined; update the code to read
formik.values.sponsor?.id (leave companyId as formik.values.sponsor?.companyId)
wherever sponsorId is derived (e.g., the sponsorId and companyId consts and any
import/targeting logic) so it matches the stored { id, name, companyId } shape
and restores correct candidate loading/import targeting.
In
`@src/pages/sponsors/sponsor-users-list-page/components/sponsor-global-new-user-popup.js`:
- Around line 43-49: The success path currently runs even when the invite fails
because sendSponsorUserInvite swallows errors; update the flow so
sendSponsorUserInvite (the thunk in src/actions/sponsor-users-actions.js)
returns a rejected promise on failure (remove the terminal .catch(console.log)
or re-throw the error) or have the caller inspect an explicit success result
before proceeding; then in sponsor-global-new-user-popup.js, only call
getSponsorUsers() and handleClose() when sendSponsorUserInvite resolves
successfully (or when the resolved payload indicates success) and ensure
setIsSaving(false) still runs in finally.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5c64094e-48bc-48bc-8ff6-a00458e2f6bf
📒 Files selected for processing (4)
src/pages/sponsors/sponsor-users-list-page/components/__tests__/sponsor-global-import-users-popup.test.jssrc/pages/sponsors/sponsor-users-list-page/components/__tests__/sponsor-global-new-user-popup.test.jssrc/pages/sponsors/sponsor-users-list-page/components/sponsor-global-import-users-popup.jssrc/pages/sponsors/sponsor-users-list-page/components/sponsor-global-new-user-popup.js
🚧 Files skipped from review as they are similar to previous changes (2)
- src/pages/sponsors/sponsor-users-list-page/components/tests/sponsor-global-new-user-popup.test.js
- src/pages/sponsors/sponsor-users-list-page/components/tests/sponsor-global-import-users-popup.test.js
ref: https://app.clickup.com/t/86ba8m3nd
Signed-off-by: Tomás Castillo tcastilloboireau@gmail.com
Summary by CodeRabbit
New Features
Bug Fixes & Improvements
Tests