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

Replaced all TextAreaForm component with Textarea shadcn ui component #10277

Conversation

NikhilA8606
Copy link
Contributor

@NikhilA8606 NikhilA8606 commented Jan 29, 2025

Replaced all TextAreaForm component with Textarea shadcn ui component

@rithviknishad

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

Release Notes

  • New Features

    • Added localization support for comment-related messages.
  • Improvements

    • Enhanced internationalization across comment and resource update components.
    • Improved error handling in resource details update form.
  • Localization

    • Added new translation key for "No comments available".
    • Replaced hardcoded strings with translatable messages.
  • Refactor

    • Removed deprecated TextAreaFormField component.
    • Updated form field implementations to use new components.

@NikhilA8606 NikhilA8606 requested a review from a team as a code owner January 29, 2025 09:37
Copy link
Contributor

coderabbitai bot commented Jan 29, 2025

Walkthrough

This pull request focuses on modernizing UI components by replacing the TextAreaFormField with the Textarea component from ShadCN UI across multiple files. The changes include updating localization files, modifying component implementations in ResourceCommentSection.tsx and ResourceDetailsUpdate.tsx, and removing the deprecated TextAreaFormField.tsx component. The modifications enhance internationalization, improve form handling, and align with the goal of using more standardized UI components.

Changes

File Change Summary
public/locale/en.json Added new localization key no_comments_available with value "No comments available"
src/components/Resource/ResourceCommentSection.tsx - Replaced TextAreaFormField with Textarea
- Added translatable strings for placeholder and button text
- Updated onChange event handling
src/components/Resource/ResourceDetailsUpdate.tsx - Added imports for Textarea and Label
- Replaced TextAreaFormField with Label and Textarea
- Updated error handling for reason field
src/components/Form/FormFields/TextAreaFormField.tsx Completely removed deprecated component

Assessment against linked issues

Objective Addressed Explanation
Replace older UI components with ShadCN UI [#10048]

Possibly related PRs

Suggested labels

needs review, needs testing, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 A rabbit's tale of UI delight,
Components dancing, now sleek and bright!
TextArea waves goodbye with grace,
ShadCN steps in to embrace
A cleaner, smoother coding flight! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 77c3b4f and f33efdd.

📒 Files selected for processing (1)
  • src/components/Resource/ResourceDetailsUpdate.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/Resource/ResourceDetailsUpdate.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Jan 29, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit f33efdd
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/679a1ee98402da000803d64a
😎 Deploy Preview https://deploy-preview-10277--care-ohc.netlify.app
📱 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 site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/components/ui/date-field.tsx (1)

44-63: Consider adding debounce to onChange events.

The current implementation triggers the onChange callback on every valid input. Consider debouncing these events to reduce unnecessary re-renders, especially when integrated with form libraries.

+import { debounce } from "lodash";
+
 export default function DateField({
   date,
   onChange,
   disabled,
   id = "date-field",
 }: DateFieldProps) {
   const { t } = useTranslation();
+  const debouncedOnChange = useMemo(
+    () => debounce((date?: Date) => onChange?.(date), 300),
+    [onChange]
+  );
+
+  useEffect(() => {
+    return () => {
+      debouncedOnChange.cancel();
+    };
+  }, [debouncedOnChange]);

   // ... rest of the component code

   const handleDayChange = (e: React.ChangeEvent<HTMLInputElement>) => {
     // ... validation logic
-    onChange?.(updatedDate);
+    debouncedOnChange(updatedDate);
   };

Also applies to: 65-85, 87-101

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9689df and 982787b.

📒 Files selected for processing (12)
  • public/locale/en.json (4 hunks)
  • src/components/Form/FormFields/DateFormField.tsx (0 hunks)
  • src/components/Patient/PatientRegistration.tsx (2 hunks)
  • src/components/Questionnaire/QuestionnaireForm.tsx (1 hunks)
  • src/components/Resource/ResourceCommentSection.tsx (2 hunks)
  • src/components/Resource/ResourceCreate.tsx (2 hunks)
  • src/components/Resource/ResourceDetailsUpdate.tsx (6 hunks)
  • src/components/ui/autocomplete.tsx (1 hunks)
  • src/components/ui/date-field.tsx (1 hunks)
  • src/components/ui/date-picker.tsx (2 hunks)
  • src/hooks/useFileManager.tsx (2 hunks)
  • src/pages/PublicAppointments/PatientRegistration.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • src/components/Form/FormFields/DateFormField.tsx
🧰 Additional context used
📓 Learnings (1)
src/components/Patient/PatientRegistration.tsx (1)
Learnt from: Jacobjeevan
PR: ohcnetwork/care_fe#10260
File: src/components/Patient/PatientRegistration.tsx:286-289
Timestamp: 2025-01-28T15:50:07.442Z
Learning: For patient registration in the frontend, either year_of_birth or date_of_birth is required for successful registration. If date_of_birth is not available, year_of_birth must be present.
🔇 Additional comments (16)
src/components/ui/date-picker.tsx (1)

19-19: LGTM! The disabled prop is well-implemented.

The addition of the disabled prop enhances the component's flexibility by allowing dynamic date disabling based on custom logic. The prop is correctly typed and properly passed through to the underlying Calendar component.

Also applies to: 22-22, 48-48

src/components/ui/date-field.tsx (3)

9-14: LGTM! Props interface is well-defined.

The DateFieldProps interface is clean and includes all necessary props with proper typing.


16-19: LGTM! Date validation is robust.

The isValidDate function uses dayjs for reliable date validation, ensuring that only valid dates are accepted.


103-151: LGTM! Accessibility and UX are well-implemented.

The component demonstrates good practices:

  • Uses semantic HTML with proper labels
  • Includes data-cy attributes for testing
  • Provides clear placeholders
  • Handles disabled state consistently
  • Uses appropriate input types and constraints
src/pages/PublicAppointments/PatientRegistration.tsx (1)

321-328: LGTM! DateField integration is clean and correct.

The DateField component is properly integrated with:

  • Correct date conversion and ISO string formatting
  • Proper id attribute for accessibility
  • Clean onChange handler implementation
src/components/Patient/PatientRegistration.tsx (1)

517-525: LGTM! DateField integration aligns with requirements.

The DateField component is properly integrated and aligns with the requirement that either year_of_birth or date_of_birth must be present for successful registration.

Note: Based on the retrieved learning from PR #10260, the implementation correctly handles the date_of_birth requirement.

src/components/ui/autocomplete.tsx (1)

21-21: LGTM! Good practice to export the interface.

The change to export the AutoCompleteOption interface improves code reusability and type consistency across components.

src/components/Resource/ResourceCommentSection.tsx (2)

45-49: LGTM! Clean migration to shadcn/ui Textarea component.

The component replacement and event handler update follow the correct patterns.


52-52: LGTM! Good internationalization practices.

The changes properly implement i18n translations for user-facing strings and maintain consistent spacing with mt-2.

Also applies to: 60-60, 66-66

src/components/Resource/ResourceDetailsUpdate.tsx (3)

229-246: LGTM! Clean migration to shadcn/ui Select component.

The status selection implementation is correct and maintains proper type safety.


267-276: LGTM! Good integration of Autocomplete component.

The facility assignment implementation correctly uses the fetched data.


321-342: LGTM! Clean implementation of emergency radio group.

The radio group implementation with error handling is correct.

src/components/Resource/ResourceCreate.tsx (1)

33-33: LGTM! Clean migration to shadcn Textarea component.

The onChange handler has been correctly updated to use e.target.value instead of the previous value object pattern, maintaining proper form state management.

Also applies to: 353-357

src/hooks/useFileManager.tsx (2)

4-4: LGTM! Well-structured imports for the new implementation.

The addition of Trans, cn utility, and shadcn UI components provides all necessary tools for localization and conditional styling.

Also applies to: 7-8, 12-13


297-319: LGTM! Enhanced form field implementation.

The new implementation offers several improvements:

  1. Better accessibility with explicit Label component
  2. Proper error state handling with conditional styling
  3. Enhanced internationalization support using Trans component
  4. Clear error message display
public/locale/en.json (1)

1022-1022: LGTM! Well-structured localization entries.

The new entries are properly formatted and provide clear, contextual translations. The HTML tags in the archive reason message are correctly escaped for proper rendering.

Also applies to: 1398-1398, 1692-1692, 2017-2017

Comment on lines 281 to 297
<Label className="text-gray-700 mb-3 mt-1">
{t("request_title")}
</Label>
<Input
name="title"
type="text"
label="Request Title*"
placeholder="Type your title here"
value={state.form.title}
onChange={handleChange}
error={state.errors.title}
onChange={(e) =>
handleChange({ name: e.target.name, value: e.target.value })
}
/>
{state.errors.title && (
<p className="text-red-500 text-sm mt-2">
{state.errors.emergency}
</p>
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix error message display.

The error messages are displaying the wrong field's error:

Apply this diff to fix the error messages:

-                  {state.errors.emergency}
+                  {state.errors.title}
-                  {state.errors.emergency}
+                  {state.errors.reason}

Also applies to: 301-317

Comment on lines 74 to 97
const [data, setData] = useState<AutoCompleteOption[]>([]);
const query = {
limit: 50,
offset: 0,
search_text: "",
all: true,
facility_type: 1510,
exclude_user: "",
};
useEffect(() => {
const retriveData = async () => {
const { data } = await request(facilityApi.getAllFacilities, { query });
const facilities: AutoCompleteOption[] = [];
data?.results!.map((facility: FacilityData) => {
facilities.push({
label: facility.name,
value: facility.id,
});
});
setData(facilities);
};

retriveData();
}, [data]);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider optimizing the facility data fetching logic.

The current implementation has potential issues:

  1. The useEffect dependency on data could cause an infinite loop
  2. The facility type is hardcoded to 1510

Apply this diff to fix the issues:

-  useEffect(() => {
+  useEffect(() => {
     const retriveData = async () => {
       const { data } = await request(facilityApi.getAllFacilities, { query });
       const facilities: AutoCompleteOption[] = [];
       data?.results!.map((facility: FacilityData) => {
         facilities.push({
           label: facility.name,
           value: facility.id,
         });
       });
       setData(facilities);
     };
 
     retriveData();
-  }, [data]);
+  }, []);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const [data, setData] = useState<AutoCompleteOption[]>([]);
const query = {
limit: 50,
offset: 0,
search_text: "",
all: true,
facility_type: 1510,
exclude_user: "",
};
useEffect(() => {
const retriveData = async () => {
const { data } = await request(facilityApi.getAllFacilities, { query });
const facilities: AutoCompleteOption[] = [];
data?.results!.map((facility: FacilityData) => {
facilities.push({
label: facility.name,
value: facility.id,
});
});
setData(facilities);
};
retriveData();
}, [data]);
const [data, setData] = useState<AutoCompleteOption[]>([]);
const query = {
limit: 50,
offset: 0,
search_text: "",
all: true,
facility_type: 1510,
exclude_user: "",
};
useEffect(() => {
const retriveData = async () => {
const { data } = await request(facilityApi.getAllFacilities, { query });
const facilities: AutoCompleteOption[] = [];
data?.results!.map((facility: FacilityData) => {
facilities.push({
label: facility.name,
value: facility.id,
});
});
setData(facilities);
};
retriveData();
}, []);

@@ -157,6 +157,7 @@ export function QuestionnaireForm({
};

const handleSubmissionError = (results: ValidationErrorResponse[]) => {
toast.error("Form Errr");
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove redundant error toast with typo.

This toast message is redundant as there's already a "questionnaire_submission_failed" error toast in the mutation's onError handler. Additionally, it contains a typo ("Errr").

Apply this diff to remove the redundant toast:

-    toast.error("Form Errr");

@NikhilA8606 NikhilA8606 force-pushed the issues/#10048/Replacing-TextAreaFormField-with-Textarea branch from 982787b to 77c3b4f Compare January 29, 2025 11:06
Copy link
Member

@rithviknishad rithviknishad left a comment

Choose a reason for hiding this comment

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

lgtm, minor things

@@ -1,3 +1,4 @@
import { Textarea } from "@headlessui/react";
Copy link
Member

Choose a reason for hiding this comment

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

ig this was accidental, import form ui instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

<Label className="text-gray-700 mb-3 mt-1">
{t("request_reason")}
</Label>
<Textarea
rows={5}
name="reason"
placeholder="Type your description here"
Copy link
Member

Choose a reason for hiding this comment

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

missing i18n

@rithviknishad rithviknishad merged commit 933fff1 into ohcnetwork:develop Jan 29, 2025
22 checks passed
Copy link

@NikhilA8606 Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Replacing older UI components with new UI components
2 participants