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