import { Card, NumberInput, Text, UnstyledButton } from "@mantine/core"; import { IconCancel, IconCheck, IconPencil, IconTrash, } from "@tabler/icons-react"; import { useState, type MouseEvent } from "react"; import { notifications } from "@mantine/notifications"; import type { SystemTeamData, SystemWithTeams } from "Types/Machine/Machine"; import { giveSystemToTeam, removeSystemFromTeam, } from "Api/QuantumBackend/MachineManagment"; import { useDeviceStore } from "Stores/DeviceStore"; function TeamInMachineListCard(props: { team: SystemTeamData; system: SystemWithTeams; }) { const [isEditing, setIsEditing] = useState(false); const { updateDevice } = useDeviceStore(); const [count, setCount] = useState(props.team.num_qubits); const handleRemovePerm = () => { // TODO: fix delete removeSystemFromTeam({ team_id: props.team.team.team_id, system_id: props.system.system.id, }) .then(() => { updateDevice(props.system.system.id, { teams: props.system.teams.filter( (team) => team.team.team_id != props.team.team.team_id, ), }); notifications.show({ radius: "md", title: "Команда удалена успешно", message: "", icon: , style: { paddingLeft: "5px" }, }); }) .catch(() => { notifications.show({ radius: "md", color: "red", title: "Не удалось удалить команду", message: "", icon: , style: { paddingLeft: "5px" }, }); }); }; return ( Команда: {props.team.team.team_name} #{props.team.team.team_id} {isEditing && ( <> Количество кубит: { setCount(Number(ev.valueOf())); }} > { giveSystemToTeam({ system_id: props.system.system.id, team_id: props.team.team.team_id, qubits_given: count, }).then(() => { const team = props.system.teams.find((t) => { return t.team.team_id == props.team.team.team_id; }); if (team) { const updatedItem = { ...team, num_qubits: count }; // Create new array with the updated item in the same position const updatedItems = props.system.teams.map( (currentItem) => currentItem.team.team_id === team.team.team_id ? updatedItem : currentItem, ); updateDevice(props.system.system.id, { teams: updatedItems, }); } setIsEditing(false); }); }} > { setCount(props.team.num_qubits); setIsEditing(false); }} > > )} {!isEditing && ( <> Количество кубит: {count} { setIsEditing(true); }} > > )} {new Date(props.team.created_at + "Z").toLocaleDateString( "ru", )}{" "} {new Date(props.team.created_at + "Z").toLocaleTimeString("ru")} { e.stopPropagation(); handleRemovePerm(); }} style={{ cursor: "pointer" }} > ); } export default TeamInMachineListCard;