42 lines
946 B
TypeScript
42 lines
946 B
TypeScript
import type { ButtonHTMLAttributes, FC, Ref } from 'react';
|
||
|
||
import { AddCashForm } from '@/entity/cash';
|
||
import { Modal } from '@/shared/ui/Modal';
|
||
|
||
import { useAddCashButton } from '../hooks/useAddCashButton';
|
||
|
||
type AddCashButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
|
||
ref?: Ref<HTMLButtonElement>;
|
||
};
|
||
|
||
const AddCashButton: FC<AddCashButtonProps> = (props) => {
|
||
const { onClick, ref, ...restProps } = props;
|
||
|
||
const {
|
||
isOpen,
|
||
isPending,
|
||
onClickHandler,
|
||
onCloseModalHandler,
|
||
onFormSubmitHandler,
|
||
} = useAddCashButton({ onClick });
|
||
|
||
return (
|
||
<>
|
||
<button
|
||
onClick={onClickHandler}
|
||
ref={ref}
|
||
type="button"
|
||
{...restProps}
|
||
>
|
||
Добавить
|
||
</button>
|
||
|
||
<Modal onClose={onCloseModalHandler} open={isOpen}>
|
||
<AddCashForm disabled={isPending} onSubmit={onFormSubmitHandler} />
|
||
</Modal>
|
||
</>
|
||
);
|
||
};
|
||
|
||
export default AddCashButton;
|