2019-08-25 14:29:28 +00:00
|
|
|
import queryString from 'query-string';
|
|
|
|
|
|
|
|
export const frontendURL = (path, params) => {
|
|
|
|
const stringifiedParams = params ? `?${queryString.stringify(params)}` : '';
|
|
|
|
return `/app/${path}${stringifiedParams}`;
|
|
|
|
};
|
2020-02-22 08:54:51 +00:00
|
|
|
|
2021-03-16 14:14:50 +00:00
|
|
|
export const conversationUrl = ({
|
|
|
|
accountId,
|
|
|
|
activeInbox,
|
|
|
|
id,
|
|
|
|
label,
|
|
|
|
teamId,
|
2021-12-09 05:50:14 +00:00
|
|
|
conversationType = '',
|
2022-01-27 02:56:12 +00:00
|
|
|
foldersId,
|
2021-03-16 14:14:50 +00:00
|
|
|
}) => {
|
2021-12-09 05:50:14 +00:00
|
|
|
let url = `accounts/${accountId}/conversations/${id}`;
|
2020-06-25 15:34:03 +00:00
|
|
|
if (activeInbox) {
|
2021-12-09 05:50:14 +00:00
|
|
|
url = `accounts/${accountId}/inbox/${activeInbox}/conversations/${id}`;
|
|
|
|
} else if (label) {
|
|
|
|
url = `accounts/${accountId}/label/${label}/conversations/${id}`;
|
|
|
|
} else if (teamId) {
|
|
|
|
url = `accounts/${accountId}/team/${teamId}/conversations/${id}`;
|
2022-01-27 02:56:12 +00:00
|
|
|
} else if (foldersId && foldersId !== 0) {
|
|
|
|
url = `accounts/${accountId}/custom_view/${foldersId}/conversations/${id}`;
|
2021-12-09 05:50:14 +00:00
|
|
|
} else if (conversationType === 'mention') {
|
|
|
|
url = `accounts/${accountId}/mentions/conversations/${id}`;
|
2020-06-25 15:34:03 +00:00
|
|
|
}
|
2021-12-09 05:50:14 +00:00
|
|
|
return url;
|
2020-02-22 08:54:51 +00:00
|
|
|
};
|
2020-04-06 16:47:07 +00:00
|
|
|
|
|
|
|
export const accountIdFromPathname = pathname => {
|
|
|
|
const isInsideAccountScopedURLs = pathname.includes('/app/accounts');
|
|
|
|
const urlParam = pathname.split('/')[3];
|
|
|
|
// eslint-disable-next-line no-restricted-globals
|
|
|
|
const isScoped = isInsideAccountScopedURLs && !isNaN(urlParam);
|
|
|
|
const accountId = isScoped ? Number(urlParam) : '';
|
|
|
|
return accountId;
|
|
|
|
};
|