import React, { useState } from 'react'; import { Send, LogOut, ThumbsUp } from 'lucide-react'; interface EntryData { date: string; kilos: number; ferme: 'H1' | 'H2'; utilisateur: 'Nordin' | 'Saad'; } function App() { const [codeInvitation, setCodeInvitation] = useState(''); const [isCodeValid, setIsCodeValid] = useState(false); const [entries, setEntries] = useState([]); const [currentEntry, setCurrentEntry] = useState({ date: '', kilos: 0, ferme: 'H1', utilisateur: 'Nordin' }); const [showThankYou, setShowThankYou] = useState(false); const handleCodeSubmit = (e: React.FormEvent) => { e.preventDefault(); setIsCodeValid(codeInvitation === '1537y'); }; const handleDisconnect = () => { setShowThankYou(true); }; const handleFinalDisconnect = () => { setIsCodeValid(false); setCodeInvitation(''); setEntries([]); setCurrentEntry({ date: '', kilos: 0, ferme: 'H1', utilisateur: 'Nordin' }); setShowThankYou(false); }; const handleEntrySubmit = async (e: React.FormEvent) => { e.preventDefault(); const newEntries = [...entries, currentEntry]; setEntries(newEntries); // Calculate totals by farm const totalH1 = newEntries .filter(entry => entry.ferme === 'H1') .reduce((sum, entry) => sum + entry.kilos, 0); const totalH2 = newEntries .filter(entry => entry.ferme === 'H2') .reduce((sum, entry) => sum + entry.kilos, 0); // Send email try { await fetch('https://api.emailjs.com/api/v1.0/email/send', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ to_email: 'yassirerraoui80@gmail.com', subject: 'Nouvelles données enregistrées', message: ` Nouvelle entrée: Date: ${currentEntry.date} Kilos: ${currentEntry.kilos} Ferme: ${currentEntry.ferme} Utilisateur: ${currentEntry.utilisateur} Total H1: ${totalH1} kg Total H2: ${totalH2} kg ` }) }); setCurrentEntry({ date: '', kilos: 0, ferme: 'H1', utilisateur: 'Nordin' }); // Check if user has made 7 entries if (newEntries.length >= 7) { setTimeout(() => { handleDisconnect(); }, 1000); } } catch (error) { console.error('Erreur d\'envoi d\'email:', error); } }; if (showThankYou) { const totalH1 = entries .filter(entry => entry.ferme === 'H1') .reduce((sum, entry) => sum + entry.kilos, 0); const totalH2 = entries .filter(entry => entry.ferme === 'H2') .reduce((sum, entry) => sum + entry.kilos, 0); return (

au cas où tu veux changer les infos, merci de demander Rabab Merkazi !

Voici le résumé de vos entrées :

Ferme H1

{totalH1} kg

Ferme H2

{totalH2} kg

); } if (!isCodeValid) { return (

Système de Gestion

setCodeInvitation(e.target.value)} className="w-full p-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-transparent" placeholder="Entrez le code" />
{codeInvitation && codeInvitation !== '1537y' && (

Code incorrect

)}
); } return (

Système de Gestion des Données

setCurrentEntry({...currentEntry, date: e.target.value})} className="w-full p-2 border border-gray-300 rounded-md" required />
setCurrentEntry({...currentEntry, kilos: Number(e.target.value)})} className="w-full p-2 border border-gray-300 rounded-md" required />
{entries.length > 0 && (
{entries.map((entry, index) => ( ))}
Date Kilos Ferme Utilisateur
{entry.date} {entry.kilos} {entry.ferme} {entry.utilisateur}
Total H1 {entries .filter(entry => entry.ferme === 'H1') .reduce((sum, entry) => sum + entry.kilos, 0)} kg
Total H2 {entries .filter(entry => entry.ferme === 'H2') .reduce((sum, entry) => sum + entry.kilos, 0)} kg
)} {entries.length >= 7 && (

Vous avez atteint la limite de 7 entrées. Vous allez être déconnecté automatiquement.

)}
); } export default App;