react-garden
Version:
React + TypeScript + ThreeJS app using Material UI on NextJS, Apollo Client, GraphQL + WordPress REST APIs, for ThreeD web development.. a part of the threed.ai code family.
62 lines (55 loc) • 1.56 kB
JavaScript
// ** React Imports
import { useState, useEffect } from 'react'
// ** Next Import
import Link from 'next/link'
// ** MUI Imports
import Grid from '@mui/material/Grid'
import Alert from '@mui/material/Alert'
// ** Third Party Components
import axios from 'axios'
// ** Demo Components Imports
import UserViewLeft from '~/views/apps/user/view/UserViewLeft'
import UserViewRight from '~/views/apps/user/view/UserViewRight'
const UserView = ({ id, invoiceData }) => {
// ** State
const [error, setError] = useState(false)
const [data, setData] = useState(null)
useEffect(() => {
axios
.get('/apps/user', { params: { id } })
.then(response => {
setData(response.data)
setError(false)
})
.catch(() => {
setData(null)
setError(true)
})
}, [id])
if (data) {
return (
<Grid container spacing={6}>
<Grid item xs={12} md={5} lg={4}>
<UserViewLeft data={data} />
</Grid>
<Grid item xs={12} md={7} lg={8}>
<UserViewRight invoiceData={invoiceData} />
</Grid>
</Grid>
)
} else if (error) {
return (
<Grid container spacing={6}>
<Grid item xs={12}>
<Alert severity='error'>
User with the id: {id} does not exist. Please check the list of users:{' '}
<Link href='/apps/user/list'>User List</Link>
</Alert>
</Grid>
</Grid>
)
} else {
return null
}
}
export default UserView