import Layout from '@/components/layout' import { useQuery } from '@apollo/client' import UserHeader from '@/components/user-header' import Button from 'react-bootstrap/Button' import styles from '@/styles/user.module.css' import { useState } from 'react' import ItemFull from '@/components/item-full' import { Form, MarkdownInput } from '@/components/form' import { useMe } from '@/components/me' import { USER_FULL } from '@/fragments/users' import { getGetServerSideProps } from '@/api/ssrApollo' import { FeeButtonProvider } from '@/components/fee-button' import { bioSchema } from '@/lib/validate' import { useRouter } from 'next/router' import PageLoading from '@/components/page-loading' import { ItemButtonBar } from '@/components/post' import useItemSubmit from '@/components/use-item-submit' import { UPSERT_BIO } from '@/fragments/paidAction' export const getServerSideProps = getGetServerSideProps({ query: USER_FULL, notFound: data => !data.user }) export function BioForm ({ handleDone, bio, me }) { const onSubmit = useItemSubmit(UPSERT_BIO, { navigateOnSubmit: false, paidMutationOptions: { update (cache, { data: { upsertBio: { result, invoice } } }) { if (!result) return cache.modify({ id: `User:${me.id}`, fields: { bio () { return result.text } } }) } }, onSuccessfulSubmit: (data, { resetForm }) => { handleDone?.() } }) return (
) } export function UserLayout ({ user, children, containClassName }) { return ( {children} ) } export default function User ({ ssrData }) { const [create, setCreate] = useState(false) const [edit, setEdit] = useState(false) const router = useRouter() const { me } = useMe() const { data } = useQuery(USER_FULL, { variables: { ...router.query } }) if (!data && !ssrData) return const { user } = data || ssrData const mine = me?.name === user.name return ( {user.bio ? (edit ? (
setEdit(false)} />
) : ) : (mine &&
{create ? setCreate(false)} /> : ( mine &&
your bio is also a post introducing yourself to other stackers
)}
)}
) }