/
Resolver.tsx
executable file
·54 lines (46 loc) · 1.35 KB
/
Resolver.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import Button from 'modules/common/components/Button';
import { CONVERSATION_STATUSES } from 'modules/inbox/constants';
import React from 'react';
import { IConversation } from '../types';
type Props = {
conversations: IConversation[];
changeStatus: (conversationIds: string[], status: string) => void;
};
class Resolver extends React.Component<Props> {
changeStatus = (status: string) => {
const { conversations, changeStatus } = this.props;
// call change status method
changeStatus(
conversations.map(c => {
return c._id;
}),
status
);
};
render() {
const hasClosedConversation = this.props.conversations.find(
conversation => conversation.status === CONVERSATION_STATUSES.CLOSED
);
const buttonText = hasClosedConversation ? 'Open' : 'Resolve';
const icon = hasClosedConversation ? 'redo' : 'check-circle';
const btnAttrs = {
size: 'small',
uppercase: false,
btnStyle: hasClosedConversation ? 'warning' : 'success',
icon,
onClick: hasClosedConversation
? () => {
this.changeStatus(CONVERSATION_STATUSES.OPEN);
}
: () => {
this.changeStatus(CONVERSATION_STATUSES.CLOSED);
}
};
return (
<>
<Button {...btnAttrs}>{buttonText}</Button>
</>
);
}
}
export default Resolver;