cal.pub0.org/components/team/TeamList.tsx

42 lines
970 B
TypeScript
Raw Normal View History

import { Team } from "@lib/team";
import TeamListItem from "./TeamListItem";
export default function TeamList(props: {
teams: Team[];
onChange: () => void;
onEditTeam: (text: Team) => void;
}) {
const selectAction = (action: string, team: Team) => {
switch (action) {
case "edit":
props.onEditTeam(team);
break;
case "disband":
deleteTeam(team);
break;
}
};
2021-09-29 17:04:47 +00:00
const deleteTeam = async (team: Team) => {
await fetch("/api/teams/" + team.id, {
method: "DELETE",
2021-09-29 17:04:47 +00:00
});
return props.onChange();
};
return (
<div>
<ul className="px-4 mb-2 bg-white border divide-y divide-gray-200 rounded">
{props.teams.map((team: Team) => (
<TeamListItem
onChange={props.onChange}
key={team.id}
team={team}
onActionSelect={(action: string) => selectAction(action, team)}></TeamListItem>
))}
</ul>
</div>
);
2021-07-30 23:05:38 +00:00
}