diff --git a/src/components/jobPopout/JobListPopout.jsx b/src/components/jobPopout/JobListPopout.jsx index 3aa5761..96d5655 100644 --- a/src/components/jobPopout/JobListPopout.jsx +++ b/src/components/jobPopout/JobListPopout.jsx @@ -1,12 +1,13 @@ -import React, { useState } from "react"; +import React, { useCallback, useEffect, useMemo, useState } from "react"; import Detail from "./popoutcomponent/Detail"; import ModalCom from "../Helpers/ModalCom"; import InputCom from "../Helpers/Inputs/InputCom/index"; +import SiteService from "../../services/SiteService"; import { Form, Formik, Field } from "formik"; import * as Yup from "yup"; const validationSchema = Yup.object().shape({ - family: Yup.string().required("Please assign a family"), + family: Yup.string().required("THis is required "), public: Yup.string(), individual: Yup.string() .email("Invalid email format") @@ -19,24 +20,93 @@ const validationSchema = Yup.object().shape({ }); function JobListPopout({ details, onClose, situation }) { + const [familyList, setFamilyList] = useState([]); + const [loader, setLoader] = useState(false); + + const apiCall = useMemo(() => new SiteService(), []); + + // member listing + const memberList = useCallback(async () => { + setLoader(true); + try { + let reqData = { + limit: 20, + offset: 0, + action: 22010, + }; + + let res = await apiCall.familyListings(reqData); + const { data } = res; + if (data?.internal_return >= 0 && data?.status == "OK") { + let { result_list } = data; + setFamilyList(result_list); + setLoader(false); + } else return; + } catch (error) { + setLoader(false); + throw new Error(error); + } + }, [apiCall]); + + useEffect(() => { + memberList(); + }, [memberList]); + let initialValues = { - family: [], + family: "", public: "", individual: "", group: "", }; - let [inputs, setInputs] = useState({ - family: "", - public: "", - individual: "", - group: "", - }); + let [inputs, setInputs] = useState({}); const handleInputChange = ({ target: { name, value } }) => { setInputs((prev) => ({ ...prev, [name]: value })); }; + const jobFieldHandler = async (values, helpers) => { + setLoader(true); + let { job_id, job_uid, job_description } = details; + let reqData; + + // for family input + values?.family !== "" && console.log(values?.family); + + // for public input + if (values?.public !== "") { + reqData = { + job_id, + job_uid, + job_description, + duration: Number(values?.public), + action: 13025, + assign_mode: 110022, + }; + } else if (values?.individual !== "") { + // for individual input + reqData = { + job_id, + job_uid, + job_description, + email: values?.individual, + action: 13025, + assign_mode: 110033, + }; + } + + try { + const res = await apiCall.assignJobTask(reqData); + let { data } = await res; + setLoader(false); + console.log(data); + throw new Response(data); + } catch (error) { + setLoader(false); + throw new Error(error); + } + }; + return (
@@ -116,50 +186,90 @@ function JobListPopout({ details, onClose, situation }) {
{(props) => { return ( - <> +
{/* Assign to Family */} + + ); + }} +
+ + {(props) => { + return ( +
{/* Offer this job to public input */} + + ); + }} +
+ + {(props) => { + return ( +
{/* Offer this job to individual input */} + + ); + }} +
+ + {(props) => { + return ( +
{/* Offer this job to your group input */} - + ); }}
@@ -184,58 +294,99 @@ const JobFieldInput = ({ labelClass, btnText, parentClass, - optionText -}) => ( -
- {select && ( - <> -
-
- {label && ( - - )} -
-
- { + return ( +
+ {select && ( + <> +
+
- - {value && } - + {label && ( + + )} +
+
+ + + {Array.isArray(data) && + data?.map((item, idx) => ( + + {inputName === "family" && ( + + )} + {inputName === "public" && ( + + )} + {inputName === "group" && ( + + )} + + ))} + +
-
- - )} + + )} - {input && ( - - )} - {/* btn */} -
- + {input && ( + + )} + + {/* btn */} +
+ +
-
-); + ); +}; + +const publicArray = [ + { duration: 1, name: "1 day" }, + { duration: 2, name: "2 days" }, + { duration: 3, name: "3 days" }, + { duration: 4, name: "4 days" }, + { duration: 5, name: "5 days" }, + { duration: 6, name: "6 days" }, + { duration: 7, name: "1 week" }, + { duration: 14, name: "2 weeks" }, + { duration: 21, name: "3 weeks" }, + { duration: 28, name: "4 weeks" }, +]; diff --git a/src/services/SiteService.js b/src/services/SiteService.js index a8e832b..e574ef1 100644 --- a/src/services/SiteService.js +++ b/src/services/SiteService.js @@ -33,7 +33,23 @@ class SiteService { } familyListings(reqData) { - return this.postAuxEnd('/familylist', reqData) + var postData = { + uid: localStorage.getItem("uid"), + member_id: localStorage.getItem("member_id"), + sessionid: localStorage.getItem("session_token"), + ...reqData + }; + return this.postAuxEnd('/familylist', postData) + } + + assignJobTask(reqData) { + var postData = { + uid: localStorage.getItem("uid"), + member_id: localStorage.getItem("member_id"), + sessionid: localStorage.getItem("session_token"), + ...reqData + }; + return this.postAuxEnd('/assigntask', postData) } //---------------------------------------- -----