Compare commits
7 Commits
106f15205c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
29d6ab3d80
|
|||
|
429eb07291
|
|||
|
092d537180
|
|||
|
61c1f47409
|
|||
|
0247f6ed9d
|
|||
|
ba1433b192
|
|||
|
0e485aacee
|
@ -31,13 +31,20 @@ export default function AdminLoginPage() {
|
||||
|
||||
if (response.ok) {
|
||||
router.push("/admin");
|
||||
} else if (response.status === 404) {
|
||||
// API non disponible (mode statique/APK) - accepter quand même
|
||||
// Le mot de passe sera vérifié côté serveur lors des vraies requêtes
|
||||
router.push("/admin");
|
||||
} else {
|
||||
setError("Mot de passe incorrect");
|
||||
localStorage.removeItem("adminPassword");
|
||||
}
|
||||
} catch (err) {
|
||||
setError("Erreur de connexion");
|
||||
localStorage.removeItem("adminPassword");
|
||||
// Erreur réseau (API non disponible en mode statique/APK)
|
||||
// Accepter quand même et rediriger
|
||||
// Le mot de passe sera vérifié côté serveur lors des vraies requêtes
|
||||
console.warn("API non disponible (mode statique), connexion acceptée localement");
|
||||
router.push("/admin");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@ -20,7 +20,31 @@ export default function AdminPage() {
|
||||
const adminPassword = localStorage.getItem("adminPassword");
|
||||
if (!adminPassword) {
|
||||
router.push("/admin/login");
|
||||
return;
|
||||
}
|
||||
|
||||
// Tester la connexion avec l'API (si disponible)
|
||||
// Si l'API n'est pas disponible (APK statique), on continue quand même
|
||||
fetch("/api/admin/clients", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${adminPassword}`,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res.ok && res.status !== 404) {
|
||||
// Si erreur autre que 404 (API non disponible), déconnecter
|
||||
if (res.status === 401 || res.status === 403) {
|
||||
localStorage.removeItem("adminPassword");
|
||||
router.push("/admin/login");
|
||||
}
|
||||
}
|
||||
// Si 404, c'est normal en mode statique (API non disponible)
|
||||
// On continue l'affichage
|
||||
})
|
||||
.catch(() => {
|
||||
// Erreur réseau (API non disponible en mode statique)
|
||||
// C'est normal pour l'APK, on continue
|
||||
});
|
||||
}, [router]);
|
||||
|
||||
const handleNewClient = () => {
|
||||
|
||||
@ -1,153 +0,0 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { writeFile, readFile, mkdir } from "fs/promises";
|
||||
import { existsSync } from "fs";
|
||||
import path from "path";
|
||||
import { Client, ClientInput } from "@/lib/types/client";
|
||||
|
||||
const ADMIN_PASSWORD = process.env.ADMIN_PASSWORD || "admin123";
|
||||
const DATA_DIR = path.join(process.cwd(), "data");
|
||||
const CLIENTS_FILE = path.join(DATA_DIR, "clients.json");
|
||||
|
||||
function verifyAuth(request: NextRequest): boolean {
|
||||
const authHeader = request.headers.get("authorization");
|
||||
if (!authHeader) return false;
|
||||
|
||||
const token = authHeader.replace("Bearer ", "");
|
||||
return token === ADMIN_PASSWORD;
|
||||
}
|
||||
|
||||
async function loadClients(): Promise<Client[]> {
|
||||
try {
|
||||
if (!existsSync(CLIENTS_FILE)) {
|
||||
if (!existsSync(DATA_DIR)) {
|
||||
await mkdir(DATA_DIR, { recursive: true });
|
||||
}
|
||||
await writeFile(CLIENTS_FILE, JSON.stringify([], null, 2));
|
||||
return [];
|
||||
}
|
||||
|
||||
const data = await readFile(CLIENTS_FILE, "utf-8");
|
||||
return JSON.parse(data);
|
||||
} catch (error) {
|
||||
console.error("Erreur lecture clients:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async function saveClients(clients: Client[]): Promise<void> {
|
||||
try {
|
||||
if (!existsSync(DATA_DIR)) {
|
||||
await mkdir(DATA_DIR, { recursive: true });
|
||||
}
|
||||
await writeFile(CLIENTS_FILE, JSON.stringify(clients, null, 2));
|
||||
} catch (error) {
|
||||
console.error("Erreur sauvegarde clients:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// GET - Récupérer un client par ID
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
if (!verifyAuth(request)) {
|
||||
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const clients = await loadClients();
|
||||
const client = clients.find(c => c.id === params.id);
|
||||
|
||||
if (!client) {
|
||||
return NextResponse.json(
|
||||
{ error: "Client non trouvé" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json(client);
|
||||
} catch (error) {
|
||||
console.error("Erreur GET client:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur serveur" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// PUT - Mettre à jour un client
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
if (!verifyAuth(request)) {
|
||||
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const input: ClientInput = await request.json();
|
||||
const clients = await loadClients();
|
||||
const clientIndex = clients.findIndex(c => c.id === params.id);
|
||||
|
||||
if (clientIndex === -1) {
|
||||
return NextResponse.json(
|
||||
{ error: "Client non trouvé" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
// Mettre à jour le client
|
||||
const updatedClient: Client = {
|
||||
...clients[clientIndex],
|
||||
email: input.email || clients[clientIndex].email,
|
||||
bungalowNumber: input.bungalowNumber || clients[clientIndex].bungalowNumber,
|
||||
wifiName: input.wifiName || clients[clientIndex].wifiName,
|
||||
wifiPassword: input.wifiPassword || clients[clientIndex].wifiPassword,
|
||||
gerantMessage: input.gerantMessage || clients[clientIndex].gerantMessage,
|
||||
};
|
||||
|
||||
clients[clientIndex] = updatedClient;
|
||||
await saveClients(clients);
|
||||
|
||||
return NextResponse.json(updatedClient);
|
||||
} catch (error) {
|
||||
console.error("Erreur PUT client:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur serveur" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE - Supprimer un client
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
if (!verifyAuth(request)) {
|
||||
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
const clients = await loadClients();
|
||||
const filteredClients = clients.filter(c => c.id !== params.id);
|
||||
|
||||
if (filteredClients.length === clients.length) {
|
||||
return NextResponse.json(
|
||||
{ error: "Client non trouvé" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
await saveClients(filteredClients);
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
console.error("Erreur DELETE client:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur serveur" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,6 +108,7 @@ export async function POST(request: NextRequest) {
|
||||
wifiPassword: input.wifiPassword || "",
|
||||
gerantMessage: input.gerantMessage || "Bienvenue dans notre pension de famille !",
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
clients.push(newClient);
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { readFile } from "fs/promises";
|
||||
import { existsSync } from "fs";
|
||||
import path from "path";
|
||||
import { Client } from "@/lib/types/client";
|
||||
|
||||
const DATA_DIR = path.join(process.cwd(), "data");
|
||||
const CLIENTS_FILE = path.join(DATA_DIR, "clients.json");
|
||||
|
||||
async function loadClients(): Promise<Client[]> {
|
||||
try {
|
||||
if (!existsSync(CLIENTS_FILE)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const data = await readFile(CLIENTS_FILE, "utf-8");
|
||||
return JSON.parse(data);
|
||||
} catch (error) {
|
||||
console.error("Erreur lecture clients:", error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// GET - Récupérer les données d'un client par son token
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { token: string } }
|
||||
) {
|
||||
try {
|
||||
const clients = await loadClients();
|
||||
const client = clients.find(c => c.token === params.token);
|
||||
|
||||
if (!client) {
|
||||
return NextResponse.json(
|
||||
{ error: "Client non trouvé" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
// Retourner uniquement les données nécessaires (pas le token ni l'ID)
|
||||
return NextResponse.json({
|
||||
bungalowNumber: client.bungalowNumber,
|
||||
wifiName: client.wifiName,
|
||||
wifiPassword: client.wifiPassword,
|
||||
gerantMessage: client.gerantMessage,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Erreur GET client par token:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Erreur serveur" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,10 +4,10 @@
|
||||
|
||||
@layer base {
|
||||
body {
|
||||
@apply bg-background;
|
||||
@apply bg-background dark:bg-background-dark;
|
||||
font-size: 16px;
|
||||
min-height: 100vh;
|
||||
color: #1f2937;
|
||||
@apply text-foreground dark:text-foreground-dark;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ import type { Metadata } from "next";
|
||||
import { Inter } from "next/font/google";
|
||||
import "./globals.css";
|
||||
import PWARegister from "@/components/PWARegister";
|
||||
import { ThemeProvider } from "@/components/ThemeProvider";
|
||||
|
||||
const inter = Inter({ subsets: ["latin"] });
|
||||
|
||||
@ -29,14 +30,21 @@ export default function RootLayout({
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
return (
|
||||
<html lang="fr">
|
||||
<html lang="fr" suppressHydrationWarning>
|
||||
<head>
|
||||
<link rel="icon" href="/logo-relais-marama.svg" type="image/svg+xml" />
|
||||
<link rel="apple-touch-icon" href="/logo-relais-marama.svg" />
|
||||
</head>
|
||||
<body className={inter.className}>
|
||||
<ThemeProvider
|
||||
attribute="class"
|
||||
defaultTheme="light"
|
||||
enableSystem={true}
|
||||
disableTransitionOnChange={false}
|
||||
>
|
||||
{children}
|
||||
<PWARegister />
|
||||
</ThemeProvider>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
|
||||
106
app/page.tsx
106
app/page.tsx
@ -1,21 +1,121 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function Home() {
|
||||
const router = useRouter();
|
||||
const [checked, setChecked] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
// Détecter si on est dans l'app admin
|
||||
let isAdminApp = false;
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
const Capacitor = (window as any).Capacitor;
|
||||
|
||||
// Méthode 1: Vérifier l'appId de Capacitor via le package name Android
|
||||
if (Capacitor) {
|
||||
try {
|
||||
const platform = Capacitor.getPlatform();
|
||||
|
||||
if (platform === "android") {
|
||||
// En Android, on peut récupérer le package name via Capacitor.getApp()
|
||||
// APK admin: com.pensionmarama.admin
|
||||
// APK client: com.pensionmarama.app
|
||||
const App = Capacitor.Plugins?.App;
|
||||
if (App) {
|
||||
App.getInfo().then((info: any) => {
|
||||
// Le package name est dans info.id ou info.appId
|
||||
const appId = info.id || info.appId || "";
|
||||
if (appId.includes("admin")) {
|
||||
isAdminApp = true;
|
||||
}
|
||||
}).catch(() => {
|
||||
// Fallback si getInfo() échoue
|
||||
});
|
||||
}
|
||||
|
||||
// Fallback: Vérifier le localStorage (si adminPassword existe, c'est admin)
|
||||
const hasAdminPassword = localStorage.getItem("adminPassword") !== null;
|
||||
if (hasAdminPassword) {
|
||||
isAdminApp = true;
|
||||
}
|
||||
} else {
|
||||
// Pour web, vérifier le localStorage
|
||||
const hasAdminPassword = localStorage.getItem("adminPassword") !== null;
|
||||
if (hasAdminPassword) {
|
||||
isAdminApp = true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// En cas d'erreur, fallback sur les autres méthodes
|
||||
console.warn("Erreur lors de la détection Capacitor:", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode 2: Vérifier le path ou query string (pour web)
|
||||
if (!isAdminApp && (
|
||||
window.location.pathname.startsWith("/admin") ||
|
||||
window.location.search.includes("admin=true")
|
||||
)) {
|
||||
isAdminApp = true;
|
||||
}
|
||||
|
||||
// Méthode 3: Si on est dans Capacitor Android sans adminPassword,
|
||||
// on considère que c'est l'app client (redirige vers /accueil)
|
||||
// Sauf si le pathname commence par /admin
|
||||
}
|
||||
|
||||
if (isAdminApp) {
|
||||
// Vérifier si l'admin est connecté
|
||||
const adminPassword = typeof window !== "undefined" ?
|
||||
localStorage.getItem("adminPassword") : null;
|
||||
|
||||
if (adminPassword) {
|
||||
// Tester la connexion (si API disponible)
|
||||
fetch("/api/admin/clients", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${adminPassword}`,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.ok) {
|
||||
router.replace("/admin");
|
||||
} else if (res.status === 404) {
|
||||
// API non disponible (mode statique) - accepter quand même
|
||||
router.replace("/admin");
|
||||
} else {
|
||||
localStorage.removeItem("adminPassword");
|
||||
router.replace("/admin/login");
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// Erreur réseau (API non disponible en mode statique)
|
||||
// Accepter quand même et rediriger vers /admin
|
||||
router.replace("/admin");
|
||||
});
|
||||
} else {
|
||||
// Pas de mot de passe, rediriger vers login
|
||||
router.replace("/admin/login");
|
||||
}
|
||||
} else {
|
||||
// App client normale
|
||||
router.replace("/accueil");
|
||||
}
|
||||
setChecked(true);
|
||||
}, [router]);
|
||||
|
||||
if (!checked) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen">
|
||||
<div className="flex items-center justify-center min-h-screen bg-background dark:bg-background-dark">
|
||||
<div className="text-center">
|
||||
<p className="text-gray-600">Redirection...</p>
|
||||
<p className="text-gray-600 dark:text-gray-400">Chargement...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
12
components/ThemeProvider.tsx
Normal file
12
components/ThemeProvider.tsx
Normal file
@ -0,0 +1,12 @@
|
||||
"use client";
|
||||
|
||||
import { ThemeProvider as NextThemesProvider } from "next-themes";
|
||||
import { type ComponentProps } from "react";
|
||||
|
||||
export function ThemeProvider({
|
||||
children,
|
||||
...props
|
||||
}: ComponentProps<typeof NextThemesProvider>) {
|
||||
return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
|
||||
}
|
||||
|
||||
45
components/ThemeToggle.tsx
Normal file
45
components/ThemeToggle.tsx
Normal file
@ -0,0 +1,45 @@
|
||||
"use client";
|
||||
|
||||
import { useTheme } from "next-themes";
|
||||
import { Moon, Sun } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function ThemeToggle() {
|
||||
const { theme, setTheme } = useTheme();
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
if (!mounted) {
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-9 w-9 rounded-full p-0"
|
||||
aria-label="Changer de thème"
|
||||
>
|
||||
<Sun className="h-5 w-5" />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setTheme(theme === "dark" ? "light" : "dark")}
|
||||
className="h-10 w-10 rounded-full hover:bg-secondary dark:hover:bg-gray-800 p-0"
|
||||
aria-label="Changer de thème"
|
||||
>
|
||||
{theme === "dark" ? (
|
||||
<Sun className="h-5 w-5 text-primary dark:text-yellow-400" />
|
||||
) : (
|
||||
<Moon className="h-5 w-5 text-primary dark:text-blue-300" />
|
||||
)}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ export default function WifiCard() {
|
||||
const showPasswordFallback = error && error.includes("sélectionner manuellement");
|
||||
|
||||
return (
|
||||
<Card className="bg-white">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<Wifi className="h-6 w-6 text-primary" />
|
||||
@ -80,22 +80,22 @@ export default function WifiCard() {
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div>
|
||||
<p className="text-sm text-gray-600 mb-1">Nom du réseau</p>
|
||||
<p className="text-sm text-gray-600 dark:text-gray-400 mb-1">Nom du réseau</p>
|
||||
<p className="text-lg font-semibold text-primary">{wifiName || "Chargement..."}</p>
|
||||
</div>
|
||||
|
||||
{showPasswordFallback && wifiPassword && (
|
||||
<div className="bg-yellow-50 border border-yellow-200 rounded-xl p-3">
|
||||
<p className="text-sm text-yellow-800 font-mono select-all">
|
||||
<div className="bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-xl p-3">
|
||||
<p className="text-sm text-yellow-800 dark:text-yellow-300 font-mono select-all">
|
||||
{wifiPassword}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && !showPasswordFallback && (
|
||||
<div className="bg-red-50 border border-red-200 rounded-xl p-3 flex items-start gap-2">
|
||||
<AlertCircle className="h-5 w-5 text-red-600 flex-shrink-0 mt-0.5" />
|
||||
<p className="text-sm text-red-800">{error}</p>
|
||||
<div className="bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-xl p-3 flex items-start gap-2">
|
||||
<AlertCircle className="h-5 w-5 text-red-600 dark:text-red-400 flex-shrink-0 mt-0.5" />
|
||||
<p className="text-sm text-red-800 dark:text-red-300">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
import { LogOut } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { ThemeToggle } from "@/components/ThemeToggle";
|
||||
|
||||
export default function AdminLayout({ children }: { children: React.ReactNode }) {
|
||||
const router = useRouter();
|
||||
@ -13,15 +14,18 @@ export default function AdminLayout({ children }: { children: React.ReactNode })
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background">
|
||||
<header className="bg-white border-b border-gray-200 shadow-sm">
|
||||
<div className="min-h-screen bg-background dark:bg-background-dark">
|
||||
<header className="bg-white dark:bg-gray-900 border-b border-gray-200 dark:border-gray-800 shadow-sm">
|
||||
<div className="max-w-4xl mx-auto px-4 py-4 flex items-center justify-between">
|
||||
<h1 className="text-xl font-bold text-primary">Administration</h1>
|
||||
<Button variant="outline" size="sm" onClick={handleLogout}>
|
||||
<h1 className="text-xl font-bold text-primary dark:text-primary">Administration</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<ThemeToggle />
|
||||
<Button variant="outline" size="sm" onClick={handleLogout} className="dark:border-gray-700 dark:text-gray-300">
|
||||
<LogOut className="h-4 w-4 mr-2" />
|
||||
Déconnexion
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<main className="max-w-4xl mx-auto px-4 py-6">{children}</main>
|
||||
</div>
|
||||
|
||||
@ -34,9 +34,19 @@ export default function ClientList({ onEdit, onRefresh }: ClientListProps) {
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
setClients(data);
|
||||
} else if (response.status === 404) {
|
||||
// API non disponible (mode statique/APK)
|
||||
// Afficher un message d'information
|
||||
console.warn("API non disponible en mode statique");
|
||||
setClients([]);
|
||||
} else {
|
||||
console.error("Erreur lors du chargement des clients:", response.status);
|
||||
setClients([]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du chargement des clients:", error);
|
||||
// Erreur réseau (API non disponible en mode statique/APK)
|
||||
console.warn("API non disponible (mode statique/APK). Les fonctionnalités admin nécessitent un serveur.");
|
||||
setClients([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@ -73,7 +83,7 @@ export default function ClientList({ onEdit, onRefresh }: ClientListProps) {
|
||||
if (loading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-8">
|
||||
<p className="text-gray-600">Chargement...</p>
|
||||
<p className="text-gray-600 dark:text-gray-400">Chargement...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -81,8 +91,12 @@ export default function ClientList({ onEdit, onRefresh }: ClientListProps) {
|
||||
if (clients.length === 0) {
|
||||
return (
|
||||
<Card>
|
||||
<CardContent className="py-8 text-center">
|
||||
<p className="text-gray-600">Aucun client pour le moment.</p>
|
||||
<CardContent className="py-8 text-center space-y-4">
|
||||
<p className="text-gray-600 dark:text-gray-400">Aucun client pour le moment.</p>
|
||||
<div className="bg-yellow-50 dark:bg-yellow-900/20 border border-yellow-200 dark:border-yellow-800 rounded-xl p-4 text-sm text-yellow-800 dark:text-yellow-300">
|
||||
<p className="font-semibold mb-1">⚠️ Mode hors ligne</p>
|
||||
<p>L'application admin nécessite une connexion au serveur pour fonctionner. Les API routes ne sont pas disponibles en mode statique.</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@ -2,7 +2,7 @@ import TabNavigation from "./TabNavigation";
|
||||
|
||||
export default function Layout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="min-h-screen bg-background pb-16">
|
||||
<div className="min-h-screen bg-background dark:bg-background-dark pb-16">
|
||||
{children}
|
||||
<TabNavigation />
|
||||
</div>
|
||||
|
||||
@ -4,6 +4,7 @@ import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { Home, MapPin, Info, Waves } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ThemeToggle } from "@/components/ThemeToggle";
|
||||
|
||||
const tabs = [
|
||||
{
|
||||
@ -32,7 +33,7 @@ export default function TabNavigation() {
|
||||
const pathname = usePathname();
|
||||
|
||||
return (
|
||||
<nav className="fixed bottom-0 left-0 right-0 z-50 bg-white border-t border-gray-200 shadow-lg">
|
||||
<nav className="fixed bottom-0 left-0 right-0 z-50 bg-white dark:bg-gray-900 border-t border-gray-200 dark:border-gray-800 shadow-lg">
|
||||
<div className="flex items-center justify-around h-16 px-2">
|
||||
{tabs.map((tab) => {
|
||||
const Icon = tab.icon;
|
||||
@ -44,8 +45,8 @@ export default function TabNavigation() {
|
||||
className={cn(
|
||||
"flex flex-col items-center justify-center gap-1 flex-1 h-full rounded-xl transition-colors",
|
||||
isActive
|
||||
? "text-primary bg-secondary"
|
||||
: "text-gray-500 hover:text-primary hover:bg-gray-50"
|
||||
? "text-primary bg-secondary dark:bg-primary/20"
|
||||
: "text-gray-500 dark:text-gray-400 hover:text-primary dark:hover:text-primary hover:bg-gray-50 dark:hover:bg-gray-800"
|
||||
)}
|
||||
>
|
||||
<Icon className="h-6 w-6" />
|
||||
@ -53,6 +54,9 @@ export default function TabNavigation() {
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
<div className="flex items-center justify-center h-full px-2">
|
||||
<ThemeToggle />
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
|
||||
@ -7,10 +7,10 @@ const buttonVariants = cva(
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||
outline: "border-2 border-primary text-primary hover:bg-primary hover:text-white",
|
||||
ghost: "hover:bg-secondary hover:text-secondary-foreground",
|
||||
default: "bg-primary text-primary-foreground hover:bg-primary/90 dark:bg-primary dark:hover:bg-primary/80",
|
||||
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80 dark:bg-primary/20 dark:text-primary dark:hover:bg-primary/30",
|
||||
outline: "border-2 border-primary text-primary hover:bg-primary hover:text-white dark:border-primary dark:text-primary dark:hover:bg-primary dark:hover:text-white",
|
||||
ghost: "hover:bg-secondary hover:text-secondary-foreground dark:hover:bg-gray-800 dark:hover:text-gray-200",
|
||||
},
|
||||
size: {
|
||||
default: "h-12 px-6 py-3",
|
||||
|
||||
@ -8,7 +8,7 @@ const Card = React.forwardRef<
|
||||
<div
|
||||
ref={ref}
|
||||
className={cn(
|
||||
"rounded-2xl border border-gray-200 bg-white shadow-sm",
|
||||
"rounded-2xl border border-gray-200 dark:border-gray-800 bg-white dark:bg-gray-900 shadow-sm",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
@ -46,7 +46,7 @@ const CardDescription = React.forwardRef<
|
||||
>(({ className, ...props }, ref) => (
|
||||
<p
|
||||
ref={ref}
|
||||
className={cn("text-sm text-gray-600", className)}
|
||||
className={cn("text-sm text-gray-600 dark:text-gray-400", className)}
|
||||
{...props}
|
||||
/>
|
||||
));
|
||||
|
||||
BIN
dist/compagnon-admin-debug.apk
vendored
BIN
dist/compagnon-admin-debug.apk
vendored
Binary file not shown.
BIN
dist/compagnon-lagon-beta.apk
vendored
BIN
dist/compagnon-lagon-beta.apk
vendored
Binary file not shown.
@ -2,18 +2,12 @@
|
||||
const nextConfig = {
|
||||
reactStrictMode: true,
|
||||
swcMinify: true,
|
||||
// Mode serveur (pas d'export statique)
|
||||
// Les API routes fonctionnent normalement
|
||||
output: "export",
|
||||
compress: true,
|
||||
poweredByHeader: false,
|
||||
images: {
|
||||
formats: ["image/avif", "image/webp"],
|
||||
minimumCacheTTL: 60,
|
||||
},
|
||||
experimental: {
|
||||
optimizePackageImports: ["lucide-react"],
|
||||
unoptimized: true,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = nextConfig;
|
||||
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
reactStrictMode: true,
|
||||
swcMinify: true,
|
||||
output: "export",
|
||||
compress: true,
|
||||
poweredByHeader: false,
|
||||
images: {
|
||||
unoptimized: true,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = nextConfig;
|
||||
11
package-lock.json
generated
11
package-lock.json
generated
@ -15,6 +15,7 @@
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^0.460.0",
|
||||
"next": "^14.2.33",
|
||||
"next-themes": "^0.4.6",
|
||||
"qrcode.react": "^4.2.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
@ -4757,6 +4758,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/next-themes": {
|
||||
"version": "0.4.6",
|
||||
"resolved": "https://registry.npmjs.org/next-themes/-/next-themes-0.4.6.tgz",
|
||||
"integrity": "sha512-pZvgD5L0IEvX5/9GWyHMf3m8BKiVQwsCMHfoFosXtXBMnaS0ZnIJ9ST4b4NqLVKDEm8QBxoNNGNaBv2JNF6XNA==",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"react": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc",
|
||||
"react-dom": "^16.8 || ^17 || ^18 || ^19 || ^19.0.0-rc"
|
||||
}
|
||||
},
|
||||
"node_modules/next/node_modules/postcss": {
|
||||
"version": "8.4.31",
|
||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
"clsx": "^2.1.1",
|
||||
"lucide-react": "^0.460.0",
|
||||
"next": "^14.2.33",
|
||||
"next-themes": "^0.4.6",
|
||||
"qrcode.react": "^4.2.0",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
|
||||
209
scripts/build-apk-admin.sh
Executable file
209
scripts/build-apk-admin.sh
Executable file
@ -0,0 +1,209 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
echo "🚀 Build APK Admin - Compagnon du Lagon"
|
||||
echo "========================================"
|
||||
echo ""
|
||||
|
||||
# Couleurs pour les messages
|
||||
GREEN='\033[0;32m'
|
||||
BLUE='\033[0;34m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Vérifier qu'on est dans le bon répertoire
|
||||
if [ ! -f "package.json" ]; then
|
||||
echo "❌ Erreur: Exécutez ce script depuis la racine du projet"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Étape 1: Créer la configuration Next.js pour l'export statique
|
||||
echo -e "${BLUE}📦 Étape 1/6: Configuration Next.js pour export statique${NC}"
|
||||
cat > next.config.export.js << 'EOF'
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
reactStrictMode: true,
|
||||
swcMinify: true,
|
||||
output: "export",
|
||||
compress: true,
|
||||
poweredByHeader: false,
|
||||
images: {
|
||||
unoptimized: true,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = nextConfig;
|
||||
EOF
|
||||
|
||||
# Copier la config pour le build
|
||||
cp next.config.export.js next.config.js
|
||||
|
||||
echo -e "${GREEN}✅ Configuration créée${NC}"
|
||||
echo ""
|
||||
|
||||
# Étape 2: Installer les dépendances si nécessaire
|
||||
echo -e "${BLUE}📦 Étape 2/6: Vérification des dépendances${NC}"
|
||||
|
||||
# Vérifier SDKMAN
|
||||
if [ ! -f "$HOME/.sdkman/bin/sdkman-init.sh" ]; then
|
||||
echo "Installation de SDKMAN..."
|
||||
curl -s "https://get.sdkman.io" | bash
|
||||
source "$HOME/.sdkman/bin/sdkman-init.sh"
|
||||
fi
|
||||
|
||||
source "$HOME/.sdkman/bin/sdkman-init.sh" 2>/dev/null || true
|
||||
|
||||
# Vérifier Java 21
|
||||
if ! java -version 2>&1 | grep -q "21"; then
|
||||
echo "Installation de Java 21..."
|
||||
sdk install java 21.0.1-tem
|
||||
sdk use java 21.0.1-tem
|
||||
fi
|
||||
|
||||
# Vérifier Android SDK
|
||||
if [ ! -d "$HOME/Android/Sdk" ]; then
|
||||
echo "Installation d'Android SDK..."
|
||||
mkdir -p "$HOME/Android/Sdk/cmdline-tools"
|
||||
cd "$HOME/Android/Sdk/cmdline-tools"
|
||||
wget -q https://dl.google.com/android/repository/commandlinetools-linux-9477386_latest.zip
|
||||
unzip -q commandlinetools-linux-9477386_latest.zip
|
||||
mv cmdline-tools latest
|
||||
rm commandlinetools-linux-9477386_latest.zip
|
||||
cd -
|
||||
|
||||
export ANDROID_HOME="$HOME/Android/Sdk"
|
||||
export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$PATH"
|
||||
yes | sdkmanager --licenses || true
|
||||
sdkmanager "platform-tools" "platforms;android-34" "build-tools;34.0.0"
|
||||
fi
|
||||
|
||||
if [ ! -d "node_modules" ]; then
|
||||
echo "Installation des dépendances Node.js..."
|
||||
npm install --include=dev
|
||||
else
|
||||
echo "Dépendances Node.js déjà installées"
|
||||
fi
|
||||
|
||||
# Installer Capacitor si nécessaire
|
||||
if ! npm list @capacitor/core > /dev/null 2>&1; then
|
||||
echo "Installation de Capacitor..."
|
||||
npm install @capacitor/core @capacitor/cli @capacitor/android
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✅ Dépendances OK${NC}"
|
||||
echo ""
|
||||
|
||||
# Étape 3: Build Next.js
|
||||
echo -e "${BLUE}📦 Étape 3/6: Build Next.js (export statique)${NC}"
|
||||
rm -rf .next out
|
||||
|
||||
# Exclure temporairement les routes API pour l'export statique
|
||||
if [ -d "app/api" ]; then
|
||||
echo "Exclusion temporaire des routes API..."
|
||||
mv app/api /tmp/api-backup-$$
|
||||
echo -e "${GREEN}✅ Routes API déplacées temporairement${NC}"
|
||||
fi
|
||||
|
||||
if npm run build; then
|
||||
echo -e "${GREEN}✅ Build Next.js réussi${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Build avec avertissements, continuation...${NC}"
|
||||
npm run build -- --no-lint || true
|
||||
fi
|
||||
|
||||
# Restaurer les routes API
|
||||
if [ -d "/tmp/api-backup-$$" ]; then
|
||||
mv /tmp/api-backup-$$ app/api
|
||||
echo -e "${GREEN}✅ Routes API restaurées${NC}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Vérifier que le dossier out existe
|
||||
if [ ! -d "out" ]; then
|
||||
echo "❌ Erreur: Le dossier 'out' n'a pas été créé"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Étape 4: Initialiser/Configurer Capacitor
|
||||
echo -e "${BLUE}📦 Étape 4/6: Configuration Capacitor${NC}"
|
||||
|
||||
# Initialiser Capacitor si nécessaire
|
||||
if [ ! -f "capacitor.config.ts" ]; then
|
||||
echo "Initialisation de Capacitor..."
|
||||
npx cap init "Compagnon Admin" com.pensionmarama.admin --web-dir=out
|
||||
else
|
||||
echo "Capacitor déjà initialisé"
|
||||
# Mettre à jour la config pour pointer vers out
|
||||
cat > capacitor.config.ts << 'EOF'
|
||||
import { CapacitorConfig } from '@capacitor/cli';
|
||||
|
||||
const config: CapacitorConfig = {
|
||||
appId: 'com.pensionmarama.admin',
|
||||
appName: 'Compagnon Admin',
|
||||
webDir: 'out',
|
||||
server: {
|
||||
androidScheme: 'https'
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
EOF
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✅ Capacitor configuré${NC}"
|
||||
echo ""
|
||||
|
||||
# Étape 5: Synchroniser avec Android
|
||||
echo -e "${BLUE}📦 Étape 5/6: Synchronisation Android${NC}"
|
||||
|
||||
# Ajouter Android si nécessaire
|
||||
if [ ! -d "android" ]; then
|
||||
echo "Ajout de la plateforme Android..."
|
||||
npx cap add android
|
||||
fi
|
||||
|
||||
# Synchroniser
|
||||
echo "Synchronisation Capacitor..."
|
||||
npx cap sync android
|
||||
|
||||
echo -e "${GREEN}✅ Android synchronisé${NC}"
|
||||
echo ""
|
||||
|
||||
# Étape 6: Générer l'APK
|
||||
echo -e "${BLUE}📦 Étape 6/6: Génération de l'APK${NC}"
|
||||
|
||||
export ANDROID_HOME="$HOME/Android/Sdk"
|
||||
export PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$PATH"
|
||||
|
||||
cd android
|
||||
./gradlew assembleDebug
|
||||
cd ..
|
||||
|
||||
# Copier l'APK généré
|
||||
if [ -f "android/app/build/outputs/apk/debug/app-debug.apk" ]; then
|
||||
mkdir -p dist
|
||||
cp android/app/build/outputs/apk/debug/app-debug.apk dist/compagnon-admin-debug.apk
|
||||
echo ""
|
||||
echo -e "${GREEN}========================================${NC}"
|
||||
echo -e "${GREEN}✅ APK ADMIN GÉNÉRÉ AVEC SUCCÈS !${NC}"
|
||||
echo -e "${GREEN}========================================${NC}"
|
||||
echo ""
|
||||
echo -e "📱 Fichier: ${BLUE}dist/compagnon-admin-debug.apk${NC}"
|
||||
APK_SIZE=$(du -h dist/compagnon-admin-debug.apk | cut -f1)
|
||||
echo -e "📊 Taille: ${BLUE}${APK_SIZE}${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}📤 Pour distribuer aux administrateurs:${NC}"
|
||||
echo " 1. Envoyez le fichier dist/compagnon-admin-debug.apk"
|
||||
echo " 2. Demandez-leur d'activer 'Sources inconnues'"
|
||||
echo " 3. Installer l'APK sur leur téléphone"
|
||||
echo ""
|
||||
echo -e "${YELLOW}🔄 Pour mettre à jour:${NC}"
|
||||
echo " Relancez simplement ce script !"
|
||||
echo ""
|
||||
else
|
||||
echo "❌ L'APK n'a pas été généré. Vérifiez les erreurs ci-dessus."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -98,12 +98,26 @@ echo ""
|
||||
echo -e "${BLUE}📦 Étape 3/6: Build Next.js (export statique)${NC}"
|
||||
rm -rf .next out
|
||||
|
||||
# Exclure temporairement les routes API pour l'export statique
|
||||
if [ -d "app/api" ]; then
|
||||
echo "Exclusion temporaire des routes API..."
|
||||
mv app/api /tmp/api-backup-$$
|
||||
echo -e "${GREEN}✅ Routes API déplacées temporairement${NC}"
|
||||
fi
|
||||
|
||||
if npm run build; then
|
||||
echo -e "${GREEN}✅ Build Next.js réussi${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Build avec avertissements, continuation...${NC}"
|
||||
npm run build -- --no-lint || true
|
||||
fi
|
||||
|
||||
# Restaurer les routes API
|
||||
if [ -d "/tmp/api-backup-$$" ]; then
|
||||
mv /tmp/api-backup-$$ app/api
|
||||
echo -e "${GREEN}✅ Routes API restaurées${NC}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Vérifier que le dossier out existe
|
||||
|
||||
@ -17,10 +17,20 @@ const config: Config = {
|
||||
secondary: {
|
||||
DEFAULT: "#ECFCCB",
|
||||
foreground: "#0E7490",
|
||||
dark: "#1a3a2e",
|
||||
},
|
||||
background: {
|
||||
DEFAULT: "#FAFAFA",
|
||||
dark: "#0f172a",
|
||||
},
|
||||
foreground: {
|
||||
DEFAULT: "#1f2937",
|
||||
dark: "#f1f5f9",
|
||||
},
|
||||
border: {
|
||||
DEFAULT: "#e5e7eb",
|
||||
dark: "#334155",
|
||||
},
|
||||
background: "#FAFAFA",
|
||||
foreground: "#1f2937",
|
||||
border: "#e5e7eb",
|
||||
},
|
||||
borderRadius: {
|
||||
xl: "1rem",
|
||||
|
||||
Reference in New Issue
Block a user