diff --git a/app/components/repas/credentials.tsx b/app/components/repas/credentials.tsx index 5d4fd7e..696c120 100644 --- a/app/components/repas/credentials.tsx +++ b/app/components/repas/credentials.tsx @@ -1,157 +1,47 @@ -import { Github, Loader2, Save } from "lucide-react"; +import { Utensils } from "lucide-react"; import { Button } from "../ui/button"; import { Card } from "../ui/card"; -import { Input } from "../ui/input"; -import { Label } from "../ui/label"; -import { Link } from "react-router"; -import { getCredentialsStatus, testCredentials } from "~/lib/api"; -import { useState } from "react"; -import { toast } from "sonner"; -import MealRegistration from "./registration"; export default function BJRepas() { - const credentials = getSavedCredentials(); - - if (credentials) { - return ; - } - - const [username, setUsername] = useState(""); - const [password, setPassword] = useState(""); - - let intervalId: NodeJS.Timeout | null = null; - const [isLoading, setLoading] = useState(false); - - const handleSaveCredentials = async () => { - try { - if (!username || !password) { - toast.error( - "Veuillez renseigner vos identifiants BJColle avant de continuer." - ); - return; - } - - await testCredentials(username, password); - setLoading(true); - - // Try every second to check if the credentials are valid - intervalId = setInterval(async () => { - try { - const res = await getCredentialsStatus(); - - // Credentials are valid - if (res.authenticated === "SUCCESS") { - saveCredentials(username, password); - toast.success("Vos identifiants ont été enregistrés avec succès."); - setLoading(false); - if (intervalId) clearInterval(intervalId); - // Reload the page to reflect the changes - window.location.reload(); - } - // Credentials are invalid - if (res.authenticated === "ERROR") { - toast.error( - "Identifiants invalides. Veuillez vérifier votre nom d'utilisateur et mot de passe." - ); - setUsername(""); - setPassword(""); - setLoading(false); - if (intervalId) clearInterval(intervalId); - } - } catch (error) { - console.error("Error testing credentials:", error); - } - }, 1000); - } catch (error) { - console.error("Error testing credentials:", error); - toast.error( - "Une erreur est survenue lors de la validation des identifiants. Veuillez réessayer plus tard." - ); - } - }; - return (

Inscription aux repas

-

- Pour vous inscrire aux repas (via BJ Repas), veuillez renseigner vos - identifiants BJColle ci-dessous. -

-

- Vos identifiants sont enregistrés localement sur votre appareil et ne - sont jamais stockés sur nos serveurs. -

+ +
+
+ +
+ +
+

+ L'inscription aux repas est désactivée +

+

+ Afin de réduire le gaspillage alimentaire à la cantine, veuillez + vous inscrire directement sur BJColle pour indiquer les jours où + vous mangerez au restaurant scolaire. +

+
- -
-

Vos identifiants BJColle

-
- - setUsername(e.target.value)} - placeholder="Entrez votre nom d'utilisateur" - className="mt-1" - /> -
-
- - setPassword(e.target.value)} - placeholder="Entrez votre mot de passe" - className="mt-1" - /> -
-
-
-

- Pour en savoir plus sur la sécurité et la confidentialité, consultez - le code source du projet.{" "} -

- - - -
+ +

+ Merci de votre participation pour limiter le gaspillage alimentaire. +

); -} - -const saveCredentials = (username: string, password: string) => { - localStorage.setItem("bj_username", username); - localStorage.setItem("bj_password", password); -}; -export const getSavedCredentials = () => { - const username = localStorage.getItem("bj_username"); - const password = localStorage.getItem("bj_password"); - if (username && password) { - return { username, password }; - } - return null; -}; +} \ No newline at end of file