diff --git a/packages/web-app-admin-settings/src/components/General/AppearanceSection.vue b/packages/web-app-admin-settings/src/components/General/AppearanceSection.vue index c064257c9f0..bd055b59027 100644 --- a/packages/web-app-admin-settings/src/components/General/AppearanceSection.vue +++ b/packages/web-app-admin-settings/src/components/General/AppearanceSection.vue @@ -65,7 +65,7 @@ export default defineComponent({ const logoInput: VNodeRef = ref(null) - const { actions: resetLogoActions } = useGeneralActionsResetLogo({ store }) + const { actions: resetLogoActions } = useGeneralActionsResetLogo() const { actions: uploadLogoActions, uploadImage } = useGeneralActionsUploadLogo({ imageInput: logoInput }) diff --git a/packages/web-app-admin-settings/src/components/Groups/CreateGroupModal.vue b/packages/web-app-admin-settings/src/components/Groups/CreateGroupModal.vue index da1bb2c796e..28a7936c37a 100644 --- a/packages/web-app-admin-settings/src/components/Groups/CreateGroupModal.vue +++ b/packages/web-app-admin-settings/src/components/Groups/CreateGroupModal.vue @@ -17,7 +17,7 @@ import { useGettext } from 'vue3-gettext' import { computed, defineComponent, ref, PropType, unref, watch } from 'vue' import { Group } from '@ownclouders/web-client/src/generated' -import { MaybeRef, Modal, useClientService, useEventBus, useStore } from '@ownclouders/web-pkg' +import { MaybeRef, Modal, useClientService, useEventBus, useMessages } from '@ownclouders/web-pkg' export default defineComponent({ name: 'CreateGroupModal', @@ -27,7 +27,7 @@ export default defineComponent({ emits: ['confirm', 'update:confirmDisabled'], setup(props, { emit, expose }) { const { $gettext } = useGettext() - const store = useStore() + const { showMessage, showErrorMessage } = useMessages() const eventBus = useEventBus() const clientService = useClientService() @@ -61,15 +61,13 @@ export default defineComponent({ try { const client = clientService.graphAuthenticated const response = await client.groups.createGroup(unref(group)) - store.dispatch('showMessage', { - title: $gettext('Group was created successfully') - }) + showMessage({ title: $gettext('Group was created successfully') }) eventBus.publish('app.admin-settings.groups.add', { ...response?.data, members: [] }) } catch (error) { console.error(error) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Failed to create group'), - error + errors: [error] }) } } diff --git a/packages/web-app-admin-settings/src/components/Users/AddToGroupsModal.vue b/packages/web-app-admin-settings/src/components/Users/AddToGroupsModal.vue index bf656e28494..9027c195f29 100644 --- a/packages/web-app-admin-settings/src/components/Users/AddToGroupsModal.vue +++ b/packages/web-app-admin-settings/src/components/Users/AddToGroupsModal.vue @@ -12,11 +12,11 @@ import { useGettext } from 'vue3-gettext' import { Group, User } from '@ownclouders/web-client/src/generated' import GroupSelect from './GroupSelect.vue' import { - useStore, useEventBus, useClientService, useConfigurationManager, - Modal + Modal, + useMessages } from '@ownclouders/web-pkg' export default defineComponent({ @@ -35,7 +35,7 @@ export default defineComponent({ }, emits: ['update:confirmDisabled'], setup(props, { emit, expose }) { - const store = useStore() + const { showMessage, showErrorMessage } = useMessages() const clientService = useClientService() const configurationManager = useConfigurationManager() const eventBus = useEventBus() @@ -75,7 +75,7 @@ export default defineComponent({ 'Group assignments already added', props.users.length * unref(selectedOptions).length ) - store.dispatch('showMessage', { title }) + showMessage({ title }) return } @@ -95,7 +95,7 @@ export default defineComponent({ { groupAssignmentCount: succeeded.length.toString() }, true ) - store.dispatch('showMessage', { title }) + showMessage({ title }) } const failed = results.filter((r) => r.status === 'rejected') @@ -114,7 +114,7 @@ export default defineComponent({ { groupAssignmentCount: failed.length.toString() }, true ) - store.dispatch('showErrorMessage', { + showErrorMessage({ title, errors: (failed as PromiseRejectedResult[]).map((f) => f.reason) }) diff --git a/packages/web-app-admin-settings/src/components/Users/CreateUserModal.vue b/packages/web-app-admin-settings/src/components/Users/CreateUserModal.vue index 426c18117a2..0bf4eb496fc 100644 --- a/packages/web-app-admin-settings/src/components/Users/CreateUserModal.vue +++ b/packages/web-app-admin-settings/src/components/Users/CreateUserModal.vue @@ -47,14 +47,14 @@ import { useGettext } from 'vue3-gettext' import { computed, defineComponent, ref, unref, PropType, watch } from 'vue' import * as EmailValidator from 'email-validator' -import { Modal, useClientService, useEventBus, useStore } from '@ownclouders/web-pkg' +import { Modal, useClientService, useEventBus, useMessages } from '@ownclouders/web-pkg' export default defineComponent({ name: 'CreateUserModal', props: { modal: { type: Object as PropType, required: true } }, emits: ['confirm', 'update:confirmDisabled'], setup(props, { emit, expose }) { - const store = useStore() + const { showMessage, showErrorMessage } = useMessages() const eventBus = useEventBus() const clientService = useClientService() const { $gettext } = useGettext() @@ -111,15 +111,13 @@ export default defineComponent({ const { data } = await client.users.createUser(unref(user)) const { id: createdUserId } = data const { data: createdUser } = await client.users.getUser(createdUserId) - store.dispatch('showMessage', { - title: $gettext('User was created successfully') - }) + showMessage({ title: $gettext('User was created successfully') }) eventBus.publish('app.admin-settings.users.add', createdUser) } catch (error) { console.error(error) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Failed to create user'), - error + errors: [error] }) } } diff --git a/packages/web-app-admin-settings/src/components/Users/LoginModal.vue b/packages/web-app-admin-settings/src/components/Users/LoginModal.vue index 956a36dc2af..4fca3d1241f 100644 --- a/packages/web-app-admin-settings/src/components/Users/LoginModal.vue +++ b/packages/web-app-admin-settings/src/components/Users/LoginModal.vue @@ -17,7 +17,13 @@ import { computed, defineComponent, onMounted, PropType, ref, unref, watch } from 'vue' import { useGettext } from 'vue3-gettext' import { User } from '@ownclouders/web-client/src/generated' -import { useClientService, useStore, useEventBus, useUserStore, Modal } from '@ownclouders/web-pkg' +import { + useClientService, + useEventBus, + useUserStore, + Modal, + useMessages +} from '@ownclouders/web-pkg' type LoginOption = { label: string @@ -35,7 +41,7 @@ export default defineComponent({ }, emits: ['update:confirmDisabled'], setup(props, { emit, expose }) { - const store = useStore() + const { showMessage, showErrorMessage } = useMessages() const clientService = useClientService() const eventBus = useEventBus() const { $gettext, $ngettext } = useGettext() @@ -93,7 +99,7 @@ export default defineComponent({ { userCount: succeeded.length.toString() }, true ) - store.dispatch('showMessage', { title }) + showMessage({ title }) } const failed = results.filter((r) => r.status === 'rejected') @@ -112,7 +118,7 @@ export default defineComponent({ { userCount: failed.length.toString() }, true ) - store.dispatch('showErrorMessage', { + showErrorMessage({ title, errors: (failed as PromiseRejectedResult[]).map((f) => f.reason) }) diff --git a/packages/web-app-admin-settings/src/components/Users/RemoveFromGroupsModal.vue b/packages/web-app-admin-settings/src/components/Users/RemoveFromGroupsModal.vue index a56cf7e85ce..38a7a42b39e 100644 --- a/packages/web-app-admin-settings/src/components/Users/RemoveFromGroupsModal.vue +++ b/packages/web-app-admin-settings/src/components/Users/RemoveFromGroupsModal.vue @@ -11,7 +11,7 @@ import { defineComponent, PropType, ref, unref, watch } from 'vue' import { useGettext } from 'vue3-gettext' import { Group, User } from '@ownclouders/web-client/src/generated' import GroupSelect from './GroupSelect.vue' -import { useStore, useEventBus, useClientService, Modal } from '@ownclouders/web-pkg' +import { useEventBus, useClientService, Modal, useMessages } from '@ownclouders/web-pkg' export default defineComponent({ name: 'RemoveFromGroupsModal', @@ -29,7 +29,7 @@ export default defineComponent({ }, emits: ['update:confirmDisabled'], setup(props, { emit, expose }) { - const store = useStore() + const { showMessage, showErrorMessage } = useMessages() const clientService = useClientService() const eventBus = useEventBus() const { $gettext, $ngettext } = useGettext() @@ -68,7 +68,7 @@ export default defineComponent({ 'Group assignments already removed', props.users.length * unref(selectedOptions).length ) - store.dispatch('showMessage', { title }) + showMessage({ title }) return } @@ -88,7 +88,7 @@ export default defineComponent({ { groupAssignmentCount: succeeded.length.toString() }, true ) - store.dispatch('showMessage', { title }) + showMessage({ title }) } const failed = results.filter((r) => r.status === 'rejected') @@ -107,7 +107,7 @@ export default defineComponent({ { groupAssignmentCount: failed.length.toString() }, true ) - store.dispatch('showErrorMessage', { + showErrorMessage({ title, errors: (failed as PromiseRejectedResult[]).map((f) => f.reason) }) diff --git a/packages/web-app-admin-settings/src/composables/actions/general/useGeneralActionsResetLogo.ts b/packages/web-app-admin-settings/src/composables/actions/general/useGeneralActionsResetLogo.ts index e9c5f663589..f10f7b2b97b 100644 --- a/packages/web-app-admin-settings/src/composables/actions/general/useGeneralActionsResetLogo.ts +++ b/packages/web-app-admin-settings/src/composables/actions/general/useGeneralActionsResetLogo.ts @@ -1,11 +1,10 @@ -import { Store } from 'vuex' import { useGettext } from 'vue3-gettext' import { computed } from 'vue' -import { useAbility, useClientService, useRouter, useStore } from '@ownclouders/web-pkg' +import { useAbility, useClientService, useMessages, useRouter } from '@ownclouders/web-pkg' import { Action } from '@ownclouders/web-pkg' -export const useGeneralActionsResetLogo = ({ store }: { store?: Store }) => { - store = store || useStore() +export const useGeneralActionsResetLogo = () => { + const { showMessage, showErrorMessage } = useMessages() const { $gettext } = useGettext() const ability = useAbility() const clientService = useClientService() @@ -15,17 +14,15 @@ export const useGeneralActionsResetLogo = ({ store }: { store?: Store }) => try { const httpClient = clientService.httpAuthenticated await httpClient.delete('/branding/logo') - store.dispatch('showMessage', { - title: $gettext('Logo was reset successfully. Reloading page...') - }) + showMessage({ title: $gettext('Logo was reset successfully. Reloading page...') }) setTimeout(() => { router.go(0) }, 1000) } catch (e) { console.error(e) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Failed to reset logo'), - error: e + errors: [e] }) } } diff --git a/packages/web-app-admin-settings/src/composables/actions/general/useGeneralActionsUploadLogo.ts b/packages/web-app-admin-settings/src/composables/actions/general/useGeneralActionsUploadLogo.ts index ab4c052c0ef..cc1d726706e 100644 --- a/packages/web-app-admin-settings/src/composables/actions/general/useGeneralActionsUploadLogo.ts +++ b/packages/web-app-admin-settings/src/composables/actions/general/useGeneralActionsUploadLogo.ts @@ -1,18 +1,11 @@ -import { Store } from 'vuex' import { supportedLogoMimeTypes } from '../../../defaults' import { computed, VNodeRef, unref } from 'vue' -import { Action } from '@ownclouders/web-pkg' -import { useAbility, useClientService, useRouter, useStore } from '@ownclouders/web-pkg' +import { Action, useMessages } from '@ownclouders/web-pkg' +import { useAbility, useClientService, useRouter } from '@ownclouders/web-pkg' import { useGettext } from 'vue3-gettext' -export const useGeneralActionsUploadLogo = ({ - store, - imageInput -}: { - store?: Store - imageInput: VNodeRef -}) => { - store = store || useStore() +export const useGeneralActionsUploadLogo = ({ imageInput }: { imageInput: VNodeRef }) => { + const { showMessage, showErrorMessage } = useMessages() const { $gettext } = useGettext() const ability = useAbility() const clientService = useClientService() @@ -26,9 +19,7 @@ export const useGeneralActionsUploadLogo = ({ } if (!supportedLogoMimeTypes.includes(file.type)) { - return store.dispatch('showErrorMessage', { - title: $gettext('The file type is unsupported') - }) + return showErrorMessage({ title: $gettext('The file type is unsupported') }) } try { @@ -40,17 +31,15 @@ export const useGeneralActionsUploadLogo = ({ 'Content-Type': 'multipart/form-data' } }) - store.dispatch('showMessage', { - title: $gettext('Logo was uploaded successfully') - }) + showMessage({ title: $gettext('Logo was uploaded successfully') }) setTimeout(() => { router.go(0) }, 1000) } catch (e) { console.error(e) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Failed to upload logo'), - error: e + errors: [e] }) } } diff --git a/packages/web-app-admin-settings/src/composables/actions/groups/useGroupActionsDelete.ts b/packages/web-app-admin-settings/src/composables/actions/groups/useGroupActionsDelete.ts index 6055f227325..ccd7cd4a165 100644 --- a/packages/web-app-admin-settings/src/composables/actions/groups/useGroupActionsDelete.ts +++ b/packages/web-app-admin-settings/src/composables/actions/groups/useGroupActionsDelete.ts @@ -1,13 +1,12 @@ import { computed } from 'vue' -import { Store } from 'vuex' -import { eventBus, useModals } from '@ownclouders/web-pkg' -import { useClientService, useStore } from '@ownclouders/web-pkg' +import { eventBus, useMessages, useModals } from '@ownclouders/web-pkg' +import { useClientService } from '@ownclouders/web-pkg' import { GroupAction, GroupActionOptions } from '@ownclouders/web-pkg' import { useGettext } from 'vue3-gettext' import { Group } from '@ownclouders/web-client/src/generated' -export const useGroupActionsDelete = ({ store }: { store?: Store }) => { - store = store || useStore() +export const useGroupActionsDelete = () => { + const { showMessage, showErrorMessage } = useMessages() const { $gettext, $ngettext } = useGettext() const clientService = useClientService() const { dispatchModal } = useModals() @@ -29,7 +28,7 @@ export const useGroupActionsDelete = ({ store }: { store?: Store }) => { { groupCount: succeeded.length.toString() }, true ) - store.dispatch('showMessage', { title }) + showMessage({ title }) } const failed = results.filter((r) => r.status === 'rejected') @@ -46,7 +45,7 @@ export const useGroupActionsDelete = ({ store }: { store?: Store }) => { { groupCount: failed.length.toString() }, true ) - store.dispatch('showErrorMessage', { + showErrorMessage({ title, errors: (failed as PromiseRejectedResult[]).map((f) => f.reason) }) diff --git a/packages/web-app-admin-settings/src/composables/actions/users/useUserActionsDelete.ts b/packages/web-app-admin-settings/src/composables/actions/users/useUserActionsDelete.ts index 8dc8f3aadeb..5ee86c78f29 100644 --- a/packages/web-app-admin-settings/src/composables/actions/users/useUserActionsDelete.ts +++ b/packages/web-app-admin-settings/src/composables/actions/users/useUserActionsDelete.ts @@ -1,13 +1,17 @@ import { computed, unref } from 'vue' -import { Store } from 'vuex' -import { eventBus, useCapabilityDeleteUsersDisabled, useModals } from '@ownclouders/web-pkg' -import { useClientService, useStore } from '@ownclouders/web-pkg' +import { + eventBus, + useCapabilityDeleteUsersDisabled, + useMessages, + useModals +} from '@ownclouders/web-pkg' +import { useClientService } from '@ownclouders/web-pkg' import { UserAction, UserActionOptions } from '@ownclouders/web-pkg' import { useGettext } from 'vue3-gettext' import { User } from '@ownclouders/web-client/src/generated' -export const useUserActionsDelete = ({ store }: { store?: Store }) => { - store = store || useStore() +export const useUserActionsDelete = () => { + const { showMessage, showErrorMessage } = useMessages() const { $gettext, $ngettext } = useGettext() const clientService = useClientService() const { dispatchModal } = useModals() @@ -29,7 +33,7 @@ export const useUserActionsDelete = ({ store }: { store?: Store }) => { { userCount: succeeded.length.toString() }, true ) - store.dispatch('showMessage', { title }) + showMessage({ title }) } const failed = results.filter((r) => r.status === 'rejected') @@ -46,7 +50,7 @@ export const useUserActionsDelete = ({ store }: { store?: Store }) => { { userCount: failed.length.toString() }, true ) - store.dispatch('showErrorMessage', { + showErrorMessage({ title, errors: (failed as PromiseRejectedResult[]).map((f) => f.reason) }) diff --git a/packages/web-app-admin-settings/src/views/Groups.vue b/packages/web-app-admin-settings/src/views/Groups.vue index 05a03d8a181..e8bc9027bce 100644 --- a/packages/web-app-admin-settings/src/views/Groups.vue +++ b/packages/web-app-admin-settings/src/views/Groups.vue @@ -71,6 +71,7 @@ import { eventBus, queryItemAsString, useClientService, + useMessages, useRouteQuery, useSideBar, useStore @@ -94,6 +95,7 @@ export default defineComponent({ }, setup() { const store = useStore() + const { showErrorMessage } = useMessages() const groups = ref([]) const template = ref() const selectedGroups = ref([]) @@ -124,7 +126,7 @@ export default defineComponent({ }) }) - const { actions: deleteActions } = useGroupActionsDelete({ store }) + const { actions: deleteActions } = useGroupActionsDelete() const batchActions = computed(() => { return [...unref(deleteActions)].filter((item) => item.isEnabled({ resources: unref(selectedGroups) }) @@ -151,9 +153,9 @@ export default defineComponent({ return updatedGroup } catch (error) { console.error(error) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Failed to edit group'), - error + errors: [error] }) } } diff --git a/packages/web-app-admin-settings/src/views/Users.vue b/packages/web-app-admin-settings/src/views/Users.vue index 61d4a90e881..0e51a364406 100644 --- a/packages/web-app-admin-settings/src/views/Users.vue +++ b/packages/web-app-admin-settings/src/views/Users.vue @@ -163,7 +163,8 @@ import { useStore, SideBarPanel, SideBarPanelContext, - useUserStore + useUserStore, + useMessages } from '@ownclouders/web-pkg' import { computed, @@ -197,6 +198,7 @@ export default defineComponent({ const router = useRouter() const route = useRoute() const store = useStore() + const { showErrorMessage } = useMessages() const accessToken = useAccessToken({ store }) const clientService = useClientService() const configurationManager = useConfigurationManager() @@ -523,9 +525,9 @@ export default defineComponent({ return updatedUser } catch (error) { console.error(error) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Failed to edit user'), - error + errors: [error] }) } } diff --git a/packages/web-app-external/src/App.vue b/packages/web-app-external/src/App.vue index 16457192ef8..f490d15bb24 100644 --- a/packages/web-app-external/src/App.vue +++ b/packages/web-app-external/src/App.vue @@ -34,6 +34,7 @@ import { isSameResource, queryItemAsString, useConfigurationManager, + useMessages, useRequest, useRouteQuery, useStore @@ -55,6 +56,7 @@ export default defineComponent({ setup(props, { emit }) { const language = useGettext() const store = useStore() + const { showErrorMessage } = useMessages() const configurationManager = useConfigurationManager() const { $gettext } = language @@ -80,19 +82,17 @@ export default defineComponent({ }) const errorPopup = (error) => { - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('An error occurred'), desc: error, - error + errors: [error] }) } const loadAppUrl = useTask(function* (signal, viewMode: string) { try { if (props.isReadOnly && viewMode === 'write') { - store.dispatch('showErrorMessage', { - title: $gettext('Cannot open file in edit mode as it is read-only') - }) + showErrorMessage({ title: $gettext('Cannot open file in edit mode as it is read-only') }) return } diff --git a/packages/web-app-files/src/HandleUpload.ts b/packages/web-app-files/src/HandleUpload.ts index fcdf316da34..856aa67cd36 100644 --- a/packages/web-app-files/src/HandleUpload.ts +++ b/packages/web-app-files/src/HandleUpload.ts @@ -10,7 +10,7 @@ import { RouteLocationNormalizedLoaded } from 'vue-router' import { Resource, SpaceResource } from '@ownclouders/web-client/src' import { urlJoin } from '@ownclouders/web-client/src/utils' import { ResourceConflict } from './helpers/resource' -import { UserStore, locationPublicLink } from '@ownclouders/web-pkg' +import { MessageStore, UserStore, locationPublicLink } from '@ownclouders/web-pkg' import { locationSpacesGeneric, UppyService, UppyResource } from '@ownclouders/web-pkg' import { isPersonalSpaceResource, isShareSpaceResource } from '@ownclouders/web-client/src/helpers' import { ClientService, queryItemAsString } from '@ownclouders/web-pkg' @@ -22,6 +22,7 @@ export interface HandleUploadOptions { route: Ref store: Store userStore: UserStore + messageStore: MessageStore uppyService: UppyService id?: string space?: SpaceResource @@ -51,6 +52,7 @@ export class HandleUpload extends BasePlugin { space: SpaceResource store: Store userStore: UserStore + messageStore: MessageStore uppyService: UppyService quotaCheckEnabled: boolean directoryTreeCreateEnabled: boolean @@ -69,6 +71,7 @@ export class HandleUpload extends BasePlugin { this.space = opts.space this.store = opts.store this.userStore = opts.userStore + this.messageStore = opts.messageStore this.uppyService = opts.uppyService this.quotaCheckEnabled = opts.quotaCheckEnabled ?? true @@ -246,7 +249,7 @@ export class HandleUpload extends BasePlugin { spaceName = $gettext('Personal') } - this.store.dispatch('showErrorMessage', { + this.messageStore.showErrorMessage({ title: $gettext('Not enough quota'), desc: $gettext( 'There is not enough quota on %{spaceName}, you need additional %{missingSpace} to upload these files', diff --git a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue index ccf7cf5f517..19ad5f74ef1 100644 --- a/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue +++ b/packages/web-app-files/src/components/AppBar/CreateAndUpload.vue @@ -192,6 +192,7 @@ import { isLocationSpacesActive, useFileActions, useFileActionsCreateNewShortcut, + useMessages, useUserStore } from '@ownclouders/web-pkg' import { useActiveLocation } from '@ownclouders/web-pkg' @@ -264,6 +265,7 @@ export default defineComponent({ const clientService = useClientService() const store = useStore() const userStore = useUserStore() + const messageStore = useMessages() const route = useRoute() const language = useGettext() const hasSpaces = useCapabilitySpacesEnabled(store) @@ -280,6 +282,7 @@ export default defineComponent({ space: props.space, store, userStore, + messageStore, uppyService }) } diff --git a/packages/web-app-files/src/components/AppBar/CreateSpace.vue b/packages/web-app-files/src/components/AppBar/CreateSpace.vue index ca6248cbbcb..74a5eb9d58f 100644 --- a/packages/web-app-files/src/components/AppBar/CreateSpace.vue +++ b/packages/web-app-files/src/components/AppBar/CreateSpace.vue @@ -16,11 +16,18 @@ diff --git a/packages/web-runtime/src/container/bootstrap.ts b/packages/web-runtime/src/container/bootstrap.ts index 22203711cc7..09c9d557bd3 100644 --- a/packages/web-runtime/src/container/bootstrap.ts +++ b/packages/web-runtime/src/container/bootstrap.ts @@ -8,7 +8,13 @@ import { loadTheme } from '../helpers/theme' import OwnCloud from 'owncloud-sdk' import { createGettext, GetTextOptions, Language } from 'vue3-gettext' import { getBackendVersion, getWebVersion } from './versions' -import { useModals, useThemeStore, useUserStore, UserStore } from '@ownclouders/web-pkg' +import { + useModals, + useThemeStore, + useUserStore, + UserStore, + useMessages +} from '@ownclouders/web-pkg' import { authService } from '../services/auth' import { ClientService, @@ -331,9 +337,10 @@ export const announceTheme = async ({ } export const announcePiniaStores = () => { + const messagesStore = useMessages() const modalStore = useModals() const userStore = useUserStore() - return { modalStore, userStore } + return { messagesStore, modalStore, userStore } } /** diff --git a/packages/web-runtime/src/layouts/Application.vue b/packages/web-runtime/src/layouts/Application.vue index a6a4ffcaf9f..49d16881199 100644 --- a/packages/web-runtime/src/layouts/Application.vue +++ b/packages/web-runtime/src/layouts/Application.vue @@ -27,14 +27,14 @@
- +
diff --git a/packages/web-runtime/src/pages/account.vue b/packages/web-runtime/src/pages/account.vue index 21f6add3d79..1039fce23a5 100644 --- a/packages/web-runtime/src/pages/account.vue +++ b/packages/web-runtime/src/pages/account.vue @@ -149,6 +149,7 @@ import { useCapabilityGraphPersonalDataExport, useClientService, useGetMatchingSpace, + useMessages, useModals, useStore, useUserStore @@ -171,6 +172,7 @@ export default defineComponent({ }, setup() { const store = useStore() + const { showMessage, showErrorMessage } = useMessages() const userStore = useUserStore() const language = useGettext() const { $gettext } = language @@ -215,9 +217,9 @@ export default defineComponent({ valuesList.value = values || [] } catch (e) { console.error(e) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Unable to load account data…'), - error: e + errors: [e] }) valuesList.value = [] } @@ -235,9 +237,9 @@ export default defineComponent({ accountBundle.value = bundles?.find((b) => b.extension === 'ocis-accounts') } catch (e) { console.error(e) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Unable to load account data…'), - error: e + errors: [e] }) accountBundle.value = undefined } @@ -249,9 +251,9 @@ export default defineComponent({ graphUser.value = data } catch (e) { console.error(e) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Unable to load account data…'), - error: e + errors: [e] }) graphUser.value = undefined } @@ -345,14 +347,12 @@ export default defineComponent({ }) } - store.dispatch('showMessage', { - title: $gettext('Preference saved.') - }) + showMessage({ title: $gettext('Preference saved.') }) } catch (e) { console.error(e) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Unable to save preference…'), - error: e + errors: [e] }) } } @@ -364,14 +364,12 @@ export default defineComponent({ valueOptions: { boolValue: !option } }) disableEmailNotificationsValue.value = option - store.dispatch('showMessage', { - title: $gettext('Preference saved.') - }) + showMessage({ title: $gettext('Preference saved.') }) } catch (e) { console.error(e) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Unable to save preference…'), - error: e + errors: [e] }) } } @@ -380,14 +378,12 @@ export default defineComponent({ try { store.commit('Files/SET_FILE_WEB_DAV_DETAILS_VISIBILITY', option) viewOptionWebDavDetailsValue.value = option - store.dispatch('showMessage', { - title: $gettext('Preference saved.') - }) + showMessage({ title: $gettext('Preference saved.') }) } catch (e) { console.error(e) - store.dispatch('showErrorMessage', { + showErrorMessage({ title: $gettext('Unable to save preference…'), - error: e + errors: [e] }) } } diff --git a/packages/web-runtime/src/store/app.ts b/packages/web-runtime/src/store/app.ts deleted file mode 100644 index 146ea578a15..00000000000 --- a/packages/web-runtime/src/store/app.ts +++ /dev/null @@ -1,74 +0,0 @@ -const state = { - messages: [] -} - -const actions = { - showErrorMessage({ commit }, message) { - const getXRequestID = (error: any): string | null => { - /** - * x-request-id response headers might be very nested in ownCloud SDK, - * only remove records if you are sure they aren't valid anymore - */ - if (error.response?.res?.res?.headers?.['x-request-id']) { - return error.response.res.res.headers['x-request-id'] - } - if (error.response?.headers?.map?.['x-request-id']) { - return error.response.headers.map['x-request-id'] - } - if (error.response?.res?.headers?.['x-request-id']) { - return error.response.res.headers['x-request-id'] - } - if (error.response?.headers?.['x-request-id']) { - return error.response.headers['x-request-id'] - } - return null - } - - message.status = message.status || 'danger' - message.timeout = message.timeout || 0 - message.errors = message.error ? [message.error] : message.errors || [] - - const xRequestIds = message.errors - .map((error) => getXRequestID(error)) - .filter((xRequestId) => xRequestId !== null) - .map((item) => `X-Request-Id: ${item}`) - .join('\r\n') - - message.errorLogContent = xRequestIds - - commit('ENQUEUE_MESSAGE', message) - }, - showMessage({ commit }, message) { - commit('ENQUEUE_MESSAGE', message) - }, - deleteMessage(context, mId) { - context.commit('REMOVE_MESSAGE', mId) - } -} - -const mutations = { - ENQUEUE_MESSAGE(state, message) { - // set random id to improve iteration in v-for & lodash - if (!message.id) { - message.id = Math.random().toString(36).slice(2, -1) - } - - state.messages.push(message) - }, - REMOVE_MESSAGE(state, item) { - state.messages.splice(state.messages.indexOf(item), 1) - } -} - -const getters = { - activeMessages: (state) => { - return state.messages - } -} - -export default { - state, - actions, - mutations, - getters -} diff --git a/packages/web-runtime/src/store/index.ts b/packages/web-runtime/src/store/index.ts index 2c63a6f851d..b851c9eefb3 100644 --- a/packages/web-runtime/src/store/index.ts +++ b/packages/web-runtime/src/store/index.ts @@ -1,5 +1,4 @@ import ancestorMetaData from './ancestorMetaData' -import app from './app' import apps from './apps' import auth from './auth' import config from './config' @@ -20,7 +19,6 @@ const runtime = { export default { modules: { - app, apps, user, config, diff --git a/packages/web-test-helpers/src/mocks/store/defaultStoreMockOptions.ts b/packages/web-test-helpers/src/mocks/store/defaultStoreMockOptions.ts index 28d4275021d..121e0723d7e 100644 --- a/packages/web-test-helpers/src/mocks/store/defaultStoreMockOptions.ts +++ b/packages/web-test-helpers/src/mocks/store/defaultStoreMockOptions.ts @@ -33,9 +33,6 @@ export const defaultStoreMockOptions = { } }, actions: { - showMessage: jest.fn(), - showErrorMessage: jest.fn(), - deleteNotification: jest.fn(), openNavigation: jest.fn(), closeNavigation: jest.fn() },