Merge branch 'resources-page' of WrenchBoard/Users-Wrench into master

This commit is contained in:
2023-07-04 15:27:51 +00:00
committed by Gogs
2 changed files with 7 additions and 44 deletions
+6 -44
View File
@@ -1,41 +1,9 @@
import React, { useMemo, useState } from "react"; import { useState } from "react";
import { getTimeAgo } from "../../lib";
import { toast } from "react-toastify";
import SuggestTask from "../FamilyPopup/SuggestTask"; import SuggestTask from "../FamilyPopup/SuggestTask";
import usersService from "../../services/UsersService";
export default function FamilyMarketCard({ className, datas, hidden = false }) { 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; // debugger;
const [popUp, setPopUp] = useState(false); const [popUp, setPopUp] = useState(false);
const popUpHandler = () => { const popUpHandler = () => {
setPopUp((prev) => !prev); setPopUp((prev) => !prev);
}; };
@@ -71,7 +39,7 @@ export default function FamilyMarketCard({ className, datas, hidden = false }) {
{hidden && <div className="flex justify-center"></div>} {hidden && <div className="flex justify-center"></div>}
</div> </div>
</div> </div>
<div className="details-area mt-12"> <div className="details-area mt-12 flex justify-between items-center gap-2">
{/* title */} {/* title */}
<button onClick={popUpHandler}> <button onClick={popUpHandler}>
<h1 className="font-bold text-xl tracking-wide line-clamp-1 text-dark-gray dark:text-white capitalize"> <h1 className="font-bold text-xl tracking-wide line-clamp-1 text-dark-gray dark:text-white capitalize">
@@ -79,24 +47,18 @@ export default function FamilyMarketCard({ className, datas, hidden = false }) {
</h1> </h1>
</button> </button>
<div className="flex justify-between"> <div className="flex justify-between">
<div className="flex items-center space-x-2"> {/* <div className="flex items-center space-x-2">
<p className="italic text-gray-400"> <p className="italic text-gray-400">
{getTimeAgo(datas?.added)} {getTimeAgo(datas?.added)}
</p> </p>
</div> </div> */}
<div> <div>
<button <button
type="button" type="button"
onClick={handleSubmit} onClick={popUpHandler}
className="px-4 py-2.5 text-white text-sm bg-pink rounded-full tracking-wide" className="px-4 py-2.5 text-white text-sm bg-pink rounded-full tracking-wide"
> >
{submitTask.loading View
? "..."
: submitTask.state == "success"
? "Sent!"
: submitTask.state == "bad"
? "Failed"
: "Send"}
</button> </button>
</div> </div>
</div> </div>
@@ -97,6 +97,7 @@ const SuggestTask = ({ details, onClose, situation }) => {
inputBg="bg-slate-100" inputBg="bg-slate-100"
type="text" type="text"
name="title" name="title"
disable={details?.title}
value={props.values.title} value={props.values.title}
inputHandler={props.handleChange} inputHandler={props.handleChange}
blurHandler={props.handleBlur} blurHandler={props.handleBlur}