Fixed the empty params and fixed broken offer link
This commit was merged in pull request #246.
This commit is contained in:
@@ -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 }) {
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
className="px-4 py-2.5 text-white text-sm bg-pink rounded-full tracking-wide"
|
||||
>
|
||||
Send
|
||||
{submitTask.loading
|
||||
? "..."
|
||||
: submitTask.state == "success"
|
||||
? "Sent!"
|
||||
: submitTask.state == "bad"
|
||||
? "Failed"
|
||||
: "Send"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -65,7 +104,11 @@ export default function FamilyMarketCard({ className, datas, hidden = false }) {
|
||||
</div>
|
||||
</div>
|
||||
{popUp && (
|
||||
<SuggestTask onClose={popUpHandler} situation={popUp} details={{...datas, selectedImage}} />
|
||||
<SuggestTask
|
||||
onClose={popUpHandler}
|
||||
situation={popUp}
|
||||
details={{ ...datas, selectedImage }}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user