Skip to content

Commit 2602787

Browse files
fix(OUT-4003): address PR #267 review
- AccountSelect distinguishes the loading state (options undefined → "Loading accounts…") from the genuinely-empty state ("No matching accounts"), and InvoiceDetail only shows the "select an account" hint once options have loaded — so enabling the toggle mid-fetch no longer shows a misleading empty message. - changeSettings is now generic over the field key (<K extends keyof InvoiceSettingType>(flag: K, value: InvoiceSettingType[K])), so the value type is tied to the field and e.g. a string can't be passed for a boolean flag. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4151d1e commit 2602787

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

src/components/dashboard/settings/sections/account/AccountSelect.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default function AccountSelect({
2424

2525
useClickOutside(dropdownRef, () => setIsOpen(false), [buttonRef])
2626

27+
const loading = options === undefined
2728
const disabled = !options || options.length === 0
2829
const selected = options?.find((o) => o.id === value)
2930
// Defends against an account being deleted in QBO between load and save —
@@ -57,7 +58,11 @@ export default function AccountSelect({
5758
</span>
5859
) : (
5960
<span className="text-gray-400">
60-
{disabled ? 'No matching accounts in QuickBooks' : placeholder}
61+
{loading
62+
? 'Loading accounts…'
63+
: disabled
64+
? 'No matching accounts in QuickBooks'
65+
: placeholder}
6166
</span>
6267
)}
6368
</div>

src/components/dashboard/settings/sections/invoice/InvoiceDetail.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { Checkbox, Spinner } from 'copilot-design-system'
66

77
type InvoiceDetailProps = {
88
settingState: InvoiceSettingType
9-
changeSettings: (
10-
flag: keyof InvoiceSettingType,
11-
value: boolean | string,
9+
changeSettings: <K extends keyof InvoiceSettingType>(
10+
flag: K,
11+
value: InvoiceSettingType[K],
1212
) => void
1313
isLoading: boolean
1414
bankAccountOptions: AccountOption[] | undefined
@@ -70,11 +70,12 @@ export default function InvoiceDetail({
7070
placeholder="Select a deposit bank account"
7171
onChange={(id) => changeSettings('bankAccountRef', id)}
7272
/>
73-
{!settingState.bankAccountRef && (
74-
<p className="text-xs text-red-600">
75-
Select a deposit bank account to enable bank deposits.
76-
</p>
77-
)}
73+
{bankAccountOptions !== undefined &&
74+
!settingState.bankAccountRef && (
75+
<p className="text-xs text-red-600">
76+
Select a deposit bank account to enable bank deposits.
77+
</p>
78+
)}
7879
</>
7980
)}
8081
</div>

src/hook/useSettings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ export const useInvoiceDetailSettings = () => {
467467
name: account.Name,
468468
}))
469469

470-
const changeSettings = async (
471-
flag: keyof InvoiceSettingType,
472-
value: boolean | string,
470+
const changeSettings = async <K extends keyof InvoiceSettingType>(
471+
flag: K,
472+
value: InvoiceSettingType[K],
473473
) => {
474474
setSettingState((prev) => ({ ...prev, [flag]: value }))
475475
}

0 commit comments

Comments
 (0)