86exm8u3j metrics in db#77
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe PR refactors the metrics reporting component from prop-driven to self-contained. A new ChangesMetrics Report Component Refactoring
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/hooks/useMetricsReport.ts`:
- Around line 15-17: Remove the hardcoded PATIENT_ID in the useMetricsReport
hook and instead obtain the patient ID from the authenticated user context or
accept it as an injected parameter to the hook; replace usages of the PATIENT_ID
constant (the declaration named PATIENT_ID and other occurrences around lines
where queries/mutations are invoked inside useMetricsReport) with the
derived/received id, and guard all query/mutation calls in useMetricsReport (and
any functions like the fetch/update calls referenced there) to only run when the
patient id is present to avoid accidental global reads/writes.
In `@src/pages/dailyReports/metricsReport/MetricsReportButton.tsx`:
- Around line 11-12: The component sets the success state (report via
setReport(true)) immediately after calling the onClick prop, which can show
success even if the async persistence fails; update the MetricsReportButton so
the onClick handler is async (or wraps the provided onClick in an async
function), await the onClick() promise, and only call setReport(true) after the
awaited call resolves successfully (and setReport(false) or handle errors if it
rejects), ensuring you reference the onClick prop and the setReport state
updater in your 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: 9db10d66-e4bf-49b0-823f-d25ef877b97e
📒 Files selected for processing (7)
src/constants/api.constants.tssrc/hooks/useMetricsReport.tssrc/pages/dailyReports/DailyReports.tsxsrc/pages/dailyReports/metricsReport/MetricsReport.tsxsrc/pages/dailyReports/metricsReport/MetricsReportButton.tsxsrc/pages/dailyReports/metricsReport/MetricsReportData.tssrc/pages/dailyReports/metricsReport/MetricsReportListCard.tsx
| //TODO: remove hardcoded user and get it from the login | ||
| const PATIENT_ID = '1622017' | ||
|
|
There was a problem hiding this comment.
Remove the hardcoded patient identifier before merge.
Line 16 hardcodes the patient context, so every user will read/write metrics for the same record. That creates a real multi-user correctness and privacy risk. Derive patient ID from authenticated user context (or pass it into the hook) and only query/mutate when it is available.
Also applies to: 21-21, 28-28
🤖 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/hooks/useMetricsReport.ts` around lines 15 - 17, Remove the hardcoded
PATIENT_ID in the useMetricsReport hook and instead obtain the patient ID from
the authenticated user context or accept it as an injected parameter to the
hook; replace usages of the PATIENT_ID constant (the declaration named
PATIENT_ID and other occurrences around lines where queries/mutations are
invoked inside useMetricsReport) with the derived/received id, and guard all
query/mutation calls in useMetricsReport (and any functions like the
fetch/update calls referenced there) to only run when the patient id is present
to avoid accidental global reads/writes.
| queryKey: ['metrics', 'today', PATIENT_ID], | ||
| queryFn: async () => { | ||
| const response = await apiService.get<boolean>(`${API_ENDPOINTS.metrics}today/${PATIENT_ID}`) | ||
| return response |
| <MetricsReportListCard /> | ||
| <MetricsReportButton onClick={onClick} /> | ||
| <MetricsReportListCard onChange={handleChange} /> | ||
| <MetricsReportButton onClick={() => submitReport(metrics)} sentToday={sentToday ?? false} /> |
Description
Save metrics in db
Please include a summary of the changes and the related issue.
Related Issue(s)
86exm8u3j
Fixes # (issue number)
Checklist:
Screenshots (if appropriate):
Summary by CodeRabbit
New Features
Refactor