@@ -12,9 +12,10 @@ import {
1212 V1Beta1Plan ,
1313} from "@raystack/frontier" ;
1414import { useFrontier } from "@raystack/frontier/react" ;
15+ import { Config , defaultConfig } from "~/utils/constants" ;
1516
1617// TODO: Setting this to 1000 initially till APIs support filters and sorting.
17- const page_size = 1000
18+ const page_size = 1000 ;
1819
1920type OrgMap = Record < string , V1Beta1Organization > ;
2021
@@ -27,6 +28,7 @@ interface AppContextValue {
2728 platformUsers ?: V1Beta1ListPlatformUsersResponse ;
2829 fetchPlatformUsers : ( ) => void ;
2930 loadMoreOrganizations : ( ) => void ;
31+ config : Config ;
3032}
3133
3234const AppContextDefaultValue = {
@@ -40,7 +42,8 @@ const AppContextDefaultValue = {
4042 serviceusers : [ ] ,
4143 } ,
4244 fetchPlatformUsers : ( ) => { } ,
43- loadMoreOrganizations : ( ) => { }
45+ loadMoreOrganizations : ( ) => { } ,
46+ config : defaultConfig ,
4447} ;
4548
4649export const AppContext = createContext < AppContextValue > (
@@ -66,6 +69,8 @@ export const AppContextProvider: React.FC<PropsWithChildren> = function ({
6669 const [ platformUsers , setPlatformUsers ] =
6770 useState < V1Beta1ListPlatformUsersResponse > ( ) ;
6871
72+ const [ config , setConfig ] = useState < Config > ( defaultConfig ) ;
73+
6974 const [ page , setPage ] = useState ( 1 ) ;
7075 const [ enabledOrgHasMoreData , setEnabledOrgHasMoreData ] = useState ( true ) ;
7176 const [ disabledOrgHasMoreData , setDisabledOrgHasMoreData ] = useState ( true ) ;
@@ -79,7 +84,11 @@ export const AppContextProvider: React.FC<PropsWithChildren> = function ({
7984 try {
8085 const [ orgResp , disabledOrgResp ] = await Promise . all ( [
8186 client ?. adminServiceListAllOrganizations ( { page_num : page , page_size } ) ,
82- client ?. adminServiceListAllOrganizations ( { state : "disabled" , page_num : page , page_size } ) ,
87+ client ?. adminServiceListAllOrganizations ( {
88+ state : "disabled" ,
89+ page_num : page ,
90+ page_size,
91+ } ) ,
8392 ] ) ;
8493
8594 if ( orgResp ?. data ?. organizations ?. length ) {
@@ -111,7 +120,10 @@ export const AppContextProvider: React.FC<PropsWithChildren> = function ({
111120 } , [ client , page , enabledOrgHasMoreData , disabledOrgHasMoreData ] ) ;
112121
113122 const loadMoreOrganizations = ( ) => {
114- if ( ! isOrgListLoading && ( enabledOrgHasMoreData || disabledOrgHasMoreData ) ) {
123+ if (
124+ ! isOrgListLoading &&
125+ ( enabledOrgHasMoreData || disabledOrgHasMoreData )
126+ ) {
115127 setPage ( ( prevPage : number ) => prevPage + 1 ) ;
116128 }
117129 } ;
@@ -136,6 +148,19 @@ export const AppContextProvider: React.FC<PropsWithChildren> = function ({
136148 }
137149 } , [ client ] ) ;
138150
151+ const fetchConfig = useCallback ( async ( ) => {
152+ setIsPlatformUsersLoading ( true ) ;
153+ try {
154+ const resp = await fetch ( "/configs" ) ;
155+ const data = ( await resp ?. json ( ) ) as Config ;
156+ setConfig ( data ) ;
157+ } catch ( err ) {
158+ console . error ( err ) ;
159+ } finally {
160+ setIsPlatformUsersLoading ( false ) ;
161+ }
162+ } , [ ] ) ;
163+
139164 useEffect ( ( ) => {
140165 async function getPlans ( ) {
141166 setIsPlansLoading ( true ) ;
@@ -149,12 +174,12 @@ export const AppContextProvider: React.FC<PropsWithChildren> = function ({
149174 setIsPlansLoading ( false ) ;
150175 }
151176 }
152-
153177 if ( isAdmin ) {
154178 getPlans ( ) ;
155179 fetchPlatformUsers ( ) ;
156180 }
157- } , [ client , isAdmin , fetchPlatformUsers ] ) ;
181+ fetchConfig ( ) ;
182+ } , [ client , isAdmin , fetchPlatformUsers , fetchConfig ] ) ;
158183
159184 const isLoading =
160185 isOrgListLoading ||
@@ -180,6 +205,7 @@ export const AppContextProvider: React.FC<PropsWithChildren> = function ({
180205 platformUsers,
181206 fetchPlatformUsers,
182207 loadMoreOrganizations,
208+ config,
183209 } }
184210 >
185211 { children }
0 commit comments