-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Persist settings panel preferences to localStorage #31
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,14 @@ export function SettingsPanel() { | |
| </div> | ||
| <input | ||
| type="number" | ||
| defaultValue={40} | ||
| value={weeklyHoursTarget} | ||
| onChange={(e) => | ||
| updateSettings({ | ||
| weeklyHoursTarget: parseInt(e.target.value, 10) || 0, | ||
| }) | ||
| } | ||
| min={0} | ||
| max={168} | ||
| 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
150
|
||
| </div> | ||
|
|
@@ -146,7 +155,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" | ||
| /> | ||
| <div className="peer h-6 w-11 rounded-full bg-dark-600 after:absolute after:left-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:bg-white after:transition-all after:content-[''] peer-checked:bg-thyme-600 peer-checked:after:translate-x-full peer-focus:outline-none peer-focus:ring-2 peer-focus:ring-thyme-500"></div> | ||
| </label> | ||
|
Comment on lines
157
to
165
|
||
| </div> | ||
|
|
||
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.
The fallback value of
0when parsing fails could result in an invalid weeklyHoursTarget. When a user clears the input field or enters invalid text,parseIntreturnsNaN, which would then be replaced with0. This means users cannot intentionally clear the field, and it will immediately snap to0, which may not be the desired behavior. Consider either maintaining the previous valid value when parsing fails, or using an empty string check before parsing to preserve user input during editing.