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

Commit f34bbc3

Browse files
author
Matthew Vita
committed
fixes for updating contact entries
1 parent 1edb4e4 commit f34bbc3

File tree

4 files changed

+58
-37
lines changed

4 files changed

+58
-37
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react'
2+
import Formsy from 'formsy-react'
3+
4+
export const FormsyHiddenInput = React.createClass({
5+
mixins: [Formsy.Mixin],
6+
7+
changeValue(event) {
8+
let value = ''
9+
10+
if (event && event.currentTarget && event.currentTarget.value) {
11+
value = event.currentTarget.value
12+
event.currentTarget.value = value
13+
}
14+
15+
this.props.onChange(event)
16+
this.setValue(value)
17+
},
18+
19+
render() {
20+
return (
21+
<div className='hidden'>
22+
<input type='hidden'
23+
onChange={this.changeValue}
24+
value={this.getValue()}
25+
name={this.props.name} />
26+
</div>
27+
);
28+
}
29+
});

‎samples/react-redux-patient-demographics-example/src/routes/Patient/Demographics/Basic/BasicComponent.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ class Basic extends React.Component {
1717
dob: moment(),
1818
cachedForm: {}
1919
}
20+
21+
this.handleCancel = this.handleCancel.bind(this)
2022
this.handleInputChange = this.handleInputChange.bind(this)
2123
this.handleEdit = this.handleEdit.bind(this)
2224
wireUpCustomFormsyValidators()
2325
}
2426

2527
handleEdit() {
28+
console.debug('Basic component in edit mode')
2629
this.setLocalStateToStoreValues()
2730
this.setState({ showForm: true })
2831
this.setState({ cachedForm: this.props.info })
@@ -32,14 +35,15 @@ class Basic extends React.Component {
3235
}
3336

3437
handleSubmit(formValues) {
38+
console.debug('Submitting basic info updates')
3539
// Convert dob back to date string
3640
formValues.dob = formValues.dob.format('YYYY-MM-DD')
3741
this.props.updatePatientData(formValues)
3842
this.setState({ showForm: false })
3943
}
4044

4145
handleCancel() {
42-
this.setState(this.state.cachedForm)
46+
console.debug('Basic component in read mode')
4347
this.setState({ cachedForm: {} })
4448
this.setState({ showForm: false })
4549
}
@@ -378,7 +382,7 @@ class Basic extends React.Component {
378382
</table>
379383

380384
<button className='btn btn-default btn-sm' type='submit'>SAVE</button>
381-
<button className='btn btn-default btn-sm' type='input' onClick={this.handleCancel.bind(this)}>CANCEL</button>
385+
<button className='btn btn-default btn-sm' type='button' onClick={this.handleCancel.bind(this)}>CANCEL</button>
382386
</Formsy.Form>
383387
)
384388
} else {

‎samples/react-redux-patient-demographics-example/src/routes/Patient/Demographics/Contact/ContactComponent.js‎

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, {Component} from 'react'
2-
import MaskedInput from 'react-text-mask' // Delete?
32
import Formsy from 'formsy-react'
43
import { FormsyInput } from '../../../../common/FormsyInput'
4+
import { FormsyHiddenInput } from '../../../../common/FormsyHiddenInput'
55
import { FormsyDatePicker } from '../../../../common/FormsyDatePicker'
66
import { FormsyMaskedInput } from '../../../../common/FormsyMaskedInput'
77
import { wireUpCustomFormsyValidators } from '../../../../common/CustomValidators'
@@ -23,25 +23,23 @@ class Contact extends Component {
2323
}
2424

2525
handleCancel() {
26-
console.log('handleCancel')
27-
this.setState(this.state.cachedForm)
28-
//this.setState({ cachedForm: {}})
29-
this.setState({showForm: false})
26+
console.debug('Basic component in read mode')
27+
this.setState({ cachedForm: {} })
28+
this.setState({ showForm: false })
3029
}
3130

3231
handleDelete() {
3332
console.log('handleDelete')
3433
}
3534

3635
handleEdit() {
37-
console.log('handleEdit')
36+
console.debug('Contact component in edit mode')
3837
this.setPropsToLocalState()
3938
this.setState({showForm: true})
40-
//this.setState({ cachedForm: this.props.contact })
39+
this.setState({ cachedForm: this.props.contact })
4140
}
4241

4342
handleInputChange(event) {
44-
console.log('handleInputChange')
4543
let value
4644
if(event.target.name === 'phone') {
4745
value = this.sanitizeToJustNumbers(event.target.value.toString())
@@ -54,9 +52,7 @@ class Contact extends Component {
5452
}
5553

5654
handleSubmit(formValues) {
57-
console.log('handleSubmit')
58-
59-
console.log(formValues);
55+
console.debug('Submitting contact info updates')
6056
this.props.updateContactData(formValues)
6157
this.setState({ showForm: false })
6258
}
@@ -70,7 +66,7 @@ class Contact extends Component {
7066
}
7167

7268
setPropsToLocalState() {
73-
const keys = ['id','name', 'relation', 'address', 'phone', 'city', 'postal', 'state', 'country', 'email']
69+
const keys = ['id','name', 'relation', 'address', 'phone', 'city', 'postal', 'state', 'country', 'email']
7470

7571
keys.forEach((keyName) => {
7672
let value
@@ -289,19 +285,16 @@ class Contact extends Component {
289285
</tr>
290286
<tr>
291287
<td>
292-
<FormsyInput type='hidden'
293-
value={this.state.id}
294-
onChange={this.handleInputChange}
295-
name='id'
296-
label='ID'
297-
298-
required />
288+
<FormsyHiddenInput value={this.state.id}
289+
onChange={this.handleInputChange}
290+
name='id'
291+
required />
299292
</td>
300293
</tr>
301294
</table>
302295

303296
<button className='btn btn-default btn-sm' type='submit'>SAVE</button>
304-
<button type='button' className='btn btn-default btn-sm' onClick={this.handleCancel}>CANCEL</button>
297+
<button type='button' className='btn btn-default btn-sm' onClick={this.handleCancel.bind(this)}>CANCEL</button>
305298

306299
</Formsy.Form>
307300

‎samples/react-redux-patient-demographics-example/src/routes/Patient/PatientModule.js‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const setPatientInContext = (patientId) => {
7070
})
7171
reject(message);
7272
} else {
73-
console.warn(`Setting patient ${patientId} as patient in context`);
73+
console.debug(`Setting patient ${patientId} as patient in context`);
7474
dispatch({
7575
type : 'SET_PATIENT_IN_CONTEXT',
7676
payload : patientId
@@ -86,6 +86,7 @@ export const setPatientInContext = (patientId) => {
8686
export const updatePatientData = (data) => {
8787
return (dispatch, getState) => {
8888
return new Promise((resolve, reject) => {
89+
console.debug(`updating basic patient data for ${getState().patient.patientInContext}`)
8990
dispatch({
9091
type : 'UPDATE_PATIENT_DATA',
9192
payload : [getState().patient.patientInContext, data]
@@ -96,9 +97,9 @@ export const updatePatientData = (data) => {
9697
}
9798

9899
export const updateContactData = (data) => {
99-
console.log("hey I'm contact data and I'm running")
100100
return (dispatch, getState) => {
101101
return new Promise((resolve, reject) => {
102+
console.debug(`updating contact patient data for ${getState().patient.patientInContext}`)
102103
dispatch({
103104
type : 'UPDATE_CONTACT_DATA',
104105
payload : [getState().patient.patientInContext, data]
@@ -118,26 +119,20 @@ export const actions = {
118119
const initialState = testData
119120
export default function patientReducer (state = initialState, action) {
120121
let result
121-
// maybe define "copy" here
122+
letcopy=clone(state)
122123
switch (action.type) {
123124
case 'SET_PATIENT_IN_CONTEXT':
124-
result = { ...state, patientInContext: action.payload }
125+
copy.patientInContext = action.payload
126+
result = copy
125127
break
126128
case 'UPDATE_PATIENT_DATA':
127-
let copy1 = clone(state)
128-
copy1[action.payload[0]].basic = action.payload[1]
129-
result = copy1
129+
copy[action.payload[0]].basic = action.payload[1]
130+
result = copy
130131
break
131132
case 'UPDATE_CONTACT_DATA':
132-
//console.log("I ran too in the store!!")
133-
// console.log([action.payload[0]].basic)
134-
// console.log(action.payload[1])
135-
let copy2 = clone(state)
136133
let id = action.payload[1].id - 1
137-
// console.log(copy2);
138-
// console.log(result);
139-
copy2[action.payload[0]].contacts[id] = action.payload[1]
140-
result = copy2
134+
copy[action.payload[0]].contacts[id] = action.payload[1]
135+
result = copy
141136
break
142137
default:
143138
result = state

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /