Skip to content

Commit a435021

Browse files
authored
feat: motd (#361)
* feat: motd * feat: ui * fix: env var
1 parent 4644f3d commit a435021

File tree

13 files changed

+189
-9
lines changed

13 files changed

+189
-9
lines changed

.env.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ PUBLIC_PICTIQUE_BASE_URL=your_public_pictique_base_url_here
44
# Blabsy Configuration
55
PUBLIC_BLABSY_BASE_URL=your_public_blabsy_base_url_here
66

7-
# Eid Wallet Configuration
7+
# Eid Wallet & Pictique Configuration (Svelte)
88
PUBLIC_REGISTRY_URL=your_public_registry_url_here
99
PUBLIC_PROVISIONER_URL=your_public_provisioner_url_here
1010

11+
# Next.js Applications Configuration (eVoting, Blabsy, Group Charter Manager)
12+
NEXT_PUBLIC_REGISTRY_URL=your_public_registry_url_here
13+
1114
# Neo4j Configuration
1215
NEO4J_URI=bolt://neo4j:7687
1316
NEO4J_USER=neo4j

platforms/blabsy/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Registry URL for fetching motd and other registry services
2+
# Note: In Next.js, environment variables exposed to the browser must be prefixed with NEXT_PUBLIC_
3+
NEXT_PUBLIC_REGISTRY_URL=http://localhost:4321
4+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { useEffect, useState } from 'react';
2+
import axios from 'axios';
3+
4+
interface Motd {
5+
status: 'up' | 'maintenance';
6+
message: string;
7+
}
8+
9+
export function MaintenanceBanner(): JSX.Element | null {
10+
const [motd, setMotd] = useState<Motd | null>(null);
11+
12+
useEffect(() => {
13+
const fetchMotd = async () => {
14+
try {
15+
const registryUrl = process.env.NEXT_PUBLIC_REGISTRY_URL || 'http://localhost:4321';
16+
const response = await axios.get<Motd>(`${registryUrl}/motd`);
17+
setMotd(response.data);
18+
} catch (error) {
19+
console.error('Failed to fetch motd:', error);
20+
}
21+
};
22+
23+
void fetchMotd();
24+
}, []);
25+
26+
if (motd?.status !== 'maintenance') {
27+
return null;
28+
}
29+
30+
return (
31+
<div className='bg-yellow-500 px-4 py-3 text-center text-sm font-medium text-black'>
32+
⚠️ {motd.message}
33+
</div>
34+
);
35+
}
36+

platforms/blabsy/src/pages/_app.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import '@styles/globals.scss';
33
import { AuthContextProvider } from '@lib/context/auth-context';
44
import { ThemeContextProvider } from '@lib/context/theme-context';
55
import { AppHead } from '@components/common/app-head';
6+
import { MaintenanceBanner } from '@components/common/maintenance-banner';
67
import type { ReactElement, ReactNode } from 'react';
78
import type { NextPage } from 'next';
89
import type { AppProps } from 'next/app';
@@ -24,6 +25,7 @@ export default function App({
2425
return (
2526
<>
2627
<AppHead />
28+
<MaintenanceBanner />
2729
<AuthContextProvider>
2830
<ThemeContextProvider>
2931
{getLayout(<Component {...pageProps} />)}

platforms/eVoting/src/app/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Metadata } from "next";
22
import "./globals.css";
33
import { AuthProvider } from "@/lib/auth-context";
4+
import { MaintenanceBanner } from "@/components/MaintenanceBanner";
45

56
export const metadata: Metadata = {
67
title: "eVoting Platform",
@@ -18,6 +19,7 @@ export default function RootLayout({
1819
return (
1920
<html lang="en">
2021
<body>
22+
<MaintenanceBanner />
2123
<AuthProvider>
2224
{children}
2325
</AuthProvider>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use client';
2+
3+
import { useEffect, useState } from 'react';
4+
import axios from 'axios';
5+
6+
interface Motd {
7+
status: 'up' | 'maintenance';
8+
message: string;
9+
}
10+
11+
export function MaintenanceBanner() {
12+
const [motd, setMotd] = useState<Motd | null>(null);
13+
14+
useEffect(() => {
15+
const fetchMotd = async () => {
16+
try {
17+
const registryUrl = process.env.NEXT_PUBLIC_REGISTRY_URL || 'http://localhost:4321';
18+
const response = await axios.get<Motd>(`${registryUrl}/motd`);
19+
setMotd(response.data);
20+
} catch (error) {
21+
console.error('Failed to fetch motd:', error);
22+
}
23+
};
24+
25+
fetchMotd();
26+
}, []);
27+
28+
if (motd?.status !== 'maintenance') {
29+
return null;
30+
}
31+
32+
return (
33+
<div className="bg-yellow-500 px-4 py-3 text-center text-sm font-medium text-black">
34+
⚠️ {motd.message}
35+
</div>
36+
);
37+
}
38+

platforms/group-charter-manager/src/app/layout.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "./globals.css";
44
import { Toaster } from "@/components/ui/toaster";
55
import { AuthProvider } from "@/components/auth/auth-provider";
66
import DisclaimerModal from "@/components/disclaimer-modal";
7+
import { MaintenanceBanner } from "@/components/MaintenanceBanner";
78

89
const inter = Inter({ subsets: ["latin"] });
910

@@ -23,6 +24,7 @@ export default function RootLayout({
2324
return (
2425
<html lang="en">
2526
<body className={inter.className}>
27+
<MaintenanceBanner />
2628
<AuthProvider>
2729
{children}
2830
<Toaster />
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use client';
2+
3+
import { useEffect, useState } from 'react';
4+
import axios from 'axios';
5+
6+
interface Motd {
7+
status: 'up' | 'maintenance';
8+
message: string;
9+
}
10+
11+
export function MaintenanceBanner() {
12+
const [motd, setMotd] = useState<Motd | null>(null);
13+
14+
useEffect(() => {
15+
const fetchMotd = async () => {
16+
try {
17+
const registryUrl = process.env.NEXT_PUBLIC_REGISTRY_URL || 'http://localhost:4321';
18+
const response = await axios.get<Motd>(`${registryUrl}/motd`);
19+
setMotd(response.data);
20+
} catch (error) {
21+
console.error('Failed to fetch motd:', error);
22+
}
23+
};
24+
25+
fetchMotd();
26+
}, []);
27+
28+
if (motd?.status !== 'maintenance') {
29+
return null;
30+
}
31+
32+
return (
33+
<div className="bg-yellow-500 px-4 py-3 text-center text-sm font-medium text-black">
34+
⚠️ {motd.message}
35+
</div>
36+
);
37+
}
38+

platforms/pictique/.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Registry URL for fetching motd and other registry services
2+
# Note: In SvelteKit, public environment variables must be prefixed with PUBLIC_
3+
PUBLIC_REGISTRY_URL=http://localhost:4321
4+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script lang="ts">
2+
import { onMount } from 'svelte';
3+
import axios from 'axios';
4+
import { PUBLIC_REGISTRY_URL } from '$env/static/public';
5+
6+
let motd = $state<{ status: 'up' | 'maintenance'; message: string } | null>(null);
7+
8+
onMount(async () => {
9+
try {
10+
const registryUrl = PUBLIC_REGISTRY_URL || 'http://localhost:4321';
11+
const response = await axios.get(`${registryUrl}/motd`);
12+
motd = response.data;
13+
} catch (error) {
14+
console.error('Failed to fetch motd:', error);
15+
}
16+
});
17+
</script>
18+
19+
{#if motd?.status === 'maintenance'}
20+
<div class="bg-yellow-500 px-4 py-3 text-center text-sm font-medium text-black">
21+
⚠️ {motd.message}
22+
</div>
23+
{/if}

0 commit comments

Comments
 (0)