chore: Replace globalConfig Mixin with useGlobalConfig Composable

This commit is contained in:
Fayaz Ahmed
2024-08-20 07:53:21 +05:30
parent 8473e72a7e
commit c798474f2b
18 changed files with 142 additions and 42 deletions
@@ -3,7 +3,7 @@ import WidgetHead from './WidgetHead.vue';
import WidgetBody from './WidgetBody.vue';
import WidgetFooter from './WidgetFooter.vue';
import InputRadioGroup from 'dashboard/routes/dashboard/settings/inbox/components/InputRadioGroup.vue';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
import { mapGetters } from 'vuex';
export default {
@@ -14,7 +14,6 @@ export default {
WidgetFooter,
InputRadioGroup,
},
mixins: [globalConfigMixin],
props: {
welcomeHeading: {
type: String,
@@ -57,6 +56,12 @@ export default {
default: '',
},
},
setup() {
const { useInstallationName } = useGlobalConfig();
return {
useInstallationName,
};
},
data() {
return {
widgetScreens: [
@@ -1,12 +1,17 @@
<script>
import { mapGetters } from 'vuex';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
import SettingsHeader from 'dashboard/routes/dashboard/settings/SettingsHeader.vue';
export default {
components: {
SettingsHeader,
},
mixins: [globalConfigMixin],
setup() {
const { useInstallationName } = useGlobalConfig();
return {
useInstallationName,
};
},
computed: {
...mapGetters({
globalConfig: 'globalConfig/get',
@@ -3,14 +3,19 @@ import ChannelItem from 'dashboard/components/widgets/ChannelItem.vue';
import router from '../../../index';
import PageHeader from '../SettingsSubPageHeader.vue';
import { mapGetters } from 'vuex';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
export default {
components: {
ChannelItem,
PageHeader,
},
mixins: [globalConfigMixin],
setup() {
const { useInstallationName } = useGlobalConfig();
return {
useInstallationName,
};
},
data() {
return {
enabledFeatures: {},
@@ -1,9 +1,14 @@
<script>
import { mapGetters } from 'vuex';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
export default {
mixins: [globalConfigMixin],
setup() {
const { useInstallationName } = useGlobalConfig();
return {
useInstallationName,
};
},
computed: {
...mapGetters({
globalConfig: 'globalConfig/get',
@@ -4,19 +4,20 @@ import { useAlert } from 'dashboard/composables';
import { useAdmin } from 'dashboard/composables/useAdmin';
import { useAccount } from 'dashboard/composables/useAccount';
import Settings from './Settings.vue';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
export default {
components: {
Settings,
},
mixins: [globalConfigMixin],
setup() {
const { isAdmin } = useAdmin();
const { accountScopedUrl } = useAccount();
const { useInstallationName } = useGlobalConfig();
return {
isAdmin,
accountScopedUrl,
useInstallationName,
};
},
data() {
@@ -10,7 +10,7 @@ import { mapGetters } from 'vuex';
import ChannelApi from '../../../../../api/channels';
import PageHeader from '../../SettingsSubPageHeader.vue';
import router from '../../../../index';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
import { loadScript } from 'dashboard/helper/DOMHelpers';
import * as Sentry from '@sentry/browser';
@@ -20,10 +20,11 @@ export default {
LoadingState,
PageHeader,
},
mixins: [globalConfigMixin],
setup() {
const { useInstallationName } = useGlobalConfig();
const { accountId } = useAccount();
return {
useInstallationName,
accountId,
v$: useVuelidate(),
};
@@ -2,10 +2,9 @@
import { mapGetters } from 'vuex';
import { frontendURL } from '../../../../helper/URLHelper';
import { useAlert } from 'dashboard/composables';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
export default {
mixins: [globalConfigMixin],
props: {
integrationId: {
type: [String, Number],
@@ -18,6 +17,12 @@ export default {
actionButtonText: { type: String, default: '' },
deleteConfirmationText: { type: Object, default: () => ({}) },
},
setup() {
const { useInstallationName } = useGlobalConfig();
return {
useInstallationName,
};
},
data() {
return {
showDeleteConfirmationPopup: false,
@@ -3,7 +3,7 @@ import { computed } from 'vue';
import { useStoreGetters } from 'dashboard/composables/store';
import { useI18n } from 'dashboard/composables/useI18n';
import { frontendURL } from 'dashboard/helper/URLHelper';
import { useInstallationName } from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
const props = defineProps({
id: {
@@ -24,6 +24,7 @@ const props = defineProps({
},
});
const { useInstallationName } = useGlobalConfig();
const getters = useStoreGetters();
const accountId = getters.getCurrentAccountId;
const globalConfig = getters['globalConfig/get'];
@@ -1,17 +1,23 @@
<script>
import { mapGetters } from 'vuex';
import { useAlert } from 'dashboard/composables';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
import messageFormatterMixin from 'shared/mixins/messageFormatterMixin';
export default {
mixins: [globalConfigMixin, messageFormatterMixin],
mixins: [messageFormatterMixin],
props: {
hasConnectedAChannel: {
type: Boolean,
default: true,
},
},
setup() {
const { useInstallationName } = useGlobalConfig();
return {
useInstallationName,
};
},
data() {
return { selectedChannelId: '', availableChannels: [] };
},
@@ -3,7 +3,7 @@ import { mapGetters } from 'vuex';
import { useAlert } from 'dashboard/composables';
import NewWebhook from './NewWebHook.vue';
import EditWebhook from './EditWebHook.vue';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
import WebhookRow from './WebhookRow.vue';
export default {
@@ -12,7 +12,12 @@ export default {
EditWebhook,
WebhookRow,
},
mixins: [globalConfigMixin],
setup() {
const { useInstallationName } = useGlobalConfig();
return {
useInstallationName,
};
},
data() {
return {
loading: {},
@@ -1,18 +1,23 @@
<script>
import { useAlert } from 'dashboard/composables';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
import { mapGetters } from 'vuex';
import WebhookForm from './WebhookForm.vue';
export default {
components: { WebhookForm },
mixins: [globalConfigMixin],
props: {
onClose: {
type: Function,
required: true,
},
},
setup() {
const { useInstallationName } = useGlobalConfig();
return {
useInstallationName,
};
},
computed: {
...mapGetters({
globalConfig: 'globalConfig/get',
@@ -4,7 +4,7 @@ import { useAlert } from 'dashboard/composables';
import { useUISettings } from 'dashboard/composables/useUISettings';
import { clearCookiesOnLogout } from 'dashboard/store/utils/api.js';
import { copyTextToClipboard } from 'shared/helpers/clipboard';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
import UserProfilePicture from './UserProfilePicture.vue';
import UserBasicDetails from './UserBasicDetails.vue';
import MessageSignature from './MessageSignature.vue';
@@ -27,8 +27,8 @@ export default {
AudioNotifications,
AccessToken,
},
mixins: [globalConfigMixin],
setup() {
const { useInstallationName } = useGlobalConfig();
const { uiSettings, updateUISettings, isEditorHotKeyEnabled } =
useUISettings();
@@ -36,6 +36,7 @@ export default {
uiSettings,
updateUISettings,
isEditorHotKeyEnabled,
useInstallationName,
};
},
data() {
@@ -1,5 +1,5 @@
<script>
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
const {
LOGO_THUMBNAIL: logoThumbnail,
@@ -8,13 +8,18 @@ const {
} = window.globalConfig || {};
export default {
mixins: [globalConfigMixin],
props: {
disableBranding: {
type: Boolean,
default: false,
},
},
setup() {
const { useInstallationName } = useGlobalConfig();
return {
useInstallationName,
};
},
data() {
return {
globalConfig: {
@@ -0,0 +1,39 @@
import { useGlobalConfig } from '../useGlobalConfig';
describe('useGlobalConfig', () => {
it('should return the string with the installation name', () => {
const str = 'Chatwoot is awesome';
const installationName = 'Acme Inc';
const { useInstallationName } = useGlobalConfig();
expect(useInstallationName(str, installationName)).toBe(
'Acme Inc is awesome'
);
});
it('should return the string without the installation name', () => {
const str = 'Chatwoot is awesome';
const installationName = '';
const { useInstallationName } = useGlobalConfig();
expect(useInstallationName(str, installationName)).toBe(
'Chatwoot is awesome'
);
});
it('should handle null installation name properly', () => {
const str = 'Chatwoot is super cool';
const installationName = null;
const { useInstallationName } = useGlobalConfig();
expect(useInstallationName(str, installationName)).toBe(
'Chatwoot is super cool'
);
});
it('should handle undefined installation name properly', () => {
const str = 'Chatwoot is super cool';
const installationName = undefined;
const { useInstallationName } = useGlobalConfig();
expect(useInstallationName(str, installationName)).toBe(
'Chatwoot is super cool'
);
});
});
@@ -0,0 +1,18 @@
/*
* Composable for using the installation name in the application.
* @param {string} str - The string to be processed.
* @param {string} installationName - The installation name.
* @returns {string} The processed string with the installation name.
*/
export const useGlobalConfig = () => {
const useInstallationName = (str, installationName) => {
if (str && installationName) {
return str.replace(/Chatwoot/g, installationName);
}
return str;
};
return {
useInstallationName,
};
};
@@ -1,12 +0,0 @@
export const useInstallationName = (str, installationName) => {
if (str && installationName) {
return str.replace(/Chatwoot/g, installationName);
}
return str;
};
export default {
methods: {
useInstallationName,
},
};
@@ -3,16 +3,16 @@ import { useVuelidate } from '@vuelidate/core';
import { mapGetters } from 'vuex';
import { useAlert } from 'dashboard/composables';
import { required, minLength, email } from '@vuelidate/validators';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
import FormInput from '../../../../components/Form/Input.vue';
import { resetPassword } from '../../../../api/auth';
import SubmitButton from '../../../../components/Button/SubmitButton.vue';
export default {
components: { FormInput, SubmitButton },
mixins: [globalConfigMixin],
setup() {
return { v$: useVuelidate() };
const { useInstallationName } = useGlobalConfig();
return { v$: useVuelidate(), useInstallationName };
},
data() {
return {
@@ -1,6 +1,6 @@
<script>
import { mapGetters } from 'vuex';
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { useGlobalConfig } from 'shared/composables/useGlobalConfig';
import SignupForm from './components/Signup/Form.vue';
import Testimonials from './components/Testimonials/Index.vue';
import Spinner from 'shared/components/Spinner.vue';
@@ -11,7 +11,12 @@ export default {
Spinner,
Testimonials,
},
mixins: [globalConfigMixin],
setup() {
const { useInstallationName } = useGlobalConfig();
return {
useInstallationName,
};
},
data() {
return { isLoading: false };
},