import { Button } from 'react-bootstrap' import { useSession } from 'next-auth/client' import Link from 'next/link' import { useRouter } from 'next/router' import Nav from 'react-bootstrap/Nav' import { useState } from 'react' import { Form, Input, SubmitButton } from './form' import InputGroup from 'react-bootstrap/InputGroup' import * as Yup from 'yup' import { gql, useApolloClient, useQuery } from '@apollo/client' const NAME_QUERY = gql` query nameAvailable($name: String!) { nameAvailable(name: $name) } ` export default function UserHeader ({ user }) { const [editting, setEditting] = useState(false) const [session] = useSession() const router = useRouter() const client = useApolloClient() const Satistics = () =>

[{user.stacked} stacked, {user.sats} sats]

const UserSchema = Yup.object({ name: Yup.string() .required('required') .matches(/^[\w_]+$/, 'only letters, numbers, and _') .max(32, 'too long') .test({ name: 'name', test: async name => { if (!name || !name.length) return false const { data } = await client.query({ query: NAME_QUERY, variables: { name } }) return data.nameAvailable }, message: 'taken' }) }) return ( <> {editting ? (
@ name='name' autoFocus noBottomMargin showValid /> setEditting(true)}>save ) : (

@{user.name}

{session && session.user && session.user.name === user.name && }
)} ) }