import { Form, Formik } from "formik"; import { useState } from "react"; import { useLocation } from "react-router-dom"; import usersService from "../../services/UsersService"; import InputCom from "../Helpers/Inputs/InputCom"; import ModalCom from "../Helpers/ModalCom"; const DEFAULT_IMAGE = require("../../assets/images/family/default.jpg"); const SuggestTask = ({ details, onClose, situation, continuePopupData }) => { const { pathname, state } = useLocation(); const [submitTask, setSubmitTask] = useState({ loading: false, msg: "", state: "", }); const [suggestedNextStep, setSuggestedNextStep] = useState("Send Task"); const switchNextStep = ({ target: value }) => { setSuggestedNextStep(value); }; const selectedImage = details?.selectedImage || DEFAULT_IMAGE; const initialValues = { title: details?.title || "", description: details?.description || "", banner: details?.banner, }; const apiCall = new usersService(); const handleSuggestedTask = async (values) => { if (!values.title && !values.description) return; try { setSubmitTask({ loading: true }); const reqData = { ...values }; const res = await apiCall.sendFamilySuggestedTasks(reqData); if (res.internal_return < 0) { setSubmitTask({ loading: false, msg: res.status, state: "bad" }); return; } setSubmitTask({ loading: false, msg: res.status, state: "success" }); setTimeout(() => { onClose(); }, 2000); } catch (error) { setSubmitTask({ loading: false, msg: error, state: "bad" }); throw new Error("Error Occurred", error); } }; const handleParentSuggestion = (values) => { if (suggestedNextStep === "Send Task") { let firstname = state?.firstname || details?.firstname; let family_uid = state?.family_uid || details?.family_uid; continuePopupData({ ...details, firstname, family_uid, }); } onClose(); }; const isActivitiesPage = pathname === "/acc-family/activities"; const isManageFamilyPage = pathname === "/manage-family"; const getButtonText = () => { if (isActivitiesPage) { return suggestedNextStep === "Send Task" ? "Continue" : "Complete"; } else { if (!isManageFamilyPage) { if (submitTask.loading) return "Submitting Task"; if (submitTask.state === "success") return "Task Submitted"; if (submitTask.state === "bad") return "An Error Occurred"; return "Send to Parents"; } else { return suggestedNextStep === "Send Task" ? "Continue" : "Complete"; } } }; return (

{isManageFamilyPage ? `${state?.firstname}'s Suggested Task` : isActivitiesPage ? `${details?.firstname}'s Suggested Task` : "Suggest to Parent"}

{(props) => { return (
{/* Image Section */}
{/* ACTION SECTION */}
{/* Title */}
{/* Description */}