Skip to content

Commit 4cb2542

Browse files
committed
form for showing Prompt
1 parent 0db489f commit 4cb2542

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React, { useState } from 'react'
2+
import { Prompt } from 'react-router-dom'
3+
import Card from '../../ui/Card'
4+
5+
const AddUser = () => {
6+
const [formIsDirty, setFormIsDirty] = useState(false)
7+
8+
function handleSubmit(e) {
9+
e.preventDefault()
10+
console.log('submit')
11+
}
12+
13+
return (
14+
<Card style={{ minHeight: '20em' }}>
15+
<Prompt when={formIsDirty} message="Are you sure you want to leave this form before saving?" />
16+
<form className="spacing" onSubmit={handleSubmit}>
17+
<input onChange={() => setFormIsDirty(true)} type="text" placeholder="Email" required />
18+
<input onChange={() => setFormIsDirty(true)} type="password" placeholder="Password" required />
19+
<button type="submit" className="button">
20+
Add User
21+
</button>
22+
</form>
23+
</Card>
24+
)
25+
}
26+
27+
export default AddUser

src/projects/authentication/AuthenticationLayout.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Panel from '../../ui/Panel'
44
import PageHeader from '../../ui/PageHeader'
55
import { PageHeaderTabs, Tab } from '../../ui/PageHeaderTabs'
66
import Users from './Users'
7+
import AddUser from './AddUser'
78
import SigninMethods from './SigninMethods'
89
import Templates from './Templates'
910

@@ -19,6 +20,7 @@ const AuthenticationLayout = ({ match }) => {
1920
</PageHeader>
2021
<Panel>
2122
<Switch>
23+
<Route path={`${match.path}/users/add-user`} component={AddUser} />
2224
<Route path={`${match.path}/users`} component={Users} />
2325
<Route path={`${match.path}/signin-method`} component={SigninMethods} />
2426
<Route path={`${match.path}/templates`} component={Templates} />

src/projects/authentication/Users.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import React from 'react'
2+
import { Link } from 'react-router-dom'
23
import Card from '../../ui/Card'
34

4-
const Users = () => {
5-
return <Card style={{ height: '20em' }}>Users</Card>
5+
const Users = ({ match }) => {
6+
return (
7+
<Card style={{ height: '20em' }}>
8+
<Link to={`${match.url}/add-user`} className="button">
9+
Add User
10+
</Link>
11+
</Card>
12+
)
613
}
714

815
export default Users

0 commit comments

Comments
 (0)