Skip to content

feat: 86extdm6t#89

Open
rachelishteren wants to merge 1 commit into
mainfrom
appointment
Open

feat: 86extdm6t#89
rachelishteren wants to merge 1 commit into
mainfrom
appointment

Conversation

@rachelishteren

@rachelishteren rachelishteren commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

What was done

  • Added React Query integration for fetching next appointment data.
  • Replaced static appointment data with backend data.
  • Connected BottomSheetDialog to the fetched appointment.

Even after a lot of effort I couldn't get the backend to run, so I couldn't check if it actually works
I would be happy if you could check the code for me theoretically

Summary by CodeRabbit

  • Refactor
    • Improved how appointment data is managed in the home page. The next appointment is now fetched dynamically rather than stored locally, and the appointment details dialog behavior has been refined for better state handling.

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Home component replaces its local Appointment | undefined state with a useQuery call to apiService.get<Appointment> using hardcoded patientID and date values. A separate boolean selectedAppointment now controls BottomSheetDialog visibility, which opens when the flag is true and a fetched appointment exists, and closes by setting the flag to false.

Changes

Home Appointment Fetch Refactor

Layer / File(s) Summary
useQuery fetch and BottomSheetDialog wiring
src/pages/home/home.tsx
Imports add useQuery and apiService; local state changes from Appointment | undefined to a boolean selectedAppointment; a useQuery call with hardcoded patientID/date fetches the next appointment via apiService.get<Appointment>; BottomSheetDialog receives appointment={appointment}, sets isOpen to selectedAppointment && !!appointment, and closes by calling setSelectedAppointment(false).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop hop, no more state held tight,
The appointment is fetched through the query's light.
A boolean flag keeps the sheet in check,
apiService answers every beck.
Clean carrots, clean code — what a delightful night! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'feat: 86extdm6t' is cryptic and does not clearly describe the actual changes (React Query integration for appointment fetching). Use a descriptive title like 'feat: integrate React Query for appointment data fetching' that clearly summarizes the main change.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description adequately covers what was done, acknowledges limitations in testing, and requests code review. While it doesn't fully match the template format, it provides sufficient context about the changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch appointment

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.

@rachelishteren rachelishteren requested a review from GilHeller June 14, 2026 20:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 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/pages/home/home.tsx`:
- Around line 40-44: The BottomSheetDialog component in the home component can
be closed via the onClose handler which sets selectedAppointment to false, but
there is no UI element that allows reopening it by setting selectedAppointment
back to true. Add a clickable UI element (such as an appointment card or button)
that calls setSelectedAppointment(true) when clicked to allow users to reopen
the dialog and access the appointment information again after closing it.
- Line 17: The selectedAppointment state is initialized to true, causing the
dialog to auto-open when the component mounts instead of waiting for user
interaction. Change the initial value of the selectedAppointment useState hook
from true to false so the dialog does not open automatically. Then add a UI
element such as a button or clickable card with an onClick handler that calls
setSelectedAppointment(true) to allow users to deliberately open the appointment
dialog when they choose to view their appointment.
- Around line 22-33: The useQuery hook for fetching the next appointment is only
destructuring the data property and ignoring isLoading and isError states.
Modify the destructuring in the useQuery call to also extract isLoading and
isError along with data, then add conditional rendering logic to display
appropriate loading indicators when isLoading is true and error messages or
fallback UI when isError is true, ensuring the user receives feedback during
slow API calls or when the appointment fetch fails.
- Around line 19-20: Replace the hardcoded patientID and date values in the home
component with dynamic, user-specific data to ensure data integrity and privacy.
First, complete the authentication implementation in useAuth.ts (address the
existing TODO) to provide authenticated user context. Then in home.tsx, replace
the hardcoded patientID constant with the actual patient identifier from the
authenticated user returned by useAuth, and replace the hardcoded date constant
with dynamic logic such as retrieving the current date or the next available
appointment date. This ensures each user sees only their own appointment data.
🪄 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: 49bf265b-8d9d-4e79-a845-018ce6823e74

📥 Commits

Reviewing files that changed from the base of the PR and between 74d158a and 51a0d00.

📒 Files selected for processing (1)
  • src/pages/home/home.tsx

Comment thread src/pages/home/home.tsx
chairNumber: 9,
treatmentNumber: 2,
status: 'confirmed',
const [selectedAppointment, setSelectedAppointment] = useState<boolean>(true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Dialog auto-opens on mount due to initial true state.

Initializing selectedAppointment to true causes the dialog to attempt opening immediately when the component mounts, creating an auto-popup experience. Users typically expect dialogs to open in response to a deliberate action (e.g., clicking a button), not automatically on page load.

🔧 Recommended fix
-  const [selectedAppointment, setSelectedAppointment] = useState<boolean>(true)
+  const [selectedAppointment, setSelectedAppointment] = useState<boolean>(false)

Then add a UI element (e.g., a button or card click handler) that calls setSelectedAppointment(true) when the user wants to view their appointment.

📝 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 [selectedAppointment, setSelectedAppointment] = useState<boolean>(true)
const [selectedAppointment, setSelectedAppointment] = useState<boolean>(false)
🤖 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/pages/home/home.tsx` at line 17, The selectedAppointment state is
initialized to true, causing the dialog to auto-open when the component mounts
instead of waiting for user interaction. Change the initial value of the
selectedAppointment useState hook from true to false so the dialog does not open
automatically. Then add a UI element such as a button or clickable card with an
onClick handler that calls setSelectedAppointment(true) to allow users to
deliberately open the appointment dialog when they choose to view their
appointment.

Comment thread src/pages/home/home.tsx
Comment on lines +19 to +20
const patientID = '1622017'
const date = '07-06-2026'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Find how user/patient ID is accessed elsewhere in the codebase

# Search for user context, auth context, or patient context patterns
rg -n -C3 --type=tsx --type=ts 'useUser|useAuth|usePatient|user.*context|patient.*context' -i

# Search for existing patterns of getting current user/patient ID
rg -n -C3 --type=tsx --type=ts 'currentUser|userId|patientId|patient.*id' -i | head -50

Repository: ColmanDevClubORG/Sagol360Management

Length of output: 135


🏁 Script executed:

# Read the home.tsx file to understand the context
cat -n src/pages/home/home.tsx | head -40

Repository: ColmanDevClubORG/Sagol360Management

Length of output: 1789


🏁 Script executed:

# Search for user/auth context patterns with corrected rg syntax
rg -n -C3 'useUser|useAuth|usePatient|useContext.*user|useContext.*auth' -t ts -t tsx

# Also search for how patientId/userId is typically accessed
rg -n -C3 'patient.*id|user.*id|currentUser' -t ts -t tsx | head -50

Repository: ColmanDevClubORG/Sagol360Management

Length of output: 135


🏁 Script executed:

# Check if there are any imports or hooks related to authentication in the codebase
fd -e ts -e tsx | xargs grep -l 'useAuth\|useUser\|user.*context' | head -20

Repository: ColmanDevClubORG/Sagol360Management

Length of output: 149


🏁 Script executed:

# Read the useAuth hook to understand how to access user context
cat -n src/hooks/useAuth.ts

Repository: ColmanDevClubORG/Sagol360Management

Length of output: 258


🏁 Script executed:

# Check ProtectedRoute to understand auth patterns
cat -n src/components/ProtectedRoute/ProtectedRoute.tsx

Repository: ColmanDevClubORG/Sagol360Management

Length of output: 380


🏁 Script executed:

# Search for other uses of patientID in the codebase to understand patterns
rg -n 'patientID|patientId' --max-count=20

Repository: ColmanDevClubORG/Sagol360Management

Length of output: 1163


🏁 Script executed:

# Look for user/session/auth context setup (try without type filters)
rg -n 'createContext|useContext|useState.*user|useState.*auth' | head -30

Repository: ColmanDevClubORG/Sagol360Management

Length of output: 61


Hardcoded test data must be replaced with dynamic user context and date logic.

These hardcoded values will cause all users to see the same appointment data (patient 1622017 on 07-06-2026), which is a critical data integrity and privacy issue. The authentication system is currently incomplete (see the TODO in useAuth.ts), but once it provides user context, patientID must be retrieved from the authenticated user instead of hardcoded here.

Before merging:

  • Implement proper user authentication in useAuth.ts to provide authenticated user/patient context
  • Replace the hardcoded patientID with the actual value from the authenticated user
  • Replace the hardcoded date with dynamic logic (e.g., current date or next available appointment date)
🤖 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/pages/home/home.tsx` around lines 19 - 20, Replace the hardcoded
patientID and date values in the home component with dynamic, user-specific data
to ensure data integrity and privacy. First, complete the authentication
implementation in useAuth.ts (address the existing TODO) to provide
authenticated user context. Then in home.tsx, replace the hardcoded patientID
constant with the actual patient identifier from the authenticated user returned
by useAuth, and replace the hardcoded date constant with dynamic logic such as
retrieving the current date or the next available appointment date. This ensures
each user sees only their own appointment data.

Comment thread src/pages/home/home.tsx
Comment on lines +22 to 33
const { data: appointment } = useQuery({
queryKey: ['nextAppointment', patientID, date],
queryFn: async () => {
const response = await apiService.get<Appointment>('/api/appointment/nextAppointment', {
params: {
patientID,
date,
},
})
return response
},
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add error and loading state handling for better user experience.

The query result is destructured to only data, ignoring isLoading and isError. If the API call is slow or fails, the user receives no feedback—the dialog simply never appears.

Consider destructuring and handling these states:

💡 Suggested enhancement
-  const { data: appointment } = useQuery({
+  const { data: appointment, isLoading, isError, error } = useQuery({
     queryKey: ['nextAppointment', patientID, date],
     queryFn: async () => {
       const response = await apiService.get<Appointment>('/api/appointment/nextAppointment', {
         params: {
           patientID,
           date,
         },
       })
       return response
     },
   })
+
+  if (isLoading) {
+    return <div>Loading appointment...</div> // Or a proper loading skeleton
+  }
+
+  if (isError) {
+    console.error('Failed to fetch appointment:', error)
+    // Show error UI or toast notification
+  }
📝 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: appointment } = useQuery({
queryKey: ['nextAppointment', patientID, date],
queryFn: async () => {
const response = await apiService.get<Appointment>('/api/appointment/nextAppointment', {
params: {
patientID,
date,
},
})
return response
},
})
const { data: appointment, isLoading, isError, error } = useQuery({
queryKey: ['nextAppointment', patientID, date],
queryFn: async () => {
const response = await apiService.get<Appointment>('/api/appointment/nextAppointment', {
params: {
patientID,
date,
},
})
return response
},
})
if (isLoading) {
return <div>Loading appointment...</div> // Or a proper loading skeleton
}
if (isError) {
console.error('Failed to fetch appointment:', error)
// Show error UI or toast notification
}
🤖 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/pages/home/home.tsx` around lines 22 - 33, The useQuery hook for fetching
the next appointment is only destructuring the data property and ignoring
isLoading and isError states. Modify the destructuring in the useQuery call to
also extract isLoading and isError along with data, then add conditional
rendering logic to display appropriate loading indicators when isLoading is true
and error messages or fallback UI when isError is true, ensuring the user
receives feedback during slow API calls or when the appointment fetch fails.

Comment thread src/pages/home/home.tsx
Comment on lines 40 to 44
<BottomSheetDialog
appointment={selectedAppointment}
isOpen={!!selectedAppointment}
onClose={() => setSelectedAppointment(undefined)}
appointment={appointment}
isOpen={selectedAppointment && !!appointment}
onClose={() => setSelectedAppointment(false)}
/>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | 🏗️ Heavy lift

No mechanism to reopen the dialog after closing.

Once the user closes the dialog, selectedAppointment is set to false (line 43), but there is no UI element in this component that allows the user to set it back to true. This makes the appointment information inaccessible until the page is refreshed, breaking a core user workflow.

🔧 Recommended solution

Add a clickable UI element (e.g., an appointment card or "View Appointment" button) that calls setSelectedAppointment(true) when clicked. For example:

<AppointmentCard 
  appointment={appointment}
  onClick={() => setSelectedAppointment(true)}
/>

or

{appointment && (
  <button onClick={() => setSelectedAppointment(true)}>
    View Next Appointment
  </button>
)}
🤖 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/pages/home/home.tsx` around lines 40 - 44, The BottomSheetDialog
component in the home component can be closed via the onClose handler which sets
selectedAppointment to false, but there is no UI element that allows reopening
it by setting selectedAppointment back to true. Add a clickable UI element (such
as an appointment card or button) that calls setSelectedAppointment(true) when
clicked to allow users to reopen the dialog and access the appointment
information again after closing it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant