@admin-layout/gluestack-ui-mobile 9.0.4-alpha.54 → 9.1.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,101 +7,103 @@ import { useDispatch } from 'react-redux';
7
7
  import { CHANGE_SETTINGS_ACTION } from '@admin-layout/client';
8
8
  import { useSelector } from 'react-redux';
9
9
 
10
+ export const Header = React.memo(
11
+ ({
12
+ navigation,
13
+ route,
14
+ options,
15
+ back,
16
+ showToggle = null,
17
+ theme = 'light',
18
+ right = null,
19
+ rightComponent,
20
+ isMixedLayout = null,
21
+ ...rest
22
+ }: any) => {
23
+ const title = rest?.title || getHeaderTitle(options, route.name);
10
24
 
11
- export const Header = React.memo(({
12
- navigation,
13
- route,
14
- options,
15
- back,
16
- showToggle = null,
17
- theme = 'light',
18
- right = null,
19
- rightComponent,
20
- isMixedLayout=null,
21
- ...rest
22
- }: any)=>{
23
- const title = rest?.title || getHeaderTitle(options, route.name);
25
+ const matches: any = title.match(/\b(\w)/g);
26
+ const acronym: any = matches.join('').substring(0, 2); // JSON
27
+ const [settingToggle, setSettingToggle] = useState(false);
28
+ const settings = useSelector<any>((state) => state.settings) as any;
29
+ const dispatch = useDispatch();
24
30
 
25
- const matches: any = title.match(/\b(\w)/g);
26
- const acronym: any = matches.join('').substring(0, 2); // JSON
27
- const [settingToggle, setSettingToggle] = useState(false);
28
- const settings = useSelector<any>((state) => state.settings) as any;
29
- const dispatch = useDispatch();
31
+ const onSettingChange = useCallback(
32
+ (config: any) =>
33
+ dispatch({
34
+ type: CHANGE_SETTINGS_ACTION,
35
+ payload: config,
36
+ }),
37
+ [dispatch],
38
+ );
30
39
 
31
- const onSettingChange = useCallback(
32
- (config: any) =>
33
- dispatch({
34
- type: CHANGE_SETTINGS_ACTION,
35
- payload: config,
36
- }),
37
- [dispatch],
38
- );
39
-
40
- return (
41
- <SafeAreaView>
42
- <StatusBar barStyle={theme === 'light' ? 'dark-content':'light-content'} />
43
- <Box bg={theme === 'light' ? '$white' : '$black'}>
44
- <HStack
45
- bg={theme === 'light' ? '$white' : '$black'}
46
- px="$1"
47
- py="$3"
48
- // justifyContent={
49
- // settings?.layout === 'bottom' || settings?.layout === 'host-bottom' ? 'center' : 'space-between'
50
- // }
51
- justifyContent={
52
- (settings?.layout === 'bottom' || settings?.layout === 'host-bottom') &&!isMixedLayout && !right
53
- ? 'center'
54
- : 'space-between'
55
- }
56
- alignItems="center"
57
- borderBottomWidth={'$1'}
58
- borderBottomColor={'#d3d3d3'}
59
- w="100%"
60
-
61
- >
62
- {back ? (
63
- <Button size="xs" bg={'transparent'} onPress={() => navigation.goBack()}>
64
- <Ionicons name={'arrow-back'} color={theme === 'light' ? 'black' : 'white'} size={20} />
65
- </Button>
66
- ) : (showToggle && settings?.layout !== 'bottom') || (showToggle && settings?.layout !== 'host-bottom') ? (
67
- <Button size="xs" bg={'transparent'} onPress={() => navigation.toggleDrawer()}>
68
- <Ionicons name={'menu'} color={theme === 'light' ? 'black' : 'white'} size={20} />
69
- </Button>
70
- ) : (
71
- <></>
72
- )}
73
- <Text
74
- px={'$2'}
75
- color={theme === 'light' ? '$black' : '$white'}
76
- style={{ fontSize: 20 }}
77
- fontWeight="$bold"
78
- >
79
- {title}
80
- </Text>
81
- {!!settingToggle ? (
82
- <SettingDrawer
83
- onSettingChange={(settings: any) => {
84
- onSettingChange(settings);
85
- setSettingToggle(false);
86
- }}
87
- />
88
- ) : null}
89
- {right ? (
90
- <HStack alignItems={'center'}>
91
- <Button size="xs" bg={'transparent'} onPress={() => setSettingToggle(!settingToggle)}>
92
- <Ionicons name={'cog'} color={theme === 'light' ? 'black' : 'white'} size={20} />
93
- </Button>
94
- {rightComponent ? <Box>{rightComponent}</Box> : null}
40
+ return (
41
+ <SafeAreaView bg={'$white'}>
42
+ <StatusBar barStyle={theme === 'light' ? 'dark-content' : 'light-content'} />
43
+ <Box bg={theme === 'light' ? '$white' : '$black'}>
44
+ <HStack
45
+ bg={theme === 'light' ? '$white' : '$black'}
46
+ px="$1"
47
+ py="$3"
48
+ // justifyContent={
49
+ // settings?.layout === 'bottom' || settings?.layout === 'host-bottom' ? 'center' : 'space-between'
50
+ // }
51
+ justifyContent={
52
+ (settings?.layout === 'bottom' || settings?.layout === 'host-bottom') &&
53
+ !isMixedLayout &&
54
+ !right
55
+ ? 'center'
56
+ : 'space-between'
57
+ }
58
+ alignItems="center"
59
+ borderBottomWidth={'$1'}
60
+ borderBottomColor={'#d3d3d3'}
61
+ w="100%"
62
+ >
63
+ {back ? (
64
+ <Button size="xs" bg={'transparent'} onPress={() => navigation.goBack()}>
65
+ <Ionicons name={'arrow-back'} color={theme === 'light' ? 'black' : 'white'} size={20} />
66
+ </Button>
67
+ ) : (showToggle && settings?.layout !== 'bottom') ||
68
+ (showToggle && settings?.layout !== 'host-bottom') ? (
69
+ <Button size="xs" bg={'transparent'} onPress={() => navigation.toggleDrawer()}>
70
+ <Ionicons name={'menu'} color={theme === 'light' ? 'black' : 'white'} size={20} />
71
+ </Button>
72
+ ) : (
73
+ <></>
74
+ )}
75
+ <Text
76
+ px={'$2'}
77
+ color={theme === 'light' ? '$black' : '$white'}
78
+ style={{ fontSize: 20 }}
79
+ fontWeight="$bold"
80
+ >
81
+ {title}
82
+ </Text>
83
+ {!!settingToggle ? (
84
+ <SettingDrawer
85
+ onSettingChange={(settings: any) => {
86
+ onSettingChange(settings);
87
+ setSettingToggle(false);
88
+ }}
89
+ />
90
+ ) : null}
91
+ {right ? (
92
+ <HStack alignItems={'center'}>
93
+ <Button size="xs" bg={'transparent'} onPress={() => setSettingToggle(!settingToggle)}>
94
+ <Ionicons name={'cog'} color={theme === 'light' ? 'black' : 'white'} size={20} />
95
+ </Button>
96
+ {rightComponent ? <Box>{rightComponent}</Box> : null}
97
+ </HStack>
98
+ ) : (
99
+ <Button bg={'transparent'} mr={'$2'}></Button>
100
+ )}
95
101
  </HStack>
96
- ) : (
97
- <Button bg={'transparent'} mr={'$2'}></Button>
98
- )}
99
- </HStack>
100
-
101
- </Box>
102
- </SafeAreaView>
103
- );
104
- });
102
+ </Box>
103
+ </SafeAreaView>
104
+ );
105
+ },
106
+ );
105
107
 
106
108
  export default Header;
107
109
 
@@ -134,7 +136,7 @@ export default Header;
134
136
 
135
137
  // return (
136
138
  // <SafeAreaView>
137
- // <StatusBar barStyle={theme === 'light' ? 'dark-content':'light-content'} />
139
+ // <StatusBar barStyle={theme === 'light' ? 'dark-content':'light-content'} />
138
140
  // <Box bg={theme === 'light' ? '$white' : '$black'}>
139
141
  // <HStack
140
142
  // bg={theme === 'light' ? '$white' : '$black'}
@@ -152,7 +154,7 @@ export default Header;
152
154
  // borderBottomWidth={'$1'}
153
155
  // borderBottomColor={'#d3d3d3'}
154
156
  // w="100%"
155
-
157
+
156
158
  // >
157
159
  // {back ? (
158
160
  // <Button size="xs" bg={'transparent'} onPress={() => navigation.goBack()}>
@@ -192,7 +194,7 @@ export default Header;
192
194
  // <Button bg={'transparent'} mr={'$2'}></Button>
193
195
  // )}
194
196
  // </HStack>
195
-
197
+
196
198
  // </Box>
197
199
  // </SafeAreaView>
198
200
  // );
@@ -2,8 +2,7 @@ import * as React from 'react';
2
2
  import { Spinner, Box, Text, Heading } from '@gluestack-ui/themed';
3
3
  import { IPermissionType, IPreDefinedPermissions } from '@adminide-stack/core';
4
4
  import { get } from 'lodash-es';
5
- import { usePermissionAutoFetch } from './usePermissionAutoFetch';
6
- import { isUserAuthenticated } from '@adminide-stack/user-auth0-client';
5
+ import { usePermissionAutoFetch } from '@adminide-stack/platform-client';
7
6
 
8
7
  export enum WithPermissionBehaviour {
9
8
  hide,
@@ -1,38 +1,26 @@
1
- import React from 'react';
2
- import { IResourceAuthority, IConfigFragmentName } from '@adminide-stack/core';
3
- import { useGetTeamContextQuery } from '@adminide-stack/platform-client';
4
- import { generateOrgUri } from '@adminide-stack/core/lib/utils/generate-uri.js';
5
- import { useSelector } from 'react-redux';
6
- import { navigationRef } from '@common-stack/client-react';
1
+ import {
2
+ IResourceAuthority,
3
+ IConfigFragmentName,
4
+ useGetContextDataQuery,
5
+ generateUserUri,
6
+ IContext,
7
+ } from '@adminide-stack/core';
7
8
  import { useSetting } from './useSetting';
8
9
 
9
10
  interface userPermissionAutoFetchProps {
10
11
  configKey?: string;
11
12
  }
12
13
  export const usePermissionAutoFetch = (options?: userPermissionAutoFetchProps) => {
13
- const [orgName, setOrgName] = React.useState<any>(null);
14
- const [orgUri, setOrgUri] = React.useState<any>(null);
15
- const platformState = useSelector((state) => (state as any).platform);
16
- const currentRoute: any = navigationRef.isReady() ? navigationRef?.getCurrentRoute() : null;
17
- const { data, loading } = useGetTeamContextQuery();
18
- const teamData = React.useMemo(() => data?.getTeamContext, [data]);
19
- React.useEffect(() => {
20
- if (currentRoute?.params?.orgName || platformState?.orgName) {
21
- const org = currentRoute?.params?.orgName || platformState?.orgName;
22
- if (org !== orgName) {
23
- setOrgName(org);
24
- }
25
- }
26
- if (orgName) {
27
- const orgUri = generateOrgUri(orgName, IConfigFragmentName.Settings);
28
- setOrgUri(orgUri);
29
- }
30
- }, [currentRoute, platformState, orgName]);
14
+ const { data, loading } = useGetContextDataQuery();
15
+ const { teamUri, orgUri, userId } = (data?.getContextData as IContext) || {};
16
+
17
+ // Determine resource based on teamUri, orgUri, or fallback to userId
18
+ let resource = teamUri || orgUri || (userId ? generateUserUri({ _id: userId }) : generateUserUri({ _id: 'guest' }));
31
19
 
32
20
  const { loading: settingLoading, ...remaining } = useSetting({
33
21
  configKey: options?.configKey || '',
34
22
  overrides: {
35
- resource: teamData?.teamUri ?? orgUri,
23
+ resource: resource,
36
24
  },
37
25
  options: {
38
26
  forceExist: false,
@@ -40,5 +28,51 @@ export const usePermissionAutoFetch = (options?: userPermissionAutoFetchProps) =
40
28
  fragment: IConfigFragmentName.Roles,
41
29
  },
42
30
  });
31
+
43
32
  return { ...remaining, loading: loading || settingLoading };
44
33
  };
34
+
35
+ // import React from 'react';
36
+ // import { IResourceAuthority, IConfigFragmentName } from '@adminide-stack/core';
37
+ // import { useGetTeamContextQuery } from '@adminide-stack/platform-client';
38
+ // import { generateOrgUri } from '@adminide-stack/core/lib/utils/generate-uri.js';
39
+ // import { useSelector } from 'react-redux';
40
+ // import { navigationRef } from '@common-stack/client-react';
41
+ // import { useSetting } from './useSetting';
42
+
43
+ // interface userPermissionAutoFetchProps {
44
+ // configKey?: string;
45
+ // }
46
+ // export const usePermissionAutoFetch = (options?: userPermissionAutoFetchProps) => {
47
+ // const [orgName, setOrgName] = React.useState<any>(null);
48
+ // const [orgUri, setOrgUri] = React.useState<any>(null);
49
+ // const platformState = useSelector((state) => (state as any).platform);
50
+ // const currentRoute: any = navigationRef.isReady() ? navigationRef?.getCurrentRoute() : null;
51
+ // const { data, loading } = useGetTeamContextQuery();
52
+ // const teamData = React.useMemo(() => data?.getTeamContext, [data]);
53
+ // React.useEffect(() => {
54
+ // if (currentRoute?.params?.orgName || platformState?.orgName) {
55
+ // const org = currentRoute?.params?.orgName || platformState?.orgName;
56
+ // if (org !== orgName) {
57
+ // setOrgName(org);
58
+ // }
59
+ // }
60
+ // if (orgName) {
61
+ // const orgUri = generateOrgUri(orgName, IConfigFragmentName.Settings);
62
+ // setOrgUri(orgUri);
63
+ // }
64
+ // }, [currentRoute, platformState, orgName]);
65
+
66
+ // const { loading: settingLoading, ...remaining } = useSetting({
67
+ // configKey: options?.configKey || '',
68
+ // overrides: {
69
+ // resource: teamData?.teamUri ?? orgUri,
70
+ // },
71
+ // options: {
72
+ // forceExist: false,
73
+ // authority: IResourceAuthority.Defaultpermissions,
74
+ // fragment: IConfigFragmentName.Roles,
75
+ // },
76
+ // });
77
+ // return { ...remaining, loading: loading || settingLoading };
78
+ // };
@@ -80,19 +80,21 @@ export function withInteractionsManaged(component: any, interationTime?: number,
80
80
  <>
81
81
  {Platform.OS === 'ios' ? (
82
82
  <>
83
- {permissionKeys ? (
83
+ <>{component}</>
84
+ {/* {permissionKeys ? (
84
85
  <WithPermissionContainer permissionKeys={permissionKeys}>{component}</WithPermissionContainer>
85
86
  ) : (
86
87
  <>{component}</>
87
- )}
88
+ )} */}
88
89
  </>
89
90
  ) : (
90
91
  <IntractionComponent interationTime={interationTime}>
91
- {permissionKeys ? (
92
+ <>{component}</>
93
+ {/* {permissionKeys ? (
92
94
  <WithPermissionContainer permissionKeys={permissionKeys}>{component}</WithPermissionContainer>
93
95
  ) : (
94
96
  <>{component}</>
95
- )}
97
+ )} */}
96
98
  </IntractionComponent>
97
99
  )}
98
100
  </>
@@ -104,19 +106,21 @@ export function withLifeCycleInteractionsManaged(component: any, interationTime?
104
106
  <>
105
107
  {Platform.OS === 'ios' ? (
106
108
  <LifecycleComponent>
107
- {permissionKeys ? (
109
+ <>{component}</>
110
+ {/* {permissionKeys ? (
108
111
  <WithPermissionContainer permissionKeys={permissionKeys}>{component}</WithPermissionContainer>
109
112
  ) : (
110
113
  <>{component}</>
111
- )}
114
+ )} */}
112
115
  </LifecycleComponent>
113
116
  ) : (
114
117
  <IntractionWithLifeCycleComponent interationTime={interationTime}>
115
- {permissionKeys ? (
118
+ <>{component}</>
119
+ {/* {permissionKeys ? (
116
120
  <WithPermissionContainer permissionKeys={permissionKeys}>{component}</WithPermissionContainer>
117
121
  ) : (
118
122
  <>{component}</>
119
- )}
123
+ )} */}
120
124
  </IntractionWithLifeCycleComponent>
121
125
  )}
122
126
  </>
@@ -126,11 +130,12 @@ export function withLifeCycleInteractionsManaged(component: any, interationTime?
126
130
  export function withLifeCycleManaged(component: any, permissionKeys = null) {
127
131
  return (
128
132
  <LifecycleComponent>
129
- {permissionKeys ? (
133
+ <>{component}</>
134
+ {/* {permissionKeys ? (
130
135
  <WithPermissionContainer permissionKeys={permissionKeys}>{component}</WithPermissionContainer>
131
136
  ) : (
132
137
  <>{component}</>
133
- )}
138
+ )} */}
134
139
  </LifecycleComponent>
135
140
  );
136
141
  }
@@ -88,11 +88,11 @@ export class GenerateMobileNavigations {
88
88
  this.#mobileStackPath = config?.mobileStackPath ?? 'mobile-stack-react';
89
89
  this.#appDirPath = path.join(path.dirname(configFilePath), this.#appPath);
90
90
  this.#modules = config?.modules ?? [];
91
- this.#initialRouteName = config?.initialRouteName ?? '';
92
- this.#unauthenticatedComponentPath = config?.unauthenticatedComponentPath ?? '';
93
- this.#customTabBarPath = config?.customTabBarPath ?? '';
94
- this.#customDrawerPath = config?.customDrawerPath ?? '';
95
- this.#customHeaderPath = config?.customHeaderPath ?? '';
91
+ this.#initialRouteName = config?.mobileConfig?.initialRouteName ?? '';
92
+ this.#unauthenticatedComponentPath = config?.mobileConfig?.unauthenticatedComponentPath ?? '';
93
+ this.#customTabBarPath = config?.mobileConfig?.customTabBarPath ?? '';
94
+ this.#customDrawerPath = config?.mobileConfig?.customDrawerPath ?? '';
95
+ this.#customHeaderPath = config?.mobileConfig?.customHeaderPath ?? '';
96
96
  this.#i18Options = config?.i18n ?? {};
97
97
  }
98
98
 
@@ -709,7 +709,11 @@ export class GenerateMobileNavigations {
709
709
  >{(props) => <AuthWrapper
710
710
  auth={${pkgRouteConfig?.props?.initialParams?.auth ?? false}}
711
711
  authority={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
712
- component={<Component${moduleNumber} {...props} />}
712
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
713
+ component={<Component${moduleNumber} {...props}
714
+ permissions={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
715
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
716
+ />}
713
717
  ${
714
718
  pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath
715
719
  ? `unauthenticatedComponent={<${customUnauthenticatedComponentName}/>}`
@@ -880,7 +884,11 @@ export class GenerateMobileNavigations {
880
884
  >{(props) => <AuthWrapper
881
885
  auth={${pkgRouteConfig?.props?.initialParams?.auth ?? false}}
882
886
  authority={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
883
- component={<Component${moduleNumber} {...props} />}
887
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
888
+ component={<Component${moduleNumber} {...props}
889
+ permissions={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
890
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
891
+ />}
884
892
  ${
885
893
  pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath
886
894
  ? `unauthenticatedComponent={<${customUnauthenticatedComponentName}/>}`
@@ -1143,7 +1151,11 @@ export class GenerateMobileNavigations {
1143
1151
  >{(props) => <AuthWrapper
1144
1152
  auth={${pkgRouteConfig?.props?.initialParams?.auth ?? false}}
1145
1153
  authority={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
1146
- component={<Component${moduleNumber} {...props} />}
1154
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
1155
+ component={<Component${moduleNumber} {...props}
1156
+ permissions={${JSON.stringify(pkgRouteConfig?.authority) ?? null}}
1157
+ extraPermissions={${JSON.stringify(pkgRouteConfig?.extraPermissions) ?? null}}
1158
+ />}
1147
1159
  ${
1148
1160
  pkgRouteConfig?.unauthenticatedComponent && customUnauthenticatedComponentPath
1149
1161
  ? `unauthenticatedComponent={<${customUnauthenticatedComponentName}/>}`
@@ -1410,6 +1422,7 @@ export class GenerateMobileNavigations {
1410
1422
  const isShowTabs = layoutType === 'mixSide' || layoutType === 'bottom' ? true : false;
1411
1423
  const isShowDefalutHeader = layoutType === 'mixSide' ? true : false;
1412
1424
  const defaultHeaderProps = {
1425
+ ...(layoutSettings || {}),
1413
1426
  showToggle: layoutSettings?.topLeftToggle || false,
1414
1427
  right: layoutSettings?.topRightSettingToggle || false,
1415
1428
  };
@@ -1461,7 +1474,11 @@ export class GenerateMobileNavigations {
1461
1474
  : ''
1462
1475
  }
1463
1476
  }})}
1464
- ${customDrawerPath ? 'drawerContent={(props) => <CustomDrawerContent {...props} />}' : ''}
1477
+ ${
1478
+ customDrawerPath
1479
+ ? 'drawerContent={(props) => <CustomDrawerContent {...props} {...defaultHeaderProps || {}} />}'
1480
+ : ''
1481
+ }
1465
1482
  >
1466
1483
  {settings?.layout == 'host-bottom' ? hostDrawerNavigations({ Drawer }) : drawerNavigations({ Drawer })}
1467
1484
  </Drawer.Navigator>