diff --git a/api/resolvers/user.js b/api/resolvers/user.js index 3e23a164..c62357e5 100644 --- a/api/resolvers/user.js +++ b/api/resolvers/user.js @@ -2,14 +2,14 @@ import { AuthenticationError, UserInputError } from 'apollo-server-errors' import { createMentions, getItem, SELECT } from './item' import serialize from './serial' -export const createBio = async (parent, { title, text }, { me, models }) => { +export const createBio = async (parent, { bio }, { me, models }) => { if (!me) { throw new AuthenticationError('you must be logged in') } const [item] = await serialize(models, models.$queryRaw(`${SELECT} FROM create_bio($1, $2, $3) AS "Item"`, - title, text, Number(me.id))) + `@${me.name}'s bio`, bio, Number(me.id))) await createMentions(item, models) diff --git a/api/typeDefs/user.js b/api/typeDefs/user.js index eb941793..532bebee 100644 --- a/api/typeDefs/user.js +++ b/api/typeDefs/user.js @@ -10,7 +10,7 @@ export default gql` extend type Mutation { setName(name: String!): Boolean - createBio(title: String!, text: String): Item! + createBio(bio: String!): Item! } type User { diff --git a/pages/[username].js b/pages/[username].js index 5cdc086c..a974878c 100644 --- a/pages/[username].js +++ b/pages/[username].js @@ -6,10 +6,13 @@ import Seo from '../components/seo' import { Button } from 'react-bootstrap' import styles from '../styles/user.module.css' import { useState } from 'react' -import { DiscussionForm } from '../components/discussion-form' import { useSession } from 'next-auth/client' import { ITEM_FIELDS } from '../fragments/items' import ItemFull from '../components/item-full' +import * as Yup from 'yup' +import { Form, MarkdownInput, SubmitButton } from '../components/form' +import ActionTooltip from '../components/action-tooltip' +import TextareaAutosize from 'react-textarea-autosize' export async function getServerSideProps ({ req, params }) { const { error, data: { user } } = await (await ApolloClient(req)).query({ @@ -45,11 +48,15 @@ export async function getServerSideProps ({ req, params }) { } } +const BioSchema = Yup.object({ + bio: Yup.string().required('required').trim() +}) + function BioForm () { const [createBio] = useMutation( gql` - mutation createBio($title: String!, $text: String) { - createBio(title: $title, text: $text) { + mutation createBio($bio: String!) { + createBio(bio: $bio) { id } }`, { @@ -68,15 +75,27 @@ function BioForm () { return (
- { +
{ const { error } = await createBio({ variables: values }) if (error) { throw new Error({ message: error.toString() }) } }} - /> + > + + + create + +
) } @@ -85,7 +104,7 @@ export default function User ({ user }) { const [create, setCreate] = useState(false) const [session] = useSession() - // need to check if this is the user's page + // need to check if this is the user's page before exposing create/edit return (