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

Render organizer message in CallListItem #1037

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions locale/lists/callList/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ item:
allocated: On-going...
notReached: Not reached
reached: Reached
organizerMsg:
noMessage: Caller did not leave a message
2 changes: 2 additions & 0 deletions locale/lists/callList/sv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ item:
allocated: Pågår...
notReached: Nåddes inte
reached: Nåddes
organizerMsg:
noMessage: Ringaren lämnade inget meddelande
4 changes: 2 additions & 2 deletions src/actions/call.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export function retrieveCalls(page = 0, filters = {}) {
};
}

export function retrieveCall(id) {
export function retrieveCall(id, retrieveMessage = false) {
return ({ dispatch, getState, z }) => {
let orgId = getState().org.activeId;

dispatch({
type: types.RETRIEVE_CALL,
meta: { id },
meta: { id, retrieveMessage },
payload: {
promise: z.resource('orgs', orgId, 'calls', id).get()
}
Expand Down
48 changes: 46 additions & 2 deletions src/components/lists/items/CallListItem.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import { connect } from 'react-redux';
import React from 'react';
import cx from 'classnames';
import { FormattedMessage as Msg } from 'react-intl';
import { retrieveCall } from '../../../actions/call';

import Avatar from '../../misc/Avatar';


@connect()
export default class CallListItem extends React.Component {
static propTypes = {
onItemClick: React.PropTypes.func.isRequired,
data: React.PropTypes.object,
};

componentDidUpdate(prevProps) {
const call = this.props.data;

if (this.props.inView && !prevProps.inView) {
if (!call || call.message_to_organizer !== undefined) {
return;
}
else if (call.organizer_action_needed) {
this.props.dispatch(retrieveCall(call.id, true))
MikaelJohnAndersson marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

render() {
let call = this.props.data;
if (!call) return null;
Expand All @@ -19,6 +34,7 @@ export default class CallListItem extends React.Component {
let stateClass = "CallListItem-state";
let stateLabel = null;
let actionStatus = null;
let organizerMessage = null;

switch (call.state) {
case 0:
Expand All @@ -41,7 +57,34 @@ export default class CallListItem extends React.Component {
actionStatus = "needed";
}

let actionClassNames  = cx('CallListItem-action', actionStatus );
if (actionStatus) {
const messageClassNames = cx('CallListItem-organizerMsg', {
loading: call.message_to_organizer === undefined,
empty: call.message_to_organizer === null,
});

let messageContent = null;

if (call.message_to_organizer === null) {
messageContent = (
<Msg tagName="span"
id="lists.callList.item.organizerMsg.noMessage"/>
);
}
else if (call.message_to_organizer && call.message_to_organizer.length > 180) {
messageContent = call.message_to_organizer.substr(0, 180) + '...';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like this?

let len = 0;
messageContent = call.message_to_organizer.split(' ').filter(s => (len += s.length + 1) && len < 40).join(' ') + '...';

}
else {
messageContent = call.message_to_organizer;
}

organizerMessage = (
<span className={ messageClassNames }>
{ messageContent }</span>
);
}

let actionClassNames  = cx('CallListItem-action', actionStatus );

return (
<div className="CallListItem"
Expand All @@ -66,6 +109,7 @@ export default class CallListItem extends React.Component {
</span>
<span className="CallListItem-caller">
{ call.caller.name }</span>
{ organizerMessage }
</div>
<div className="CallListItem-callStatuses"/>
<div className="CallListItem-organizerStatuses"/>
Expand Down
43 changes: 39 additions & 4 deletions src/components/lists/items/CallListItem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
.CallListItem-content {
@include col(11,12);
padding: 1em;

@include medium-screen {
@include col(12,12);
}
}

.CallListItem-target {
Expand Down Expand Up @@ -107,6 +103,38 @@
@include icon($fa-var-phone);
}
}

.CallListItem-organizerMsg {
@include col(12,12, $align:middle, $first:true);
display: flex;
align-items: baseline;

@include small-screen {
margin-top: 0.5em;
padding: 0;
}

&:before {
@include icon($fa-var-sticky-note-o);
min-width: 1.6em;
}

&.loading {
&::after {
display: inline-block;
animation: CallListItem-organizerMsg-loadingAnimation steps(1, end) 1s infinite;
content: '.';
}
}

&.empty {
span {
font-size: inherit;
font-style: italic;
color: #666666;
}
}
}
}

.CallListItem-action {
Expand Down Expand Up @@ -185,3 +213,10 @@
}
}
}

@keyframes CallListItem-organizerMsg-loadingAnimation {
0% { content: '.'; }
33% { content: '..'; }
66% { content: '...'; }
99% { content: '.'; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line needed?

}
4 changes: 3 additions & 1 deletion src/store/calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ export default function calls(state = null, action) {
});

case types.RETRIEVE_CALL + '_PENDING':
const messageIsPending = action.meta.retrieveMessage;

return Object.assign({
callList: updateOrAddListItem(state.callList,
action.meta.id, null, { isPending: true }),
action.meta.id, null, { isPending: !messageIsPending }),
});

case types.RETRIEVE_CALL + '_FULFILLED':
Expand Down