Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit ca2d04e

Browse files
committed
Merge branch 'develop' of github.com:RocketChat/Rocket.Chat.Livechat into develop
2 parents 8da8b8b + 1ee9420 commit ca2d04e

File tree

8 files changed

+93
-9
lines changed

8 files changed

+93
-9
lines changed

src/i18n/fa.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"change_department_523a16e8": "تغییر بخش",
99
"chat_finished_effbd589": "گفتگو پایان یافت",
1010
"chat_now_3d7f6769": "Chat now",
11-
"chat_started_3b1db6d6": "Chat started",
11+
"chat_started_3b1db6d6": "گفتگو شروع شد",
1212
"choose_a_department_b106da55": "یک بخش را انتخاب کنید ...",
1313
"choose_a_department_fe9755fd": "یک بخش را انتخاب کنید",
1414
"choose_an_option_26ac97d2": "یک گزینه را انتخاب کنید",
@@ -28,7 +28,7 @@
2828
"error_removing_user_data_ce507478": "خطا در حذف اطلاعات کاربر.",
2929
"error_starting_a_new_conversation_reason_a1b491a1": "خطا در ایجاد گفتگوی جدید: %{reason}",
3030
"expand_chat_a0045dbd": "گسترش گفتگو",
31-
"field_required_fc5c6b05": "Field required",
31+
"field_required_fc5c6b05": "ورودی الزامی",
3232
"file_exceeds_allowed_size_of_size_bd65c389": "حجم فایل بیشتر از حد مجاز (%{size}) است.",
3333
"fileupload_error_9eedee68": "خطا در آپلود فایل",
3434
"finish_this_chat_87b79542": "پایان این گفتگو",
@@ -43,14 +43,14 @@
4343
"i_need_help_with_61054e21": "نیاز به کمک در بخش زیر را دارم",
4444
"if_you_have_any_other_questions_just_press_the_but_ceaadfa0": "اگر هرگونه سوال دیگری دارید، بر روی دکمه ی زیر کلیک کنید تا یک گفتگو آغاز شود",
4545
"insert_your_field_here_d631e875": "Insert your %{field} here...",
46-
"invalid_email_e82f3682": "Invalid email",
47-
"invalid_value_12ca12c2": "Invalid value",
46+
"invalid_email_e82f3682": "ایمیل نامعتبر",
47+
"invalid_value_12ca12c2": "مقدار نامعتبر",
4848
"leave_a_message_5b581048": "یک پیغام بگذارید",
4949
"livechat_connected_afee1c5b": "Livechat وصل شد.",
5050
"livechat_is_not_connected_b40328ca": "Livechat وصل نشد.",
5151
"media_types_not_accepted_4e25676a": "این نوع فایل قابل قبول نیست.",
5252
"message_5c38209d": "پیام",
53-
"messages_64e7435f": "Messages",
53+
"messages_64e7435f": "پیام‌ها",
5454
"minimize_chat_804b3135": "کوچک کردن گفتگو",
5555
"name_1aed4a1b": "نام",
5656
"need_help_803a61": "نیاز به کمک دارید?",
@@ -88,4 +88,4 @@
8888
"your_spot_is_spot_a35cd288": "Your spot is #%{spot}",
8989
"your_spot_is_spot_estimated_wait_time_estimatedwai_d0ff46e0": "Your spot is #%{spot} (Estimated wait time: %{estimatedWaitTime})"
9090
}
91-
}
91+
}

src/lib/hooks.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Livechat } from '../api';
22
import { store } from '../store';
33
import CustomFields from './customFields';
44
import { setWidgetLanguage } from './locale';
5-
import { loadConfig } from './main';
5+
import { loadConfig, updateBusinessUnit } from './main';
66
import { parentCall } from './parentCall';
77
import { createToken } from './random';
88
import Triggers from './triggers';
@@ -69,6 +69,21 @@ const api = {
6969
updateIframeGuestData({ department });
7070
},
7171

72+
async setBusinessUnit(newBusinessUnit) {
73+
if (!newBusinessUnit || !newBusinessUnit.trim().length) {
74+
throw new Error('Error! Invalid business ids');
75+
}
76+
77+
const { businessUnit: existingBusinessUnit } = store.state;
78+
79+
return existingBusinessUnit !== newBusinessUnit && updateBusinessUnit(newBusinessUnit);
80+
},
81+
82+
async clearBusinessUnit() {
83+
const { businessUnit } = store.state;
84+
return businessUnit && updateBusinessUnit();
85+
},
86+
7287
clearDepartment() {
7388
updateIframeGuestData({ department: '' });
7489
},

src/lib/main.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,43 @@ import I18n from '../i18n';
77
import store from '../store';
88
import constants from './constants';
99

10+
export const updateBusinessUnit = async (newBusinessUnit) => {
11+
const {
12+
token,
13+
config: existingConfig,
14+
} = store.state;
15+
if (!token) {
16+
throw new Error('Error! no livechat token found. please make sure you initialize widget first before setting business unit');
17+
}
18+
19+
const { departments } = await Livechat.config({
20+
token,
21+
...newBusinessUnit && { businessUnit: newBusinessUnit },
22+
});
23+
24+
if (newBusinessUnit) {
25+
return store.setState({
26+
config: {
27+
...existingConfig,
28+
departments,
29+
},
30+
businessUnit: newBusinessUnit,
31+
});
32+
}
33+
34+
await store.setState({
35+
config: {
36+
...existingConfig,
37+
departments,
38+
},
39+
});
40+
await store.unsetSinglePropInStateByName('businessUnit');
41+
};
42+
1043
export const loadConfig = async () => {
1144
const {
1245
token,
46+
businessUnit = null,
1347
} = store.state;
1448

1549
Livechat.credentials.token = token;
@@ -21,7 +55,10 @@ export const loadConfig = async () => {
2155
resources: { sound: src = null } = {},
2256
queueInfo,
2357
...config
24-
} = await Livechat.config({ token });
58+
} = await Livechat.config({
59+
token,
60+
...businessUnit && { businessUnit },
61+
});
2562

2663
await store.setState({
2764
config,

src/lib/room.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const closeChat = async ({ transcriptRequested } = {}) => {
2626

2727
if (clearLocalStorageWhenChatEnded) {
2828
// exclude UI-affecting flags
29-
const { minimized, visible, undocked, expanded, ...initial } = initialState();
29+
const { minimized, visible, undocked, expanded, businessUnit, ...initial } = initialState();
3030
await store.setState(initial);
3131
}
3232

src/store/Store.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ export default class Store {
7878
this.emit('change', [this._state, prevState, partialState]);
7979
}
8080

81+
unsetSinglePropInStateByName(propName) {
82+
const prevState = this._state;
83+
delete prevState[propName];
84+
this._state = { ...prevState };
85+
this.persist();
86+
this.emit('change', [this._state, prevState]);
87+
}
88+
8189
setStoredState(storedState) {
8290
const prevState = this._state;
8391

src/store/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const initialState = () => ({
3535
unread: null,
3636
incomingCallAlert: null,
3737
ongoingCall: null, // TODO: store call info like url, startTime, timeout, etc here
38+
businessUnit: null,
3839
});
3940

4041
const dontPersist = ['messages', 'typing', 'loading', 'alerts', 'unread', 'noMoreMessages', 'modal', 'incomingCallAlert', 'ongoingCall'];

src/widget.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ function setDepartment(department) {
263263
callHook('setDepartment', department);
264264
}
265265

266+
function setBusinessUnit(businessUnit) {
267+
callHook('setBusinessUnit', businessUnit);
268+
}
269+
270+
function clearBusinessUnit() {
271+
callHook('clearBusinessUnit');
272+
}
273+
266274
function setGuestToken(token) {
267275
callHook('setGuestToken', token);
268276
}
@@ -334,6 +342,10 @@ function initialize(params) {
334342
case 'department':
335343
setDepartment(params[method]);
336344
continue;
345+
case 'businessUnit': {
346+
setBusinessUnit(params[method]);
347+
continue;
348+
}
337349
case 'guestToken':
338350
setGuestToken(params[method]);
339351
continue;
@@ -436,6 +448,8 @@ window.RocketChat.livechat = {
436448
hideWidget,
437449
maximizeWidget,
438450
minimizeWidget,
451+
setBusinessUnit,
452+
clearBusinessUnit,
439453

440454
// callbacks
441455
onChatMaximized(fn) { registerCallback('chat-maximized', fn); },

widget-demo.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@
5151
j.src = 'build/rocketchat-livechat.min.js?_=' + Math.random();
5252
h.parentNode.insertBefore(j, h);
5353
})(window, document, 'script', 'http://localhost:8080');
54+
RocketChat(function() {
55+
this.setTheme({
56+
color: '#04436A', // widget title background color
57+
fontColor: '#FFFFFF', // widget title font color
58+
iconColor: '#1d74f5', // widget icon color
59+
title: "Welcome to Rocket.Chat", // default widget title when the status of service is online
60+
offlineTitle: "Service is offline", // default widget title when the status of service is online
61+
});
62+
});
5463
</script>
5564
</body>
5665

0 commit comments

Comments
 (0)