Simplification complète de l'app - Suppression admin/WiFi/bungalow
- Suppression de toute la partie admin (routes, composants, API) - Suppression du WiFi et du numéro de bungalow - Simplification de l'accueil (logo, météo, message statique) - App 100% statique maintenant - Redirection simple vers /accueil - Nettoyage des hooks et types inutilisés
This commit is contained in:
@ -1,15 +0,0 @@
|
||||
export function verifyAdminPassword(password: string): boolean {
|
||||
const adminPassword = process.env.ADMIN_PASSWORD || "admin123";
|
||||
return password === adminPassword;
|
||||
}
|
||||
|
||||
export function requireAdminAuth(request: Request): boolean {
|
||||
const authHeader = request.headers.get("authorization");
|
||||
if (!authHeader) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const token = authHeader.replace("Bearer ", "");
|
||||
return verifyAdminPassword(token);
|
||||
}
|
||||
|
||||
@ -1,101 +0,0 @@
|
||||
import { randomBytes } from "crypto";
|
||||
import { Client, ClientInput } from "@/lib/types/client";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { join } from "path";
|
||||
|
||||
const CLIENTS_FILE = join(process.cwd(), "lib/data/clients.json");
|
||||
|
||||
export function generateToken(): string {
|
||||
return randomBytes(32).toString("hex");
|
||||
}
|
||||
|
||||
export function validateEmail(email: string): boolean {
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
return emailRegex.test(email);
|
||||
}
|
||||
|
||||
export function loadClients(): Client[] {
|
||||
try {
|
||||
const data = readFileSync(CLIENTS_FILE, "utf-8");
|
||||
return JSON.parse(data);
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function saveClients(clients: Client[]): void {
|
||||
try {
|
||||
writeFileSync(CLIENTS_FILE, JSON.stringify(clients, null, 2), "utf-8");
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la sauvegarde des clients:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export function createClient(input: ClientInput): Client {
|
||||
const clients = loadClients();
|
||||
|
||||
// Vérifier si l'email existe déjà
|
||||
if (clients.some((c) => c.email === input.email)) {
|
||||
throw new Error("Un client avec cet email existe déjà");
|
||||
}
|
||||
|
||||
const now = new Date().toISOString();
|
||||
const client: Client = {
|
||||
id: `client-${Date.now()}`,
|
||||
email: input.email,
|
||||
token: generateToken(),
|
||||
bungalowNumber: input.bungalowNumber,
|
||||
wifiName: input.wifiName,
|
||||
wifiPassword: input.wifiPassword,
|
||||
gerantMessage: input.gerantMessage,
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
};
|
||||
|
||||
clients.push(client);
|
||||
saveClients(clients);
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
export function getClientByToken(token: string): Client | null {
|
||||
const clients = loadClients();
|
||||
return clients.find((c) => c.token === token) || null;
|
||||
}
|
||||
|
||||
export function getClientByEmail(email: string): Client | null {
|
||||
const clients = loadClients();
|
||||
return clients.find((c) => c.email === email) || null;
|
||||
}
|
||||
|
||||
export function updateClient(id: string, input: Partial<ClientInput>): Client | null {
|
||||
const clients = loadClients();
|
||||
const index = clients.findIndex((c) => c.id === id);
|
||||
|
||||
if (index === -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
clients[index] = {
|
||||
...clients[index],
|
||||
...input,
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
|
||||
saveClients(clients);
|
||||
return clients[index];
|
||||
}
|
||||
|
||||
export function deleteClient(id: string): boolean {
|
||||
const clients = loadClients();
|
||||
const filtered = clients.filter((c) => c.id !== id);
|
||||
|
||||
if (filtered.length === clients.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
saveClients(filtered);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
export const config = {
|
||||
bungalowNumber: process.env.NEXT_PUBLIC_BUNGALOW_NUMBER || "1",
|
||||
wifiName: process.env.NEXT_PUBLIC_WIFI_NAME || "Lagon-WiFi",
|
||||
wifiPassword: process.env.NEXT_PUBLIC_WIFI_PASSWORD || "motdepasse123",
|
||||
gerantMessage: process.env.NEXT_PUBLIC_GERANT_MESSAGE || "Bienvenue dans notre pension de famille !",
|
||||
gerantMessage: process.env.NEXT_PUBLIC_GERANT_MESSAGE || "Bienvenue dans notre pension de famille ! Nous espérons que vous passerez un séjour inoubliable à Fakarava.",
|
||||
contact: {
|
||||
email: process.env.NEXT_PUBLIC_CONTACT_EMAIL || undefined,
|
||||
phone: process.env.NEXT_PUBLIC_CONTACT_PHONE || undefined,
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
[
|
||||
{
|
||||
"id": "client-1763884046464",
|
||||
"email": "sylvestre@anuanua.fr",
|
||||
"token": "017e529de30383c9dba62705fc92df7062f1bcc8872985bc55a8f7dcb7407bd4",
|
||||
"bungalowNumber": "4",
|
||||
"wifiName": "Lagon-WiFi",
|
||||
"wifiPassword": "le motepasseduwifi987",
|
||||
"gerantMessage": "Bienvenue dans notre pension de famille !",
|
||||
"createdAt": "2025-11-23T07:47:26.464Z",
|
||||
"updatedAt": "2025-11-23T07:47:26.464Z"
|
||||
}
|
||||
]
|
||||
@ -1,110 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { config } from "@/lib/config";
|
||||
|
||||
export interface ClientData {
|
||||
bungalowNumber: string;
|
||||
wifiName: string;
|
||||
wifiPassword: string;
|
||||
gerantMessage: string;
|
||||
}
|
||||
|
||||
const STORAGE_KEY = "clientData";
|
||||
|
||||
function loadFromStorage(): ClientData | null {
|
||||
if (typeof window === "undefined") return null;
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
if (stored) {
|
||||
return JSON.parse(stored);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du chargement depuis localStorage:", error);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function useClientData() {
|
||||
// Utiliser window.location pour l'export statique (compatible)
|
||||
const [token, setToken] = useState<string | null>(null);
|
||||
// Charger immédiatement depuis localStorage pour éviter le délai
|
||||
const [clientData, setClientData] = useState<ClientData | null>(() => loadFromStorage());
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
// Récupérer le token depuis l'URL (compatible export statique)
|
||||
if (typeof window !== "undefined") {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
setToken(urlParams.get("token"));
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (token === null && typeof window !== "undefined") {
|
||||
// Attendre que le token soit récupéré
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
setToken(urlParams.get("token"));
|
||||
return;
|
||||
}
|
||||
|
||||
const loadClientData = async () => {
|
||||
// 1. Charger d'abord depuis localStorage pour un affichage immédiat
|
||||
const storedData = loadFromStorage();
|
||||
if (storedData) {
|
||||
setClientData(storedData);
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
// 2. Vérifier s'il y a un token dans l'URL
|
||||
|
||||
if (token) {
|
||||
try {
|
||||
// 3. Charger les données depuis l'API pour mettre à jour
|
||||
const response = await fetch(`/api/client/${token}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
const clientInfo: ClientData = {
|
||||
bungalowNumber: data.bungalowNumber,
|
||||
wifiName: data.wifiName,
|
||||
wifiPassword: data.wifiPassword,
|
||||
gerantMessage: data.gerantMessage,
|
||||
};
|
||||
|
||||
// 4. Sauvegarder dans localStorage
|
||||
if (typeof window !== "undefined") {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(clientInfo));
|
||||
}
|
||||
setClientData(clientInfo);
|
||||
} else {
|
||||
// Token invalide, garder les données sauvegardées si disponibles
|
||||
if (!storedData) {
|
||||
setClientData(null);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du chargement des données client:", error);
|
||||
// En cas d'erreur, garder les données sauvegardées si disponibles
|
||||
if (!storedData) {
|
||||
setClientData(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
loadClientData();
|
||||
}, [token]);
|
||||
|
||||
// Retourner les données client ou les valeurs par défaut
|
||||
return useMemo(() => ({
|
||||
bungalowNumber: clientData?.bungalowNumber || config.bungalowNumber,
|
||||
wifiName: clientData?.wifiName || config.wifiName,
|
||||
wifiPassword: clientData?.wifiPassword || config.wifiPassword,
|
||||
gerantMessage: clientData?.gerantMessage || config.gerantMessage,
|
||||
loading,
|
||||
}), [clientData, loading]);
|
||||
}
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
export interface Client {
|
||||
id: string;
|
||||
email: string;
|
||||
token: string;
|
||||
bungalowNumber: string;
|
||||
wifiName: string;
|
||||
wifiPassword: string;
|
||||
gerantMessage: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export interface ClientInput {
|
||||
email: string;
|
||||
bungalowNumber: string;
|
||||
wifiName: string;
|
||||
wifiPassword: string;
|
||||
gerantMessage: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user