Skip to content

Commit 50276c9

Browse files
author
Matthew Vita
authored
Merge pull request #91 from GoTeamEpsilon/contact_additions
Contact additions
2 parents 505feec + 0fbf727 commit 50276c9

File tree

7 files changed

+195
-58
lines changed

7 files changed

+195
-58
lines changed

samples/react-redux-patient-demographics-example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"rimraf": "^2.5.4",
113113
"sass-loader": "^4.0.0",
114114
"style-loader": "^0.13.1",
115+
"underscore": "^1.8.3",
115116
"url-loader": "^0.5.6",
116117
"webpack": "^1.12.14",
117118
"yargs": "^6.3.0"
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: 8 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
}
@@ -382,7 +386,9 @@ class Basic extends React.Component {
382386
</table>
383387

384388
<button className='btn btn-default btn-sm' type='submit'>SAVE</button>
385-
<button className='btn btn-default btn-sm' type='input' onClick={this.handleCancel.bind(this)}>CANCEL</button>
389+
<button className='btn btn-default btn-sm'
390+
type='button'
391+
onClick={this.handleCancel.bind(this)}>CANCEL</button>
386392
</Formsy.Form>
387393
)
388394
} else {

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

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
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'
5-
import { FormsyDatePicker } from '../../../../common/FormsyDatePicker'
4+
import { FormsyHiddenInput } from '../../../../common/FormsyHiddenInput'
65
import { FormsyMaskedInput } from '../../../../common/FormsyMaskedInput'
76
import { wireUpCustomFormsyValidators } from '../../../../common/CustomValidators'
87
import {telephoneFormat} from '../../../../common/Formatters'
98

10-
119
class Contact extends Component {
1210
constructor() {
1311
super()
@@ -18,32 +16,38 @@ class Contact extends Component {
1816

1917
this.handleCancel = this.handleCancel.bind(this)
2018
this.handleEdit = this.handleEdit.bind(this)
19+
this.handleDelete = this.handleDelete.bind(this)
2120
this.handleInputChange = this.handleInputChange.bind(this)
2221
wireUpCustomFormsyValidators()
2322
}
2423

2524
handleCancel() {
26-
console.log('handleCancel')
27-
this.setState(this.state.cachedForm)
25+
console.debug(`Contact ${this.props.contact.id} component in cancel mode`)
2826
this.setState({ cachedForm: {} })
29-
this.setState({showForm: false})
27+
this.setState({ showForm: false })
3028
}
3129

3230
handleDelete() {
33-
console.log('handleDelete')
31+
console.debug(`Contact ${this.props.contact.id} component is being deleted`)
32+
this.props.deleteContact(this.props.contact.id)
3433
}
3534

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

42+
componentDidMount() {
43+
if (this.props.contact.isNewContact) {
44+
this.handleEdit()
45+
}
46+
}
47+
4348
handleInputChange(event) {
44-
console.log('handleInputChange')
4549
let value
46-
if(event.target.name === 'phone') {
50+
if (event.target.name === 'phone') {
4751
value = this.sanitizeToJustNumbers(event.target.value.toString())
4852
} else {
4953
value = event.target.value
@@ -54,8 +58,8 @@ class Contact extends Component {
5458
}
5559

5660
handleSubmit(formValues) {
57-
console.log('handleSubmit')
58-
this.props.updatePatientData(formValues)
61+
console.debug('Submitting contact info updates')
62+
this.props.updateContactData(formValues)
5963
this.setState({ showForm: false })
6064
}
6165

@@ -68,13 +72,15 @@ class Contact extends Component {
6872
}
6973

7074
setPropsToLocalState() {
71-
const keys = ['name', 'relation', 'address', 'phone', 'city', 'postal', 'state', 'country', 'email']
75+
const keys = ['id', 'name', 'relation', 'address', 'phone', 'city', 'postal', 'state', 'country', 'email']
7276

7377
keys.forEach((keyName) => {
7478
let value
75-
76-
if (keyName === 'phone'){
77-
value = this.sanitizeToJustNumbers(this.props.contact[keyName].toString())
79+
// Make switch statement
80+
if (keyName === 'phone') {
81+
value = this.sanitizeToJustNumbers((this.props.contact[keyName] || '').toString())
82+
} else if (keyName === 'id') {
83+
value = this.props.contact[keyName]
7884
} else {
7985
value = this.props.contact[keyName]
8086
}
@@ -109,23 +115,23 @@ class Contact extends Component {
109115
</tr>
110116
<tr>
111117
<td><strong>Email:</strong> {this.props.contact.email}</td>
112-
<td></td>
113118
</tr>
114119
</tbody>
115120
</table>
116121

117122
<button type='button' className='btn btn-default btn-sm' onClick={this.handleDelete}>DELETE</button>
118123
<button type='button' className='btn btn-default btn-sm' onClick={this.handleEdit}>EDIT</button>
119-
<br/>
120-
<br/>
124+
125+
<hr/>
126+
121127
</div>
122128
)
123129
} else if (this.props.contact && this.state.showForm === true) {
124130
return (
125131

126132
<Formsy.Form onValidSubmit={this.handleSubmit.bind(this)}
127133
name='contactInfoForm'
128-
className='contact-info-form'
134+
className='container contact-info-form'
129135
noValidate>
130136
<table className='table'>
131137
<tbody>
@@ -149,8 +155,8 @@ class Contact extends Component {
149155
<td>
150156
<FormsyInput value={this.state.relation}
151157
onChange={this.handleInputChange}
152-
name='relationship'
153-
label='Relationship'
158+
name='relation'
159+
label='Relation'
154160
validations={{
155161
maxLength: 25,
156162
minLength: 1
@@ -212,22 +218,6 @@ class Contact extends Component {
212218
}}
213219
required />
214220
</td>
215-
<td>
216-
<FormsyInput value={this.state.postal}
217-
onChange={this.handleInputChange}
218-
name='postal'
219-
label='Postal'
220-
validations={{
221-
maxLength: 5,
222-
minLength: 5
223-
}}
224-
validationErrors={{
225-
isDefaultRequiredValue: 'Valid postal code is required',
226-
maxLength: 'You must enter a valid postal code',
227-
minLength: 'You must enter a valid postal code'
228-
}}
229-
required />
230-
</td>
231221
</tr>
232222
<tr>
233223
<td>
@@ -246,18 +236,38 @@ class Contact extends Component {
246236
}}
247237
required />
248238
</td>
239+
240+
<td>
241+
<FormsyInput
242+
value={this.state.postal}
243+
onChange={this.handleInputChange}
244+
name='postal'
245+
label='Postal'
246+
validations={{
247+
maxLength: 10,
248+
minLength: 4
249+
}}
250+
validationErrors={{
251+
isDefaultRequiredValue: 'Valid postal is required',
252+
maxLength: 'You must not enter more than 10 characters',
253+
minLength: 'You must enter at least 4 characters'
254+
}}
255+
required />
256+
</td>
257+
</tr>
258+
<tr>
249259
<td>
250260
<FormsyInput value={this.state.country}
251261
onChange={this.handleInputChange}
252262
name='country'
253263
label='Country'
254264
validations={{
255-
maxLength: 20,
265+
maxLength: 30,
256266
minLength: 2
257267
}}
258268
validationErrors={{
259269
isDefaultRequiredValue: 'Valid country is required',
260-
maxLength: 'You must not enter more than 20 characters',
270+
maxLength: 'You must not enter more than 30 characters',
261271
minLength: 'You must enter at least 2 characters'
262272
}}
263273
required />
@@ -280,17 +290,25 @@ class Contact extends Component {
280290
}}
281291
required />
282292
</td>
283-
<td></td>
284293
</tr>
285-
</tbody>
294+
<tr>
295+
<td>
296+
<FormsyHiddenInput value={this.state.id}
297+
onChange={this.handleInputChange}
298+
name='id'
299+
required />
300+
</td>
301+
</tr>
302+
</tbody>
286303
</table>
287304

288305
<button className='btn btn-default btn-sm' type='submit'>SAVE</button>
289-
<button type='button' className='btn btn-default btn-sm' onClick={this.handleCancel}>CANCEL</button>
290-
<br/>
291-
<br/>
306+
<button type='button'
307+
className='btn btn-default btn-sm'
308+
onClick={this.handleCancel.bind(this)}>CANCEL</button>
292309

293310
</Formsy.Form>
311+
294312
)
295313
}
296314
}

samples/react-redux-patient-demographics-example/src/routes/Patient/Demographics/PatientDemographicsComponent.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class PatientDemographics extends React.Component {
2626
});
2727
}
2828

29+
addNewContact() {
30+
this.props.startAddingNewContact(this.props.routeParams.pid)
31+
}
32+
2933
determineIfRouteIsValid() {
3034
return this.props.routeParams.pid
3135
}
@@ -49,7 +53,8 @@ class PatientDemographics extends React.Component {
4953
}
5054

5155
render() {
52-
let children = null;
56+
let children = null
57+
let addContactVisibility = 'hidden'
5358

5459
switch (this.state.tab) {
5560
case this.TABS.BASIC:
@@ -58,10 +63,15 @@ class PatientDemographics extends React.Component {
5863
break;
5964
case this.TABS.CONTACTS:
6065
if (this.props.contacts) {
61-
children = this.props.contacts.map(contact =>
62-
<Contact key={contact.id} contact={contact}/>
66+
children = this.props.contacts.map((contact) => {
67+
return <Contact updateContactData={this.props.updateContactData}
68+
deleteContact={this.props.deleteContact}
69+
key={contact.id}
70+
contact={contact}/>
71+
}
6372
)
6473
}
74+
addContactVisibility = 'visible'
6575
break;
6676
}
6777

@@ -86,6 +96,12 @@ class PatientDemographics extends React.Component {
8696
</div>
8797

8898
{children}
99+
100+
<br />
101+
102+
<button type='button'
103+
className={['btn', 'btn-default', 'btn-sm', addContactVisibility].join(' ')}
104+
onClick={this.addNewContact.bind(this)}>ADD NEW CONTACT</button>
89105
</div>
90106
</div>
91107
)

samples/react-redux-patient-demographics-example/src/routes/Patient/Demographics/PatientDemographicsContainer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { connect } from 'react-redux'
2-
import { setPatientInContext, updatePatientData } from '../PatientModule'
2+
import { setPatientInContext, updatePatientData, updateContactData, deleteContact, startAddingNewContact }
3+
from '../PatientModule'
34
import PatientDemographics from './PatientDemographicsComponent'
45

56
const mapDispatchToProps = {
67
setPatientInContext,
7-
updatePatientData
8+
updatePatientData,
9+
updateContactData,
10+
deleteContact,
11+
startAddingNewContact
812
}
913

1014
const extractBasicInfo = (state) => {

0 commit comments

Comments
 (0)