Merge pull request #955 from chaotixkilla/fix-date-parsing-with-date-fns
Fix date parsing and formatting
This commit is contained in:
commit
3556e8d8cb
8 changed files with 40 additions and 23 deletions
|
|
@ -158,14 +158,14 @@ const Accounting = () => {
|
||||||
width: 150,
|
width: 150,
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
view: it => formatDate(it.created, timezone, 'YYYY-MM-DD')
|
view: it => formatDate(it.created, timezone, 'yyyy-MM-dd')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Time',
|
header: 'Time',
|
||||||
width: 150,
|
width: 150,
|
||||||
size: 'sm',
|
size: 'sm',
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
view: it => formatDate(it.created, timezone, 'YYYY-MM-DD')
|
view: it => formatDate(it.created, timezone, 'yyyy-MM-dd')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import Grid from '@material-ui/core/Grid'
|
import Grid from '@material-ui/core/Grid'
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
import { differenceInYears, format } from 'date-fns/fp'
|
import { differenceInYears, parse, format } from 'date-fns/fp'
|
||||||
import _ from 'lodash/fp'
|
import _ from 'lodash/fp'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import { useState, React } from 'react'
|
import { useState, React } from 'react'
|
||||||
|
|
@ -115,13 +115,22 @@ const CustomerData = ({ customer, updateCustomer }) => {
|
||||||
{
|
{
|
||||||
name: 'birthDate',
|
name: 'birthDate',
|
||||||
label: 'Birth Date',
|
label: 'Birth Date',
|
||||||
value: (rawDob && format('yyyy-MM-dd', rawDob)) ?? '',
|
value:
|
||||||
|
(rawDob &&
|
||||||
|
format('yyyy-MM-dd')(parse(new Date(), 'yyyyMMdd', rawDob))) ??
|
||||||
|
'',
|
||||||
component: TextInput
|
component: TextInput
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'age',
|
name: 'age',
|
||||||
label: 'Age',
|
label: 'Age',
|
||||||
value: (rawDob && differenceInYears(rawDob, new Date())) ?? '',
|
value:
|
||||||
|
(rawDob &&
|
||||||
|
differenceInYears(
|
||||||
|
parse(new Date(), 'yyyyMMdd', rawDob),
|
||||||
|
new Date()
|
||||||
|
)) ??
|
||||||
|
'',
|
||||||
component: TextInput
|
component: TextInput
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -140,7 +149,11 @@ const CustomerData = ({ customer, updateCustomer }) => {
|
||||||
name: 'expirationDate',
|
name: 'expirationDate',
|
||||||
label: 'Expiration Date',
|
label: 'Expiration Date',
|
||||||
value:
|
value:
|
||||||
(rawExpirationDate && format('yyyy-MM-dd', rawExpirationDate)) ?? '',
|
(rawExpirationDate &&
|
||||||
|
format('yyyy-MM-dd')(
|
||||||
|
parse(new Date(), 'yyyyMMdd', rawExpirationDate)
|
||||||
|
)) ??
|
||||||
|
'',
|
||||||
component: TextInput
|
component: TextInput
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ const CustomersList = ({ data, locale, onClick, loading }) => {
|
||||||
header: 'Last active',
|
header: 'Last active',
|
||||||
width: 137,
|
width: 137,
|
||||||
view: it =>
|
view: it =>
|
||||||
(it.lastActive && format('yyyy-MM-d', new Date(it.lastActive))) ?? ''
|
(it.lastActive && format('yyyy-MM-dd', new Date(it.lastActive))) ?? ''
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Last transaction',
|
header: 'Last transaction',
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { Box } from '@material-ui/core'
|
import { Box } from '@material-ui/core'
|
||||||
import { differenceInYears, format } from 'date-fns/fp'
|
import { differenceInYears, format, parse } from 'date-fns/fp'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import React, { memo } from 'react'
|
import React, { memo } from 'react'
|
||||||
|
|
||||||
|
|
@ -9,7 +9,6 @@ import {
|
||||||
OVERRIDE_REJECTED
|
OVERRIDE_REJECTED
|
||||||
} from 'src/pages/Customers/components/propertyCard'
|
} from 'src/pages/Customers/components/propertyCard'
|
||||||
import { ifNotNull } from 'src/utils/nullCheck'
|
import { ifNotNull } from 'src/utils/nullCheck'
|
||||||
import { toUtc } from 'src/utils/timezones'
|
|
||||||
|
|
||||||
import { getName } from '../helper'
|
import { getName } from '../helper'
|
||||||
|
|
||||||
|
|
@ -34,15 +33,21 @@ const IdDataCard = memo(({ customerData, updateCustomer }) => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Birth Date',
|
header: 'Birth Date',
|
||||||
display: ifNotNull(rawDob, format('YYYY-MM-DD', rawDob)),
|
display:
|
||||||
|
(rawDob &&
|
||||||
|
format('yyyy-MM-dd')(parse(new Date(), 'yyyyMMdd', rawDob))) ??
|
||||||
|
'',
|
||||||
size: 110
|
size: 110
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Age',
|
header: 'Age',
|
||||||
display: ifNotNull(
|
display:
|
||||||
rawDob,
|
(rawDob &&
|
||||||
differenceInYears(toUtc(rawDob), toUtc(new Date()))
|
differenceInYears(
|
||||||
),
|
parse(new Date(), 'yyyyMMdd', rawDob),
|
||||||
|
new Date()
|
||||||
|
)) ??
|
||||||
|
'',
|
||||||
size: 50
|
size: 50
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -59,7 +64,7 @@ const IdDataCard = memo(({ customerData, updateCustomer }) => {
|
||||||
header: 'Expiration Date',
|
header: 'Expiration Date',
|
||||||
display: ifNotNull(
|
display: ifNotNull(
|
||||||
rawExpirationDate,
|
rawExpirationDate,
|
||||||
format('YYYY-MM-DD', rawExpirationDate)
|
format('yyyy-MM-dd', rawExpirationDate)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,9 @@ const TransactionsList = ({ customer, data, loading, locale }) => {
|
||||||
size: 142,
|
size: 142,
|
||||||
value:
|
value:
|
||||||
!R.isNil(timezone) &&
|
!R.isNil(timezone) &&
|
||||||
ifNotNull(
|
((customer.lastActive &&
|
||||||
customer.lastActive,
|
formatDate(customer.lastActive, timezone, 'yyyy-MM-dd')) ??
|
||||||
formatDate(customer.lastActive, timezone, 'yyyy-MM-d')
|
'')
|
||||||
)
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Last transaction',
|
header: 'Last transaction',
|
||||||
|
|
@ -122,7 +121,7 @@ const TransactionsList = ({ customer, data, loading, locale }) => {
|
||||||
{
|
{
|
||||||
header: 'Date',
|
header: 'Date',
|
||||||
width: 100,
|
width: 100,
|
||||||
view: it => formatDate(it.created, timezone, 'yyyy-MM-d')
|
view: it => formatDate(it.created, timezone, 'yyyy-MM-dd')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: 'Time (h:m:s)',
|
header: 'Time (h:m:s)',
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ const Logs = () => {
|
||||||
<TableRow key={idx} size="sm">
|
<TableRow key={idx} size="sm">
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{timezone &&
|
{timezone &&
|
||||||
formatDate(log.timestamp, timezone, 'YYYY-MM-DD HH:mm')}
|
formatDate(log.timestamp, timezone, 'yyyy-MM-dd HH:mm')}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{log.logLevel}</TableCell>
|
<TableCell>{log.logLevel}</TableCell>
|
||||||
<TableCell>{log.message}</TableCell>
|
<TableCell>{log.message}</TableCell>
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ const CashboxHistory = ({ machines, currency }) => {
|
||||||
header: 'Date',
|
header: 'Date',
|
||||||
width: 135,
|
width: 135,
|
||||||
textAlign: 'right',
|
textAlign: 'right',
|
||||||
view: it => formatDate(it.created, timezone, 'YYYY-MM-DD')
|
view: it => formatDate(it.created, timezone, 'yyyy-MM-dd')
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'time',
|
name: 'time',
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ const MachineDetailsRow = ({ it: machine, onActionSuccess, timezone }) => {
|
||||||
<Label>Paired at</Label>
|
<Label>Paired at</Label>
|
||||||
<span>
|
<span>
|
||||||
{timezone &&
|
{timezone &&
|
||||||
formatDate(machine.pairedAt, timezone, 'YYYY-MM-DD HH:mm:ss')}
|
formatDate(machine.pairedAt, timezone, 'yyyy-MM-dd HH:mm:ss')}
|
||||||
</span>
|
</span>
|
||||||
</Item>
|
</Item>
|
||||||
<Item xs={6}>
|
<Item xs={6}>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue