File tree Expand file tree Collapse file tree 7 files changed +80
-1
lines changed
e2e/__tests__/app-impress Expand file tree Collapse file tree 7 files changed +80
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ and this project adheres to
1515- 🌐(frontend) Add German translation #255
1616- ✨(frontend) Add a broadcast store #387
1717- ✨(backend) whitelist pod's IP address #443
18+ - ✨(backend) config endpoint #425
19+ - ✨(frontend) config endpoint #424
1820
1921## Changed
2022
Original file line number Diff line number Diff line change 1+ import { expect , test } from '@playwright/test' ;
2+
3+ test . describe ( 'Config' , ( ) => {
4+ test ( 'it checks the config api is called' , async ( { page } ) => {
5+ const responsePromise = page . waitForResponse (
6+ ( response ) =>
7+ response . url ( ) . includes ( '/config/' ) && response . status ( ) === 200 ,
8+ ) ;
9+
10+ await page . goto ( '/' ) ;
11+
12+ const response = await responsePromise ;
13+ expect ( response . ok ( ) ) . toBeTruthy ( ) ;
14+
15+ expect ( await response . json ( ) ) . toStrictEqual ( {
16+ COLLABORATION_SERVER_URL : 'ws://localhost:4444' ,
17+ ENVIRONMENT : 'development' ,
18+ FRONTEND_THEME : 'dsfr' ,
19+ MEDIA_BASE_URL : 'http://localhost:8083' ,
20+ LANGUAGES : [
21+ [ 'en-us' , 'English' ] ,
22+ [ 'fr-fr' , 'French' ] ,
23+ [ 'de-de' , 'German' ] ,
24+ ] ,
25+ LANGUAGE_CODE : 'en-us' ,
26+ SENTRY_DSN : null ,
27+ } ) ;
28+ } ) ;
29+ } ) ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import '@/i18n/initI18n';
77import { useResponsiveStore } from '@/stores/' ;
88
99import { Auth } from './auth/' ;
10+ import { ConfigProvider } from './config/' ;
1011
1112/**
1213 * QueryClient:
@@ -39,7 +40,9 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
3940 return (
4041 < QueryClientProvider client = { queryClient } >
4142 < CunninghamProvider theme = { theme } >
42- < Auth > { children } </ Auth >
43+ < ConfigProvider >
44+ < Auth > { children } </ Auth >
45+ </ ConfigProvider >
4346 </ CunninghamProvider >
4447 </ QueryClientProvider >
4548 ) ;
Original file line number Diff line number Diff line change 1+ import { PropsWithChildren } from 'react' ;
2+
3+ import { useConfig } from './api/useConfig' ;
4+
5+ export const ConfigProvider = ( { children } : PropsWithChildren ) => {
6+ useConfig ( ) ;
7+
8+ return children ;
9+ } ;
Original file line number Diff line number Diff line change 1+ export * from './useConfig' ;
Original file line number Diff line number Diff line change 1+ import { useQuery } from '@tanstack/react-query' ;
2+
3+ import { APIError , errorCauses , fetchAPI } from '@/api' ;
4+
5+ interface ConfigResponse {
6+ SENTRY_DSN : string ;
7+ COLLABORATION_SERVER_URL : string ;
8+ ENVIRONMENT : string ;
9+ FRONTEND_THEME : string ;
10+ LANGUAGES : [ string , string ] [ ] ;
11+ LANGUAGE_CODE : string ;
12+ MEDIA_BASE_URL : string ;
13+ }
14+
15+ export const getConfig = async ( ) : Promise < ConfigResponse > => {
16+ const response = await fetchAPI ( `config/` ) ;
17+
18+ if ( ! response . ok ) {
19+ throw new APIError ( 'Failed to get the doc' , await errorCauses ( response ) ) ;
20+ }
21+
22+ return response . json ( ) as Promise < ConfigResponse > ;
23+ } ;
24+
25+ export const KEY_CONFIG = 'config' ;
26+
27+ export function useConfig ( ) {
28+ return useQuery < ConfigResponse , APIError , ConfigResponse > ( {
29+ queryKey : [ KEY_CONFIG ] ,
30+ queryFn : ( ) => getConfig ( ) ,
31+ staleTime : Infinity ,
32+ } ) ;
33+ }
Original file line number Diff line number Diff line change 1+ export * from './api/useConfig' ;
2+ export * from './ConfigProvider' ;
You can’t perform that action at this time.
0 commit comments