Skip to content

Commit

Permalink
feat: Show user their portal userId on the settings page (#1196)
Browse files Browse the repository at this point in the history
* add userId to settings

* add more margin

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
gidjin and mergify[bot] authored Jan 22, 2024
1 parent 845a148 commit 534a51a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/initIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import {
faSmog,
faSnowflake,
faBoltLightning,
faCopy,
faCheck,
} from '@fortawesome/free-solid-svg-icons'

library.add(
Expand Down Expand Up @@ -52,5 +54,7 @@ library.add(
faMoon,
faSmog,
faSnowflake,
faBoltLightning
faBoltLightning,
faCopy,
faCheck
)
29 changes: 28 additions & 1 deletion src/pages/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useState } from 'react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import styles from 'styles/pages/settings.module.scss'
import EditDisplayName from 'components/EditDisplayName/EditDisplayName'
import { withDefaultLayout } from 'layout/DefaultLayout/DefaultLayout'
Expand All @@ -6,12 +8,23 @@ import { useUser } from 'hooks/useUser'
import Loader from 'components/Loader/Loader'

const Settings = () => {
const { loading, portalUser } = useUser()
const { loading, portalUser, user } = useUser()
const [isCopied, setIsCopied] = useState(false)

const [handleEditDisplayName] = useEditDisplayNameMutation()

const userDisplayName = (portalUser?.displayName || '') as string

const copyTextToClipboard = async () => {
try {
await navigator.clipboard.writeText(user?.userId || '')
setIsCopied(true)
setTimeout(() => setIsCopied(false), 3000)
} catch (err) {
console.error('Failed to copy: ', err)
}
}

return loading ? (
<Loader />
) : (
Expand All @@ -32,6 +45,20 @@ const Settings = () => {
}}
/>
</section>
<hr />
<span className={styles.copyClipboard}>
Your user id is: {user?.userId}
</span>
<button
type="button"
className={`usa-button usa-button--unstyled ${styles.copyButton}`}
onClick={copyTextToClipboard}>
<FontAwesomeIcon
className={styles.copyIcon}
icon={isCopied ? 'check' : 'copy'}
/>
{isCopied ? 'Copied!' : 'Copy To Clipboard'}
</button>
</div>
</div>
)
Expand Down
9 changes: 9 additions & 0 deletions src/styles/pages/settings.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@
section {
margin-top: units('205');
}

.copyIcon {
margin-right: units(0.5);
}

.copyButton {
cursor: pointer;
margin-left: units(1);
}
}

0 comments on commit 534a51a

Please sign in to comment.