-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Popover for Upgrade icon in the status bar
- Loading branch information
1 parent
f107c42
commit 4019d26
Showing
10 changed files
with
316 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
...onents/suite/layouts/SuiteLayout/Sidebar/QuickActions/Update/UpdateNotificationBanner.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import styled from 'styled-components'; | ||
import { Column, ElevationContext, Icon, Row, Text } from '@trezor/components'; | ||
import { borders, Elevation, mapElevationToBackground, spacingsPx, zIndices } from '@trezor/theme'; | ||
import { | ||
UpdateStatus, | ||
UpdateStatusSuite, | ||
UpdateStatusDevice, | ||
mapSuiteUpdateToClick, | ||
mapDeviceUpdateToClick, | ||
} from './updateQuickActionTypes'; | ||
import { Translation, TranslationKey } from '../../../../../Translation'; | ||
import { useDispatch } from '../../../../../../../hooks/suite'; | ||
import { MouseEvent } from 'react'; | ||
import { createPortal } from 'react-dom'; | ||
|
||
type ContainerProps = { $elevation: Elevation }; | ||
|
||
const Container = styled.div<ContainerProps>` | ||
position: absolute; | ||
bottom: 56px; | ||
left: ${spacingsPx.xs}; | ||
z-index: ${zIndices.navigationBar}; | ||
display: flex; | ||
flex-direction: column; | ||
width: 262px; | ||
padding: ${spacingsPx.xs} ${spacingsPx.sm}; | ||
background: ${mapElevationToBackground}; | ||
border-radius: ${borders.radii.sm}; | ||
box-shadow: ${({ theme }) => theme.boxShadowElevated}; | ||
cursor: ${({ onClick }) => (onClick !== undefined ? 'pointer' : undefined)}; | ||
`; | ||
|
||
const CloseIconBackground = styled.div` | ||
width: 36px; | ||
height: 36px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
background-color: ${({ theme }) => theme.backgroundSurfaceElevation2}; | ||
border-radius: ${borders.radii.full}; | ||
cursor: ${({ onClick }) => (onClick !== undefined ? 'pointer' : undefined)}; | ||
`; | ||
|
||
type UpdateNotificationBannerProps = { | ||
updateStatusDevice: UpdateStatusDevice; | ||
updateStatusSuite: UpdateStatusSuite; | ||
onClose: () => void; | ||
}; | ||
|
||
const mapDeviceUpdateStatusToTranslation: Record<UpdateStatusDevice, TranslationKey | null> = { | ||
'just-updated': 'TR_QUICK_ACTION_UPDATE_POPOVER_TREZOR_HAS_BEEN_UPDATED', | ||
'up-to-date': null, | ||
'update-available': 'TR_QUICK_ACTION_UPDATE_POPOVER_TREZOR_UPDATE_AVAILABLE', | ||
}; | ||
|
||
const mapSuiteUpdateStatusToHeaderTranslation: Record<UpdateStatusSuite, TranslationKey | null> = { | ||
'update-downloaded-auto-restart-to-update': | ||
'TR_QUICK_ACTION_UPDATE_POPOVER_APP_HAS_BEEN_UPDATED', | ||
'update-downloaded-manual': 'TR_QUICK_ACTION_UPDATE_POPOVER_APP_DOWNLOADED', | ||
'just-updated': 'TR_QUICK_ACTION_UPDATE_POPOVER_APP_HAS_BEEN_UPDATED', | ||
'up-to-date': null, | ||
'update-available': 'TR_QUICK_ACTION_UPDATE_POPOVER_APP_UPDATE_AVAILABLE', | ||
}; | ||
|
||
const mapSuiteUpdateStatusToCallToActionTranslation: Record<UpdateStatus, TranslationKey | null> = { | ||
'just-updated': 'TR_QUICK_ACTION_UPDATE_POPOVER_WHATS_NEW', | ||
'up-to-date': null, | ||
'update-available': 'TR_QUICK_ACTION_UPDATE_POPOVER_CLICK_TO_START_UPDATE', | ||
'update-downloaded-auto-restart-to-update': | ||
'TR_QUICK_ACTION_UPDATE_POPOVER_CLICK_TO_START_UPDATE', | ||
'update-downloaded-manual': 'TR_QUICK_ACTION_UPDATE_POPOVER_CLICK_TO_START_UPDATE', | ||
}; | ||
|
||
export const UpdateNotificationBanner = ({ | ||
updateStatusDevice, | ||
updateStatusSuite, | ||
onClose, | ||
}: UpdateNotificationBannerProps) => { | ||
const dispatch = useDispatch(); | ||
|
||
const translationHeader = | ||
updateStatusSuite !== 'up-to-date' // Update suite first, because it will contain the newest firmware | ||
? mapSuiteUpdateStatusToHeaderTranslation[updateStatusSuite] | ||
: mapDeviceUpdateStatusToTranslation[updateStatusDevice]; | ||
|
||
const translationCallToAction = | ||
mapSuiteUpdateStatusToCallToActionTranslation[ | ||
updateStatusSuite !== 'up-to-date' ? updateStatusSuite : updateStatusDevice | ||
]; | ||
|
||
if (translationHeader === null || translationCallToAction === null) { | ||
return null; | ||
} | ||
|
||
const handleOnClick = () => { | ||
const onClick = | ||
updateStatusSuite !== 'up-to-date' | ||
? mapSuiteUpdateToClick[updateStatusSuite] | ||
: mapDeviceUpdateToClick[updateStatusDevice]; | ||
|
||
if (onClick !== null) { | ||
onClick({ dispatch }); | ||
onClose(); | ||
} | ||
}; | ||
|
||
const handleOnClose = (e: MouseEvent<HTMLDivElement>) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
onClose(); | ||
}; | ||
|
||
return createPortal( | ||
<ElevationContext baseElevation={1}> | ||
<Container $elevation={1} onClick={handleOnClick}> | ||
<Row justifyContent="stretch"> | ||
<Column flex="1" alignItems="start"> | ||
<Text> | ||
<Translation id={translationHeader} /> | ||
</Text> | ||
<Text variant="primary"> | ||
<Translation id={translationCallToAction} /> | ||
</Text> | ||
</Column> | ||
<CloseIconBackground onClick={handleOnClose}> | ||
<Icon name="x" size="medium" /> | ||
</CloseIconBackground> | ||
</Row> | ||
</Container> | ||
</ElevationContext>, | ||
document.body, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.