-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Persist settings panel preferences to localStorage #32
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { useState, useEffect } from 'react'; | |||||||
| import { Card } from '@/components/ui'; | ||||||||
| import { bcClient } from '@/services/bc/bcClient'; | ||||||||
| import { useAuth } from '@/services/auth'; | ||||||||
| import { useSettingsStore } from '@/hooks/useSettingsStore'; | ||||||||
| import { | ||||||||
| BuildingOffice2Icon, | ||||||||
| EnvelopeIcon, | ||||||||
|
|
@@ -26,6 +27,7 @@ interface CompanyInfo { | |||||||
|
|
||||||||
| export function SettingsPanel() { | ||||||||
| const { account } = useAuth(); | ||||||||
| const { weeklyHoursTarget, notificationsEnabled, updateSettings } = useSettingsStore(); | ||||||||
| const [companyInfo, setCompanyInfo] = useState<CompanyInfo | null>(null); | ||||||||
| const [isLoading, setIsLoading] = useState(true); | ||||||||
| const [error, setError] = useState<string | null>(null); | ||||||||
|
|
@@ -136,7 +138,13 @@ export function SettingsPanel() { | |||||||
| </div> | ||||||||
| <input | ||||||||
| type="number" | ||||||||
| defaultValue={40} | ||||||||
| value={weeklyHoursTarget} | ||||||||
| onChange={(e) => | ||||||||
| updateSettings({ | ||||||||
| weeklyHoursTarget: Math.max(0, parseInt(e.target.value) || 0), | ||||||||
| }) | ||||||||
| } | ||||||||
| min={0} | ||||||||
| className="w-20 rounded-lg border border-dark-600 bg-dark-800 px-3 py-2 text-dark-100 focus:outline-none focus:ring-2 focus:ring-thyme-500" | ||||||||
| /> | ||||||||
|
Comment on lines
139
to
149
|
||||||||
| </div> | ||||||||
|
|
@@ -146,7 +154,12 @@ export function SettingsPanel() { | |||||||
| <p className="text-sm text-dark-400">Get reminded to fill in your timesheet</p> | ||||||||
| </div> | ||||||||
| <label className="relative inline-flex cursor-pointer items-center"> | ||||||||
| <input type="checkbox" defaultChecked className="peer sr-only" /> | ||||||||
| <input | ||||||||
| type="checkbox" | ||||||||
| checked={notificationsEnabled} | ||||||||
| onChange={(e) => updateSettings({ notificationsEnabled: e.target.checked })} | ||||||||
| className="peer sr-only" | ||||||||
|
||||||||
| className="peer sr-only" | |
| className="peer sr-only" | |
| aria-label="Timesheet Reminders" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the input is cleared completely (empty string), parseInt will return NaN, and the fallback to 0 will set weeklyHoursTarget to 0. This means users cannot backspace to clear the field and type a new value without the field immediately resetting to 0. Consider using a controlled input pattern that allows temporary invalid states while typing, or use a separate local state to handle the input value and only update the store onBlur.