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:
parent
9dfdfe7329
commit
2b2f2d589c
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue