Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): Add attached pipette info to intercom support #2140

Merged
merged 1 commit into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion app/src/components/RobotSettings/ResetRobotModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ function makeMapStateToProps (): (state: State, ownProps: OP) => SP {
const {robot} = ownProps
const optionsRequest = getResetOptions(state, robot)
const optionsResponse = optionsRequest.response
console.log('OPTIONS', {optionsResponse})
return {
options: optionsResponse && optionsResponse.options,
resetRequest: getResetRequest(state, robot),
Expand Down
31 changes: 28 additions & 3 deletions app/src/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ const intercom = (...args) => {
}
}

// intercom api calls
const BOOT = 'boot'
const UPDATE = 'update'

// custom intercom properties
const APP_VERSION = 'App Version'
const ROBOT_NAME = 'Robot Name'
const PIPETTE_MODEL_LEFT = 'Pipette Model Left'
const PIPETTE_MODEL_RIGHT = 'Pipette Model Right'

export function initializeSupport (): ThunkAction {
return (_, getState) => {
const config = getState().config.support
Expand All @@ -34,26 +44,41 @@ export function initializeSupport (): ThunkAction {
}

export const supportMiddleware: Middleware = (store) => (next) => (action) => {
let update

if (action.type === 'robot:CONNECT_RESPONSE') {
const state = store.getState()
const robot = state.robot.connection.connectRequest.name

intercom('update', {user_id: userId, 'Robot Name': robot})
update = {[ROBOT_NAME]: robot}
} else if (action.type === 'api:PIPETTES_SUCCESS') {
const state = store.getState()

if (state.robot.connection.connectedTo === action.payload.robot.name) {
const {left, right} = action.payload.pipettes

update = {
[PIPETTE_MODEL_LEFT]: left.model,
[PIPETTE_MODEL_RIGHT]: right.model
}
}
}

if (update) intercom(UPDATE, {user_id: userId, ...update})

return next(action)
}

function initializeIntercom (config: SupportConfig) {
if (INTERCOM_ID) {
userId = config.userId

intercom('boot', {
intercom(BOOT, {
app_id: INTERCOM_ID,
user_id: userId,
created_at: config.createdAt,
name: config.name,
'App Version': version
[APP_VERSION]: version
})
}
}