feat: Adds support for draft in conversation reply box (#4205)

* 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>
This commit is contained in:
Nithin David Thomas
2022-04-07 22:16:45 +05:30
committed by GitHub
parent dfb56f6bb8
commit 5ea0436051
10 changed files with 202 additions and 24 deletions

View File

@@ -5,7 +5,12 @@ import * as types from '../mutation-types';
import authAPI from '../../api/auth';
import createAxios from '../../helper/APIHelper';
import actionCable from '../../helper/actionCable';
import { setUser, getHeaderExpiry, clearCookiesOnLogout } from '../utils/api';
import {
setUser,
getHeaderExpiry,
clearCookiesOnLogout,
clearLocalStorageOnLogout,
} from '../utils/api';
import { getLoginRedirectURL } from '../../helper/URLHelper';
const state = {
@@ -94,9 +99,9 @@ export const actions = {
.login(credentials)
.then(response => {
commit(types.default.SET_CURRENT_USER);
clearLocalStorageOnLogout();
window.axios = createAxios(axios);
actionCable.init(Vue);
window.location = getLoginRedirectURL(ssoAccountId, response.data);
resolve();
})

View File

@@ -35,3 +35,10 @@ export const applyPageFilters = (conversation, filters) => {
return shouldFilter;
};
export const trimMessage = (content = '', maxLength = 1024) => {
if (content.length > maxLength) {
return content.substring(0, maxLength);
}
return content;
};

View File

@@ -1,6 +1,7 @@
import {
findPendingMessageIndex,
applyPageFilters,
trimMessage,
} from '../../conversations/helpers';
const conversationList = [
@@ -119,3 +120,9 @@ describe('#applyPageFilters', () => {
});
});
});
describe('#trimMessage', () => {
expect(trimMessage('Hello world', 5)).toEqual('Hello');
expect(trimMessage('Hello', 5)).toEqual('Hello');
expect(trimMessage(undefined, 5)).toEqual('');
});