import { useContext, useEffect, useState } from "react"; import { AuthContext } from "../../../../contexts/Auth/AuthContext"; import { EventDetailContext } from "../../../../contexts/EventDetail/EventDetailContext"; import Button from "../../../../components/ui/Button/Button"; import Modal from "../../../../components/ui/Modal/Modal"; import TextInput from "../../../../components/ui/Input/Input"; import styles from "../../EventDetailPage.module.css"; import updateTask from "../../../../utils/tasks/updateTask"; type EditTaskBtnProps = { taskId: number; eventId: number | string; }; export default function EditTaskBtn({ taskId, eventId }: EditTaskBtnProps) { const { user } = useContext(AuthContext) as any; const { tasks, updateEventInfo } = useContext(EventDetailContext) as any; const task = tasks?.find((t: any) => t.id === taskId); const [open, setOpen] = useState(false); const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [start, setStart] = useState(""); const [end, setEnd] = useState(""); const [location, setLocation] = useState(""); const [maxParticipants, setMaxParticipants] = useState(""); useEffect(() => { if (open && task) { setName(task.name ?? ""); setDescription(task.description ?? ""); setStart(task.start ? task.start.slice(0, 16) : ""); setEnd(task.end ? task.end.slice(0, 16) : ""); setLocation(task.location ?? ""); setMaxParticipants(task.max_participants?.toString() ?? ""); } }, [open, task]); if (!user?.isAdmin) return null; const handleSubmit = async () => { await updateTask(taskId, { name, description, start, end, location, max_participants: Number(maxParticipants), }); await updateEventInfo(eventId); setOpen(false); }; return ( <> setOpen(false)} title={"Modifier la tâche"}>

Nom

setName(e.target.value)} placeholder="Nom de la tâche" />

Description

setDescription(e.target.value)} placeholder="Description" />

Lieu

setLocation(e.target.value)} placeholder="Lieu" />

Participants max

setMaxParticipants(e.target.value)} placeholder="Participants max" />

Début

setStart(e.target.value)} />

Fin

setEnd(e.target.value)} />
); }