rename web/desktop packages to pos-web/pos-desktop and
This commit is contained in:
@@ -19,8 +19,9 @@ import {
|
||||
EnterpriseModalContext,
|
||||
EnterpriseTranslationContext,
|
||||
} from '../hooks/use-module.context';
|
||||
import { defaultPrivileges, noPrivileges } from '../constant/default-privilege';
|
||||
import { Forbidden } from '../../../components';
|
||||
import { useEnterpriseStorage } from '../hooks/enterprise-storage.context';
|
||||
import { defaultPrivileges, noPrivileges } from '../constant';
|
||||
|
||||
export interface EnterpriseModuleProviderProps<
|
||||
E extends BaseEntity,
|
||||
@@ -45,22 +46,20 @@ export function EnterpriseModuleProvider<
|
||||
// ---------------------------------------------------------------------------
|
||||
// Config Slice (Static)
|
||||
// ---------------------------------------------------------------------------
|
||||
const storage = useEnterpriseStorage();
|
||||
const [parsedPrivileges, setParsedPrivileges] = useState<PrivilegeEntity>(defaultPrivileges);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchPrivilegeData = async () => {
|
||||
try {
|
||||
// FIXME: Uncomment and complete the logic below to fetch real data.
|
||||
// Currently, this is hardcoded to use `defaultPrivileges`.
|
||||
// You need to retrieve the user privileges from the local database,
|
||||
// extract the specific config using `moduleKey`, and apply the mapping function.
|
||||
const moduleKey: string | undefined = config?.moduleKey;
|
||||
if (!moduleKey) {
|
||||
setParsedPrivileges(noPrivileges);
|
||||
return;
|
||||
}
|
||||
|
||||
// const privilege: any = await appDatabase.getItem(AppDatabaseKey.USER_PRIVILEGE);
|
||||
// const moduleKey: string | undefined = config?.moduleKey;
|
||||
// const privilegeConfig = privilege[moduleKey];
|
||||
|
||||
// TODO: Replace this with the mapped result, e.g., setParsedPrivileges(mappingUserPrivilege(privilegeConfig));
|
||||
setParsedPrivileges(defaultPrivileges);
|
||||
const privilegeConfig = await storage.getPrivileges(moduleKey);
|
||||
setParsedPrivileges(privilegeConfig ?? noPrivileges);
|
||||
} catch (error) {
|
||||
setParsedPrivileges(noPrivileges);
|
||||
console.error('Failed to retrieve privilege data:', error);
|
||||
@@ -68,7 +67,7 @@ export function EnterpriseModuleProvider<
|
||||
};
|
||||
|
||||
fetchPrivilegeData();
|
||||
}, [config?.moduleKey]);
|
||||
}, [config?.moduleKey, storage]);
|
||||
|
||||
const configSlice: ConfigSlice = useMemo(() => {
|
||||
return { config, privileges: parsedPrivileges, IS_MACOS: IS_MACOS };
|
||||
@@ -175,7 +174,7 @@ export function EnterpriseModuleProvider<
|
||||
// Render
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const { ALLOW_VIEW } = configSlice.privileges;
|
||||
const { ALLOW_VIEW } = configSlice.privileges ?? {};
|
||||
|
||||
if (!ALLOW_VIEW) return <Forbidden homeUrl="/app" height={500} />;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user