add filter, comments api

This commit is contained in:
Mahdi Rahimi 2026-01-03 22:01:10 +03:30
parent 400a916541
commit 2f6a46794f
3 changed files with 75 additions and 32 deletions

View File

@ -6,11 +6,17 @@ import Group from "../../assets/icons/Group.svg";
import Pic1 from "../../assets/icons/pic1.svg"; import Pic1 from "../../assets/icons/pic1.svg";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import cafeService from "../../services/cafe"; import cafeService from "../../services/cafe";
import { FiFilter } from "react-icons/fi";
const CafeManagement = () => { const CafeManagement = () => {
const [cafes, setCafes] = useState([]); const [cafes, setCafes] = useState([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState(""); const [error, setError] = useState("");
const [filters, setFilters] = useState({
search: "",
});
const [openFilter, setOpenFilter] = useState(false);
useEffect(() => { useEffect(() => {
const fetchCafes = async () => { const fetchCafes = async () => {
@ -186,13 +192,26 @@ const CafeManagement = () => {
}; };
return ( return (
<section dir="rtl" className="w-full pt-24 max-w-full overflow-x-hidden"> <section dir="rtl" className="w-full pt-20 max-w-full overflow-x-hidden">
{/* بخش دکمه اضافه کردن */} {/* بخش دکمه اضافه کردن */}
<div className="flex items-center justify-between mb-8"> <div className="flex items-center justify-between mb-8">
<button className="flex items-center justify-center gap-3 px-6 py-3 bg-button1 text-white rounded-3xl text-sm lg:text-base font-medium hover:bg-hover2 transition-all duration-300 cursor-pointer"> <button className="flex items-center justify-center gap-3 px-6 py-3 bg-button1 text-white rounded-3xl text-sm lg:text-base font-medium hover:bg-hover2 transition-all duration-300 cursor-pointer">
<span>افزودن شعبه جدید</span> <span>افزودن شعبه جدید</span>
<img src={Vector9} alt="افزودن" className="w-5 h-5" /> <img src={Vector9} alt="افزودن" className="w-5 h-5" />
</button> </button>
<div className="relative">
<button
onClick={()=> setOpenFilter(prev => !prev)}
className="text-text1 hover:scale-110 rounded-3xl text-sm lg:text-base font-medium transition-all duration-300">
<FiFilter size={23} />
</button>
{openFilter && (
<div className="absolute top-0 left-10 w-48 bg-bg border-2 border-border rounded-xl shadow-lg p-4 z-10">
<h3 className="text-text1 font-bold text-sm mb-2">فیلترها</h3>
<input className="w-full border-2 border-border rounded-lg p-2 text-sm placeholder:text-gray-500 dark:placeholder:text-gray-300" placeholder="جستجو..." />
</div>
)}
</div>
</div> </div>
{/* عنوان */} {/* عنوان */}

View File

@ -100,7 +100,8 @@ export default function EditCafe() {
const [newCategory, setNewCategory] = useState(""); const [newCategory, setNewCategory] = useState("");
const [editingIndex, setEditingIndex] = useState(null); const [editingIndex, setEditingIndex] = useState(null);
const [editValue, setEditValue] = useState(""); const [editValue, setEditValue] = useState("");
const [location, setLocation] = useState({lat: 32.64762831857033, lng: 51.71143696482368}); const [location, setLocation] = useState({ lat: 32.64762831857033, lng: 51.71143696482368 });
const [comments, setComments] = useState([]);
// Effects // Effects
useEffect(() => { useEffect(() => {
@ -173,7 +174,27 @@ export default function EditCafe() {
setEditValue(""); setEditValue("");
}; };
console.log("Cafe location:", location); useEffect(() => {
const getComments = async () => {
const params = { page: 1, limit: 10 };
try {
const response = await cafeService.getCafeComments(id, params);
setComments(response.data?.data?.comments || []);
} catch (error) {
console.error("Error fetching cafe comments:", error);
}
};
getComments();
}, [id]);
const toPersianDate = (dateString) => {
const date = new Date(dateString);
return date.toLocaleDateString('fa-IR');
};
console.log("Cafe comments:", comments);
// Render States // Render States
if (loading) { if (loading) {
@ -390,34 +411,35 @@ export default function EditCafe() {
<div> <div>
<h3 className="font-bold text-text1">کامنت ها </h3> <h3 className="font-bold text-text1">کامنت ها </h3>
</div> </div>
<div className=" flex-col bg-[#EFEEEE] flex mt-5 rounded-2xl overflow-hidden p-3 "> {comments.map((comment) => (
<div className=" w-full flex justify-center "> <div key={comment?._id} className=" flex-col bg-[#EFEEEE] flex mt-5 rounded-2xl overflow-hidden p-3 ">
<img <div className=" w-full flex justify-center ">
className="w-20 h-20" <img
src={defaultuser} className="w-20 h-20"
alt="defaultuser" src={defaultuser}
/> alt="defaultuser"
<div className=" w-full mr-4 flex flex-col gap-3 "> />
<div className="w-full flex justify-between "> <div className=" w-full mr-4 flex flex-col gap-3 ">
<h4 font-semibold text-text1> <div className="w-full flex justify-between ">
روزبه سام <h4 font-semibold text-text1>
</h4> روزبه سام
<p className="text-sm">2مهر</p> </h4>
<p className="text-sm">{toPersianDate(comment?.createdAt)}</p>
</div>
<p className=" text-[#66585B] ">
{comment?.content}
</p>
</div> </div>
<p className=" text-[#66585B] "> </div>
فضای خیلی دنج و آرومی داشت، قهوه ترکش فوقالعاده بود 👌 <div className="self-end pl-2 flex gap-2 mt-2.5 ">
دوباره حتما میام. <span className="text-text1 text-sm font-semibold">پاسخ</span>
</p> <RiDeleteBinLine className="ml-2" />
<SlLike />
<SlDislike />
</div> </div>
</div> </div>
<div className="self-end pl-2 flex gap-2 mt-2.5 "> ))}
<span className="text-text1 text-sm font-semibold">پاسخ</span> {/* <div className=" flex-col bg-[#EFEEEE] flex mt-5 rounded-2xl overflow-hidden p-3 ">
<RiDeleteBinLine className="ml-2" />
<SlLike />
<SlDislike />
</div>
</div>
<div className=" flex-col bg-[#EFEEEE] flex mt-5 rounded-2xl overflow-hidden p-3 ">
<div className=" w-full flex justify-center "> <div className=" w-full flex justify-center ">
<img <img
className="w-20 h-20" className="w-20 h-20"
@ -447,8 +469,8 @@ export default function EditCafe() {
<SlLike /> <SlLike />
<SlDislike /> <SlDislike />
</div> </div>
</div> </div> */}
<div className=" flex-col bg-[#EFEEEE] flex mt-5 rounded-2xl overflow-hidden p-3 "> {/* <div className=" flex-col bg-[#EFEEEE] flex mt-5 rounded-2xl overflow-hidden p-3 ">
<div className=" w-full flex justify-center "> <div className=" w-full flex justify-center ">
<img <img
className="w-20 h-20" className="w-20 h-20"
@ -475,9 +497,9 @@ export default function EditCafe() {
<SlLike /> <SlLike />
<SlDislike /> <SlDislike />
</div> </div>
</div> </div> */}
<div className="flex justify-between mt-8"> <div className="flex justify-between mt-8">
<p>29 دیدگاه</p>{" "} <p>{comments.length} دیدگاه</p>{" "}
<p className="font-bold text-text1">مشاهده بیشتر</p>{" "} <p className="font-bold text-text1">مشاهده بیشتر</p>{" "}
</div> </div>

View File

@ -15,6 +15,8 @@ const cafeService = {
addCategory: (categoryData) => requests.post(`/cafemenu/add-category`, categoryData), addCategory: (categoryData) => requests.post(`/cafemenu/add-category`, categoryData),
getCafeComments: (cafeId, params) => requests.getByParams(`/comment/v1/cafe/${cafeId}`, params),
}; };
export default cafeService; export default cafeService;