Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/constants/api.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export const API_ENDPOINTS = {
patient: '/api/patients/',
metrics: '/api/metrics/',
metricsToday: '/api/metrics/today/',
email: '/api/email',
tips: '/api/tips/daily',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why did you remove it? This is a reference for a working route

}
13 changes: 13 additions & 0 deletions src/hooks/useDailyTip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useQuery } from '@tanstack/react-query'
import { API_ENDPOINTS } from '@/constants/api.constants'
import { apiService } from '@/services/api/api.service'
import type { DailyTip } from '@/services/api/tips.service'

export const useDailyTip = () => {
const { data, isLoading, error } = useQuery({
queryKey: ['dailyTip'],
queryFn: () => apiService.get<DailyTip>(API_ENDPOINTS.tips),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You had implemented getDailyTip() in src/services/api/tips.service.ts. Why don't you use it?

})

return { tip: data, isLoading, error }
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { useTranslation } from 'react-i18next'
import { SGLTypography } from '@/components/UI/Typography/SGLTypography'
import { titleAndDescriptionStyles } from './styles'
import { useDailyTip } from '@/hooks/useDailyTip'

export const TitleAndDescription = () => {
const { t } = useTranslation()
const { tip, isLoading, error } = useDailyTip()

if (isLoading) return null
if (error || !tip) return null
Comment on lines +8 to +9

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 | 🟡 Minor | ⚡ Quick win

Don’t render a blank section on error/no-data.

On Line 8-9, return null for error or missing tip removes all feedback. Please render a lightweight fallback message (or previous default copy) so the UI stays informative.

Proposed fix
-  if (isLoading) return null
-  if (error || !tip) return null
+  if (isLoading) return null
+  if (error || !tip) {
+    return (
+      <>
+        <SGLTypography variant="smallTitle" styles={titleAndDescriptionStyles.title}>
+          Daily tip
+        </SGLTypography>
+        <SGLTypography variant="smallText" styles={titleAndDescriptionStyles.description}>
+          Tip is currently unavailable.
+        </SGLTypography>
+      </>
+    )
+  }
🤖 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/dailyTips/titleAndDescription/TitleAndDescription.tsx` around
lines 8 - 9, The TitleAndDescription component currently returns null when there
is an error or no tip data (the condition on line 8-9), which leaves the UI
blank with no user feedback. Instead of returning null in both the error and
no-data cases, render a lightweight fallback message or default copy that keeps
the UI informative and provides clear feedback to the user about the state of
the content.

Comment on lines +8 to +9

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Component should return JSX return </> instead of null


return (
<>
<SGLTypography variant="smallTitle" styles={titleAndDescriptionStyles.title}>
{t('daily.tip.title')}
{tip.title}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why did you removed the translation support?

</SGLTypography>
<SGLTypography variant="smallText" styles={titleAndDescriptionStyles.description}>
{t('daily.tip.description')}
{tip.description}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here.

change the language

</SGLTypography>
</>
)
Expand Down
10 changes: 10 additions & 0 deletions src/services/api/tips.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { apiService } from './api.service'

export interface DailyTip {
title: string
description: string
}

export const getDailyTip = (): Promise<DailyTip> => {
return apiService.get<DailyTip>('/tips/daily')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

consider to use const and move it to the appropriate file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

API_ENDPOINTS.tips

}
Loading