fix: Handle updatedAt as string in admin form autosave
Fixed TypeError when updatedAt field from JSON responses was incorrectly treated as Date object. Added type guards to handle both string and Date types in autosave callbacks across all admin forms.
This commit is contained in:
parent
5e58d31f7e
commit
0b46ebd433
4 changed files with 15 additions and 5 deletions
|
|
@ -46,7 +46,13 @@
|
|||
let editorInstance = $state<{ save: () => Promise<JSONContent>; clear: () => void } | undefined>()
|
||||
let activeTab = $state('metadata')
|
||||
let pendingMediaIds = $state<number[]>([]) // Photos to add after album creation
|
||||
let updatedAt = $state<string | undefined>(album?.updatedAt?.toISOString())
|
||||
let updatedAt = $state<string | undefined>(
|
||||
album?.updatedAt
|
||||
? typeof album.updatedAt === 'string'
|
||||
? album.updatedAt
|
||||
: album.updatedAt.toISOString()
|
||||
: undefined
|
||||
)
|
||||
|
||||
const tabOptions = [
|
||||
{ value: 'metadata', label: 'Metadata' },
|
||||
|
|
@ -114,7 +120,8 @@
|
|||
return await response.json()
|
||||
},
|
||||
onSaved: (saved: Album, { prime }) => {
|
||||
updatedAt = saved.updatedAt.toISOString()
|
||||
updatedAt =
|
||||
typeof saved.updatedAt === 'string' ? saved.updatedAt : saved.updatedAt.toISOString()
|
||||
prime(buildPayload())
|
||||
if (draftKey) clearDraft(draftKey)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,8 @@
|
|||
return await response.json()
|
||||
},
|
||||
onSaved: (saved: Post, { prime }) => {
|
||||
updatedAt = saved.updatedAt.toISOString()
|
||||
updatedAt =
|
||||
typeof saved.updatedAt === 'string' ? saved.updatedAt : saved.updatedAt.toISOString()
|
||||
prime(buildPayload())
|
||||
if (draftKey) clearDraft(draftKey)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,8 @@ let autoSave = mode === 'edit' && postId
|
|||
return await response.json()
|
||||
},
|
||||
onSaved: (saved: Post, { prime }) => {
|
||||
updatedAt = saved.updatedAt.toISOString()
|
||||
updatedAt =
|
||||
typeof saved.updatedAt === 'string' ? saved.updatedAt : saved.updatedAt.toISOString()
|
||||
prime(buildPayload())
|
||||
if (draftKey) clearDraft(draftKey)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,8 @@ let autoSave = mode === 'edit' && postId
|
|||
return await response.json()
|
||||
},
|
||||
onSaved: (saved: Post, { prime }) => {
|
||||
updatedAt = saved.updatedAt.toISOString()
|
||||
updatedAt =
|
||||
typeof saved.updatedAt === 'string' ? saved.updatedAt : saved.updatedAt.toISOString()
|
||||
prime(buildPayload())
|
||||
if (draftKey) clearDraft(draftKey)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue