Lab 4 - доп.задание

This commit is contained in:
AnnZhimol 2023-04-17 22:41:54 +04:00
parent f024215f82
commit f9c5202f6b
4 changed files with 23 additions and 7 deletions

View File

@ -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) {
<Table
headers={props.headers}
items={props.items}
onChoose={handleChoose}
onEdit={handleEdit}
onDelete={handleRemove}
/>

View File

@ -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 <div className="container-lg pt-5 min-vh-100">
<Button onClick={showModalFormChoosing} variant="info">Перейти к автошколе</Button>
<ModalForm show={showModalForm} onClose={unshowModalFormChoosing} modalTitle={"Выбор автошколы"} form={formChooseDrivingSchool}></ModalForm>
<Catalog name={nameCatalog}
headers={headers}
@ -143,6 +143,7 @@ export default function DrivingSchools(props) {
onAdd={handleAdd}
onEdit={handleEdit}
onDelete={handleDelete}
onChoose={redirectToDrivingSchool}
onClose={reset}
onBtnAdd={reset}
form={form}>

View File

@ -6,12 +6,16 @@ export default function ItemTable(props) {
function remove() {
props.onDelete(props.item.id);
}
function chooseDrivingSchool() {
props.onChoose(props.item.id);
}
return <tr key={props.item.id}>
{
props.headers.map((header) => <td key={`${header.name}_${props.item.id}`}>{props.item[header.name]}</td>)
}
{props.isOnlyView || <td key={`controls_${props.item.id}`}>
<Button variant="btn btn-outline-warning" onClick={chooseDrivingSchool}>Выбрать</Button>
<Button variant="btn btn-outline-primary" onClick={edit}>Редактировать</Button>
<Button variant="btn btn-outline-danger" onClick={remove}>Удалить</Button></td>}
</tr>

View File

@ -6,6 +6,10 @@ export default function Table(props) {
function remove(itemId) {
props.onDelete(itemId);
}
function chooseDrivingSchool(itemId) {
props.onChoose(itemId);
}
return <div >
<table className={`table table-hover`}>
<thead>
@ -26,6 +30,7 @@ export default function Table(props) {
item={item}
onDelete={remove}
onEdit={edit}
onChoose={chooseDrivingSchool}
isOnlyView={props.isOnlyView}/>)
}
</tbody>