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

Appointment detail flicker problem resolved #9987

Conversation

NikhilA8606
Copy link
Contributor

@NikhilA8606 NikhilA8606 commented Jan 15, 2025

Appointment page flicker issue

  • Added new file called AppointmentDialog.tsx
  • Added the AppointmentDialog component to new file

@ohcnetwork/care-fe-code-reviewers

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

  • New Features

    • Added a new AppointmentDialog component for managing patient appointment details
    • Implemented functionality to view and potentially cancel appointments
    • Integrated internationalization support for appointment-related interactions
  • Improvements

    • Enhanced patient appointment management with a structured dialog interface

@NikhilA8606 NikhilA8606 requested a review from a team as a code owner January 15, 2025 10:13
Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Warning

Rate limit exceeded

@NikhilA8606 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between a9d10e6 and d64611a.

📒 Files selected for processing (2)
  • src/pages/Patient/components/AppointmentDialog.tsx (1 hunks)
  • src/pages/Patient/index.tsx (3 hunks)

Walkthrough

The pull request introduces a new AppointmentDialog component in the patient management section of the application. This component provides a comprehensive dialog for displaying appointment details, with functionality to cancel or reschedule appointments. It leverages React hooks, context, and internationalization to create an interactive and user-friendly interface for managing patient appointments.

Changes

File Change Summary
src/pages/Patient/AppointmentDialog.tsx New component added for displaying and managing appointment details, including cancellation functionality
src/pages/Patient/index.tsx Partial modifications to the PatientIndex component, with some useMutation related changes

Sequence Diagram

sequenceDiagram
    participant User
    participant AppointmentDialog
    participant QueryClient
    participant Backend

    User->>AppointmentDialog: Open Dialog
    AppointmentDialog->>AppointmentDialog: Render Appointment Details
    User->>AppointmentDialog: Click Cancel Appointment
    AppointmentDialog->>Backend: Send Cancellation Request
    Backend-->>AppointmentDialog: Cancellation Response
    AppointmentDialog->>QueryClient: Invalidate Queries
    AppointmentDialog->>User: Close Dialog
Loading

Possibly related PRs

Suggested labels

needs testing, needs review

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 Hop, hop, a dialog springs to life,
Appointments dance with cancel's strife,
Buttons click, details unfurl,
Patient care in a digital swirl,
CodeRabbit's magic takes its flight! 🏥


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.

@NikhilA8606 NikhilA8606 changed the title appointment detail flicker problem resolved Appointment detail flicker problem resolved Jan 15, 2025
Copy link

netlify bot commented Jan 15, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit d64611a
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6787984f23c46f0008feffcb
😎 Deploy Preview https://deploy-preview-9987--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 (3)
src/pages/Patient/AppointmentDialog.tsx (2)

50-52: Remove debug console.log statement.

The console.log statement for debugging the open state should be removed before merging.

-  useEffect(() => {
-    console.log("IsOpen", open);
-  }, [open]);

42-42: Remove debug console.log statement.

Remove the console.log statement from the mutation success callback.

-      console.log("Mutation Success!");
src/pages/Patient/index.tsx (1)

Line range hint 63-71: Optimize appointment filtering.

The appointments are filtered twice, once for past and once for scheduled appointments. Consider filtering once and storing the results.

+ const now = dayjs();
+ const [pastAppointments, scheduledAppointments] = appointments?.reduce(
+   (acc, appointment) => {
+     const isPast = now.isAfter(dayjs(appointment.token_slot.start_datetime));
+     acc[isPast ? 0 : 1].push(appointment);
+     return acc;
+   },
+   [[], []] as [Appointment[], Appointment[]]
+ ) ?? [[], []];
-  const pastAppointments = appointments?.filter((appointment) =>
-    dayjs().isAfter(dayjs(appointment.token_slot.start_datetime)),
-  );
-
-  const scheduledAppointments = appointments?.filter((appointment) =>
-    dayjs().isBefore(dayjs(appointment.token_slot.start_datetime)),
-  );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 45a26d0 and d00dc40.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • .env (1 hunks)
  • src/pages/Patient/AppointmentDialog.tsx (1 hunks)
  • src/pages/Patient/index.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (2)
src/pages/Patient/AppointmentDialog.tsx (1)

104-106: Add onClick handler for reschedule button.

The reschedule button is currently non-functional. Either implement the reschedule functionality or remove the button if the feature is not ready.

src/pages/Patient/index.tsx (1)

Line range hint 165-173: LGTM! Dialog integration looks good.

The AppointmentDialog integration is well implemented with proper state management for visibility and selected appointment.

Comment on lines 58 to 110
{open && (
<DialogContent className="p-0">
<DialogHeader className="p-3">
<DialogTitle>{t("appointment_details")}</DialogTitle>
<DialogDescription className="mb-4">
{t("appointment_details")}
</DialogDescription>
<div className="flex flex-row justify-between">
<div className="space-y-1">
<Label className="text-xs">{t("practitioner")}</Label>
<p className="text-base font-semibold">
{formatName(appointment.user)}
</p>
<p className="text-sm font-semibold text-gray-600">
{formatAppointmentSlotTime(appointment)}
</p>
</div>
<div className="space-y-1">
<Label className="text-xs">{t("patient_name")}</Label>
<p className="font-semibold text-base">
{appointment.patient.name}
</p>
<p className="text-sm text-gray-600 font-medium">
{formatPatientAge(appointment.patient as any, true)},{" "}
{t(`GENDER__${appointment.patient.gender}`)}
</p>
</div>
</div>
</DialogHeader>
<DialogFooter className="flex flex-row sm:justify-between items-center bg-blue-200 m-0 w-full p-3 rounded-b-lg">
<span className="text-sm font-semibold text-blue-700">
{t(appointment.status)}
</span>
<span className="flex flex-row gap-2">
<Button
variant="destructive"
disabled={isPending}
onClick={() => {
cancelAppointment({
appointment: appointment.id,
patient: appointment.patient.id,
});
}}
>
<span>{t("cancelli")}</span>
</Button>
<Button variant="secondary">
<span>{t("reschedule")}</span>
</Button>
</span>
</DialogFooter>
</DialogContent>
)}
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

Prevent dialog content flicker.

The current implementation may cause flickering as the dialog content is conditionally rendered based on the open state. To prevent this, move the condition to control visibility rather than mounting/unmounting.

    <Dialog open={open} onOpenChange={onOpenChange}>
-      {open && (
        <DialogContent className="p-0">
          {/* ... dialog content ... */}
        </DialogContent>
-      )}
    </Dialog>

Committable suggestion skipped: line range outside the PR's diff.

{appointment.patient.name}
</p>
<p className="text-sm text-gray-600 font-medium">
{formatPatientAge(appointment.patient as any, true)},{" "}
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 unsafe type casting.

The type casting to any should be avoided. Instead, ensure proper typing for the patient object.

-  {formatPatientAge(appointment.patient as any, true)},{" "}
+  {formatPatientAge(appointment.patient, true)},{" "}

Committable suggestion skipped: line range outside the PR's diff.

.env Outdated
@@ -7,7 +7,7 @@ REACT_APP_COVER_IMAGE_ALT=https://cdn.ohc.network/care_logo.svg
REACT_PUBLIC_URL=https://care.ohc.network

# Care API URL without the /api prefix
REACT_CARE_API_URL=https://careapi.ohc.network
REACT_CARE_API_URL=https://care-api.do.ohc.network
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Update API endpoint references in configuration files

The new Care API endpoint has been configured in .env, but there are still references to the old endpoint that need to be updated:

  • vercel.json: Update the destination URL from careapi.ohc.network to care-api.do.ohc.network
  • README.md: Update the Swagger documentation link to use the new endpoint
🔗 Analysis chain

Verify API endpoint change impact.

The Care API endpoint has been updated. Please ensure:

  1. The new endpoint is properly configured and accessible
  2. All API calls in the application are tested with the new endpoint
  3. No hardcoded references to the old endpoint exist in the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any hardcoded references to the old API endpoint
rg -i "careapi\.ohc\.network"

Length of output: 179


Script:

#!/bin/bash
# Search for variations of both endpoints and environment variable usage
rg -i "care.?api\..*ohc\.network"
rg "REACT_CARE_API_URL"
fd -e json -e yaml -e yml -e env | xargs cat

Length of output: 69284

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: 2

🧹 Nitpick comments (4)
src/pages/Patient/AppointmentDialog.tsx (4)

49-51: Remove development console.log statement.

Remove the console.log statement used for debugging as it's not needed in production code.

-  useEffect(() => {
-    console.log("IsOpen", open);
-  }, [open]);

53-53: Add loading state handling.

Instead of returning an empty fragment when appointment is undefined, consider showing a loading state or skeleton UI to improve user experience.

-  if (!appointment) return <></>;
+  if (!appointment) {
+    return (
+      <Dialog open={open} onOpenChange={onOpenChange}>
+        <DialogContent className="p-0">
+          <div className="p-3 animate-pulse">
+            <div className="h-4 bg-gray-200 rounded w-1/4 mb-4"></div>
+            <div className="space-y-3">
+              <div className="h-4 bg-gray-200 rounded w-3/4"></div>
+              <div className="h-4 bg-gray-200 rounded w-1/2"></div>
+            </div>
+          </div>
+        </DialogContent>
+      </Dialog>
+    );
+  }

86-86: Validate appointment status translation key.

Direct usage of status as translation key could lead to missing translations. Consider maintaining a mapping of status to translation keys.

-  {t(appointment.status)}
+  {t(APPOINTMENT_STATUS_TRANSLATIONS[appointment.status] ?? 'unknown_status')}

24-109: Consider splitting the component for better maintainability.

While the component successfully implements the appointment dialog functionality, it could benefit from being split into smaller, more focused components:

  1. A separate component for patient information display
  2. A separate component for action buttons
  3. A custom hook for appointment cancellation logic

This would improve maintainability and make the code more testable.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d00dc40 and a6d60e2.

📒 Files selected for processing (1)
  • src/pages/Patient/AppointmentDialog.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Test
  • GitHub Check: CodeQL-Build
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (1)
src/pages/Patient/AppointmentDialog.tsx (1)

78-78: Remove unsafe type casting.

The type casting to any should be avoided. Instead, ensure proper typing for the patient object.

-  {formatPatientAge(appointment.patient as any, true)},{" "}
+  {formatPatientAge(appointment.patient, true)},{" "}

Comment on lines 101 to 103
<Button variant="secondary">
<span>{t("reschedule")}</span>
</Button>
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

Add onClick handler for reschedule button.

The reschedule button is missing an onClick handler, making it non-functional.

-  <Button variant="secondary">
+  <Button 
+    variant="secondary"
+    onClick={() => {
+      // Add reschedule logic here
+      // Consider navigating to reschedule page or opening reschedule dialog
+    }}
+  >
     <span>{t("reschedule")}</span>
   </Button>
📝 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
<Button variant="secondary">
<span>{t("reschedule")}</span>
</Button>
<Button
variant="secondary"
onClick={() => {
// Add reschedule logic here
// Consider navigating to reschedule page or opening reschedule dialog
}}
>
<span>{t("reschedule")}</span>
</Button>

Comment on lines 34 to 47
const { mutate: cancelAppointment, isPending } = useMutation({
mutationFn: mutate(PublicAppointmentApi.cancelAppointment, {
headers: {
Authorization: `Bearer ${tokenData?.token}`,
},
}),
onSuccess: () => {
console.log("Mutation Success!");
queryClient.invalidateQueries({
queryKey: ["appointment", tokenData?.phoneNumber],
});
props.setAppointmentDialogOpen(false);
},
});
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

Enhance mutation handling.

The mutation setup needs improvements:

  1. Remove the console.log statement
  2. Add error handling
  3. Show success/error feedback to the user
  const { mutate: cancelAppointment, isPending } = useMutation({
    mutationFn: mutate(PublicAppointmentApi.cancelAppointment, {
      headers: {
        Authorization: `Bearer ${tokenData?.token}`,
      },
    }),
    onSuccess: () => {
-     console.log("Mutation Success!");
      queryClient.invalidateQueries({
        queryKey: ["appointment", tokenData?.phoneNumber],
      });
      props.setAppointmentDialogOpen(false);
+     // Show success toast/notification
+     toast.success(t("appointment_cancelled_successfully"));
    },
+   onError: (error) => {
+     // Show error toast/notification
+     toast.error(t("error_cancelling_appointment"));
+     console.error("Error cancelling appointment:", error);
+   },
  });

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Member

Choose a reason for hiding this comment

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

We have a pattern that we follow for placing components.

src/pages/<module_name>/<page_name> are where the pages are kept
src/pages/<module_name>/components/<component_name> are where the components of that module are kept

let's move this file to components folder of this module.

Copy link
Member

Choose a reason for hiding this comment

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

other than this, lgtm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay

@rithviknishad rithviknishad merged commit 2fc9e33 into ohcnetwork:develop Jan 15, 2025
16 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.

2 participants