import { useState } from "react" import { useDispatch } from "react-redux" import InputText from '@/Components/Input/InputText' import ErrorText from '@/Components/Typography/ErrorText' import { showNotification } from '@/Components/features/common/headerSlice' import { addNewLead } from "../leadSlice" const INITIAL_LEAD_OBJ = { first_name: "", last_name: "", email: "" } function AddLeadModalBody({ closeModal }) { const dispatch = useDispatch() const [loading, setLoading] = useState(false) const [errorMessage, setErrorMessage] = useState("") const [leadObj, setLeadObj] = useState(INITIAL_LEAD_OBJ) const saveNewLead = () => { if (leadObj.first_name.trim() === "") return setErrorMessage("First Name is required!") else if (leadObj.email.trim() === "") return setErrorMessage("Email id is required!") else { let newLeadObj = { "id": 7, "email": leadObj.email, "first_name": leadObj.first_name, "last_name": leadObj.last_name, "avatar": "https://reqres.in/img/faces/1-image.jpg" } dispatch(addNewLead({ newLeadObj })) dispatch(showNotification({ message: "New Lead Added!", status: 1 })) closeModal() } } const updateFormValue = ({ updateType, value }) => { setErrorMessage("") setLeadObj({ ...leadObj, [updateType]: value }) } return ( <> {errorMessage}
) } export default AddLeadModalBody