import { Github, Loader2, Save } 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"; export default function BJRepas() { const credentials = getSavedCredentials(); const [username, setUsername] = useState(credentials?.username || ""); const [password, setPassword] = useState(credentials?.password || ""); 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); } // 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 (
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.
Pour en savoir plus sur la sécurité et la confidentialité, consultez le code source du projet.{" "}