diff --git a/src/components/Cards/FamilyMarketCard.jsx b/src/components/Cards/FamilyMarketCard.jsx
index 8b1de50..b9850a1 100644
--- a/src/components/Cards/FamilyMarketCard.jsx
+++ b/src/components/Cards/FamilyMarketCard.jsx
@@ -1,8 +1,38 @@
-import React, { useState } from "react";
+import React, { useMemo, useState } from "react";
import { getTimeAgo } from "../../lib";
+import { toast } from "react-toastify";
import SuggestTask from "../FamilyPopup/SuggestTask";
+import usersService from "../../services/UsersService";
export default function FamilyMarketCard({ className, datas, hidden = false }) {
+ const [submitTask, setSubmitTask] = useState({
+ loading: false,
+ msg: "",
+ state: "",
+ });
+
+ const apiCall = useMemo(() => new usersService(), []);
+
+ const handleSubmit = async () => {
+ try {
+ setSubmitTask({ loading: true });
+ const reqData = {
+ title: datas?.title,
+ description: datas?.description,
+ };
+ 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" });
+ toast.success("Task has been sent!");
+ } catch (error) {
+ setSubmitTask({ loading: false, msg: error, state: "bad" });
+ throw new Error("Error Occurred", error);
+ }
+ };
+
// debugger;
const [popUp, setPopUp] = useState(false);
@@ -10,7 +40,9 @@ export default function FamilyMarketCard({ className, datas, hidden = false }) {
setPopUp((prev) => !prev);
};
// Image
- let selectedImage = require(`../../assets/images/family/${datas.banner || "default.jpg"}`);
+ let selectedImage = require(`../../assets/images/family/${
+ datas.banner || "default.jpg"
+ }`);
return (
<>
@@ -55,9 +87,16 @@ export default function FamilyMarketCard({ className, datas, hidden = false }) {
@@ -65,7 +104,11 @@ export default function FamilyMarketCard({ className, datas, hidden = false }) {
{popUp && (
-
+
)}
>
);
diff --git a/src/components/FamilyPopup/SuggestTask.jsx b/src/components/FamilyPopup/SuggestTask.jsx
index 43d5194..03e2575 100644
--- a/src/components/FamilyPopup/SuggestTask.jsx
+++ b/src/components/FamilyPopup/SuggestTask.jsx
@@ -21,6 +21,7 @@ const SuggestTask = ({ details, onClose, situation }) => {
const apiCall = new usersService();
const handleSubmit = async (values) => {
+ if(!values.title && !values.description) return;
try {
setSubmitTask({ loading: true });
const reqData = { ...values };
@@ -29,8 +30,8 @@ const SuggestTask = ({ details, onClose, situation }) => {
setSubmitTask({ loading: false, msg: res.status, state: "bad" });
return;
}
+ setSubmitTask({ loading: false, msg: res.status, state: "success" });
setTimeout(() => {
- setSubmitTask({ loading: false, msg: res.status, state: "success" });
onClose();
}, 2000);
} catch (error) {
@@ -144,14 +145,10 @@ const SuggestTask = ({ details, onClose, situation }) => {
Cancel
- {/* {requestStatus.loading ? (
-
- ) : ( */}