Skip to content

Commit

Permalink
Merge pull request #147 from u9520107/refactor/call-logger
Browse files Browse the repository at this point in the history
Refactor/call logger
  • Loading branch information
u9520107 authored Mar 30, 2017
2 parents 8a14283 + 33bbefa commit 2c562d2
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"redux-thunk": "^2.1.0",
"ringcentral": "3.0.0",
"ringcentral-client": "^1.0.0-rc1",
"ringcentral-integration": "^0.5.9",
"ringcentral-integration": "^0.5.13",
"sass-loader": "^4.1.1",
"source-map-loader": "^0.1.5",
"style-loader": "^0.13.1",
Expand Down
12 changes: 9 additions & 3 deletions src/components/CallItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ export default class CallItem extends Component {
const activityMatches = nextProps.call.activityMatches;
for (const activity of activityMatches) {
const index = contactMatches.findIndex(contact => (
activity.additionalParams['regarding.id'] === contact.id
// TODO find a better name or mechanism...
this.props.isLoggedContact(nextProps.call, activity, contact)
));
if (index > -1) return index;
}
Expand Down Expand Up @@ -308,6 +309,7 @@ export default class CallItem extends Component {
onViewContact,
onLogCall,
dateTimeFormatter,
isLogging,
} = this.props;
const phoneNumber = this.getPhoneNumber();
const contactMatches = this.getContactMatches();
Expand Down Expand Up @@ -342,7 +344,7 @@ export default class CallItem extends Component {
onLogCall={this.logCall}
isLogged={activityMatches.length > 0}
disabled={disableLinks}
isLogging={this.state.isLogging} />
isLogging={isLogging || this.state.isLogging} />
);
}
let contactLinkEl;
Expand All @@ -369,7 +371,7 @@ export default class CallItem extends Component {
selected={this.state.selected}
onSelectContact={this.onSelectContact}
disabled={disableLinks}
isLogging={this.state.isLogging}
isLogging={isLogging || this.state.isLogging}
fallBackName={fallbackContactName}
areaCode={areaCode}
countryCode={countryCode}
Expand Down Expand Up @@ -410,12 +412,16 @@ CallItem.propTypes = {
currentLocale: PropTypes.string.isRequired,
onLogCall: PropTypes.func,
onViewContact: PropTypes.func,
isLoggedContact: PropTypes.func,
disableLinks: PropTypes.bool.isRequired,
active: PropTypes.bool.isRequired,
dateTimeFormatter: PropTypes.func.isRequired,
isLogging: PropTypes.bool,
};

CallItem.defaultProps = {
onLogCall: undefined,
onViewContact: undefined,
isLoggedContact: () => false,
isLogging: false,
};
7 changes: 7 additions & 0 deletions src/components/CallList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ function CallList({
countryCode,
onViewContact,
onLogCall,
isLoggedContact,
disableLinks,
active,
dateTimeFormatter,
loggingMap,
}) {
if (calls && calls.length) {
return (
Expand All @@ -36,9 +38,11 @@ function CallList({
countryCode={countryCode}
onViewContact={onViewContact}
onLogCall={onLogCall}
isLoggedContact={isLoggedContact}
disableLinks={disableLinks}
active={active}
dateTimeFormatter={dateTimeFormatter}
isLogging={!!loggingMap[call.sessionId]}
/>
))}
</div>
Expand All @@ -60,6 +64,8 @@ CallList.propTypes = {
countryCode: PropTypes.string.isRequired,
onViewContact: PropTypes.func,
onLogCall: PropTypes.func,
isLoggedContact: PropTypes.func,
loggingMap: PropTypes.object,
disableLinks: PropTypes.bool,
dateTimeFormatter: PropTypes.func.isRequired,
};
Expand All @@ -69,6 +75,7 @@ CallList.defaultProps = {
disableLinks: false,
onViewContact: undefined,
onLogCall: undefined,
loggingMap: {},
};

export default CallList;
7 changes: 7 additions & 0 deletions src/components/CallsPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export default function CallsPanel({
countryCode,
onViewContact,
onLogCall,
isLoggedContact,
disableLinks,
dateTimeFormatter,
showSpinner,
title,
active,
loggingMap,
}) {
const content = showSpinner ?
<SpinnerOverlay /> :
Expand All @@ -31,9 +33,11 @@ export default function CallsPanel({
countryCode={countryCode}
onViewContact={onViewContact}
onLogCall={onLogCall}
isLoggedContact={isLoggedContact}
disableLinks={disableLinks}
dateTimeFormatter={dateTimeFormatter}
active={active}
loggingMap={loggingMap}
/>
);
return (
Expand All @@ -55,11 +59,13 @@ CallsPanel.propTypes = {
countryCode: PropTypes.string.isRequired,
onViewContact: PropTypes.func,
onLogCall: PropTypes.func,
isLoggedContact: PropTypes.func,
disableLinks: PropTypes.bool.isRequired,
dateTimeFormatter: PropTypes.func.isRequired,
showSpinner: PropTypes.bool,
title: PropTypes.string,
active: PropTypes.bool,
loggingMap: PropTypes.object,
};

CallsPanel.defaultProps = {
Expand All @@ -68,4 +74,5 @@ CallsPanel.defaultProps = {
showSpinner: false,
title: '',
active: false,
loggingMap: {},
};
13 changes: 13 additions & 0 deletions src/containers/CallHistoryPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function mapToProps(_, {
regionSettings,
connectivityMonitor,
dateTimeFormat,
callLogger,
}) {
return {
title: i18n.getString('title', locale.currentLocale),
Expand All @@ -16,6 +17,7 @@ function mapToProps(_, {
areaCode: regionSettings.areaCode,
countryCode: regionSettings.countryCode,
disableLinks: !connectivityMonitor.connectivity,
loggingMap: callLogger.loggingMap,
showSpinner: !(
callHistory.ready &&
locale.ready &&
Expand All @@ -31,10 +33,21 @@ function mapToFunctions(_, {
dateTimeFormatter = utcTimestamp => dateTimeFormat.formatDateTime({
utcTimestamp,
}),
callLogger,
onLogCall,
isLoggedContact,
}) {
return {
dateTimeFormatter,
onViewContact,
isLoggedContact,
onLogCall: onLogCall || (callLogger && (async ({ call, contact, redirect = true }) => {
await callLogger.logCall({
call,
contact,
redirect,
});
})),
};
}

Expand Down
19 changes: 17 additions & 2 deletions src/containers/CallMonitorPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ function mapToProps(_, {
callMonitor,
regionSettings,
connectivityMonitor,
dateTimeFormat
dateTimeFormat,
callLogger,
}) {
return {
active: true,
Expand All @@ -17,12 +18,14 @@ function mapToProps(_, {
areaCode: regionSettings.areaCode,
countryCode: regionSettings.countryCode,
disableLinks: !connectivityMonitor.connectivity,
loggingMap: callLogger.loggingMap,
showSpinner: !(
locale.ready &&
callMonitor.ready &&
regionSettings.ready &&
connectivityMonitor.ready &&
dateTimeFormat.ready
dateTimeFormat.ready &&
callLogger.ready
),
};
}
Expand All @@ -32,10 +35,22 @@ function mapToFunctions(_, {
dateTimeFormatter = utcTimestamp => dateTimeFormat.formatDateTime({
utcTimestamp,
}),
callLogger,
onLogCall,
isLoggedContact,

}) {
return {
dateTimeFormatter,
onViewContact,
isLoggedContact,
onLogCall: onLogCall || (callLogger && (async ({ call, contact, redirect = true }) => {
await callLogger.logCall({
call,
contact,
redirect,
});
})),
};
}

Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6368,9 +6368,9 @@ ringcentral-client@^1.0.0-rc1:
form-data "^2.1.2"
isomorphic-fetch "^2.2.1"

ringcentral-integration@^0.5.9:
version "0.5.9"
resolved "https://registry.yarnpkg.com/ringcentral-integration/-/ringcentral-integration-0.5.9.tgz#8fea2ac025d8ff4aebf38160c5a4f0a17dbd5089"
ringcentral-integration@^0.5.13:
version "0.5.13"
resolved "https://registry.yarnpkg.com/ringcentral-integration/-/ringcentral-integration-0.5.13.tgz#56f760b28e49adfbf3c1f38b1c23ac5e7e5d9831"
dependencies:
data-types "git+https://github.com/u9520107/data-types.git#release"
json-mask "^0.3.8"
Expand Down

0 comments on commit 2c562d2

Please sign in to comment.