Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Formik based form samples#1

Open
reinhard wants to merge29 commits intomaster
base:master
Choose a base branch
Loading
fromRP-Feature-forms
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
29 commits
Select commitHold shift + click to select a range
ecdb3c7
Forms: add page
reinhardJan 29, 2018
349593c
initial UserForm
reinhardFeb 26, 2018
e4c16ce
user addresses subforms
reinhardFeb 26, 2018
e8074fb
userform: move addresses
reinhardFeb 26, 2018
bc0f990
update dependencies
reinhardMar 9, 2018
7c15053
form styling; restructure code
reinhardMar 9, 2018
f374edf
form: restructure code
reinhardMar 9, 2018
ff14cc2
visual cleanup
reinhardMar 9, 2018
bdfd590
forms: use redux store
reinhardMar 11, 2018
81dcd97
forms: use a map as user store
reinhardMar 12, 2018
983c0c6
forms: saveUser
reinhardMar 13, 2018
3a4c7d9
forms: routing with react-router
reinhardMar 14, 2018
1c88738
router: use combineReducersWithRouter helper function
reinhardMar 14, 2018
8290c70
forms: addUser, server-side validation
reinhardMar 14, 2018
4bc852e
add source-map-explorer
reinhardMar 15, 2018
64a9209
cleanup code
reinhardMar 15, 2018
67bfb6a
update deps
reinhardMar 16, 2018
8318fcd
pin deps
reinhardMar 16, 2018
addf73b
forms: no auto-complete for input fields
reinhardMar 16, 2018
49fa74e
link logo
reinhardMar 16, 2018
5f8c030
forms: focus -> style
reinhardMar 16, 2018
aefde4f
formatting
reinhardApr 18, 2018
353d14f
merge with master: cleanup dependencies and .gitignore
reinhardApr 18, 2018
e28f226
use alpha releases of indoqa-react-fela and indoqa-react-app
reinhardApr 19, 2018
dda1a8f
merge with master
reinhardApr 19, 2018
ced5dd5
v2.4.0
reinhardApr 19, 2018
97a5ad3
merge with master
reinhardApr 20, 2018
c465c95
Update README.md
reinhardApr 21, 2018
e8bbb37
merge README.md with master
reinhardMay 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
forms: saveUser
  • Loading branch information
@reinhard
reinhard committedMar 13, 2018
commit983c0c6d49456d08e6bad17b27acb0ecd2393b10
7 changes: 4 additions & 3 deletionssrc/main/forms/components/UserForm.react.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@ import type {User} from '../types/User.js'

type Props = {
user: User,
onSubmit: Function,
}

const validationSchema = () => {
Expand All@@ -26,12 +27,12 @@ const validationSchema = () => {
})
}

const UserForm = ({user}:Props) => {
const UserForm = ({user, onSubmit}:Props) => {
return (
<Formik
key={user.id}
key={user.id + user.lastModified.toString()}
displayName="UserForm"
onSubmit={(values) =>console.log(values)}
onSubmit={(values) =>onSubmit(values)}
initialValues={user}
validateOnChange={false}
validationSchema={validationSchema}
Expand Down
10 changes: 8 additions & 2 deletionssrc/main/forms/components/UserPage.react.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,6 +12,12 @@ type Props = {
router: any,
currentUser: User,
loadUser: Function,
saveUser: Function,
}

const s = (user: User, saveUser: Function) => {
console.log('user', user)
saveUser(user)
}

class UserPage extends React.Component<Props> {
Expand All@@ -23,7 +29,7 @@ class UserPage extends React.Component<Props> {
}

render() {
const {currentUser} = this.props
const {currentUser, saveUser} = this.props

if (currentUser === null) {
return null
Expand All@@ -32,7 +38,7 @@ class UserPage extends React.Component<Props> {
return (
<MainMenuTemplate title="Forms: Edit user">
<Box m={3}>
<UserForm user={currentUser} />
<UserForm user={currentUser}onSubmit={(user) => s(user, saveUser)}/>
</Box>
</MainMenuTemplate>
)
Expand Down
4 changes: 2 additions & 2 deletionssrc/main/forms/components/UserPage.redux.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@
import {connect} from 'react-redux'
import {selectCurrentUser} from '../store/forms.selectors'

import {loadUser} from '../store/forms.actions'
import {loadUser, saveUser} from '../store/forms.actions'
import UserPage from './UserPage.react'

import type {FormsState} from '../types/FormsState'
Expand All@@ -11,4 +11,4 @@ const mapStateToProps = (state: FormsState) => ({
currentUser: selectCurrentUser(state),
})

export default connect(mapStateToProps, {loadUser})(UserPage)
export default connect(mapStateToProps, {loadUser, saveUser})(UserPage)
5 changes: 5 additions & 0 deletionssrc/main/forms/store/forms.actions.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,11 @@ export const loadUser = (id: string): Action => ({
id,
})

export const saveUser = (user: User): Action => ({
type: 'FORMS_SAVE_USER',
user,
})

export const setCurrentUser = (currentUser: User): Action => ({
type: 'FORMS_SET_CURRENT_USER',
currentUser,
Expand Down
16 changes: 15 additions & 1 deletionsrc/main/forms/store/forms.reducer.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,13 +21,15 @@ const user1: User = {
country: 'Austria',
}
],
lastModified: new Date(),
}

const user2: User = {
id: 'okhj7',
name: 'Gruber',
email: 'f.gruber@example.com',
addresses: [],
lastModified: new Date(),
}

const initialState: FormsState = {
Expand All@@ -41,7 +43,19 @@ const initialState: FormsState = {
export default (state: FormsState = initialState, action: Action) => {
switch (action.type) {
case 'FORMS_SAVE_USER':
return state
return {
...state,
users: {
...state.users,
[action.user.id]: {
...action.user,
addresses: [
...action.user.addresses,
],
lastModified: new Date(),
},
},
}

case 'FORMS_LOAD_USER':
return {
Expand Down
1 change: 1 addition & 0 deletionssrc/main/forms/types/User.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,4 +6,5 @@ export type User = {
name: string,
email: string,
addresses: Array<Address>,
lastModified: Date,
}

[8]ページ先頭

©2009-2025 Movatter.jp