diff --git a/src/components/master/CreateActivity.jsx b/src/components/master/CreateActivity.jsx index bb207b53..604adeea 100644 --- a/src/components/master/CreateActivity.jsx +++ b/src/components/master/CreateActivity.jsx @@ -16,59 +16,11 @@ const schema = z.object({ .optional(), }); -const CreateActivity = () => +const CreateActivity = ({onClose}) => { const [ isLoading, setIsLoading ] = useState( false ) - - // const { - // register, - // handleSubmit, - // formState: { errors },reset - // } = useForm({ - // resolver: zodResolver(schema), - // defaultValues: { - // activityName: "", - // unitOfMeasurement: "", - // checkList: [''] - // }, - // }); - - // const onSubmit = (data) => { - // setIsLoading(true) - // const result = { - // name: data.activityName, - // description: data.unitOfMeasurement, - // }; - // console.log( result ) - // reset() - // MasterRespository.createJobRole(result).then((resp)=>{ - // setIsLoading(false) - // resetForm() - // const cachedData = getCachedData("Job Role"); - // const updatedData = [...cachedData, resp?.data]; - // cacheData("Job Role", updatedData); - // showToast("JobRole Added successfully.", "success"); - - // onClose() - // }).catch((error)=>{ - // showToast(error.message, "error"); - // setIsLoading(false) - // }) - - // }; - // const resetForm =()=>{ - // reset({ - // activityName:"", - // unitOfMeasurement:"" - // }) - // } - - // useEffect(()=>{ - // return ()=>resetForm() - // }, [] ) - const { register, handleSubmit, @@ -99,8 +51,25 @@ const CreateActivity = () => }); // Form submission handler - const onSubmit = (data) => { - console.log('Submitted:', data); + const onSubmit = ( data ) => + { + console.log(data) + setIsLoading(true) + + + MasterRespository.updateActivity(data).then((resp)=>{ + setIsLoading(false) + + const cachedData = getCachedData("Activity"); + const updatedData = [...cachedData, resp?.data]; + cacheData("Activity", updatedData); + showToast("Activity Added successfully.", "success"); + + onClose() + }).catch((error)=>{ + showToast(error.message, "error"); + setIsLoading(false) + }) }; // Add a new checklist item @@ -130,6 +99,12 @@ const CreateActivity = () => const handleChecklistChange = (index, value) => { setValue(`checkList.${index}`, value); }; + + const handleClose = () => + { + reset() + onClose() + } return (