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 { Link } from "react-router-dom";
import cafeService from "../../services/cafe";
import { FiFilter } from "react-icons/fi";
const CafeManagement = () => {
const [cafes, setCafes] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState("");
const [filters, setFilters] = useState({
search: "",
});
const [openFilter, setOpenFilter] = useState(false);
useEffect(() => {
const fetchCafes = async () => {
@ -186,13 +192,26 @@ const CafeManagement = () => {
};
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">
<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>
<img src={Vector9} alt="افزودن" className="w-5 h-5" />
</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>
{/* عنوان */}

View File

@ -101,6 +101,7 @@ export default function EditCafe() {
const [editingIndex, setEditingIndex] = useState(null);
const [editValue, setEditValue] = useState("");
const [location, setLocation] = useState({ lat: 32.64762831857033, lng: 51.71143696482368 });
const [comments, setComments] = useState([]);
// Effects
useEffect(() => {
@ -173,7 +174,27 @@ export default function EditCafe() {
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
if (loading) {
@ -390,7 +411,8 @@ export default function EditCafe() {
<div>
<h3 className="font-bold text-text1">کامنت ها </h3>
</div>
<div className=" flex-col bg-[#EFEEEE] flex mt-5 rounded-2xl overflow-hidden p-3 ">
{comments.map((comment) => (
<div key={comment?._id} className=" flex-col bg-[#EFEEEE] flex mt-5 rounded-2xl overflow-hidden p-3 ">
<div className=" w-full flex justify-center ">
<img
className="w-20 h-20"
@ -402,11 +424,10 @@ export default function EditCafe() {
<h4 font-semibold text-text1>
روزبه سام
</h4>
<p className="text-sm">2مهر</p>
<p className="text-sm">{toPersianDate(comment?.createdAt)}</p>
</div>
<p className=" text-[#66585B] ">
فضای خیلی دنج و آرومی داشت، قهوه ترکش فوقالعاده بود 👌
دوباره حتما میام.
{comment?.content}
</p>
</div>
</div>
@ -417,7 +438,8 @@ export default function EditCafe() {
<SlDislike />
</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 ">
<img
className="w-20 h-20"
@ -447,8 +469,8 @@ export default function EditCafe() {
<SlLike />
<SlDislike />
</div>
</div>
<div className=" flex-col bg-[#EFEEEE] flex mt-5 rounded-2xl overflow-hidden p-3 ">
</div> */}
{/* <div className=" flex-col bg-[#EFEEEE] flex mt-5 rounded-2xl overflow-hidden p-3 ">
<div className=" w-full flex justify-center ">
<img
className="w-20 h-20"
@ -475,9 +497,9 @@ export default function EditCafe() {
<SlLike />
<SlDislike />
</div>
</div>
</div> */}
<div className="flex justify-between mt-8">
<p>29 دیدگاه</p>{" "}
<p>{comments.length} دیدگاه</p>{" "}
<p className="font-bold text-text1">مشاهده بیشتر</p>{" "}
</div>

View File

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