import React, { useState } from 'react' import { DragDropContext, Draggable, Droppable } from '@hello-pangea/dnd'; import useAdmin from '@/hook/useAdmin'; function reorder(list, startIndex, endIndex) { const result = Array.from(list); const [removed] = result.splice(startIndex, 1); result.splice(endIndex, 0, removed); return result; }; function TeamListItem({ team, index }) { const { removeTeam } = useAdmin(); function handleRemove() { removeTeam(team.id); } return ( onSelected(team.id)}> {provided => (

{team.name}

{String(team.id).padStart(6, '0').replace(/(\d{3})(\d{3})/, "$1 $2")}

)}
); } export default function TeamList() { const { teams, reorderTeams, addTeam } = useAdmin(); const [teamName, setTeamName] = useState(''); function handleSubmit(e) { e.preventDefault(); if (teamName !== "") { addTeam(teamName); setTeamName("") } } function onDragEnd(result) { if (!result.destination) return; if (result.destination.index === result.source.index) return; const newTeams = reorder(teams, result.source.index, result.destination.index); reorderTeams(newTeams); } return (
setTeamName(e.target.value)} type="text" className="w-full h-full p-4 ring-1 ring-inset ring-gray-300" />
{provided => (
    {teams.map((team, i) => (
  • ))} {provided.placeholder}
)}
); }