Use common date format function for last login date in table and detailview

This commit is contained in:
ShootingStar91
2024-07-16 10:46:01 +03:00
parent 3873472479
commit 93c6693440
2 changed files with 8 additions and 1 deletions
+5
View File
@@ -2,6 +2,11 @@ import { MRT_ColumnDef } from 'material-react-table'
import { Reference } from './backendTypes'
import { Cell } from './components/commonComponents'
export const formatLastLoginDate = (date: Date) => {
const dateFormat = new Intl.DateTimeFormat('en-GB', { year: 'numeric', month: 'long', day: 'numeric' })
return dateFormat.format(new Date(date))
}
export const referenceTableColumns: MRT_ColumnDef<Reference>[] = [
{
id: 'id',
@@ -3,6 +3,7 @@ import { type MRT_ColumnDef } from 'material-react-table'
import { useGetAllPersonsQuery } from '../../redux/personReducer'
import { PersonDetailsType } from '@/backendTypes'
import { TableView } from '../TableView/TableView'
import { formatLastLoginDate } from '@/common'
export const PersonTable = ({ selectorFn }: { selectorFn?: (id: PersonDetailsType) => void }) => {
const personQuery = useGetAllPersonsQuery()
@@ -44,7 +45,8 @@ export const PersonTable = ({ selectorFn }: { selectorFn?: (id: PersonDetailsTyp
header: 'User name',
},
{
accessorKey: 'user.last_login',
accessorFn: (person: PersonDetailsType) =>
person.user?.last_login ? formatLastLoginDate(person.user?.last_login) : 'None',
header: 'Last login',
},
],