-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathindex.tsx
82 lines (75 loc) · 2.04 KB
/
index.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
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import {
DIRECTION_COLUMN,
Flex,
JUSTIFY_CENTER,
JUSTIFY_END,
Modal,
PrimaryButton,
SPACING,
} from '@opentrons/components'
import {
setLocalStorageItem,
getLocalStorageItem,
localStorageAnnouncementKey,
} from '../../../persist'
import { useAnnouncements } from './announcements'
interface AnnouncementModalProps {
isViewReleaseNotes?: boolean
onClose?: () => void
}
export const AnnouncementModal = (
props: AnnouncementModalProps
): JSX.Element => {
const { onClose, isViewReleaseNotes = false } = props
const { i18n, t } = useTranslation(['modal', 'button'])
const announcements = useAnnouncements()
const { announcementKey, message, heading, image } = announcements[
announcements.length - 1
]
const userHasNotSeenAnnouncement =
getLocalStorageItem(localStorageAnnouncementKey) !== announcementKey
const [showAnnouncementModal, setShowAnnouncementModal] = useState<boolean>(
isViewReleaseNotes || userHasNotSeenAnnouncement
)
const handleClick = (): void => {
if (onClose != null) {
onClose()
}
setLocalStorageItem(localStorageAnnouncementKey, announcementKey)
setShowAnnouncementModal(false)
}
return (
<>
{showAnnouncementModal && (
<Modal
childrenPadding={SPACING.spacing24}
marginLeft="0"
title={heading}
type="info"
footer={
<Flex
justifyContent={JUSTIFY_END}
paddingX={SPACING.spacing24}
paddingBottom={SPACING.spacing24}
>
<PrimaryButton onClick={handleClick}>
{i18n.format(t('close'), 'capitalize')}
</PrimaryButton>
</Flex>
}
>
<Flex
flexDirection={DIRECTION_COLUMN}
justifyContent={JUSTIFY_CENTER}
gridGap={SPACING.spacing12}
>
{image != null && image}
{message}
</Flex>
</Modal>
)}
</>
)
}