Skip to content

Commit

Permalink
feat(ui): use date formatting component for rendering date [LN-Zap#3600]
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulbile committed Nov 9, 2020
1 parent 5f8cc3e commit 891c2c4
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 52 deletions.
7 changes: 4 additions & 3 deletions renderer/components/Activity/Invoice/Invoice.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import PropTypes from 'prop-types'
import { FormattedTime, FormattedMessage, injectIntl } from 'react-intl'
import { FormattedMessage, injectIntl } from 'react-intl'
import { Box, Flex } from 'rebass/styled-components'
import { intlShape } from '@zap/i18n'
import { Text } from 'components/UI'
import Zap from 'components/Icon/Zap'
import { CryptoValue, FiatValue } from 'containers/UI'
import { CryptoValue, FiatValue, FormattedDateTime } from 'containers/UI'
import messages from './messages'
import Clock from 'components/Icon/Clock'

Expand Down Expand Up @@ -33,7 +33,8 @@ const Invoice = ({ activity, showActivityModal, cryptoUnitName, intl, ...rest })
<FormattedMessage {...messages[activity.isSettled ? 'received' : 'requested']} />
</Text>
<Text color="gray" fontSize="xs" fontWeight="normal">
<FormattedTime
<FormattedDateTime
format="time"
value={activity.isSettled ? activity.settleDate * 1000 : activity.creationDate * 1000}
/>
</Text>
Expand Down
6 changes: 3 additions & 3 deletions renderer/components/Activity/Payment/Payment.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react'
import PropTypes from 'prop-types'
import { FormattedMessage, FormattedTime, injectIntl } from 'react-intl'
import { FormattedMessage, injectIntl } from 'react-intl'
import { Box, Flex } from 'rebass/styled-components'
import { intlShape } from '@zap/i18n'
import { getDisplayNodeName } from 'reducers/payment/utils'
import { Message, Text } from 'components/UI'
import Zap from 'components/Icon/Zap'
import { CryptoValue, FiatValue } from 'containers/UI'
import { CryptoValue, FiatValue, FormattedDateTime } from 'containers/UI'
import ErrorLink from '../ErrorLink'
import messages from './messages'

Expand Down Expand Up @@ -57,7 +57,7 @@ const Payment = ({
</>
) : (
<Text color="gray" fontSize="xs" fontWeight="normal">
<FormattedTime value={activity.creationDate * 1000} />
<FormattedDateTime format="time" value={activity.creationDate * 1000} />
</Text>
)}
</Box>
Expand Down
20 changes: 11 additions & 9 deletions renderer/components/Activity/PaymentModal/PaymentModal.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import React from 'react'
import PropTypes from 'prop-types'
import { FormattedDate, FormattedTime, FormattedMessage, injectIntl } from 'react-intl'
import { FormattedMessage, injectIntl } from 'react-intl'
import { Flex } from 'rebass/styled-components'
import { intlShape } from '@zap/i18n'
import { getDisplayNodeName } from 'reducers/payment/utils'
import { Bar, DataRow, Header, Panel, Text } from 'components/UI'
import { getTag } from '@zap/utils/crypto'
import { CopyButton, CryptoSelector, CryptoValue, FiatSelector, FiatValue } from 'containers/UI'
import {
CopyButton,
CryptoSelector,
CryptoValue,
FormattedDateTime,
FiatSelector,
FiatValue,
} from 'containers/UI'
import { Truncate } from 'components/Util'
import Lightning from 'components/Icon/Lightning'
import Route from './Route'
Expand Down Expand Up @@ -78,15 +85,10 @@ class PaymentModal extends React.PureComponent {
right={
<>
<Text>
<FormattedDate
day="2-digit"
month="long"
value={item.creationDate * 1000}
year="numeric"
/>
<FormattedDateTime format="date" month="long" value={item.creationDate * 1000} />
</Text>
<Text>
<FormattedTime value={item.creationDate * 1000} />
<FormattedDateTime format="time" value={item.creationDate * 1000} />
</Text>
</>
}
Expand Down
4 changes: 2 additions & 2 deletions renderer/components/Activity/Row.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react'
import PropTypes from 'prop-types'
import { FormattedDate } from 'react-intl'
import { Box } from 'rebass/styled-components'
import { Bar, Heading } from 'components/UI'
import { FormattedDateTime } from 'containers/UI'

const Row = ({ style, item, RowComponent }) => (
<div style={style}>
{item.title ? (
<Box mt={4} pl={4}>
<Heading.H4 fontWeight="normal">
<FormattedDate day="2-digit" month="short" value={item.title} year="numeric" />
<FormattedDateTime format="date" month="short" value={new Date(item.title)} />
</Heading.H4>
<Bar my={1} />
</Box>
Expand Down
6 changes: 3 additions & 3 deletions renderer/components/Activity/Transaction/Transaction.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react'
import PropTypes from 'prop-types'
import findLast from 'lodash/findLast'
import { FormattedTime, FormattedMessage, injectIntl } from 'react-intl'
import { FormattedMessage, injectIntl } from 'react-intl'
import { Box, Flex } from 'rebass/styled-components'
import config from 'config'
import { intlShape } from '@zap/i18n'
import { CoinBig } from '@zap/utils/coin'
import { Message, Text } from 'components/UI'
import ChainLink from 'components/Icon/ChainLink'
import { CryptoValue, FiatValue } from 'containers/UI'
import { CryptoValue, FiatValue, FormattedDateTime } from 'containers/UI'
import ErrorLink from '../ErrorLink'
import messages from './messages'

Expand Down Expand Up @@ -45,7 +45,7 @@ const Transaction = ({
if (CoinBig(numConfirmations).gt(confirmed)) {
return (
<Text color="gray" fontSize="xs" fontWeight="normal">
<FormattedTime value={activity.timeStamp * 1000} />
<FormattedDateTime format="time" value={activity.timeStamp * 1000} />
</Text>
)
}
Expand Down
24 changes: 12 additions & 12 deletions renderer/components/Activity/TransactionModal/TransactionModal.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import React from 'react'
import PropTypes from 'prop-types'
import get from 'lodash/get'
import {
FormattedDate,
FormattedTime,
FormattedMessage,
FormattedNumber,
injectIntl,
} from 'react-intl'
import { FormattedMessage, FormattedNumber, injectIntl } from 'react-intl'
import { Flex } from 'rebass/styled-components'
import { CoinBig } from '@zap/utils/coin'
import { intlShape } from '@zap/i18n'
import blockExplorer from '@zap/utils/blockExplorer'
import { Bar, DataRow, Header, Link, Panel, Span, Text, Button } from 'components/UI'
import { CopyButton, CryptoSelector, CryptoValue, FiatSelector, FiatValue } from 'containers/UI'
import {
CopyButton,
CryptoSelector,
CryptoValue,
FiatSelector,
FiatValue,
FormattedDateTime,
} from 'containers/UI'
import { Truncate } from 'components/Util'
import Onchain from 'components/Icon/Onchain'
import Padlock from 'components/Icon/Padlock'
Expand Down Expand Up @@ -127,15 +128,14 @@ class TransactionModal extends React.PureComponent {
item.numConfirmations ? (
<>
<Text>
<FormattedDate
day="2-digit"
<FormattedDateTime
format="date"
month="long"
value={item.timeStamp * 1000}
year="numeric"
/>
</Text>
<Text>
<FormattedTime value={item.timeStamp * 1000} />
<FormattedDateTime format="time" value={item.timeStamp * 1000} />
</Text>
</>
) : (
Expand Down
12 changes: 3 additions & 9 deletions renderer/components/Channels/ChannelData.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react'
import PropTypes from 'prop-types'
import { FormattedDate, FormattedTime, FormattedMessage, injectIntl } from 'react-intl'
import { FormattedMessage, injectIntl } from 'react-intl'
import styled from 'styled-components'
import { opacity } from 'styled-system'
import { Box as BaseBox, Flex } from 'rebass/styled-components'
import { intlShape } from '@zap/i18n'
import blockExplorer from '@zap/utils/blockExplorer'
import { Bar, DataRow, Link, Text } from 'components/UI'
import { Truncate } from 'components/Util'
import { CopyButton, CryptoValue } from 'containers/UI'
import { CopyButton, CryptoValue, FormattedDateTime } from 'containers/UI'
import { CHANNEL_DATA_VIEW_MODE_BASIC, CHANNEL_DATA_VIEW_MODE_FULL } from './constants'
import messages from './messages'

Expand Down Expand Up @@ -62,13 +62,7 @@ const ChannelData = ({ channel, cryptoUnitName, intl, networkInfo, viewMode, ...
body: <FormattedMessage {...messages.funding_date_description} />,
value: (
<Text>
<FormattedDate
day="2-digit"
month="short"
value={fundingTxTimestamp * 1000}
year="numeric"
/>{' '}
<FormattedTime value={fundingTxTimestamp * 1000} />
<FormattedDateTime month="short" value={fundingTxTimestamp * 1000} />
</Text>
),
}),
Expand Down
21 changes: 10 additions & 11 deletions renderer/components/Request/RequestSummary.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import { Box, Flex } from 'rebass/styled-components'
import { FormattedMessage, FormattedTime, useIntl } from 'react-intl'
import { FormattedMessage, useIntl } from 'react-intl'
import copy from 'copy-to-clipboard'
import { Bar, DataRow, Button, QRCode, Text, Countdown } from 'components/UI'
import { CryptoSelector, CryptoValue, FiatSelector, FiatValue } from 'containers/UI'
import {
CryptoSelector,
CryptoValue,
FiatSelector,
FiatValue,
FormattedDateTime,
} from 'containers/UI'
import { Truncate } from 'components/Util'
import RequestSettlePrompt from './RequestSettlePrompt'
import messages from './messages'
Expand Down Expand Up @@ -99,9 +105,7 @@ const RequestSummary = ({

<DataRow
left={<FormattedMessage {...messages.created} />}
right={
<FormattedTime day="2-digit" month="long" value={creationDate * 1000} year="numeric" />
}
right={<FormattedDateTime month="long" value={creationDate * 1000} />}
/>

<Bar variant="light" />
Expand Down Expand Up @@ -213,12 +217,7 @@ const RequestSummary = ({
>
<FormattedMessage {...messages.paid} />
<br />
<FormattedTime
day="2-digit"
month="long"
value={settleDate * 1000}
year="numeric"
/>
<FormattedDateTime month="long" value={settleDate * 1000} />
</Text>
) : (
<Text color={getStatusColor()} fontWeight="light">
Expand Down
39 changes: 39 additions & 0 deletions renderer/containers/UI/FormattedDateTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { FormattedDate, FormattedTime } from 'react-intl'
import { settingsSelectors } from 'reducers/settings'

const mapStateToProps = state => ({
clockFormat24: settingsSelectors.currentConfig(state).clockFormat24,
})

const FormattedDateTime = ({ clockFormat24, format, month = 'long', value }) => {
switch (format) {
case 'date':
return <FormattedDate day="2-digit" month={month} value={value} year="numeric" />
case 'time':
return <FormattedTime hour12={!clockFormat24} value={value} />
default:
return (
<FormattedDate
day="2-digit"
hour="numeric"
hour12={!clockFormat24}
minute="numeric"
month={month}
value={value}
year="numeric"
/>
)
}
}

FormattedDateTime.propTypes = {
clockFormat24: PropTypes.string,
format: PropTypes.string,
month: PropTypes.string,
value: PropTypes.instanceOf(Date),
}

export default connect(mapStateToProps)(FormattedDateTime)
1 change: 1 addition & 0 deletions renderer/containers/UI/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export CopyButton from './CopyButton'
export CryptoSelector from './CryptoSelector'
export CryptoValue from './CryptoValue'
export FormattedDateTime from './FormattedDateTime'
export FiatSelector from './FiatSelector'
export FiatValue from './FiatValue'
export CryptoValueSelector from './CryptoValueSelector'

0 comments on commit 891c2c4

Please sign in to comment.