#Payload DateField Not Displaying Properly in UI

4 messages · Page 1 of 1 (latest)

sage bridgeBOT
#

Can I get eyes on this for a second? I feel like I'm missing something really simple...
Field definition:


type PublishedAt = () => [DateField]

export const publishedAtField: PublishedAt = () => {
    
    const publishedAtField: DateField = {
        name: 'publishedAt',
        type: 'date',
        label: 'Published At',
        admin: {
            readOnly: true,
            position: 'sidebar'
        }
    }

    return [publishedAtField]
}```

collection hook:
```import type { CollectionBeforeChangeHook } from "payload";

export const trackPublishHook = 
() : CollectionBeforeChangeHook => 
    async ({operation, data, originalDoc}) => {
        if(operation === 'update'){
            if(data._status !== originalDoc?._status 
                && (originalDoc?._status === 'draft' && data._status === 'published')){
                    data.publishedAt = data.updatedAt
                    return data;
            }
        }
    }```


I'm importing the field into my collection like this
`...publishedAtField(),`
and then adding the hook:
```hooks: {
      beforeChange: [trackPublishHook()]
    }```

I see the data for publishedAt populating in the database, but on my screen the field is empty. What am I missing here?
wary wagonBOT
#

Original message from @reef lynx - Moved from #general message

wary wagonBOT