Skip to content

Commit

Permalink
[WebApp] BackupCodesPage: COPY button - added (#1192)
Browse files Browse the repository at this point in the history
* BackupCodesPage: COPY button - added

* BackupCodesPage: disabled state for COPY button - added
  • Loading branch information
vitto-moz authored Aug 27, 2024
1 parent 28be6d7 commit a6ba160
Showing 1 changed file with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Button, LoadingSpinner, Text } from '@saladtechnologies/garden-components'
import { Copy } from '@saladtechnologies/garden-icons'
import type CSS from 'csstype'
import moment from 'moment'
import { useEffect, type FC } from 'react'
import { useEffect, useState, type FC } from 'react'
import Scrollbars from 'react-custom-scrollbars-2'
import type { WithStyles } from 'react-jss'
import withStyles from 'react-jss'
Expand Down Expand Up @@ -85,13 +86,22 @@ const styles: (theme: SaladTheme) => Record<string, CSS.Properties> = (theme: Sa
flexWrap: 'wrap',
width: '100%',
},
generateBackupCodesButtonWrapper: {
backupCodesButtonsWrapper: {
marginTop: '24px',
marginBottom: '24px',
display: 'flex',
justifyContent: 'center',
alignItems: 'flex-start',
flexDirection: 'column',
gap: '8px',
},
backupCodeText: {
width: '150px',
},
buttonIcon: {
position: 'relative',
top: '-2gpx',
},
})

interface Props extends WithStyles<typeof styles> {
Expand All @@ -108,9 +118,19 @@ const _BackupCodesPage: FC<Props> = ({
onGenerateNewBackupCodesClick,
getBackupCodes,
}) => {
const [isCopied, setIsCopied] = useState(false)
const location = useLocation<{ isFirstPasskeyAdded: string }>()
const isFirstPasskeyAdded = location.state?.isFirstPasskeyAdded

const handleCopyClick = () => {
// eslint-disable-next-line compat/compat
window.navigator.clipboard.writeText(backupCodes.codes.join('\n'))
setIsCopied(true)
setTimeout(() => {
setIsCopied(false)
}, 2000)
}

useEffect(() => {
getBackupCodes()
}, [getBackupCodes])
Expand Down Expand Up @@ -155,7 +175,23 @@ const _BackupCodesPage: FC<Props> = ({
</div>
)}
</div>
<div className={classes.generateBackupCodesButtonWrapper}>
<div className={classes.backupCodesButtonsWrapper}>
<Button
onClick={handleCopyClick}
label={isCopied ? 'Copied!' : 'Copy'}
disabled={!backupCodes?.codes}
variant="primary-basic"
leadingIcon={
isCopied ? null : (
<div className={classes.buttonIcon}>
<Copy />
</div>
)
}
width={90}
size="small"
data-rh={'Keep chopping to discover this veggie'}
/>
<Button
variant="primary-basic"
size="small"
Expand Down

0 comments on commit a6ba160

Please sign in to comment.