diff --git a/src/Umbraco.Web.UI.Client/src/packages/users/user-groups/repository/user-group.store.ts b/src/Umbraco.Web.UI.Client/src/packages/users/user-groups/repository/user-group.store.ts index 8fe2457412..8ca9044e7c 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/users/user-groups/repository/user-group.store.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/users/user-groups/repository/user-group.store.ts @@ -2,10 +2,7 @@ import type { UserGroupDetails } from '../types.js'; import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; import { UmbArrayState } from '@umbraco-cms/backoffice/observable-api'; -import { UmbEntityDetailStore, UmbStoreBase } from '@umbraco-cms/backoffice/store'; - -// TODO: get rid of this type addition & { ... }: -//export type UmbUserGroupStoreItemType = UserGroupDetails & { users?: Array }; +import { UmbStoreBase } from '@umbraco-cms/backoffice/store'; export const UMB_USER_GROUP_STORE_CONTEXT_TOKEN = new UmbContextToken('UmbUserGroupStore'); @@ -15,74 +12,8 @@ export const UMB_USER_GROUP_STORE_CONTEXT_TOKEN = new UmbContextToken { - #groups = new UmbArrayState([], (x) => x.id); - public groups = this.#groups.asObservable(); - +export class UmbUserGroupStore extends UmbStoreBase { constructor(host: UmbControllerHostElement) { super(host, UMB_USER_GROUP_STORE_CONTEXT_TOKEN.toString(), new UmbArrayState([], (x) => x.id)); } - - getScaffold(entityType: string, parentId: string | null) { - return { - id: '', - name: '', - icon: '', - type: 'user-group', - hasChildren: false, - parentId: '', - sections: [], - permissions: [], - users: [], - } as UserGroupDetails; - } - - getAll() { - // TODO: use Fetcher API. - // TODO: only fetch if the data type is not in the store? - fetch(`/umbraco/backoffice/user-groups/list/items`) - .then((res) => res.json()) - .then((data) => { - this.#groups.append(data.items); - }); - - return this.groups; - } - - getByKey(id: string) { - // TODO: use Fetcher API. - // TODO: only fetch if the data type is not in the store? - fetch(`/umbraco/backoffice/user-groups/details/${id}`) - .then((res) => res.json()) - .then((data) => { - this.#groups.append([data]); - }); - - return this.#groups.asObservablePart((userGroups) => userGroups.find((userGroup) => userGroup.id === id)); - } - - async save(userGroups: Array) { - // TODO: use Fetcher API. - - // TODO: implement so user group store updates the users, but these needs to save as well..? - /* - if (this._userStore && userGroup.users) { - await this._userStore.updateUserGroup(userGroup.users, userGroup.id); - } - */ - - try { - const res = await fetch('/umbraco/backoffice/user-groups/save', { - method: 'POST', - body: JSON.stringify(userGroups), - headers: { - 'Content-Type': 'application/json', - }, - }); - const json = await res.json(); - this.#groups.append(json); - } catch (error) { - console.error('Save Data Type error', error); - } - } }