Skip to content

Commit 432325e

Browse files
author
Daniel Ehrlich
committed
new branch connecting my component to the store
1 parent e8c6c78 commit 432325e

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ class Contact extends Component {
5555

5656
handleSubmit(formValues) {
5757
console.log('handleSubmit')
58-
this.props.updatePatientData(formValues)
5958
this.setState({ showForm: false })
59+
this.props.updateContactData(formValues)
60+
6061
}
6162

6263
sanitizeToJustNumbers(value) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class PatientDemographics extends React.Component {
5959
case this.TABS.CONTACTS:
6060
if (this.props.contacts) {
6161
children = this.props.contacts.map(contact =>
62-
<Contact key={contact.id} contact={contact}/>
62+
<Contact updateContactData={this.props.updateContactData} key={contact.id} contact={contact}/>
6363
)
6464
}
6565
break;

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

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

55
const mapDispatchToProps = {
66
setPatientInContext,
7-
updatePatientData
7+
updatePatientData,
8+
updateContactData
89
}
910

1011
const extractBasicInfo = (state) => {

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ export const updatePatientData = (data) => {
9595
}
9696
}
9797

98+
export const updateContactData = (data) => {
99+
console.log("hey I'm contact data and I'm running")
100+
return (dispatch, getState) => {
101+
return new Promise((resolve, reject) => {
102+
dispatch({
103+
type : 'UPDATE_CONTACT_DATA',
104+
payload : [getState().patient.patientInContext, data]
105+
})
106+
resolve()
107+
})
108+
}
109+
}
110+
98111
export const actions = {
99112
setPatientInContext
100113
};
@@ -105,14 +118,23 @@ export const actions = {
105118
const initialState = testData
106119
export default function patientReducer (state = initialState, action) {
107120
let result
121+
// maybe define "copy" here
108122
switch (action.type) {
109123
case 'SET_PATIENT_IN_CONTEXT':
110124
result = { ...state, patientInContext: action.payload }
111125
break
112126
case 'UPDATE_PATIENT_DATA':
113-
let copy = clone(state)
127+
let copy1 = clone(state)
114128
copy[action.payload[0]].basic = action.payload[1]
115-
result = copy
129+
result = copy1
130+
break
131+
case 'UPDATE_CONTACT_DATA':
132+
//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
116138
break
117139
default:
118140
result = state

0 commit comments

Comments
 (0)