This commit is contained in:
Elijah Lucian 2021-04-11 16:51:24 -07:00
parent 69a7dd3816
commit 46e58722d6
6 changed files with 46 additions and 22 deletions

View File

@ -1,6 +1,7 @@
import { User } from '../../types' import { User } from '../../types'
export const mockUser: User = { export const mockUser: User = {
username: 'TestUser42',
id: '4242-4242-4242-4242', id: '4242-4242-4242-4242',
username: 'TestUser42',
email: 'testuser@email.com',
} }

View File

@ -6,6 +6,7 @@ import { Route, Switch } from 'react-router'
import { Dashboard } from './pages/Dashboard' import { Dashboard } from './pages/Dashboard'
import { NavRoute, AppHeader } from './layout/AppHeader' import { NavRoute, AppHeader } from './layout/AppHeader'
import { Profile } from './pages/Profile' import { Profile } from './pages/Profile'
import { NewUser } from './forms/NewUser'
export const CoreLayout = () => { export const CoreLayout = () => {
const { user } = useUserContext() const { user } = useUserContext()
@ -13,6 +14,7 @@ export const CoreLayout = () => {
const routes: NavRoute[] = [ const routes: NavRoute[] = [
{ exact: true, path: '/', label: 'Dashboard', component: Dashboard }, { exact: true, path: '/', label: 'Dashboard', component: Dashboard },
{ path: '/profile', label: 'Profile', component: Profile }, { path: '/profile', label: 'Profile', component: Profile },
{ path: '/new/user', label: 'New User', component: NewUser },
] ]
if (!user) if (!user)

View File

@ -1,6 +1,9 @@
import { Button, Form, Input, message } from 'antd' import { Button, Form, Input, Layout, message } from 'antd'
import axios from 'axios'
import { User } from '../../types' import { User } from '../../types'
axios.defaults.baseURL = 'http://localhost:8080/'
type NewUserForm = Omit<User, 'id'> & { type NewUserForm = Omit<User, 'id'> & {
password1: string password1: string
password2: string password2: string
@ -10,13 +13,20 @@ export const NewUser = () => {
const [form] = Form.useForm<NewUserForm>() const [form] = Form.useForm<NewUserForm>()
const handleFinish = (user: NewUserForm) => { const handleFinish = (user: NewUserForm) => {
console.log('Asdfdas')
if (user.password1 !== user.password2) { if (user.password1 !== user.password2) {
message.error('passwords do not match') message.error('passwords do not match')
return return
} }
axios.post(`/dj-rest-auth/registration`, user)
} }
console.log('ASDFUASDJF')
return ( return (
<Layout>
<Layout.Content>
<Form form={form} onFinish={handleFinish}> <Form form={form} onFinish={handleFinish}>
<Form.Item label="username" name="name"> <Form.Item label="username" name="name">
<Input></Input> <Input></Input>
@ -30,7 +40,11 @@ export const NewUser = () => {
<Form.Item label="confirm" name="password2"> <Form.Item label="confirm" name="password2">
<Input></Input> <Input></Input>
</Form.Item> </Form.Item>
<Button htmlType="submit">Create</Button> <Button type="primary" htmlType="submit">
Create
</Button>
</Form> </Form>
</Layout.Content>
</Layout>
) )
} }

View File

@ -32,7 +32,9 @@ export const AppHeader = ({ user, routes }: Props) => {
<div className="header-left"> <div className="header-left">
<Typography.Title level={3}>MVP Django React! 🤠</Typography.Title> <Typography.Title level={3}>MVP Django React! 🤠</Typography.Title>
{routes?.map((route) => ( {routes?.map((route) => (
<Link to={route.path}>{route.label}</Link> <Link key={`${route.path}-${route.label}`} to={route.path}>
{route.label}
</Link>
))} ))}
</div> </div>
<div> <div>

View File

@ -35,10 +35,10 @@ export const UserContextProvider = ({ children }: Props) => {
useEffect(() => { useEffect(() => {
const login = async () => { const login = async () => {
try { try {
const res = axios.post('/dj-rest-auth/login', { // const res = axios.post('/dj-rest-auth/login', {
email: 'blah', // email: 'blah',
password: 'blah', // password: 'blah',
}) // })
const user = await getLoggedInUser() const user = await getLoggedInUser()
if (!user) throw new Error() if (!user) throw new Error()
setUser(user) setUser(user)

View File

@ -43,3 +43,8 @@
padding: 0; padding: 0;
} }
} }
.ant-layout-content {
max-width: 900px;
margin: auto;
}