Skip to content

Commit 65e450c

Browse files
committed
✨(frontend) add custom css style
From the config, we can add custom css style to the app.
1 parent 725cae5 commit 65e450c

File tree

4 files changed

+39
-5
lines changed

4 files changed

+39
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to
2121
## Added
2222

2323
- 📄(legal) Require contributors to sign a DCO #779
24+
- ✨(frontend) add custom css style #771
2425

2526
## Changed
2627

src/frontend/apps/e2e/__tests__/app-impress/config.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,30 @@ test.describe('Config', () => {
174174
page.locator('#crisp-chatbox').getByText('Invalid website'),
175175
).toBeVisible();
176176
});
177+
178+
test('it checks FRONTEND_CSS_URL config', async ({ page }) => {
179+
await page.route('**/api/v1.0/config/', async (route) => {
180+
const request = route.request();
181+
if (request.method().includes('GET')) {
182+
await route.fulfill({
183+
json: {
184+
...config,
185+
FRONTEND_CSS_URL: 'http://localhost:123465/css/style.css',
186+
},
187+
});
188+
} else {
189+
await route.continue();
190+
}
191+
});
192+
193+
await page.goto('/');
194+
195+
await expect(
196+
page
197+
.locator('head link[href="http://localhost:123465/css/style.css"]')
198+
.first(),
199+
).toBeAttached();
200+
});
177201
});
178202

179203
test.describe('Config: Not loggued', () => {

src/frontend/apps/impress/src/core/config/ConfigProvider.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Loader } from '@openfun/cunningham-react';
2+
import Head from 'next/head';
23
import { PropsWithChildren, useEffect } from 'react';
34

45
import { Box } from '@/components';
@@ -54,10 +55,17 @@ export const ConfigProvider = ({ children }: PropsWithChildren) => {
5455
}
5556

5657
return (
57-
<AnalyticsProvider>
58-
<CrispProvider websiteId={conf?.CRISP_WEBSITE_ID}>
59-
{children}
60-
</CrispProvider>
61-
</AnalyticsProvider>
58+
<>
59+
{conf?.FRONTEND_CSS_URL && (
60+
<Head>
61+
<link rel="stylesheet" href={conf?.FRONTEND_CSS_URL} />
62+
</Head>
63+
)}
64+
<AnalyticsProvider>
65+
<CrispProvider websiteId={conf?.CRISP_WEBSITE_ID}>
66+
{children}
67+
</CrispProvider>
68+
</AnalyticsProvider>
69+
</>
6270
);
6371
};

src/frontend/apps/impress/src/core/config/api/useConfig.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface ConfigResponse {
1111
COLLABORATION_WS_URL?: string;
1212
CRISP_WEBSITE_ID?: string;
1313
FRONTEND_THEME?: Theme;
14+
FRONTEND_CSS_URL?: string;
1415
MEDIA_BASE_URL?: string;
1516
POSTHOG_KEY?: PostHogConf;
1617
SENTRY_DSN?: string;

0 commit comments

Comments
 (0)