import React, { useCallback, useMemo, useState } from "react"; import ModalCom from "../../Helpers/ModalCom"; import { toast } from "react-toastify"; import { Form, Formik } from "formik"; import usersService from "../../../services/UsersService"; import LoadingSpinner from "../../Spinners/LoadingSpinner"; import { PriceFormatter } from "../../Helpers/PriceFormatter"; const MarketPopUp = ({ details, onClose, situation, marketInt }) => { const [marketMsg, setMarketMsg] = useState({ loading: false, data: {}, state: undefined, }); const [manageInt, setManageInt] = useState({ loading: false, data: {}, state: undefined, msg: "", }); const [textValue, setTextValue] = useState(""); const handleInputChange = ({ target: { value } }) => { setTextValue(value); }; const apiCall = useMemo(() => new usersService(), []); const marketCalls = useCallback( async (e) => { try { const nameOfCall = e?.target?.name; const { offer_code } = details; const reqData = { offer_code }; if (nameOfCall === "market-message") { setMarketMsg({ loading: true }); if (!textValue) return; reqData.yourmessage = textValue; const marketMessage = await apiCall.MarketMessage(reqData); const marketMessageRes = marketMessage?.data; if (marketMessageRes?.internal_return < 0) { toast.warn("Something wrong happened", { autoClose: 2000, hideProgressBar: true, }); onClose(); return; } toast.success("Message sent", { autoClose: 2500, hideProgressBar: true, }); setMarketMsg({ data: marketMessageRes, state: true }); setTimeout(() => onClose(), 2000); } else { setManageInt({ loading: true }); const manageInt = await apiCall.MarketInterest(reqData); const manageIntRes = manageInt?.data; if (manageIntRes?.internal_return < 0) { setManageInt({ loading: false, msg: `Error - ${manageIntRes?.status}`, data: manageIntRes, state: false, }); } else { setManageInt({ loading: false, msg: manageIntRes?.status, data: manageIntRes, state: true, }); } setTimeout(() => setManageInt({ msg: "" }), 3000); return; } } catch (error) { throw new Error(error); } finally { setTimeout(() => { setTextValue(""); setMarketMsg({ loading: false }); }, 2000); } }, [apiCall, details, onClose, textValue] ); let thePrice = PriceFormatter( details?.price * 0.01, details?.currency_code, details?.currency ); // let addedIntDate = marketInt?.added?.split(" ")[0]; let expireIntDate = marketInt?.expire?.split(" ")[0]; return (

{details.offer_code}

{details?.title}

{/* INPUT SECTION */} {[ { name: "Description", content: details.description, }, { name: "", content: { text: `Timeline: ${details.timeline_days} day(s) -- `, bold: `Budget: ${thePrice}`, }, }, { name: "Delivery Detail", content: details.job_description, danger: true, }, ].map(({ name, content, danger }, idx) => (
{danger ? (

) : (

{name !== "Delivery Detail" ? ( <> {typeof content !== "object" ? content : null} {typeof content === "object" && ( <>


{content?.text} {thePrice}
)} ) : ( "" )}

)}
))}