11import React from 'react' ;
22import moment from "moment" ;
33
4- import { Button , ModalBody , ModalFooter , Box , FormControl , FormLabel , Input , Flex , Select , NumberDecrementStepper , NumberIncrementStepper , NumberInput , NumberInputField , NumberInputStepper , InputRightElement , InputGroup , FormHelperText , Tag , TagLabel , TagCloseButton , Wrap , WrapItem } from "@chakra-ui/react" ;
4+ import { Button , ModalBody , ModalFooter , Box , FormControl , FormLabel , Input , Flex , Select , NumberDecrementStepper , NumberIncrementStepper , NumberInput , NumberInputField , NumberInputStepper , InputRightElement , InputGroup , FormHelperText , Tag , TagLabel , TagCloseButton , Wrap , WrapItem , useToast } from "@chakra-ui/react" ;
55import { CreateShiftFormStepComponentType , CreateShiftFormStepProps , Frequency , ServiceRequestType } from '../../../types/ServiceRequestTypes' ;
66import { titleCase } from '../../../utils/FormatUtils' ;
77import EARLIEST_SHIFT_TIME from '../../../constants/ServiceRequestConstants' ;
8+ import { validateEmail } from '../../../utils/ValidationUtils'
89
910const CreateShiftMain : CreateShiftFormStepComponentType = ( { onSubmit, updateFields, updateErrorFields, data, errors } : CreateShiftFormStepProps ) : React . ReactElement => {
1011 const { requestName, shiftTime, shiftEndTime, frequency, currentEmail, inviteEmails, requestType } = data ;
1112 const { shiftTimeError, shiftEndTimeError } = errors ;
13+ const toast = useToast ( ) ;
1214
1315
1416 const formatDate = ( date : Date ) => {
@@ -84,11 +86,23 @@ const CreateShiftMain: CreateShiftFormStepComponentType = ({ onSubmit, updateFie
8486 updateShiftTimeErrorFields ( new Date ( shiftTime ) , endTime ) ;
8587 }
8688 } ;
87- const handleAddEmail = ( ) => {
89+
90+ const handleAddEmail = ( ) => {
8891 if ( currentEmail && currentEmail . trim ( ) ) {
92+ const emailError = validateEmail ( currentEmail ) ;
93+ if ( emailError ) {
94+ toast ( {
95+ title : "Invalid Email" ,
96+ description : "Please enter a valid email address." ,
97+ status : "error" ,
98+ position : 'top-right' ,
99+ duration : 5000 ,
100+ isClosable : true ,
101+ } ) ;
102+ return ; // Stop execution if email is invalid
103+ }
89104 const updatedEmails = [ ...( inviteEmails || [ ] ) , currentEmail . trim ( ) ] ;
90- updateFields ( { inviteEmails : updatedEmails , currentEmail : "" } ) ;
91- console . log ( updatedEmails )
105+ updateFields ( { inviteEmails : updatedEmails , currentEmail : "" } ) ;
92106 }
93107 } ;
94108
@@ -97,8 +111,6 @@ const CreateShiftMain: CreateShiftFormStepComponentType = ({ onSubmit, updateFie
97111 updateFields ( { inviteEmails : updatedEmails } ) ;
98112 } ;
99113
100-
101-
102114 const isButtonDisabled =
103115 ! requestName ||
104116 ! shiftTime ||
0 commit comments