-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathNotices.tsx
115 lines (105 loc) · 3.46 KB
/
Notices.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import React, { Fragment, FC } from 'react'
import { FormattedMessage, FormattedDate } from 'react-intl'
import { Button } from 'vtex.styleguide'
import { useCssHandles } from 'vtex.css-handles'
import FormattedPrice from './components/FormattedPrice'
import { useOrderGroup } from './components/OrderGroupContext'
import { parseBankInvoiceUrl, getPaymentMethodsInfoFromOrder } from './utils'
const CSS_HANDLES = ['noticesList', 'noticeListItem']
// TODO: add json schema to add/remove extra notice messages
const Notices: FC = () => {
const handles = useCssHandles(CSS_HANDLES)
const { orders, totalDeliveryParcels, totalPickUpParcels } = useOrderGroup()
const hasDelivery = totalDeliveryParcels.length > 0
const hasPickUp = totalPickUpParcels.length > 0
if (!hasDelivery && !hasPickUp) {
return null
}
const numOrders = orders.length
const isSplitOrder = numOrders > 1
const paymentMethodsFromOrders = orders.map(getPaymentMethodsInfoFromOrder)
const bankInvoice = paymentMethodsFromOrders
.flat()
.find(({ paymentGroup, url }) => paymentGroup === 'bankInvoice' && !!url)
const listItems = [
bankInvoice == null && (
<FormattedMessage id="store/warnings.payment.approval" />
),
hasDelivery && <FormattedMessage id="store/warnings.delivery.time" />,
hasDelivery && <FormattedMessage id="store/warnings.delivery.tracking" />,
hasPickUp && <FormattedMessage id="store/warnings.pickup.time" />,
isSplitOrder && (
<FormattedMessage
id="store/warnings.order.split"
values={{ numOrders }}
/>
),
bankInvoice != null && (
<FormattedMessage
id="store/warnings.payment.bankInvoice.approval"
values={{ paymentSystemName: bankInvoice.paymentSystemName }}
/>
),
bankInvoice != null && (
<Fragment>
{bankInvoice.dueDate ? (
<FormattedMessage
id="store/warnings.payment.bankInvoice.value.duedate"
values={{
paymentDueDate: (
<strong>
<FormattedDate value={bankInvoice.dueDate} timeZone="utc" />
</strong>
),
paymentValue: (
<strong>
<FormattedPrice value={bankInvoice.value} />
</strong>
),
}}
/>
) : (
<FormattedMessage
id="store/warnings.payment.bankInvoice.value"
values={{
paymentValue: (
<strong>
<FormattedPrice value={bankInvoice.value} />
</strong>
),
}}
/>
)}
<div className="mt4">
{bankInvoice.url && (
<Button
href={parseBankInvoiceUrl(bankInvoice.url)}
variation="primary"
target="_blank"
>
<FormattedMessage
id="store/payments.bankinvoice.print"
values={{ paymentSystemName: bankInvoice.paymentSystemName }}
/>
</Button>
)}
</div>
</Fragment>
),
].filter(Boolean)
return (
<ul
className={`${handles.noticesList} list ma0 pl0 t-body bg-muted-5 tc-m lh-copy`}
>
{listItems.map((item, index) => (
<li
className={`${handles.noticeListItem} pv6 w-80-ns w-90 center c-on-base b--muted-4 bb`}
key={index}
>
{item}
</li>
))}
</ul>
)
}
export default Notices