* Add draft support * Fixes issue with draft loading * Adds draft for private notes * Use localstorage helper * .remove instead of .clear * Remove timestamp * clearLocalStorageOnLogout * Fix draft save on refresh * Remove usage of delete operator * Adds autosave for draft messages * Remove setinterval and add debounce * Removes draft redundancy check * Adds test cases for debouncer * Update app/javascript/shared/helpers/specs/TimeHelpers.spec.js Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> * Update app/javascript/shared/helpers/specs/TimeHelpers.spec.js Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> * Review fixes * Fixes issue with debouncer * FIxes debouncer issue * Fixes issue with draft empty message * Removes empty keys from local storage drafts * Fixes error with empty draft Co-authored-by: Pranav Raj S <pranav@chatwoot.com> Co-authored-by: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com>
61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
/* eslint no-param-reassign: 0 */
|
|
import fromUnixTime from 'date-fns/fromUnixTime';
|
|
import differenceInDays from 'date-fns/differenceInDays';
|
|
import Cookies from 'js-cookie';
|
|
import { frontendURL } from '../../helper/URLHelper';
|
|
import {
|
|
ANALYTICS_IDENTITY,
|
|
ANALYTICS_RESET,
|
|
CHATWOOT_RESET,
|
|
CHATWOOT_SET_USER,
|
|
} from '../../helper/scriptHelpers';
|
|
import { LocalStorage, LOCAL_STORAGE_KEYS } from '../../helper/localStorage';
|
|
|
|
Cookies.defaults = { sameSite: 'Lax' };
|
|
|
|
export const getLoadingStatus = state => state.fetchAPIloadingStatus;
|
|
export const setLoadingStatus = (state, status) => {
|
|
state.fetchAPIloadingStatus = status;
|
|
};
|
|
|
|
export const setUser = (user, expiryDate, options = {}) => {
|
|
if (options && options.setUserInSDK) {
|
|
window.bus.$emit(CHATWOOT_SET_USER, { user });
|
|
window.bus.$emit(ANALYTICS_IDENTITY, { user });
|
|
}
|
|
Cookies.set('user', user, {
|
|
expires: differenceInDays(expiryDate, new Date()),
|
|
});
|
|
};
|
|
|
|
export const getHeaderExpiry = response =>
|
|
fromUnixTime(response.headers.expiry);
|
|
|
|
export const setAuthCredentials = response => {
|
|
const expiryDate = getHeaderExpiry(response);
|
|
Cookies.set('auth_data', response.headers, {
|
|
expires: differenceInDays(expiryDate, new Date()),
|
|
});
|
|
setUser(response.data.data, expiryDate);
|
|
};
|
|
|
|
export const clearBrowserSessionCookies = () => {
|
|
Cookies.remove('auth_data');
|
|
Cookies.remove('user');
|
|
};
|
|
|
|
export const clearLocalStorageOnLogout = () => {
|
|
LocalStorage.remove(LOCAL_STORAGE_KEYS.DRAFT_MESSAGES);
|
|
};
|
|
|
|
export const clearCookiesOnLogout = () => {
|
|
window.bus.$emit(CHATWOOT_RESET);
|
|
window.bus.$emit(ANALYTICS_RESET);
|
|
clearBrowserSessionCookies();
|
|
clearLocalStorageOnLogout();
|
|
const globalConfig = window.globalConfig || {};
|
|
const logoutRedirectLink =
|
|
globalConfig.LOGOUT_REDIRECT_LINK || frontendURL('login');
|
|
window.location = logoutRedirectLink;
|
|
};
|