Show Alert Message on Settings Page (#1179)

* Show alert message

* Add extra line

* Use css var

* Restore lightning in filter

* Show alert at top of page
This commit is contained in:
Tom Smith 2024-05-17 16:47:06 +01:00 committed by GitHub
parent 9dfdfe7329
commit 2b2f2d589c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -38,6 +38,19 @@ function bech32encode (hexString) {
return bech32.encode('npub', bech32.toWords(Buffer.from(hexString, 'hex'))) return bech32.encode('npub', bech32.toWords(Buffer.from(hexString, 'hex')))
} }
// sort to prevent hydration mismatch
const getProviders = (authMethods) =>
Object.keys(authMethods).filter(k => k !== '__typename' && k !== 'apiKey').sort()
// Show alert message if user only has one auth method activated
// as users are losing access to their accounts
const hasOnlyOneAuthMethod = (authMethods) => {
const activatedAuths = getProviders(authMethods)
.filter(provider => !!authMethods[provider])
return activatedAuths.length === 1
}
export function SettingsHeader () { export function SettingsHeader () {
const router = useRouter() const router = useRouter()
const pathParts = router.asPath.split('/').filter(segment => !!segment) const pathParts = router.asPath.split('/').filter(segment => !!segment)
@ -94,6 +107,7 @@ export default function Settings ({ ssrData }) {
return ( return (
<Layout> <Layout>
<div className='pb-3 w-100 mt-2' style={{ maxWidth: '600px' }}> <div className='pb-3 w-100 mt-2' style={{ maxWidth: '600px' }}>
{hasOnlyOneAuthMethod(settings?.authMethods) && <div className={styles.alert}>Please add a second auth method to avoid losing access to your account.</div>}
<SettingsHeader /> <SettingsHeader />
<Form <Form
initial={{ initial={{
@ -673,8 +687,7 @@ function AuthMethods ({ methods, apiKeyEnabled }) {
} }
) )
// sort to prevent hydration mismatch const providers = getProviders(methods)
const providers = Object.keys(methods).filter(k => k !== '__typename' && k !== 'apiKey').sort()
const unlink = async type => { const unlink = async type => {
// if there's only one auth method left // if there's only one auth method left

View File

@ -15,3 +15,8 @@
.nav :global .active { .nav :global .active {
border-bottom: 2px solid var(--bs-primary); border-bottom: 2px solid var(--bs-primary);
} }
.alert {
color: var(--bs-danger);
margin-bottom: 10px;
}