Files
inbuxa-admin/src/stores/accountStore.ts
T
2026-04-20 15:02:57 +02:00

38 lines
988 B
TypeScript

/*
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
import { create } from 'zustand';
type Edition = 'enterprise' | 'community' | 'oss';
interface AccountState {
permissions: string[];
edition: Edition;
locale: string;
setAccountInfo: (permissions: string[], edition: Edition, locale: string) => void;
hasPermission: (perm: string) => boolean;
hasObjectPermission: (prefix: string, action: 'Get' | 'Query' | 'Create' | 'Update' | 'Destroy') => boolean;
}
export const useAccountStore = create<AccountState>()((set, get) => ({
permissions: [],
edition: 'community',
locale: 'en',
setAccountInfo: (permissions, edition, locale) => {
set({ permissions, edition, locale });
},
hasPermission: (perm) => {
return get().permissions.includes(perm);
},
hasObjectPermission: (prefix, action) => {
return get().permissions.includes(`${prefix}${action}`);
},
}));