refactor: implement enterprise storage provider

This commit is contained in:
Firman Ramdhani
2026-07-31 14:20:01 +07:00
parent 90e1bc2ea0
commit c9c5b2c86e
5 changed files with 146 additions and 35 deletions
@@ -1,4 +1,5 @@
import { CoreAppShell, CoreAppShellConfig } from '@repo/ui/components';
import { EnterpriseStorageProvider } from '@repo/ui/foundations';
import { registerModuleNamespace } from '@repo/core-i18n';
import HeaderLayout from './components/header.layout';
import { SidebarMenu } from './components/sidebar';
@@ -6,6 +7,7 @@ import { HistoryDrawer } from './components/history';
import { BookmarkDrawer } from './components/bookmark';
import { useHistoryTracker } from './hooks/useHistoryTracker';
import { MENU_ITEMS } from './data/menu.data';
import { enterpriseStorageAdapter } from '../../../core/lib/enterprise-storage-adapter';
import navEn from './languages/en/nav.json';
import navId from './languages/id/nav.json';
@@ -40,17 +42,19 @@ export default function ModuleLayout({ children }: { children: React.ReactNode }
};
return (
<CoreAppShell
config={configAppShell}
slots={{
header: <HeaderLayout />,
sidebar: <SidebarMenu items={MENU_ITEMS} withToggle />,
sidebarMobile: <SidebarMenu items={MENU_ITEMS} variantOverride="expanded" />,
}}
>
{children}
<HistoryDrawer />
<BookmarkDrawer />
</CoreAppShell>
<EnterpriseStorageProvider adapter={enterpriseStorageAdapter}>
<CoreAppShell
config={configAppShell}
slots={{
header: <HeaderLayout />,
sidebar: <SidebarMenu items={MENU_ITEMS} withToggle />,
sidebarMobile: <SidebarMenu items={MENU_ITEMS} variantOverride="expanded" />,
}}
>
{children}
<HistoryDrawer />
<BookmarkDrawer />
</CoreAppShell>
</EnterpriseStorageProvider>
);
}
@@ -0,0 +1,25 @@
import type { EnterpriseStorageAdapter } from '@repo/ui/foundations';
import type { PrivilegeEntity } from '@repo/ui/foundations';
import { appDatabase, AppDatabaseKey } from '../storage/local';
/**
* Concrete storage adapter that wires the Enterprise Module framework
* to this app's IndexedDB instance.
*
* Passed to `<EnterpriseStorageProvider adapter={enterpriseStorageAdapter}>`.
*/
export const enterpriseStorageAdapter: EnterpriseStorageAdapter = {
async getPrivileges(moduleKey: string): Promise<PrivilegeEntity | null> {
const allPrivileges: any = await appDatabase.getItem(AppDatabaseKey.USER_PRIVILEGE);
if (!allPrivileges) return null;
return allPrivileges[moduleKey] ?? null;
},
async getDrafts(): Promise<Record<string, any> | null> {
return appDatabase.getItem<Record<string, any>>(AppDatabaseKey.OFFLINE_DRAFT);
},
async setDrafts(drafts: Record<string, any>): Promise<void> {
await appDatabase.setItem(AppDatabaseKey.OFFLINE_DRAFT, drafts);
},
};