From f9c5202f6bfa5780f6a320a027b6ed209c835168 Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Mon, 17 Apr 2023 22:41:54 +0400 Subject: [PATCH] =?UTF-8?q?Lab=204=20-=20=D0=B4=D0=BE=D0=BF.=D0=B7=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/components/Catalog.jsx | 6 ++++++ front/src/components/DrivingSchools.jsx | 13 +++++++------ front/src/components/commons/ItemTable.jsx | 4 ++++ front/src/components/commons/Table.jsx | 7 ++++++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/front/src/components/Catalog.jsx b/front/src/components/Catalog.jsx index 45a1807..6c1aec3 100644 --- a/front/src/components/Catalog.jsx +++ b/front/src/components/Catalog.jsx @@ -17,6 +17,11 @@ export default function Catalog(props) { handleShow(); } + function handleChoose(itemId) { + setModalTitle("Выбрать"); + props.onChoose(itemId); + handleShow(); + } function handleEdit(itemId) { setModalTitle("Редактирование"); props.onEdit(itemId); @@ -35,6 +40,7 @@ export default function Catalog(props) { diff --git a/front/src/components/DrivingSchools.jsx b/front/src/components/DrivingSchools.jsx index 9307bd8..7f662fc 100644 --- a/front/src/components/DrivingSchools.jsx +++ b/front/src/components/DrivingSchools.jsx @@ -27,6 +27,8 @@ export default function DrivingSchools(props) { loadItems(); }, []); + const [selectedId, setSelectedId] = useState(null); + function loadItems() { DataService.readAll(url, (data) => new DrivingSchool(data)) .then(data => setItems(data)); @@ -127,15 +129,13 @@ export default function DrivingSchools(props) { } const [chosenDrivingSchool, setChosenDrivingSchool] = useState(0); const navigate = useNavigate(); - function redirectToDrivingSchool() { - - if (chosenDrivingSchool !== 0) { - navigate(`/drivingSchool/${chosenDrivingSchool}`); - } + + function redirectToDrivingSchool(item) { + setSelectedId(item); + navigate(`/drivingSchool/${item}`); } return
- diff --git a/front/src/components/commons/ItemTable.jsx b/front/src/components/commons/ItemTable.jsx index 997d40e..307c6f4 100644 --- a/front/src/components/commons/ItemTable.jsx +++ b/front/src/components/commons/ItemTable.jsx @@ -6,12 +6,16 @@ export default function ItemTable(props) { function remove() { props.onDelete(props.item.id); } + function chooseDrivingSchool() { + props.onChoose(props.item.id); + } return
{ props.headers.map((header) => ) } {props.isOnlyView || } diff --git a/front/src/components/commons/Table.jsx b/front/src/components/commons/Table.jsx index 2be8fc5..0b990d7 100644 --- a/front/src/components/commons/Table.jsx +++ b/front/src/components/commons/Table.jsx @@ -6,6 +6,10 @@ export default function Table(props) { function remove(itemId) { props.onDelete(itemId); } + function chooseDrivingSchool(itemId) { + props.onChoose(itemId); + } + return
{props.item[header.name]} +
@@ -25,7 +29,8 @@ export default function Table(props) { headers={props.headers} item={item} onDelete={remove} - onEdit={edit} + onEdit={edit} + onChoose={chooseDrivingSchool} isOnlyView={props.isOnlyView}/>) }