wip
This commit is contained in:
parent
69a7dd3816
commit
46e58722d6
|
@ -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',
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,13 +13,20 @@ 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 (
|
||||
<Layout>
|
||||
<Layout.Content>
|
||||
<Form form={form} onFinish={handleFinish}>
|
||||
<Form.Item label="username" name="name">
|
||||
<Input></Input>
|
||||
|
@ -30,7 +40,11 @@ export const NewUser = () => {
|
|||
<Form.Item label="confirm" name="password2">
|
||||
<Input></Input>
|
||||
</Form.Item>
|
||||
<Button htmlType="submit">Create</Button>
|
||||
<Button type="primary" htmlType="submit">
|
||||
Create
|
||||
</Button>
|
||||
</Form>
|
||||
</Layout.Content>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -43,3 +43,8 @@
|
|||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-layout-content {
|
||||
max-width: 900px;
|
||||
margin: auto;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user