File tree Expand file tree Collapse file tree 2 files changed +18
-12
lines changed
Expand file tree Collapse file tree 2 files changed +18
-12
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { IconButton } from "@mui/material"
44import { Close } from "@mui/icons-material"
55import { NewOwnerDto } from "@/generated/owners.ts"
66import { useForm } from "react-hook-form"
7+ import { addConfirmationNotification } from "@/shared/utils/utils.ts"
78
89type TProps = {
910 onClose : ( ) => void
@@ -19,17 +20,32 @@ export const CreateNewClientModal = ({
1920 const form = useForm < NewOwnerDto > ( {
2021 mode : "all" ,
2122 } )
23+ const confirmationNotification = addConfirmationNotification ( )
24+
25+ const onCloseAndReset = ( ) => {
26+ onClose ( )
27+ form . reset ( )
28+ }
29+
30+ const handleCloseModal = ( ) => {
31+ if ( form . formState . isDirty ) {
32+ confirmationNotification ( onCloseAndReset )
33+ } else {
34+ onCloseAndReset ( )
35+ }
36+ }
37+
2238 return (
2339 < MultiStepModal
2440 ariaDescribedby = "createnewclientheader"
2541 ariaLabelledby = "createnewclientbody"
2642 form = { form }
2743 formId = "id"
2844 isOpen = { isOpen }
29- onClose = { onClose }
45+ onClose = { handleCloseModal }
3046 onSubmit = { handleCreateClient }
3147 renderHeader = { ( ) => (
32- < IconButton onClick = { onClose } >
48+ < IconButton onClick = { handleCloseModal } >
3349 < Close />
3450 </ IconButton >
3551 ) }
Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ export const steps: TStep<NewOwnerDto>[] = [
1212 {
1313 label : "Фамилия" ,
1414 name : "lastName" ,
15- isRequired : true ,
1615 validation : {
1716 minLength : {
1817 message : "Введите больше 2-ух символов" ,
@@ -22,12 +21,7 @@ export const steps: TStep<NewOwnerDto>[] = [
2221 value : 30 ,
2322 message : "Введите меньше 30 символов" ,
2423 } ,
25- required : {
26- message : "Пожалуйста, заполните это поле" ,
27- value : true ,
28- } ,
2924 } ,
30- placeholder : "Фамилия" ,
3125 } ,
3226 {
3327 label : "Имя" ,
@@ -60,10 +54,6 @@ export const steps: TStep<NewOwnerDto>[] = [
6054 value : 30 ,
6155 message : "Введите меньше 30 символов" ,
6256 } ,
63- required : {
64- value : true ,
65- message : "Пожалуйста, заполните это поле" ,
66- } ,
6757 } ,
6858 } ,
6959 {
You can’t perform that action at this time.
0 commit comments