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'
export const mockUser: User = {
username: 'TestUser42',
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 { NavRoute, AppHeader } from './layout/AppHeader'
import { Profile } from './pages/Profile'
import { NewUser } from './forms/NewUser'
export const CoreLayout = () => {
const { user } = useUserContext()
@ -13,6 +14,7 @@ export const CoreLayout = () => {
const routes: NavRoute[] = [
{ exact: true, path: '/', label: 'Dashboard', component: Dashboard },
{ path: '/profile', label: 'Profile', component: Profile },
{ path: '/new/user', label: 'New User', component: NewUser },
]
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'
axios.defaults.baseURL = 'http://localhost:8080/'
type NewUserForm = Omit<User, 'id'> & {
password1: string
password2: string
@ -10,27 +13,38 @@ export const NewUser = () => {
const [form] = Form.useForm<NewUserForm>()
const handleFinish = (user: NewUserForm) => {
console.log('Asdfdas')
if (user.password1 !== user.password2) {
message.error('passwords do not match')
return
}
axios.post(`/dj-rest-auth/registration`, user)
}
console.log('ASDFUASDJF')
return (
<Form form={form} onFinish={handleFinish}>
<Form.Item label="username" name="name">
<Input></Input>
</Form.Item>
<Form.Item label="email" name="email">
<Input></Input>
</Form.Item>
<Form.Item label="password" name="password1">
<Input></Input>
</Form.Item>
<Form.Item label="confirm" name="password2">
<Input></Input>
</Form.Item>
<Button htmlType="submit">Create</Button>
</Form>
<Layout>
<Layout.Content>
<Form form={form} onFinish={handleFinish}>
<Form.Item label="username" name="name">
<Input></Input>
</Form.Item>
<Form.Item label="email" name="email">
<Input></Input>
</Form.Item>
<Form.Item label="password" name="password1">
<Input></Input>
</Form.Item>
<Form.Item label="confirm" name="password2">
<Input></Input>
</Form.Item>
<Button type="primary" htmlType="submit">
Create
</Button>
</Form>
</Layout.Content>
</Layout>
)
}

View File

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

View File

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

View File

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