Skip to content

Conversation

@Sreyas62
Copy link
Contributor

@Sreyas62 Sreyas62 commented Jan 11, 2026

Proposed Changes

Fixes #15068

  • Consolidated the two useEffects that handles both create and edit modes based on isOpen state, eliminating the race condition that caused form reset on second open.
  • Added shouldDirty: true flag so the form properly tracks changes in slug values, enabling the Update button in ChargeItemDefinitionForm.
  • Find and fixed similar issue in ProductKnowledgeForm and ResourceCategoryForm
Recording.2026-01-12.003029.mp4

Tagging: @ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate the bug or test the new feature.
  • Update product documentation.
  • Ensure that UI text is placed in I18n files.
  • Prepare a screenshot or demo video for the changelog entry and attach it to the issue.
  • Request peer reviews.
  • Complete QA on mobile devices.
  • Complete QA on desktop devices.
  • Add or update Playwright tests for related changes

Summary by CodeRabbit

  • Bug Fixes
    • Consolidated form initialization for create/edit sheets so fields reset or populate only when the sheet opens, preventing stale state.
    • Slug inputs now mark changes as “dirty” so validation and change tracking run reliably during edits.

✏️ Tip: You can customize this high-level summary in your review settings.

@Sreyas62 Sreyas62 requested review from a team and Copilot January 11, 2026 19:12
@netlify
Copy link

netlify bot commented Jan 11, 2026

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 3d5084c
🔍 Latest deploy log https://app.netlify.com/projects/care-ohc/deploys/6964e0cd4824510008da5cfa
😎 Deploy Preview https://deploy-preview-15099.preview.ohc.network
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 11, 2026

Walkthrough

Consolidates ResourceCategoryForm initialization into one effect triggered when the sheet opens (handles create vs edit) and updates slug sanitization handlers in three forms to set the slug field as dirty so validation and dirty state propagate on edits.

Changes

Cohort / File(s) Summary
Form Initialization Consolidation
src/components/Common/ResourceCategoryForm.tsx
Merges separate effects into a single effect that runs when the sheet is open; initializes form fields from categoryData in edit mode and resets to defaults in create mode. Adds shouldDirty: true when updating slug_value during edits.
Slug Dirty State Marking
src/pages/Facility/settings/chargeItemDefinitions/ChargeItemDefinitionForm.tsx, src/pages/Facility/settings/productKnowledge/ProductKnowledgeForm.tsx
When sanitizing slug input, form.setValue now includes shouldDirty: true so the slug field is marked dirty and validation/diff state updates during edits.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: fixes for edit form bugs in resource category and charge item definition forms.
Description check ✅ Passed The description includes issue reference, clear explanation of changes, and links to video demonstration. However, it marks some merge checklist items as incomplete (product documentation, I18n, Playwright tests).
Linked Issues check ✅ Passed The PR addresses all objectives from issue #15068: fixes form reset race condition in ResourceCategoryForm, enables dirty-state tracking for slug edits in ChargeItemDefinitionForm, and applies the pattern to ProductKnowledgeForm.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the bugs identified in #15068. No unrelated modifications were introduced.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d22267 and 3d5084c.

📒 Files selected for processing (1)
  • src/components/Common/ResourceCategoryForm.tsx
🧰 Additional context used
📓 Path-based instructions (13)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{ts,tsx}: Write concise, technical TypeScript code with accurate examples
Use TypeScript for all code; prefer interfaces over types
Avoid enums; use maps instead
Use TanStack Query for data fetching from the API along with query and mutate utilities for the queryFn and mutationFn
Use raviger for routing

**/*.{ts,tsx}: Use TypeScript with strict mode and ES2022 target
Use interface for defining object types in TypeScript
Avoid explicit any type in TypeScript
Use proper nullability annotations in TypeScript types
Use dedicated error handlers and TypeScript strict null checks

**/*.{ts,tsx}: Use TypeScript for all new code
Prefer interfaces over types for object definitions in TypeScript
Avoid using any type; use proper type definitions in TypeScript
Use type inference where possible in TypeScript
Use TanStack Query for API data management
Prefer React Context for global state management

**/*.{ts,tsx}: Use TanStack Query with the query and mutate utilities from @/Utils/request/
Use appropriate query keys following the resource pattern for TanStack Query
Leverage TanStack Query built-in features for pagination and debouncing
Implement proper error handling using the global error handler for TanStack Query operations
Use useQuery hook with queryKey and queryFn parameters, where queryFn wraps the API route with the query() utility
Use useMutation hook with mutationFn parameter wrapping API routes with the mutate() utility, and implement onSuccess callbacks to invalidate related queries
Support path parameters in TanStack Query using the pathParams option in query/mutate utilities
Support query parameters in TanStack Query using the queryParams option in query/mutate utilities
Use the silent: true option to suppress global error notifications when custom error handling is needed

**/*.{ts,tsx}: Use TypeScript with strict mode and ES2022 target
Use interface for defining object types
Avoid explicit any types and maint...

Files:

  • src/components/Common/ResourceCategoryForm.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursorrules)

**/*.{ts,tsx,js,jsx}: Use functional and declarative programming patterns; avoid classes
Prefer iteration and modularization over code duplication
Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError)
Use the "function" keyword for pure functions
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements

**/*.{ts,tsx,js,jsx}: Use path aliases for imports from src (@/*)
Use double quotes for strings
Semicolons are required at end of statements
Order imports as: 3rd-party → library → CAREUI → UI → components → hooks → utils → relative
Use PascalCase for component and class names
Use camelCase for variable and function names

**/*.{ts,tsx,js,jsx}: Use path aliases @/* for imports from src directory
Use double quotes for strings
Require semicolons at end of statements
Order imports: 3rd-party → library → CAREUI → UI → components → hooks → utils → relative
Use PascalCase for component and class names
Use camelCase for variable and function names

Files:

  • src/components/Common/ResourceCategoryForm.tsx
**/*.{tsx,jsx}

📄 CodeRabbit inference engine (.cursorrules)

Use declarative JSX

Files:

  • src/components/Common/ResourceCategoryForm.tsx
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/**/*.{ts,tsx}: Use strict TypeScript configuration for medical data safety in all TypeScript source files
All literal strings must use i18next for multi-language support in healthcare interfaces
Use comprehensive error boundaries and user-friendly error messages for medical workflow debugging without exposing PHI
Follow ESLint configured rules for React hooks, accessibility, and code quality
Use @tanstack/react-query for server state management in API client code
Localize date and time formats for medical timestamps using locale-aware formatting functions
Use date-fns for date handling and manipulation with locale awareness for medical timestamps

Files:

  • src/components/Common/ResourceCategoryForm.tsx
src/**/*{[Ff]orm,[Ii]nput,[Ff]ield}*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use react-hook-form with zod validation for medical data integrity in form components

Files:

  • src/components/Common/ResourceCategoryForm.tsx
src/components/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/components/**/*.{ts,tsx}: Implement WCAG 2.1 AA accessibility compliance in medical applications with screen reader compatibility and keyboard navigation
Include medical use cases, accessibility notes, and WCAG compliance documentation in component documentation
Follow established React component patterns and folder structure organized by feature and domain

src/components/**/*.{ts,tsx}: Use path aliases: @/components/, @/types/, @/lib/, @/pages/ for imports
Follow import order: External packages → @/components/ui/@/components/@/CAREUI/@/types/@/lib/ → relative imports
Use named exports from lucide-react for icons (e.g., import { SettingsIcon } from "lucide-react")
Import useTranslation from react-i18next for internationalization
Use React 19.1.1 hooks pattern - Functional components only
Always define TypeScript Props interfaces (e.g., PatientInfoCardProps) for component props
Use handle prefix for event handlers (e.g., handleSubmit, handleTagsUpdate, handlePatientSelect)
Use shadcn/ui components as primary UI system (Button, Card, Badge, etc.) from @/components/ui/
Use healthcare-specific CAREUI custom components (Calendar, WeekdayCheckbox, Zoom) from @/CAREUI/
Use buttonVariants from @/components/ui/button with CVA patterns for button styling
Follow <Card><CardHeader> pattern for consistent card layouts
Use PatientRead type from @/types/emr/patient/patient for patient data handling
Implement TagAssignmentSheet with TagEntityType for patient/facility tags
Use PatientHoverCard for patient info overlays
Use Badge components to display patient status, facility capacity, medication dosage with color variants
Use cva() from class variance authority for variant-based component styling
Use cn() from @/lib/utils for conditional class composition
Follow Tailwind CSS 4.1.3 color system: primary-700, gray-900, red-500 pattern with dark mode variants
Use Tailwind shadow system: shadow-sm, shadow-xs for el...

Files:

  • src/components/Common/ResourceCategoryForm.tsx
src/**/*.{ts,tsx,css}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use Prettier for consistent code formatting across the healthcare application

Files:

  • src/components/Common/ResourceCategoryForm.tsx
src/**/*.{tsx,ts}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

src/**/*.{tsx,ts}: Use React 19.1.1 features and patterns following React 19 Documentation for healthcare application development
Use shadcn/ui as primary component system and CAREUI for healthcare-specific components
Use framer-motion for animations in healthcare UI interfaces

Files:

  • src/components/Common/ResourceCategoryForm.tsx
src/**/*.{tsx,css}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use Tailwind CSS 4.1.3 utility classes with custom healthcare-specific design system for styling

Files:

  • src/components/Common/ResourceCategoryForm.tsx
**/*

📄 CodeRabbit inference engine (CLAUDE.md)

Use 2-space indentation

Files:

  • src/components/Common/ResourceCategoryForm.tsx
**/*.tsx

📄 CodeRabbit inference engine (.cursor/rules/02-coding-standards.mdc)

**/*.tsx: Use functional components with proper type definitions in React
One component per file is preferred
Prefer default exports for React components
Follow the component naming pattern: ComponentName.tsx for React components
Use Tailwind CSS for styling
Use Shadcn UI components when available
Use local state for component-specific data
Use PascalCase for component file names (e.g., AuthWizard.tsx)

Files:

  • src/components/Common/ResourceCategoryForm.tsx
**/*.{tsx,ts}

📄 CodeRabbit inference engine (.cursor/rules/04-ui-components.mdc)

**/*.{tsx,ts}: Use Shadcn UI components as the primary component library
Follow the component documentation for proper usage
Customize components using Tailwind CSS
Use navigate and useRedirect from raviger for navigation and redirects
Use Tailwind's responsive classes and follow mobile-first approach
Implement proper ARIA attributes for accessibility
Ensure keyboard navigation works in components
Define component props using TypeScript interfaces
Use translation keys from src/Locale/ for internationalization
Support RTL languages in components
Use proper date/time formatting for multiple language support

Files:

  • src/components/Common/ResourceCategoryForm.tsx
**/*.{ts,tsx,js,jsx,json,css,scss,html}

📄 CodeRabbit inference engine (AGENTS.md)

Use 2-space indentation

Files:

  • src/components/Common/ResourceCategoryForm.tsx
🧠 Learnings (12)
📚 Learning: 2025-11-25T13:50:46.407Z
Learnt from: CR
Repo: ohcnetwork/care_fe PR: 0
File: .github/instructions/careui.instructions.md:0-0
Timestamp: 2025-11-25T13:50:46.407Z
Learning: Applies to src/CAREUI/**/*.{ts,tsx} : Ensure full compatibility with react-hook-form for medical data collection in CAREUI components

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
📚 Learning: 2025-11-25T13:51:23.408Z
Learnt from: CR
Repo: ohcnetwork/care_fe PR: 0
File: .github/instructions/context.instructions.md:0-0
Timestamp: 2025-11-25T13:51:23.408Z
Learning: Applies to src/context/**/*.{ts,tsx} : Use data minimization principles in context implementations

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
📚 Learning: 2024-11-20T19:08:38.025Z
Learnt from: Jacobjeevan
Repo: ohcnetwork/care_fe PR: 9080
File: src/components/Users/UserEditDetails.tsx:90-97
Timestamp: 2024-11-20T19:08:38.025Z
Learning: In the React component `UserEditDetails` (src/components/Users/UserEditDetails.tsx), error handling for form submissions is handled within the `UserAddEditForm` component, so additional error handling is unnecessary.

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
📚 Learning: 2025-03-30T12:22:58.576Z
Learnt from: hrit2773
Repo: ohcnetwork/care_fe PR: 11447
File: src/components/Questionnaire/QuestionnaireEditor.tsx:1055-1069
Timestamp: 2025-03-30T12:22:58.576Z
Learning: In the QuestionnaireEditor component, React Hook Form's onChange handlers are intentionally overridden with custom updateField calls to maintain component-specific state management instead of relying on React Hook Form's internal state.

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
📚 Learning: 2025-04-13T03:41:38.805Z
Learnt from: rithviknishad
Repo: ohcnetwork/care_fe PR: 11815
File: src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx:332-341
Timestamp: 2025-04-13T03:41:38.805Z
Learning: Form inputs in React components should use the controlled component pattern (using `value` instead of `defaultValue`) to ensure they properly reflect changes from all sources, particularly for textareas and form elements that may be updated from multiple places.

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
📚 Learning: 2024-11-25T09:21:37.265Z
Learnt from: sarvesh-official
Repo: ohcnetwork/care_fe PR: 9196
File: src/hooks/useFileManager.tsx:76-76
Timestamp: 2024-11-25T09:21:37.265Z
Learning: In the React TypeScript file `src/hooks/useFileManager.tsx`, resetting `currentIndex` in a `useEffect` when `uploadedFiles` changes will reset the current index every time and can cause uncontrolled issues. It's better to manage `currentIndex` without automatically resetting it upon `uploadedFiles` changes to avoid unexpected behavior.

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
📚 Learning: 2024-12-11T01:32:56.923Z
Learnt from: Jacobjeevan
Repo: ohcnetwork/care_fe PR: 8956
File: src/components/Shifting/ShiftDetailsUpdate.tsx:348-370
Timestamp: 2024-12-11T01:32:56.923Z
Learning: In the `ShiftDetailsUpdate` component (`src/components/Shifting/ShiftDetailsUpdate.tsx`), the field `approving_facility` is not required in `initForm`.

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
📚 Learning: 2025-04-13T03:41:38.805Z
Learnt from: rithviknishad
Repo: ohcnetwork/care_fe PR: 11815
File: src/components/Questionnaire/QuestionTypes/EncounterQuestion.tsx:332-341
Timestamp: 2025-04-13T03:41:38.805Z
Learning: Textareas and other form inputs in the codebase should use the controlled component pattern (using `value` instead of `defaultValue`) to ensure they properly reflect changes from all sources.

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
📚 Learning: 2025-08-22T14:24:18.226Z
Learnt from: Denyme24
Repo: ohcnetwork/care_fe PR: 13297
File: src/pages/Facility/settings/productKnowledge/ProductKnowledgeForm.tsx:200-206
Timestamp: 2025-08-22T14:24:18.226Z
Learning: In React Hook Form with complex nested schemas, setting initial default values to null can cause forms to become immediately "dirty" when components auto-initialize object structures, which can interfere with form submission button disable logic that relies on isDirty state.

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
📚 Learning: 2025-11-25T13:53:40.623Z
Learnt from: CR
Repo: ohcnetwork/care_fe PR: 0
File: .github/instructions/utils.instructions.md:0-0
Timestamp: 2025-11-25T13:53:40.623Z
Learning: Applies to src/Utils/**/*.{ts,tsx} : Implement proper text sanitization and formatting in string utilities

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
📚 Learning: 2025-12-17T19:47:58.152Z
Learnt from: AdityaJ2305
Repo: ohcnetwork/care_fe PR: 14821
File: src/components/Location/LocationNavigation.tsx:161-163
Timestamp: 2025-12-17T19:47:58.152Z
Learning: To ensure the remove-unused-i18n.js cleanup script detects i18n keys, avoid wrapping keys inside a ternary expression passed directly to t(). Instead, call t() separately in each branch of a conditional, e.g. condition ? t("key1") : t("key2"), or compute the key in a variable before passing to t(). For LocationNavigation.tsx (and similar TSX files in the repo), prefer explicit separate i18n calls per branch or a shared precomputed key to guarantee all keys are statically detectable by the script.

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
📚 Learning: 2025-12-22T10:16:36.690Z
Learnt from: Jacobjeevan
Repo: ohcnetwork/care_fe PR: 14804
File: src/pages/Facility/services/pharmacy/DispensesView.tsx:117-135
Timestamp: 2025-12-22T10:16:36.690Z
Learning: In the care_fe repository, prefer the native HTML title attribute for simple tooltips over using shadcn/ui Tooltip components. Use Tooltip components only when the tooltip requires richer content, interactivity, or accessibility enhancements that cannot be achieved with a plain title. For simple cases, add a title attribute to the element (e.g., <span title="...">). If a Tooltip is used, ensure it is accessible and necessary, and avoid duplicating content available in the title attribute.

Applied to files:

  • src/components/Common/ResourceCategoryForm.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: build
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Test
  • GitHub Check: CodeQL-Build
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: deploy-preview
🔇 Additional comments (2)
src/components/Common/ResourceCategoryForm.tsx (2)

99-118: LGTM! Well-structured consolidation of form initialization logic.

The single effect triggered by isOpen correctly handles both create and edit modes, eliminating the race condition where separate effects could conflict. The early return when !isOpen prevents unnecessary resets, and the conditional form data population is clean.

One minor observation: including form in the dependency array is safe here since react-hook-form's useForm returns a stable reference, but you could also use form.reset directly if you wanted to be more explicit about the dependency.


254-261: Correct fix for dirty state tracking on slug edits.

Adding shouldDirty: true ensures the form recognizes slug modifications, enabling the Update button. This is necessary because form.setValue() doesn't mark fields dirty by default, and the sanitization logic replaces the native field.onChange behavior.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Jan 11, 2026

🚀 Preview Deployment Ready!

Name Details
🔗 Preview URL https://95942997.care-preview-a7w.pages.dev
📝 Commit 3d5084c
🌐 Environment pr-15099

This preview will be automatically updated when you push new commits to this PR.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request resolves form state management issues in resource category, charge item definition, and product knowledge forms. The changes fix a bug where the Update button was not enabled when editing slug values, and consolidates useEffect logic to prevent race conditions during form resets.

Changes:

  • Added shouldDirty: true flag to slug field setValue calls across all three forms to properly track manual edits
  • Consolidated two separate useEffects in ResourceCategoryForm into a single effect that handles both create and edit modes based on the isOpen state

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/components/Common/ResourceCategoryForm.tsx Merged two useEffects into one to eliminate race condition on form reset; added shouldDirty: true to slug input onChange handler
src/pages/Facility/settings/chargeItemDefinitions/ChargeItemDefinitionForm.tsx Added shouldDirty: true to slug input onChange handler to enable Update button on manual edits
src/pages/Facility/settings/productKnowledge/ProductKnowledgeForm.tsx Added shouldDirty: true to slug input onChange handler to enable Update button on manual edits

@github-actions
Copy link

github-actions bot commented Jan 11, 2026

🎭 Playwright Test Results

Status: ✅ Passed
Test Shards: 3

Metric Count
Total Tests 251
✅ Passed 251
❌ Failed 0
⏭️ Skipped 0

📊 Detailed results are available in the playwright-final-report artifact.

Run: #4553

Comment on lines 111 to 112
} else if (!isEditing) {
// Create mode: reset to empty defaults
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} else if (!isEditing) {
// Create mode: reset to empty defaults
} else {

if (!isOpen) return;

if (isEditing && categoryData) {
// Edit mode: populate form with existing data
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Edit mode: populate form with existing data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Resource categrory and Charge item defintion edit form

2 participants