-
Notifications
You must be signed in to change notification settings - Fork 61
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
chore(j-s): Add loading state to create subpoena button #16612
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (3)
apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx (3)
Line range hint 55-82
: Consider splitting handleNavigationTo into smaller functions.
The function handles multiple responsibilities: updating defendants, clearing conclusions, and updating court dates. Consider splitting it into smaller, more focused functions for better maintainability and testing.
const updateDefendants = async () => {
const promises = workingCase.defendants?.map((defendant) =>
updateDefendant({
caseId: workingCase.id,
defendantId: defendant.id,
subpoenaType: defendant.subpoenaType,
})
) ?? [];
return Promise.all(promises);
};
const clearConclusion = () => {
return isArraignmentScheduled && workingCase.indictmentDecision
? [{
indictmentDecision: null,
courtSessionType: null,
courtDate: null,
postponedIndefinitelyExplanation: null,
indictmentRulingDecision: null,
mergeCaseId: null,
force: true,
}]
: undefined;
};
Also applies to: 105-107
80-82
: Enhance error messages with specific failure details.
The current error messages are generic. Consider providing more specific error messages that indicate which operation failed and why.
-toast.error(formatMessage(errors.updateDefendant))
+toast.error(formatMessage(errors.updateDefendant, {
+ details: 'Failed to update defendant information. Please try again.',
+}))
-toast.error(formatMessage(errors.updateCase))
+toast.error(formatMessage(errors.updateCase, {
+ details: 'Failed to update court date. Please try again.',
+}))
Also applies to: 105-107
Line range hint 27-271
: Consider extracting subpoena creation logic into a custom hook.
To improve code organization and reusability, consider extracting the subpoena creation logic into a custom hook (e.g., useSubpoenaCreation
). This would:
- Simplify the component by moving complex state management logic
- Make the code more testable
- Follow React's composition pattern
Example implementation:
const useSubpoenaCreation = (workingCase, onSuccess) => {
const [isCreating, setIsCreating] = useState(false);
const createSubpoena = async () => {
setIsCreating(true);
try {
// Subpoena creation logic here
onSuccess();
} catch (error) {
toast.error(error.message);
} finally {
setIsCreating(false);
}
};
return { isCreating, createSubpoena };
};
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx (1)
Pattern apps/**/*
: "Confirm that the code adheres to the following:
- NextJS best practices, including file structure, API routes, and static generation methods.
- Efficient state management and server-side rendering techniques.
- Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (2)
apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx (2)
5-5
: LGTM: Import changes follow best practices.
The addition of toast notifications and centralized error messages follows good practices for consistent error handling.
Also applies to: 8-8
267-267
: LGTM: Modal loading state prevents duplicate submissions.
The addition of isPrimaryButtonLoading
effectively prevents users from creating duplicate subpoenas by disabling the button during submission.
apps/judicial-system/web/src/routes/Court/Indictments/Subpoena/Subpoena.tsx
Show resolved
Hide resolved
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #16612 +/- ##
=======================================
Coverage 36.78% 36.78%
=======================================
Files 6855 6855
Lines 142311 142315 +4
Branches 40584 40584
=======================================
+ Hits 52348 52350 +2
- Misses 89963 89965 +2 Flags with carried forward coverage won't be shown. Click here to find out more.
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Datadog ReportAll test runs ✅ 22 Total Test Services: 0 Failed, 21 Passed Test ServicesThis report shows up to 10 services
🔻 Code Coverage Decreases vs Default Branch (1)
|
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.
Some changes suggested.
Add loading state to create subpoena button
Asana
What
When a user clicks the "Create subpoena" button, we update the defendant and clear the court date. This could take some time and the users can click the button again while this is happening, creating a duplicate subpoena.
Why
We never want to create duplicate subpoenas
Screenshots / Gifs
Screen.Recording.2024-10-29.at.11.27.34.mov
Checklist:
Summary by CodeRabbit
New Features
Bug Fixes