Skip to content

Commit

Permalink
feat(app): Add attached pipette info to intercom support (#2140)
Browse files Browse the repository at this point in the history
Closes #2019
  • Loading branch information
Kadee80 authored and mcous committed Sep 5, 2018
1 parent af09a4b commit b06e845
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
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
})
}
}

0 comments on commit b06e845

Please sign in to comment.