Skip to content

feat: connect daily tips to backend#90

Open
tg14102005-a11y wants to merge 1 commit into
mainfrom
feat/daily-tips-connect
Open

feat: connect daily tips to backend#90
tg14102005-a11y wants to merge 1 commit 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

  • New Features
    • Daily tips are now dynamically fetched and displayed in the app.
    • Added loading indicators and error handling for the daily tip feature.

@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

📝 Walkthrough

Walkthrough

Adds a DailyTip interface and getDailyTip function in a new tips API service, then introduces a useDailyTip hook that fetches the daily tip on mount. TitleAndDescription is updated to consume the hook, replacing static i18next translation strings with live tip.title/tip.description values and returning null during loading, error, or missing data.

Changes

Daily Tip API Integration

Layer / File(s) Summary
DailyTip interface and API fetch function
src/services/api/tips.service.ts
Defines the DailyTip interface (title, description) and exports getDailyTip, which calls apiService.get<DailyTip> on the /tips/daily endpoint.
useDailyTip hook
src/hooks/useDailyTip.ts
Creates the hook that invokes getDailyTip on mount via useEffect, manages tip, isLoading (starts true), and error (set to 'error' string on failure), and returns all three.
TitleAndDescription renders live tip data
src/pages/home/dailyTips/titleAndDescription/TitleAndDescription.tsx
Replaces useTranslation with useDailyTip; adds early null returns for loading, error, and missing tip; swaps t('daily.tip.*') calls for tip.title and tip.description.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • ColmanDevClubORG/Sagol360Management#30: Previously wired TitleAndDescription with i18next-based static strings — this PR reverses that by removing useTranslation and replacing it with live API data from useDailyTip.

Suggested reviewers

  • Tamir198

Poem

🐇 A tip a day keeps the dullness away,
No more static strings from i18n's tray!
The hook fetches data right on mount,
From /tips/daily — what a count!
With loading and error, we guard the view,
Live tips now render, shiny and new! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning PR description contains non-English text and lacks required issue number; most checklist items are incomplete or malformed. Provide description in English, include a valid issue number in 'Fixes #', and ensure checklist formatting is correct (use '- [x]' for checked items).
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objective: connecting daily tips functionality to the backend API.
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

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.

@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
Comment on lines +9 to +14
useEffect(() => {
getDailyTip()
.then(setTip)
.catch(() => setError('error'))
.finally(() => setIsLoading(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 | 🟡 Minor | ⚡ Quick win

Add unmount/cancel protection for async state updates.

On Line 9-14, the pending request can still call setTip/setError/setIsLoading after unmount. Add a cleanup guard (or request cancellation) to avoid stale updates.

Proposed fix
 useEffect(() => {
+  let isActive = true
   getDailyTip()
-    .then(setTip)
-    .catch(() => setError('error'))
-    .finally(() => setIsLoading(false))
+    .then((data) => {
+      if (isActive) setTip(data)
+    })
+    .catch(() => {
+      if (isActive) setError('error')
+    })
+    .finally(() => {
+      if (isActive) setIsLoading(false)
+    })
+
+  return () => {
+    isActive = false
+  }
 }, [])
📝 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
useEffect(() => {
getDailyTip()
.then(setTip)
.catch(() => setError('error'))
.finally(() => setIsLoading(false))
}, [])
useEffect(() => {
let isActive = true
getDailyTip()
.then((data) => {
if (isActive) setTip(data)
})
.catch(() => {
if (isActive) setError('error')
})
.finally(() => {
if (isActive) setIsLoading(false)
})
return () => {
isActive = 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/hooks/useDailyTip.ts` around lines 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.

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

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.

2 participants