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

[NEW] Ability for RC server to check the business hour for a specific department #25436

Merged
merged 5 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 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,18 @@ const api = {
});
},

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

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

updateIframeGuestData({ department });

if (department !== existingDepartment) {
await loadConfig();
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
await loadMessages();
}
},

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

Livechat.credentials.token = token;

const {
agent,
room,
guest: user,
guest,
resources: { sound: src = null } = {},
queueInfo,
...config
} = await Livechat.config({
token,
...businessUnit && { businessUnit },
...department && { department },
});

await store.setState({
config,
agent: agent && agent.hiddenInfo ? { hiddenInfo: true } : agent, // TODO: revert it when the API is updated
room,
user,
user: guest,
tiagoevanp marked this conversation as resolved.
Show resolved Hide resolved
guest,
queueInfo,
sound: { src, enabled: true, play: false },
messages: [],
Expand Down
5 changes: 3 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,10 @@ const SwitchDepartmentConnector = ({ ref, ...props }) => (
fontColor: customFontColor,
iconColor: customIconColor,
} = {},
guest,
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
} = {},
room,
loading = false,
department,
dispatch,
alerts,
token,
Expand All @@ -33,7 +33,8 @@ const SwitchDepartmentConnector = ({ ref, ...props }) => (
iconColor: customIconColor,
}}
loading={loading}
departments={departments.filter((dept) => dept.showOnRegistration && dept._id !== department)}
guest={guest}
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 } = 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({ 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();
KevLehman marked this conversation as resolved.
Show resolved Hide resolved
h.parentNode.insertBefore(j, h);
})(window, document, 'script', 'http://localhost:8080');
RocketChat(function() {
Expand Down