58 lines
1.2 KiB
TypeScript
58 lines
1.2 KiB
TypeScript
import type { ButtonProps } from '@mui/material';
|
||
import type { FC, Ref } from 'react';
|
||
|
||
import { Button } from '@mui/material';
|
||
|
||
import type { CashItem } from '@/entity/cash';
|
||
|
||
import { EditCashForm } from '@/entity/cash';
|
||
import { DataTestId } from '@/shared/constants';
|
||
import { Modal } from '@/shared/ui/Modal';
|
||
|
||
import { useEditCashButton } from '../hooks/useEditCashButton';
|
||
|
||
export type EditCashButtonProps = ButtonProps & {
|
||
cash: CashItem;
|
||
ref?: Ref<HTMLButtonElement>;
|
||
};
|
||
const EditCashButton: FC<EditCashButtonProps> = (props) => {
|
||
const {
|
||
cash,
|
||
onClick,
|
||
ref,
|
||
...restProps
|
||
} = props;
|
||
|
||
const {
|
||
isOpen,
|
||
isPending,
|
||
onClickHandler,
|
||
onCloseModalHandler,
|
||
onFormSubmitHandler,
|
||
} = useEditCashButton({ cash });
|
||
|
||
return (
|
||
<>
|
||
<Button
|
||
data-testid={DataTestId.EDIT_CASH_BUTTON}
|
||
onClick={onClickHandler}
|
||
ref={ref}
|
||
size="small"
|
||
{...restProps}
|
||
>
|
||
Редактировать
|
||
</Button>
|
||
|
||
<Modal onClose={onCloseModalHandler} open={isOpen}>
|
||
<EditCashForm
|
||
cash={cash}
|
||
disabled={isPending}
|
||
onSubmit={onFormSubmitHandler}
|
||
/>
|
||
</Modal>
|
||
</>
|
||
);
|
||
};
|
||
|
||
export default EditCashButton;
|