import { Autocomplete, Box, Divider, FormControl, IconButton, Stack, TextField } from '@mui/material'; import { memo, useEffect, useState } from 'react'; import { toast } from 'react-toastify'; import { ExpenseItemApi } from '../../../api/expense-item'; import { DangerOutlinedButton, PrimaryButton } from '../../common/Buttons/Buttons'; import { HeaderContainer, ModalBackdrop, ModalContainer, ModalTitle } from '../../common/Modal/ModalStyled'; import { Cancel } from '../../common/icons/icons'; import { compareExpenseItems, getExpenseItemLabel } from '../utils/expenseItemOptions'; const SelectExpenseItemModalComponent = ({ isOpen, onClose, onSelect, formId, title = '', isSaving = false, sheet }) => { const [selectedValue, setSelectedValue] = useState(''); const [expenseItemOptions, setExpenseItemOption] = useState([]); useEffect(() => { if (!isOpen || formId == null) return; ExpenseItemApi.getAll({ r_start: true, sheet: sheet }).then((data) => { if (data.success) { setExpenseItemOption([...data.result].sort(compareExpenseItems)); return; } toast.error('Ошибка получения статья расходов'); }); }, [formId, isOpen, sheet]); useEffect(() => { if (!isOpen) { setSelectedValue(''); } }, [isOpen]); const handleCancel = () => { setSelectedValue(''); onClose(); }; const handleBackdropClick = (e) => { if (e.target === e.currentTarget) { handleCancel(); } }; const handleSave = () => { onSelect?.(selectedValue); onClose(); }; const isFormValid = selectedValue; if (!isOpen) return null; return ( {title} {/* Выбор ВСП */} option.id} value={selectedValue} onChange={(_event, newValue) => { setSelectedValue(newValue); }} slotProps={{ popper: { style: { zIndex: 60 }, }, }} renderInput={(params) => ( )} /> Отмена Выбрать ); }; export const SelectExpenseItemModal = memo(SelectExpenseItemModalComponent);