Created
November 30, 2016 16:58
-
-
Save masonforest/dba26a8d9266bbdbb8232e3041ff372a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { connect } from 'react-redux'; | |
import Contacts from 'components/Contacts'; | |
import { openFullScreenModal } from 'modules/FullScreenModal'; | |
import { SCHEDULE_MODAL } from 'modules/ScheduleModal'; | |
import { CONTACT_MODAL } from 'modules/ContactModal'; | |
import { START_CALL_MODAL, VIDEO_CALL, AUDIO_CALL } from 'modules/StartCallModal'; | |
import { | |
actions, | |
CONTACTS_FILTER_OPTION_AVAILABLE, | |
CONTACTS_FILTER_OPTION_MY_CONTACTS | |
} from 'modules/Contact'; | |
import { apiActions as nucleusApiActions, contactSelectors } from 'lifesize-sky-nucleus'; | |
import { createSelector } from 'reselect'; | |
/* Object of action creators (can also be function that returns object). | |
Keys will be passed as props to presentational components. Here we are | |
implementing our wrapper around increment; the component doesn't care */ | |
function mapDispatchToProps(dispatch) { | |
return { | |
handleFilterChange: (type, value) => dispatch(actions.contactsFilterChange(type, value)), | |
handleCreateContact: () => dispatch(openFullScreenModal(CONTACT_MODAL, { isCreate: true })), | |
handleSelectContact: contact => | |
(contact && contact.id ? | |
dispatch(actions.selectContact(contact.id)) : | |
dispatch(actions.selectContact())), | |
handleEdit: contact => | |
dispatch(openFullScreenModal(CONTACT_MODAL, { contact })), | |
handleDelete: contact => | |
dispatch(openFullScreenModal(CONTACT_MODAL, { contact, isDelete: true })), | |
handleVideoCall: id => | |
dispatch(openFullScreenModal(START_CALL_MODAL, { id, type: VIDEO_CALL })), | |
handleFavoriteToggle: (id, value) => { | |
dispatch(nucleusApiActions.contactSetFavorite(id, value)); | |
}, | |
handleAudioCall: id => | |
dispatch(openFullScreenModal(START_CALL_MODAL, { id, type: AUDIO_CALL })), | |
handleChat: extension => dispatch(actions.chatWith(extension)), | |
handleSchedule: id => dispatch(openFullScreenModal(SCHEDULE_MODAL, id)) | |
}; | |
} | |
const filterValue = state => state.app.contacts.filters.contacts; | |
const contactsSwitch = createSelector( | |
filterValue, | |
contactSelectors.usersSelector, | |
contactSelectors.availableUsers, | |
contactSelectors.myPersonalContacts, | |
(filter, all, available, personal) => { | |
switch (filter) { | |
case CONTACTS_FILTER_OPTION_MY_CONTACTS: | |
return personal; | |
case CONTACTS_FILTER_OPTION_AVAILABLE: | |
return available; | |
default: | |
return all; | |
} | |
} | |
); | |
const mapStateToProps = state => ({ | |
contacts: contactsSwitch(state), | |
filter: filterValue(state), | |
selectedContact: contactSelectors | |
.getContactByIdGenerator(state)(state.app.contacts.selectedContactId) | |
}); | |
export default connect(mapStateToProps, mapDispatchToProps)(Contacts); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment