Skip to content

Commit

Permalink
[NEW] Ability for RC server to check the business hour for a specific…
Browse files Browse the repository at this point in the history
… department (#25436)
  • Loading branch information
murtaza98 authored and ggazzo committed May 30, 2022
1 parent d9a2f12 commit 9ff3776
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
13 changes: 9 additions & 4 deletions packages/livechat/src/lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import CustomFields from './customFields';
import { loadConfig, updateBusinessUnit } from './main';
import { parentCall } from './parentCall';
import { createToken } from './random';
import { loadMessages } from './room';
import Triggers from './triggers';

const createOrUpdateGuest = async (guest) => {
Expand Down Expand Up @@ -60,13 +61,17 @@ const api = {
});
},

setDepartment(value) {
const { config: { departments = [] } } = store.state;
async setDepartment(value) {
const { config: { departments = [] }, user: { department: existingDepartment } = {} } = store.state;

const dept = departments.find((dep) => dep._id === value || dep.name === value);
const department = (dept && dept._id) || '';
const department = departments.find((dep) => dep._id === value || dep.name === value)?._id || '';

updateIframeGuestData({ department });

if (department !== existingDepartment) {
await loadConfig();
await loadMessages();
}
},

async setBusinessUnit(newBusinessUnit) {
Expand Down
2 changes: 2 additions & 0 deletions packages/livechat/src/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const loadConfig = async () => {
const {
token,
businessUnit = null,
iframe: { guest: { department } = {} } = {},
} = store.state;

Livechat.credentials.token = token;
Expand All @@ -56,6 +57,7 @@ export const loadConfig = async () => {
} = await Livechat.config({
token,
...businessUnit && { businessUnit },
...department && { department },
});

await store.setState({
Expand Down
6 changes: 4 additions & 2 deletions packages/livechat/src/routes/SwitchDepartment/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ const SwitchDepartmentConnector = ({ ref, ...props }) => (
fontColor: customFontColor,
iconColor: customIconColor,
} = {},
guest,
} = {},
iframe,
room,
loading = false,
department,
dispatch,
alerts,
token,
Expand All @@ -33,7 +34,8 @@ const SwitchDepartmentConnector = ({ ref, ...props }) => (
iconColor: customIconColor,
}}
loading={loading}
departments={departments.filter((dept) => dept.showOnRegistration && dept._id !== department)}
iframe={iframe}
departments={departments.filter((dept) => dept.showOnRegistration && dept._id !== guest?.department)}
dispatch={dispatch}
room={room}
alerts={alerts}
Expand Down
4 changes: 2 additions & 2 deletions packages/livechat/src/routes/SwitchDepartment/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SwitchDepartmentContainer extends Component {
}

handleSubmit = async (fields) => {
const { alerts, dispatch, room, token, t } = this.props;
const { alerts, dispatch, room, token, t, guest, iframe } = this.props;
const { department } = fields;

const confirm = await this.confirmChangeDepartment();
Expand All @@ -42,7 +42,7 @@ class SwitchDepartmentContainer extends Component {
throw t('no_available_agents_to_transfer');
}

await dispatch({ department, loading: false });
await dispatch({ iframe: { ...iframe, guest: { ...guest, department } }, loading: false });
await loadConfig();

await ModalManager.alert({
Expand Down
2 changes: 1 addition & 1 deletion packages/livechat/widget-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
var h = d.getElementsByTagName(s)[0],
j = d.createElement(s);
j.async = true;
j.src = 'build/rocketchat-livechat.min.js?_=' + Math.random();
j.src = 'dist/rocketchat-livechat.min.js?_=' + Math.random();
h.parentNode.insertBefore(j, h);
})(window, document, 'script', 'http://localhost:8080');
RocketChat(function() {
Expand Down

0 comments on commit 9ff3776

Please sign in to comment.