chore: Fix loading state in the inbox settings page (#4926)
This commit is contained in:
parent
263b8240d3
commit
c0249a1b5b
12 changed files with 106 additions and 97 deletions
|
@ -98,7 +98,10 @@
|
||||||
"LABEL": "Widget Color",
|
"LABEL": "Widget Color",
|
||||||
"PLACEHOLDER": "Update the widget color used in widget"
|
"PLACEHOLDER": "Update the widget color used in widget"
|
||||||
},
|
},
|
||||||
"SUBMIT_BUTTON": "Create inbox"
|
"SUBMIT_BUTTON": "Create inbox",
|
||||||
|
"API": {
|
||||||
|
"ERROR_MESSAGE": "We were not able to create a website channel, please try again"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"TWILIO": {
|
"TWILIO": {
|
||||||
"TITLE": "Twilio SMS/WhatsApp Channel",
|
"TITLE": "Twilio SMS/WhatsApp Channel",
|
||||||
|
@ -339,7 +342,7 @@
|
||||||
"API": {
|
"API": {
|
||||||
"SUCCESS_MESSAGE": "Inbox settings updated successfully",
|
"SUCCESS_MESSAGE": "Inbox settings updated successfully",
|
||||||
"AUTO_ASSIGNMENT_SUCCESS_MESSAGE": "Auto assignment updated successfully",
|
"AUTO_ASSIGNMENT_SUCCESS_MESSAGE": "Auto assignment updated successfully",
|
||||||
"ERROR_MESSAGE": "Could not update widget color. Please try again later."
|
"ERROR_MESSAGE": "We couldn't update inbox settings. Please try again later."
|
||||||
},
|
},
|
||||||
"EMAIL_COLLECT_BOX": {
|
"EMAIL_COLLECT_BOX": {
|
||||||
"ENABLED": "Enabled",
|
"ENABLED": "Enabled",
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
</div>
|
</div>
|
||||||
<woot-submit-button
|
<woot-submit-button
|
||||||
:button-text="$t('INBOX_MGMT.IMAP.UPDATE')"
|
:button-text="$t('INBOX_MGMT.IMAP.UPDATE')"
|
||||||
:loading="uiFlags.isUpdatingInbox"
|
:loading="uiFlags.isUpdatingIMAP"
|
||||||
:disabled="($v.$invalid && isIMAPEnabled) || uiFlags.isUpdatingIMAP"
|
:disabled="($v.$invalid && isIMAPEnabled) || uiFlags.isUpdatingIMAP"
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -64,10 +64,9 @@
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<woot-submit-button
|
<woot-submit-button
|
||||||
:button-text="$t('INBOX_MGMT.SETTINGS_POPUP.UPDATE')"
|
:button-text="$t('INBOX_MGMT.SETTINGS_POPUP.UPDATE')"
|
||||||
:loading="uiFlags.isUpdatingInbox"
|
:loading="uiFlags.isUpdating"
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -294,7 +294,7 @@
|
||||||
type="submit"
|
type="submit"
|
||||||
:disabled="$v.webhookUrl.$invalid"
|
:disabled="$v.webhookUrl.$invalid"
|
||||||
:button-text="$t('INBOX_MGMT.SETTINGS_POPUP.UPDATE')"
|
:button-text="$t('INBOX_MGMT.SETTINGS_POPUP.UPDATE')"
|
||||||
:loading="uiFlags.isUpdatingInbox"
|
:loading="uiFlags.isUpdating"
|
||||||
@click="updateInbox"
|
@click="updateInbox"
|
||||||
/>
|
/>
|
||||||
<woot-submit-button
|
<woot-submit-button
|
||||||
|
@ -302,7 +302,7 @@
|
||||||
type="submit"
|
type="submit"
|
||||||
:disabled="$v.$invalid"
|
:disabled="$v.$invalid"
|
||||||
:button-text="$t('INBOX_MGMT.SETTINGS_POPUP.UPDATE')"
|
:button-text="$t('INBOX_MGMT.SETTINGS_POPUP.UPDATE')"
|
||||||
:loading="uiFlags.isUpdatingInbox"
|
:loading="uiFlags.isUpdating"
|
||||||
@click="updateInbox"
|
@click="updateInbox"
|
||||||
/>
|
/>
|
||||||
</settings-section>
|
</settings-section>
|
||||||
|
@ -542,7 +542,9 @@ export default {
|
||||||
await this.$store.dispatch('inboxes/updateInbox', payload);
|
await this.$store.dispatch('inboxes/updateInbox', payload);
|
||||||
this.showAlert(this.$t('INBOX_MGMT.EDIT.API.SUCCESS_MESSAGE'));
|
this.showAlert(this.$t('INBOX_MGMT.EDIT.API.SUCCESS_MESSAGE'));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.showAlert(this.$t('INBOX_MGMT.EDIT.API.SUCCESS_MESSAGE'));
|
this.showAlert(
|
||||||
|
error.message || this.$t('INBOX_MGMT.EDIT.API.ERROR_MESSAGE')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleImageUpload({ file, url }) {
|
handleImageUpload({ file, url }) {
|
||||||
|
|
|
@ -79,7 +79,7 @@
|
||||||
</div>
|
</div>
|
||||||
<woot-submit-button
|
<woot-submit-button
|
||||||
:button-text="$t('INBOX_MGMT.SMTP.UPDATE')"
|
:button-text="$t('INBOX_MGMT.SMTP.UPDATE')"
|
||||||
:loading="uiFlags.isUpdatingInbox"
|
:loading="uiFlags.isUpdatingSMTP"
|
||||||
:disabled="($v.$invalid && isSMTPEnabled) || uiFlags.isUpdatingSMTP"
|
:disabled="($v.$invalid && isSMTPEnabled) || uiFlags.isUpdatingSMTP"
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
|
@ -215,7 +215,6 @@ export default {
|
||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
id: this.inbox.id,
|
id: this.inbox.id,
|
||||||
formData: false,
|
|
||||||
channel: {
|
channel: {
|
||||||
smtp_enabled: this.isSMTPEnabled,
|
smtp_enabled: this.isSMTPEnabled,
|
||||||
smtp_address: this.address,
|
smtp_address: this.address,
|
||||||
|
|
|
@ -131,12 +131,14 @@ import { mapGetters } from 'vuex';
|
||||||
import router from '../../../../index';
|
import router from '../../../../index';
|
||||||
import PageHeader from '../../SettingsSubPageHeader';
|
import PageHeader from '../../SettingsSubPageHeader';
|
||||||
import GreetingsEditor from 'shared/components/GreetingsEditor';
|
import GreetingsEditor from 'shared/components/GreetingsEditor';
|
||||||
|
import alertMixin from 'shared/mixins/alertMixin';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
PageHeader,
|
PageHeader,
|
||||||
GreetingsEditor,
|
GreetingsEditor,
|
||||||
},
|
},
|
||||||
|
mixins: [alertMixin],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
inboxName: '',
|
inboxName: '',
|
||||||
|
@ -164,28 +166,35 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async createChannel() {
|
async createChannel() {
|
||||||
const website = await this.$store.dispatch(
|
try {
|
||||||
'inboxes/createWebsiteChannel',
|
const website = await this.$store.dispatch(
|
||||||
{
|
'inboxes/createWebsiteChannel',
|
||||||
name: this.inboxName,
|
{
|
||||||
greeting_enabled: this.greetingEnabled,
|
name: this.inboxName,
|
||||||
greeting_message: this.greetingMessage,
|
greeting_enabled: this.greetingEnabled,
|
||||||
channel: {
|
greeting_message: this.greetingMessage,
|
||||||
type: 'web_widget',
|
channel: {
|
||||||
website_url: this.channelWebsiteUrl,
|
type: 'web_widget',
|
||||||
widget_color: this.channelWidgetColor,
|
website_url: this.channelWebsiteUrl,
|
||||||
welcome_title: this.channelWelcomeTitle,
|
widget_color: this.channelWidgetColor,
|
||||||
welcome_tagline: this.channelWelcomeTagline,
|
welcome_title: this.channelWelcomeTitle,
|
||||||
|
welcome_tagline: this.channelWelcomeTagline,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
router.replace({
|
||||||
|
name: 'settings_inboxes_add_agents',
|
||||||
|
params: {
|
||||||
|
page: 'new',
|
||||||
|
inbox_id: website.id,
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
} catch (error) {
|
||||||
router.replace({
|
this.showAlert(
|
||||||
name: 'settings_inboxes_add_agents',
|
error.message ||
|
||||||
params: {
|
this.$t('INBOX_MGMT.ADD.WEBSITE_CHANNEL.API.ERROR_MESSAGE')
|
||||||
page: 'new',
|
);
|
||||||
inbox_id: website.id,
|
}
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -50,7 +50,7 @@
|
||||||
</div>
|
</div>
|
||||||
<woot-submit-button
|
<woot-submit-button
|
||||||
:button-text="$t('INBOX_MGMT.BUSINESS_HOURS.UPDATE')"
|
:button-text="$t('INBOX_MGMT.BUSINESS_HOURS.UPDATE')"
|
||||||
:loading="uiFlags.isUpdatingInbox"
|
:loading="uiFlags.isUpdating"
|
||||||
:disabled="hasError"
|
:disabled="hasError"
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -5,6 +5,7 @@ import InboxesAPI from '../../api/inboxes';
|
||||||
import WebChannel from '../../api/channel/webChannel';
|
import WebChannel from '../../api/channel/webChannel';
|
||||||
import FBChannel from '../../api/channel/fbChannel';
|
import FBChannel from '../../api/channel/fbChannel';
|
||||||
import TwilioChannel from '../../api/channel/twilioChannel';
|
import TwilioChannel from '../../api/channel/twilioChannel';
|
||||||
|
import { parseAPIErrorResponse } from '../utils/api';
|
||||||
|
|
||||||
const buildInboxData = inboxParams => {
|
const buildInboxData = inboxParams => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
|
@ -36,13 +37,17 @@ export const state = {
|
||||||
isFetchingItem: false,
|
isFetchingItem: false,
|
||||||
isCreating: false,
|
isCreating: false,
|
||||||
isUpdating: false,
|
isUpdating: false,
|
||||||
isUpdatingAutoAssignment: false,
|
|
||||||
isDeleting: false,
|
isDeleting: false,
|
||||||
isUpdatingIMAP: false,
|
isUpdatingIMAP: false,
|
||||||
isUpdatingSMTP: false,
|
isUpdatingSMTP: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const throwErrorMessage = error => {
|
||||||
|
const errorMessage = parseAPIErrorResponse(error);
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
};
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
getInboxes($state) {
|
getInboxes($state) {
|
||||||
return $state.records;
|
return $state.records;
|
||||||
|
@ -149,7 +154,7 @@ export const actions = {
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
commit(types.default.SET_INBOXES_UI_FLAG, { isCreating: false });
|
commit(types.default.SET_INBOXES_UI_FLAG, { isCreating: false });
|
||||||
throw new Error(error);
|
return throwErrorMessage(error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
createTwilioChannel: async ({ commit }, params) => {
|
createTwilioChannel: async ({ commit }, params) => {
|
||||||
|
@ -177,73 +182,39 @@ export const actions = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateInbox: async ({ commit }, { id, formData = true, ...inboxParams }) => {
|
updateInbox: async ({ commit }, { id, formData = true, ...inboxParams }) => {
|
||||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdating: true });
|
||||||
isUpdatingAutoAssignment: true,
|
|
||||||
});
|
|
||||||
try {
|
try {
|
||||||
const response = await InboxesAPI.update(
|
const response = await InboxesAPI.update(
|
||||||
id,
|
id,
|
||||||
formData ? buildInboxData(inboxParams) : inboxParams
|
formData ? buildInboxData(inboxParams) : inboxParams
|
||||||
);
|
);
|
||||||
commit(types.default.EDIT_INBOXES, response.data);
|
commit(types.default.EDIT_INBOXES, response.data);
|
||||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdating: false });
|
||||||
isUpdatingAutoAssignment: false,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdating: false });
|
||||||
isUpdatingAutoAssignment: false,
|
throwErrorMessage(error);
|
||||||
});
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateInboxIMAP: async (
|
updateInboxIMAP: async ({ commit }, { id, ...inboxParams }) => {
|
||||||
{ commit },
|
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingIMAP: true });
|
||||||
{ id, formData = true, ...inboxParams }
|
|
||||||
) => {
|
|
||||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
|
||||||
isUpdatingIMAP: true,
|
|
||||||
});
|
|
||||||
try {
|
try {
|
||||||
const response = await InboxesAPI.update(
|
const response = await InboxesAPI.update(id, inboxParams);
|
||||||
id,
|
|
||||||
formData ? buildInboxData(inboxParams) : inboxParams
|
|
||||||
);
|
|
||||||
commit(types.default.EDIT_INBOXES, response.data);
|
commit(types.default.EDIT_INBOXES, response.data);
|
||||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingIMAP: false });
|
||||||
isUpdatingIMAP: false,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingIMAP: false });
|
||||||
isUpdatingIMAP: false,
|
throwErrorMessage(error);
|
||||||
});
|
|
||||||
if (error.response?.data?.message) {
|
|
||||||
throw new Error(error.response?.data?.message);
|
|
||||||
} else {
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateInboxSMTP: async (
|
updateInboxSMTP: async ({ commit }, { id, ...inboxParams }) => {
|
||||||
{ commit },
|
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingSMTP: true });
|
||||||
{ id, formData = true, ...inboxParams }
|
|
||||||
) => {
|
|
||||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
|
||||||
isUpdatingSMTP: true,
|
|
||||||
});
|
|
||||||
try {
|
try {
|
||||||
const response = await InboxesAPI.update(
|
const response = await InboxesAPI.update(id, inboxParams);
|
||||||
id,
|
|
||||||
formData ? buildInboxData(inboxParams) : inboxParams
|
|
||||||
);
|
|
||||||
commit(types.default.EDIT_INBOXES, response.data);
|
commit(types.default.EDIT_INBOXES, response.data);
|
||||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingSMTP: false });
|
||||||
isUpdatingSMTP: false,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
commit(types.default.SET_INBOXES_UI_FLAG, {
|
commit(types.default.SET_INBOXES_UI_FLAG, { isUpdatingSMTP: false });
|
||||||
isUpdatingSMTP: false,
|
throwErrorMessage(error);
|
||||||
});
|
|
||||||
throw new Error(error);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
delete: async ({ commit }, inboxId) => {
|
delete: async ({ commit }, inboxId) => {
|
||||||
|
|
|
@ -81,12 +81,9 @@ describe('#actions', () => {
|
||||||
{ id: updatedInbox.id, inbox: { enable_auto_assignment: false } }
|
{ id: updatedInbox.id, inbox: { enable_auto_assignment: false } }
|
||||||
);
|
);
|
||||||
expect(commit.mock.calls).toEqual([
|
expect(commit.mock.calls).toEqual([
|
||||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: true }],
|
[types.default.SET_INBOXES_UI_FLAG, { isUpdating: true }],
|
||||||
[types.default.EDIT_INBOXES, updatedInbox],
|
[types.default.EDIT_INBOXES, updatedInbox],
|
||||||
[
|
[types.default.SET_INBOXES_UI_FLAG, { isUpdating: false }],
|
||||||
types.default.SET_INBOXES_UI_FLAG,
|
|
||||||
{ isUpdatingAutoAssignment: false },
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
it('sends correct actions if API is error', async () => {
|
it('sends correct actions if API is error', async () => {
|
||||||
|
@ -98,11 +95,8 @@ describe('#actions', () => {
|
||||||
)
|
)
|
||||||
).rejects.toThrow(Error);
|
).rejects.toThrow(Error);
|
||||||
expect(commit.mock.calls).toEqual([
|
expect(commit.mock.calls).toEqual([
|
||||||
[types.default.SET_INBOXES_UI_FLAG, { isUpdatingAutoAssignment: true }],
|
[types.default.SET_INBOXES_UI_FLAG, { isUpdating: true }],
|
||||||
[
|
[types.default.SET_INBOXES_UI_FLAG, { isUpdating: false }],
|
||||||
types.default.SET_INBOXES_UI_FLAG,
|
|
||||||
{ isUpdatingAutoAssignment: false },
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -53,7 +53,6 @@ describe('#getters', () => {
|
||||||
isFetchingItem: false,
|
isFetchingItem: false,
|
||||||
isCreating: false,
|
isCreating: false,
|
||||||
isUpdating: false,
|
isUpdating: false,
|
||||||
isUpdatingAutoAssignment: false,
|
|
||||||
isDeleting: false,
|
isDeleting: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -62,7 +61,6 @@ describe('#getters', () => {
|
||||||
isFetchingItem: false,
|
isFetchingItem: false,
|
||||||
isCreating: false,
|
isCreating: false,
|
||||||
isUpdating: false,
|
isUpdating: false,
|
||||||
isUpdatingAutoAssignment: false,
|
|
||||||
isDeleting: false,
|
isDeleting: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -45,3 +45,13 @@ export const clearCookiesOnLogout = () => {
|
||||||
const logoutRedirectLink = globalConfig.LOGOUT_REDIRECT_LINK || '/';
|
const logoutRedirectLink = globalConfig.LOGOUT_REDIRECT_LINK || '/';
|
||||||
window.location = logoutRedirectLink;
|
window.location = logoutRedirectLink;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const parseAPIErrorResponse = error => {
|
||||||
|
if (error?.response?.data?.message) {
|
||||||
|
return error?.response?.data?.message;
|
||||||
|
}
|
||||||
|
if (error?.response?.data?.error) {
|
||||||
|
return error?.response?.data?.error;
|
||||||
|
}
|
||||||
|
return error;
|
||||||
|
};
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
import { getLoadingStatus, setLoadingStatus } from '../api';
|
import {
|
||||||
|
getLoadingStatus,
|
||||||
|
parseAPIErrorResponse,
|
||||||
|
setLoadingStatus,
|
||||||
|
} from '../api';
|
||||||
|
|
||||||
describe('#getLoadingStatus', () => {
|
describe('#getLoadingStatus', () => {
|
||||||
it('returns correct status', () => {
|
it('returns correct status', () => {
|
||||||
|
@ -13,3 +17,23 @@ describe('#setLoadingStatus', () => {
|
||||||
expect(state.fetchAPIloadingStatus).toBe(false);
|
expect(state.fetchAPIloadingStatus).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#parseAPIErrorResponse', () => {
|
||||||
|
it('returns correct values', () => {
|
||||||
|
expect(
|
||||||
|
parseAPIErrorResponse({
|
||||||
|
response: { data: { message: 'Error Message [message]' } },
|
||||||
|
})
|
||||||
|
).toBe('Error Message [message]');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
parseAPIErrorResponse({
|
||||||
|
response: { data: { error: 'Error Message [error]' } },
|
||||||
|
})
|
||||||
|
).toBe('Error Message [error]');
|
||||||
|
|
||||||
|
expect(parseAPIErrorResponse('Error: 422 Failed')).toBe(
|
||||||
|
'Error: 422 Failed'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue