Skip to content

Commit 60b5032

Browse files
author
Daniel Ehrlich
committed
now works with store but deletes the relationship after submitting for some reason...
1 parent 432325e commit 60b5032

File tree

2 files changed

+73
-20
lines changed

2 files changed

+73
-20
lines changed

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

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Contact extends Component {
2525
handleCancel() {
2626
console.log('handleCancel')
2727
this.setState(this.state.cachedForm)
28-
this.setState({ cachedForm: {} })
28+
//this.setState({ cachedForm: {} })
2929
this.setState({showForm: false})
3030
}
3131

@@ -37,7 +37,7 @@ class Contact extends Component {
3737
console.log('handleEdit')
3838
this.setPropsToLocalState()
3939
this.setState({showForm: true})
40-
this.setState({ cachedForm: this.props.contact })
40+
//this.setState({ cachedForm: this.props.contact })
4141
}
4242

4343
handleInputChange(event) {
@@ -55,9 +55,10 @@ class Contact extends Component {
5555

5656
handleSubmit(formValues) {
5757
console.log('handleSubmit')
58-
this.setState({ showForm: false })
58+
59+
console.log(formValues);
5960
this.props.updateContactData(formValues)
60-
61+
this.setState({ showForm: false })
6162
}
6263

6364
sanitizeToJustNumbers(value) {
@@ -69,13 +70,15 @@ class Contact extends Component {
6970
}
7071

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

7475
keys.forEach((keyName) => {
7576
let value
76-
77-
if (keyName === 'phone'){
77+
// Make switch statement
78+
if (keyName === 'phone') {
7879
value = this.sanitizeToJustNumbers(this.props.contact[keyName].toString())
80+
} else if (keyName === 'id'){
81+
value = this.props.contact[keyName]
7982
} else {
8083
value = this.props.contact[keyName]
8184
}
@@ -129,7 +132,7 @@ class Contact extends Component {
129132
noValidate>
130133
<table className='table'>
131134
<tr>
132-
<td><strong>Name:</strong>
135+
<td>
133136
<FormsyInput value={this.state.name}
134137
onChange={this.handleInputChange}
135138
name='name'
@@ -145,7 +148,7 @@ class Contact extends Component {
145148
}}
146149
required />
147150
</td>
148-
<td><strong>Relation:</strong>
151+
<td>
149152
<FormsyInput value={this.state.relation}
150153
onChange={this.handleInputChange}
151154
name='relationship'
@@ -163,7 +166,7 @@ class Contact extends Component {
163166
</td>
164167
</tr>
165168
<tr>
166-
<td><strong>Address:</strong>
169+
<td>
167170
<FormsyInput value={this.state.address}
168171
onChange={this.handleInputChange}
169172
name='address'
@@ -178,7 +181,7 @@ class Contact extends Component {
178181
minLength: 'You must enter at least 2 characters'
179182
}}
180183
required /></td>
181-
<td><strong>Phone:</strong>
184+
<td>
182185
<FormsyMaskedInput mask={['(',/[1-9]/,/\d/,/\d/,')',' ',/\d/,/\d/,/\d/,'-',/\d/,/\d/,/\d/,/\d/]}
183186
value={this.state.phone}
184187
onChange={this.handleInputChange}
@@ -195,7 +198,7 @@ class Contact extends Component {
195198
required /></td>
196199
</tr>
197200
<tr>
198-
<td><strong>City:</strong>
201+
<td>
199202
<FormsyInput value={this.state.city}
200203
onChange={this.handleInputChange}
201204
name='city'
@@ -213,7 +216,7 @@ class Contact extends Component {
213216
</td>
214217
</tr>
215218
<tr>
216-
<td><strong>State:</strong>
219+
<td>
217220
<FormsyInput value={this.state.state}
218221
onChange={this.handleInputChange}
219222
name='state'
@@ -229,9 +232,45 @@ class Contact extends Component {
229232
}}
230233
required />
231234
</td>
235+
236+
<td>
237+
<FormsyInput
238+
value={this.state.postal}
239+
onChange={this.handleInputChange}
240+
name='postal'
241+
label='Postal'
242+
validations={{
243+
maxLength: 10,
244+
minLength: 4
245+
}}
246+
validationErrors={{
247+
isDefaultRequiredValue: 'Valid postal is required',
248+
maxLength: 'You must not enter more than 10 characters',
249+
minLength: 'You must enter at least 4 characters'
250+
}}
251+
required />
252+
</td>
232253
</tr>
233254
<tr>
234-
<td><strong>Email:</strong>
255+
<td>
256+
<FormsyInput value={this.state.country}
257+
onChange={this.handleInputChange}
258+
name='country'
259+
label='Country'
260+
validations={{
261+
maxLength: 30,
262+
minLength: 2
263+
}}
264+
validationErrors={{
265+
isDefaultRequiredValue: 'Valid country is required',
266+
maxLength: 'You must not enter more than 30 characters',
267+
minLength: 'You must enter at least 2 characters'
268+
}}
269+
required />
270+
</td>
271+
</tr>
272+
<tr>
273+
<td>
235274
<FormsyInput value={this.state.email}
236275
onChange={this.handleInputChange}
237276
name='email'
@@ -248,6 +287,17 @@ class Contact extends Component {
248287
required />
249288
</td>
250289
</tr>
290+
<tr>
291+
<td>
292+
<FormsyInput type='hidden'
293+
value={this.state.id}
294+
onChange={this.handleInputChange}
295+
name='id'
296+
label='ID'
297+
298+
required />
299+
</td>
300+
</tr>
251301
</table>
252302

253303
<button className='btn btn-default btn-sm' type='submit'>SAVE</button>

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,19 @@ export default function patientReducer (state = initialState, action) {
125125
break
126126
case 'UPDATE_PATIENT_DATA':
127127
let copy1 = clone(state)
128-
copy[action.payload[0]].basic = action.payload[1]
128+
copy1[action.payload[0]].basic = action.payload[1]
129129
result = copy1
130130
break
131131
case 'UPDATE_CONTACT_DATA':
132132
//console.log("I ran too in the store!!")
133-
console.log(action.payload[0].contacts)
134-
console.log(action.payload[1])
135-
//let copy2 = clone(state)
136-
//copy2[action.payload[0]].contacts[0] = action.payload[1]
137-
//result = copy2
133+
// console.log([action.payload[0]].basic)
134+
// console.log(action.payload[1])
135+
let copy2 = clone(state)
136+
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
138141
break
139142
default:
140143
result = state

0 commit comments

Comments
 (0)