|
1 | 1 | 'use client' |
2 | 2 | import type { DateFieldClient, DefaultCellComponentProps } from 'payload' |
3 | 3 |
|
| 4 | +import { getObjectDotNotation } from 'payload/shared' |
4 | 5 | import React from 'react' |
5 | 6 |
|
6 | 7 | import { useConfig } from '../../../../../providers/Config/index.js' |
7 | 8 | import { useTranslation } from '../../../../../providers/Translation/index.js' |
8 | 9 | import { formatDate } from '../../../../../utilities/formatDocTitle/formatDateTitle.js' |
9 | 10 |
|
10 | | -export const DateCell: React.FC<DefaultCellComponentProps<DateFieldClient>> = ({ |
11 | | - cellData, |
12 | | - field: { admin: { date } = {} }, |
13 | | -}) => { |
| 11 | +export const DateCell: React.FC< |
| 12 | + DefaultCellComponentProps<{ accessor?: string } & DateFieldClient> |
| 13 | +> = (props) => { |
| 14 | + const { |
| 15 | + cellData, |
| 16 | + field: { name, accessor, admin: { date } = {}, timezone: timezoneFromField }, |
| 17 | + rowData, |
| 18 | + } = props |
| 19 | + |
14 | 20 | const { |
15 | 21 | config: { |
16 | 22 | admin: { dateFormat: dateFormatFromRoot }, |
17 | 23 | }, |
18 | 24 | } = useConfig() |
| 25 | + const { i18n } = useTranslation() |
19 | 26 |
|
20 | | - const dateFormat = date?.displayFormat || dateFormatFromRoot |
| 27 | + const fieldPath = accessor || name |
21 | 28 |
|
22 | | - const { i18n } = useTranslation() |
| 29 | + const timezoneFieldName = `${fieldPath}_tz` |
| 30 | + const timezone = |
| 31 | + Boolean(timezoneFromField) && rowData |
| 32 | + ? getObjectDotNotation(rowData, timezoneFieldName, undefined) |
| 33 | + : undefined |
| 34 | + |
| 35 | + const dateFormat = date?.displayFormat || dateFormatFromRoot |
23 | 36 |
|
24 | | - return <span>{cellData && formatDate({ date: cellData, i18n, pattern: dateFormat })}</span> |
| 37 | + return ( |
| 38 | + <span> |
| 39 | + {Boolean(cellData) && formatDate({ date: cellData, i18n, pattern: dateFormat, timezone })} |
| 40 | + </span> |
| 41 | + ) |
25 | 42 | } |
0 commit comments