Skip to content

Commit dfa29ee

Browse files
committed
Profile avatar - show client avatar param removed from user message function
1 parent e2c3300 commit dfa29ee

File tree

7 files changed

+13
-19
lines changed

7 files changed

+13
-19
lines changed

src/components/Widget/components/Conversation/components/Messages/index.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ function Messages({ profileAvatar, profileClientAvatar, showTimeStamp }: Props)
5656
{messages?.map((message, index) =>
5757
<div className={`rcw-message ${isClient(message.sender) ? 'rcw-message-client' : ''}`}
5858
key={`${index}-${format(message.timestamp, 'hh:mm')}`}>
59-
{(profileAvatar || (profileClientAvatar && isClient(message.sender))) &&
60-
message.showAvatar &&
61-
<img src={isClient(message.sender) ? profileClientAvatar : profileAvatar} className={
62-
`rcw-avatar ${isClient(message.sender) ? 'rcw-avatar-client' : ''}`
63-
} alt="profile" />
59+
{((profileAvatar && !isClient(message.sender)) || (profileClientAvatar && isClient(message.sender))) &&
60+
message.showAvatar &&
61+
<img
62+
src={isClient(message.sender) ? profileClientAvatar : profileAvatar}
63+
className={`rcw-avatar ${isClient(message.sender) ? 'rcw-avatar-client' : ''}`}
64+
alt="profile"
65+
/>
6466
}
6567
{getComponentToRender(message)}
6668
</div>

src/components/Widget/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function Widget({
7272
}
7373

7474
handleSubmit?.(userInput);
75-
dispatch(addUserMessage(userInput, !!profileClientAvatar));
75+
dispatch(addUserMessage(userInput));
7676
handleNewUserMessage(userInput);
7777
}
7878

src/store/actions/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ export function toggleInputDisabled(): actionsTypes.ToggleInputDisabled {
1515
};
1616
}
1717

18-
export function addUserMessage(text: string, showClientAvatar: boolean, id?: string): actionsTypes.AddUserMessage {
18+
export function addUserMessage(text: string, id?: string): actionsTypes.AddUserMessage {
1919
return {
2020
type: actionsTypes.ADD_NEW_USER_MESSAGE,
2121
text,
22-
showClientAvatar,
2322
id
2423
};
2524
}

src/store/actions/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export interface ToggleInputDisabled {
2929
export interface AddUserMessage {
3030
type: typeof ADD_NEW_USER_MESSAGE;
3131
text: string;
32-
showClientAvatar: boolean;
3332
id?: string;
3433
}
3534

src/store/dispatcher.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import store from '.';
44
import * as actions from './actions';
55
import { LinkParams, ImageState } from './types';
66

7-
export function addUserMessage(text: string, showClientAvatar: boolean, id?: string) {
8-
store.dispatch(actions.addUserMessage(text, showClientAvatar, id));
7+
export function addUserMessage(text: string, id?: string) {
8+
store.dispatch(actions.addUserMessage(text, id));
99
}
1010

1111
export function addResponseMessage(text: string, id?: string) {

src/store/reducers/messagesReducer.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ const initialState = {
2323

2424
const messagesReducer = {
2525
[ADD_NEW_USER_MESSAGE]: (state: MessagesState, { text, showClientAvatar, id }) =>
26-
({ ...state, messages: [...state.messages, createNewMessage(
27-
text,
28-
MESSAGE_SENDER.CLIENT,
29-
showClientAvatar,
30-
id)
31-
]}),
26+
({ ...state, messages: [...state.messages, createNewMessage(text, MESSAGE_SENDER.CLIENT, id)]}),
3227

3328
[ADD_NEW_RESPONSE_MESSAGE]: (state: MessagesState, { text, id }) =>
3429
({ ...state, messages: [...state.messages, createNewMessage(text, MESSAGE_SENDER.RESPONSE, id)], badgeCount: state.badgeCount + 1 }),

src/utils/messages.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { MESSAGES_TYPES, MESSAGE_SENDER, MESSAGE_BOX_SCROLL_DURATION } from '../
1111
export function createNewMessage(
1212
text: string,
1313
sender: string,
14-
showClientAvatar: boolean,
1514
id?: string,
1615
): MessageI {
1716
return {
@@ -20,7 +19,7 @@ export function createNewMessage(
2019
text,
2120
sender,
2221
timestamp: new Date(),
23-
showAvatar: sender === MESSAGE_SENDER.RESPONSE || showClientAvatar,
22+
showAvatar: true,
2423
customId: id,
2524
unread: sender === MESSAGE_SENDER.RESPONSE
2625
};

0 commit comments

Comments
 (0)