import { Checkbox, Form, Input, SubmitButton, Select } from '../components/form'
import * as Yup from 'yup'
import { Alert, Button, InputGroup, Modal } from 'react-bootstrap'
import LayoutCenter from '../components/layout-center'
import { useState } from 'react'
import { gql, useMutation, useQuery } from '@apollo/client'
import { getGetServerSideProps } from '../api/ssrApollo'
import LoginButton from '../components/login-button'
import { signIn } from 'next-auth/client'
import ModalButton from '../components/modal-button'
import { LightningAuth } from '../components/lightning-auth'
import { SETTINGS, SET_SETTINGS } from '../fragments/users'
import { useRouter } from 'next/router'
import Info from '../components/info'
import { CURRENCY_SYMBOLS } from '../components/price'
export const getServerSideProps = getGetServerSideProps(SETTINGS)
const supportedCurrencies = Object.keys(CURRENCY_SYMBOLS)
export const SettingsSchema = Yup.object({
tipDefault: Yup.number().typeError('must be a number').required('required')
.positive('must be positive').integer('must be whole'),
fiatCurrency: Yup.string().required('required').oneOf(supportedCurrencies)
})
const warningMessage = 'If I logout, even accidentally, I will never be able to access my account again'
export const WarningSchema = Yup.object({
warning: Yup.string().matches(warningMessage, 'does not match').required('required')
})
export default function Settings ({ data: { settings } }) {
const [success, setSuccess] = useState()
const [setSettings] = useMutation(SET_SETTINGS, {
update (cache, { data: { setSettings } }) {
cache.modify({
id: 'ROOT_QUERY',
fields: {
settings () {
return setSettings
}
}
})
}
}
)
const { data } = useQuery(SETTINGS)
if (data) {
({ settings } = data)
}
return (
}
name='hideInvoiceDesc'
/>
content
wild west mode
don't hide flagged content
don't down rank flagged content
}
name='wildWestMode'
groupClassName='mb-0'
/>
greeter mode
see and screen free posts and comments
help onboard users to SN and Lightning
you might be subject to more spam
}
name='greeterMode'
/>
save
saturday newsletter
(re)subscribe
{settings?.authMethods &&
}
)
}
function AuthMethods ({ methods }) {
const router = useRouter()
const [unlinkAuth] = useMutation(
gql`
mutation unlinkAuth($authType: String!) {
unlinkAuth(authType: $authType) {
lightning
email
twitter
github
}
}`, {
update (cache, { data: { unlinkAuth } }) {
cache.modify({
id: 'ROOT_QUERY',
fields: {
settings (existing) {
return { ...existing, authMethods: { ...unlinkAuth } }
}
}
})
}
}
)
const [obstacle, setObstacle] = useState()
const unlink = async type => {
// if there's only one auth method left
let links = 0
links += methods.lightning ? 1 : 0
links += methods.email ? 1 : 0
links += methods.twitter ? 1 : 0
links += methods.github ? 1 : 0
if (links === 1) {
setObstacle(type)
} else {
await unlinkAuth({ variables: { authType: type } })
}
}
return (
<>
setObstacle(null)}
>
setObstacle(null)}>X
You are removing your last auth method. It is recommended you link another auth method before removing
your last auth method. If you'd like to proceed anyway, type the following below
If I logout, even accidentally, I will never be able to access my account again
auth methods
{methods.lightning
? {
await unlink('lightning')
}
}
/>
: (
}>
)}
{
if (methods.twitter) {
await unlink('twitter')
} else {
signIn('twitter')
}
}
}
/>
{
if (methods.github) {
await unlink('github')
} else {
signIn('github')
}
}
}
/>
{methods.email
? (
{
await unlink('email')
}
}
>Unlink Email
)
:
}
>
)
}
export const EmailSchema = Yup.object({
email: Yup.string().email('email is no good').required('required')
})
export function EmailLinkForm ({ callbackUrl }) {
const [linkUnverifiedEmail] = useMutation(
gql`
mutation linkUnverifiedEmail($email: String!) {
linkUnverifiedEmail(email: $email)
}`
)
return (
)
}