Add user form and fix bug

This commit is contained in:
2023-10-27 09:36:57 +07:00
parent 44e0d76e33
commit dfd6582f94
5 changed files with 261 additions and 11 deletions
@@ -0,0 +1,39 @@
import { forwardRef, useEffect } from 'react';
// Components
import Dialog from '../../components/Dialog';
import UserForm from './Form';
// Interfaces
import { IDialogProps } from '../../globals/interfaces';
const UserDialog = forwardRef((props, ref) => {
const dialogRef = ref as React.MutableRefObject<
HTMLDialogElement | undefined
>;
const { onClose } = props;
useEffect(() => {
if (dialogRef.current) {
dialogRef.current.addEventListener('click', (e: MouseEvent) => {
const dialogDimensions = dialogRef.current!.getBoundingClientRect();
if (
e.clientX < dialogDimensions.left ||
e.clientX > dialogDimensions.right ||
e.clientY < dialogDimensions.top ||
e.clientY > dialogDimensions.bottom
) {
dialogRef.current!.close();
}
});
}
});
return (
<Dialog title={'Add user'} onClose={onClose} ref={dialogRef}>
<UserForm onClose={onClose!} />
</Dialog>
);
}) as React.FC<IDialogProps>;
export default UserDialog;