Skip to content

feat: connect daily tips to backend#90

Open
tg14102005-a11y wants to merge 3 commits into
mainfrom
feat/daily-tips-connect
Open

feat: connect daily tips to backend#90
tg14102005-a11y wants to merge 3 commits into
mainfrom
feat/daily-tips-connect

Conversation

@tg14102005-a11y

@tg14102005-a11y tg14102005-a11y commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Description

Please include a summary of the changes and the related issue.
חיברתי את הטיפ היומי לבאקאנד.
יצרתי tips.service.ts עם הקריאה ל-API, hook של useDailyTip שמושך את הדאטה
ועדכנתי את TitleAndDescription שיציג את הדאטה האמיתית.

.

Related Issue(s)

Fixes # (issue number)

Checklist:

  • [ x] I have performed a self-review of my own code
  • [x ] My changes generate no new warnings

Screenshots (if appropriate):

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Daily tips are now fetched from a server endpoint and rendered dynamically on the home page.
  • Behavior Changes
    • The daily tip section now respects loading and error states (it won’t render placeholder content while loading, and it won’t display stale/missing data when no tip is available).

@tg14102005-a11y tg14102005-a11y requested a review from Tamir198 June 16, 2026 23:18
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 24fe0574-123b-4032-b716-1e7b1323f2d1

📥 Commits

Reviewing files that changed from the base of the PR and between 78a55a0 and df815fe.

📒 Files selected for processing (2)
  • src/constants/api.constants.ts
  • src/hooks/useDailyTip.ts

📝 Walkthrough

Walkthrough

Adds a daily tips API contract and react-query hook, then updates the home daily tip component to render fetched title and description values with null guards for loading, error, and missing data.

Changes

Daily Tip API Integration

Layer / File(s) Summary
DailyTip API contract
src/constants/api.constants.ts, src/services/api/tips.service.ts
Defines the DailyTip interface, adds the daily tips endpoint constant, and exports getDailyTip for fetching tip data.
useDailyTip query hook
src/hooks/useDailyTip.ts
Replaces manual state management with a useQuery call keyed by ['dailyTip'] that fetches DailyTip data and returns tip, isLoading, and error.
TitleAndDescription uses tip data
src/pages/home/dailyTips/titleAndDescription/TitleAndDescription.tsx
Consumes useDailyTip, returns null while loading, on error, or without data, and renders tip.title and tip.description instead of translation strings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • Tamir198

Poem

🐇 A tip from the server, bright and new,
Hops through the hook and lands in view.
No static strings in the meadow tonight,
Just title and description, fetched just right.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: connecting daily tips to the backend.
Description check ✅ Passed The description includes a change summary, related issue section, and checklist, though the issue number is still a placeholder.
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 feat/daily-tips-connect
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/daily-tips-connect

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.

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

🤖 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/hooks/useDailyTip.ts`:
- Around line 9-14: The useEffect hook in the getDailyTip promise chain (setTip,
setError, setIsLoading calls) lacks protection against state updates after
component unmount, which can cause memory leaks and warnings. Add a cleanup
function to the useEffect that prevents these state setters from being called
after unmount by using a mounted ref flag that gets set to false in the cleanup
function, then check this flag before executing any setState calls in the
promise handlers.

In `@src/pages/home/dailyTips/titleAndDescription/TitleAndDescription.tsx`:
- Around line 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.
🪄 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: 5b5a53f3-4582-4758-bcf9-31957594482c

📥 Commits

Reviewing files that changed from the base of the PR and between 74d158a and 78a55a0.

📒 Files selected for processing (3)
  • src/hooks/useDailyTip.ts
  • src/pages/home/dailyTips/titleAndDescription/TitleAndDescription.tsx
  • src/services/api/tips.service.ts

Comment thread src/hooks/useDailyTip.ts Outdated
Comment on lines +8 to +9
if (isLoading) return null
if (error || !tip) return null

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 thread src/hooks/useDailyTip.ts Outdated
const [error, setError] = useState<string | null>(null)

useEffect(() => {
getDailyTip()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We are not using useEffect for api calls, we are using tanstack query, check other examples of how we are calling api

@tg14102005-a11y

Copy link
Copy Markdown
Collaborator Author

Fixed! Replaced useEffect with useQuery from tanstack query. Also resolved merge conflict in api.constants.ts

@tg14102005-a11y tg14102005-a11y requested a review from Tamir198 June 24, 2026 19:02
<>
<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

}

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

Comment thread src/hooks/useDailyTip.ts
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?

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

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

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

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.

3 participants