refactor: make JournalEntryForm reusable with embedded mode
Add props for initialLines, initialDate, initialDescription, sourceType, sourceId, submitUrl, embedded, and onEntryCreated to support embedding the form in dialogs. Auto-fill line description from account name. Improve AccountCombobox to only emit valid account numbers and reset on blur. Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
@@ -139,7 +139,10 @@ export default function AccountCombobox({ value, accounts, onChange }: AccountCo
|
||||
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const newValue = e.target.value
|
||||
setSearch(newValue)
|
||||
onChange(newValue)
|
||||
// Only emit valid account numbers to parent
|
||||
if (/^\d{4}$/.test(newValue) && accounts.some(a => a.account_number === newValue)) {
|
||||
onChange(newValue)
|
||||
}
|
||||
if (!isOpen) {
|
||||
setIsOpen(true)
|
||||
}
|
||||
@@ -149,6 +152,15 @@ export default function AccountCombobox({ value, accounts, onChange }: AccountCo
|
||||
setIsOpen(true)
|
||||
}
|
||||
|
||||
const handleBlur = () => {
|
||||
// Small delay to allow dropdown click to fire first
|
||||
setTimeout(() => {
|
||||
if (!accounts.some(a => a.account_number === search)) {
|
||||
setSearch(value)
|
||||
}
|
||||
}, 150)
|
||||
}
|
||||
|
||||
// Find matching account for helper text
|
||||
const matchedAccount = useMemo(() => {
|
||||
if (!value || value.length !== 4) return null
|
||||
@@ -162,16 +174,16 @@ export default function AccountCombobox({ value, accounts, onChange }: AccountCo
|
||||
value={search}
|
||||
onChange={handleInputChange}
|
||||
onFocus={handleFocus}
|
||||
onBlur={handleBlur}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder="1930"
|
||||
className="font-mono h-8"
|
||||
maxLength={4}
|
||||
autoComplete="off"
|
||||
/>
|
||||
|
||||
{/* Account name helper text (md+ screens only) */}
|
||||
{/* Account name helper text */}
|
||||
{matchedAccount && (
|
||||
<p className="hidden md:block text-[11px] text-muted-foreground truncate mt-0.5 leading-tight">
|
||||
<p className="text-[11px] text-muted-foreground truncate mt-0.5 leading-tight">
|
||||
{matchedAccount.account_name}
|
||||
</p>
|
||||
)}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user