Added list of user's form to user page

This commit is contained in:
Dmitriy Shishkov 2020-10-18 22:29:49 +05:00
parent 95ec7daaef
commit b7910a5de2
No known key found for this signature in database
GPG Key ID: D76D70029F55183E
2 changed files with 28 additions and 5 deletions

View File

@ -43,6 +43,10 @@ const USER = gql`
email
id
name
forms {
id
title
}
}
}
`

View File

@ -1,20 +1,39 @@
import { useQuery } from '@apollo/client'
import React from 'react'
import { USER } from '../../apollo'
import { User } from '../../apollo/typeDefs.gen'
interface UserQuery {
user: User
}
const UserPage: React.FC = () => {
const { data, error, loading } = useQuery(USER)
const { data, error, loading } = useQuery<UserQuery>(USER)
if (loading) return <p>Loading...</p>
if (error) return <p>{error.message}</p>
const { name, email, id } = data.user
const { user } = data!
return (
<div>
<h1>Username: {name}</h1>
<h3>Email: {email}</h3>
<p>User ID: {id}</p>
<h1>Username: {user.name}</h1>
<h3>Email: {user.email}</h3>
<p>User ID: {user.id}</p>
{user.forms && (
<>
<h2>Forms list</h2>
<ul>
{user.forms.map((form, index) => (
<li key={index}>
<a href={`http://localhost:3000/form/${form.id}`}>
{form.title}
</a>
</li>
))}
</ul>
</>
)}
</div>
)
}