芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/rentandbuyrealty.com/rentandbuyrealty.com/web/src/Components/User/UserDashboard.jsx
"use client" import React, { useEffect, useState } from "react"; import HomeIcon from "@mui/icons-material/Home"; import StarIcon from "@mui/icons-material/Star"; import { useSelector } from "react-redux"; import { GetFeturedListingsApi, GetLimitsApi } from "@/store/actions/campaign"; import Table from "@mui/material/Table"; import TableBody from "@mui/material/TableBody"; import TableCell from "@mui/material/TableCell"; import TableContainer from "@mui/material/TableContainer"; import TableHead from "@mui/material/TableHead"; import TableRow from "@mui/material/TableRow"; import Paper from "@mui/material/Paper"; import { Menu, Dropdown, Button, Space } from "antd"; import { EditOutlined, DeleteOutlined } from "@ant-design/icons"; import { settingsData } from "@/store/reducer/settingsSlice"; import { useRouter } from "next/router"; import { BsThreeDotsVertical } from "react-icons/bs"; import ReactPagination from "../../../src/Components/Pagination/ReactPagination.jsx"; import { deletePropertyApi } from "@/store/actions/campaign"; import Loader from "../../../src/Components/Loader/Loader.jsx"; import toast from "react-hot-toast"; import { FaCrown } from "react-icons/fa"; import { MdOutlineSell } from "react-icons/md"; import FeatureModal from "@/Components/FeatureModal/FeatureModal.jsx"; import ChangeStatusModal from "@/Components/ChangeStatusModal/ChangeStatusModal.jsx"; import { placeholderImage, translate } from "@/utils/index.js"; import { languageData } from "@/store/reducer/languageSlice.js"; import Swal from "sweetalert2"; import Image from "next/image"; import dynamic from "next/dynamic.js"; import { FaRegEye } from "react-icons/fa"; import Link from "next/link.js"; import TablePagination from "../Pagination/TablePagination.jsx"; const VerticleLayout = dynamic(() => import('../AdminLayout/VerticleLayout.jsx'), { ssr: false }) const UserDashboard = () => { const limit = 8; const router = useRouter(); const [isLoading, setIsLoading] = useState(false); const [getFeaturedListing, setGetFeaturedListing] = useState([]); const [total, setTotal] = useState(0); const [view, setView] = useState(0); const [offsetdata, setOffsetdata] = useState(0); const [anchorEl, setAnchorEl] = React.useState(null); const [propertyIdToDelete, setPropertyIdToDelete] = useState(null); const [propertyId, setPropertyId] = useState(null); const [propertyType, setPropertyType] = useState(null); const [changeStatus, setChangeStatus] = useState(false); const [isFeatureModalVisible, setIsFeatureModalVisible] = useState(false); const [changestatusModal, setChangestatusModal] = useState(false); const startIndex = total > 0 ? (offsetdata * limit) + 1 : 0; const endIndex = Math.min((offsetdata + 1) * limit, total); const SettingsData = useSelector(settingsData); const lang = useSelector(languageData); useEffect(() => { }, [lang]); const handleClickEdit = (propertyId) => { router.push(`/user/edit-property/${propertyId}`); }; const handleClickDelete = (propertyId) => { if (SettingsData.demo_mode === true) { Swal.fire({ title: "Opps!", text: "This Action is Not Allowed in Demo Mode", icon: "warning", showCancelButton: false, customClass: { confirmButton: 'Swal-confirm-buttons', cancelButton: "Swal-cancel-buttons" }, confirmButtonText: "OK", }); return false; } setPropertyIdToDelete(propertyId); setIsLoading(true); deletePropertyApi( propertyId, (response) => { setIsLoading(true); toast.success(response.message); GetFeturedListingsApi({ offset: offsetdata.toString(), limit: limit.toString(), userid: isLoggedIn ? userCurrentId : "", onSuccess: (response) => { setTotal(response.total); setView(response.total_clicks); const FeaturedListingData = response.data; setIsLoading(false); setGetFeaturedListing(FeaturedListingData); }, onError: (error) => { setIsLoading(false); console.log(error); } } ); }, (error) => { setIsLoading(false); toast.error(error); } ); }; const handleFeatureClick = (propertyId) => { if (SettingsData.demo_mode === true) { Swal.fire({ title: "Opps!", text: "This Action is Not Allowed in Demo Mode", icon: "warning", showCancelButton: false, customClass: { confirmButton: 'Swal-buttons', }, cancelButtonColor: "#d33", confirmButtonText: "OK", }); return false; } GetLimitsApi( "advertisement", (response) => { if (response.message === "Please Subscribe for Advertisement") { Swal.fire({ icon: "error", title: "Oops...", text: "Your Package Limit is Over. Please Purchase Package.", allowOutsideClick: false, customClass: { confirmButton: 'Swal-confirm-buttons', }, }).then((result) => { if (result.isConfirmed) { router.push("/subscription-plan"); // Redirect to the subscription page } }); } else { setPropertyId(propertyId); setIsFeatureModalVisible(true); } }, (error) => { console.log("API Error:", error); } ) }; const handleChangeStatusClick = (propertyId, propertyType) => { if (SettingsData.demo_mode === true) { Swal.fire({ title: "Opps!", text: "This Action is Not Allowed in Demo Mode", icon: "warning", showCancelButton: false, customClass: { confirmButton: 'Swal-buttons', }, cancelButtonColor: "#d33", confirmButtonText: "OK", }); return false; } setPropertyId(propertyId); setPropertyType(propertyType); setChangestatusModal(true); }; const priceSymbol = useSelector(settingsData); const CurrencySymbol = priceSymbol && priceSymbol.currency_symbol; const isLoggedIn = useSelector((state) => state.User_signup); const userCurrentId = isLoggedIn && isLoggedIn.data ? isLoggedIn.data.data.id : null; const userData = isLoggedIn && isLoggedIn?.data?.data?.name; useEffect(() => { setIsLoading(true); GetFeturedListingsApi({ offset: offsetdata.toString(), limit: limit.toString(), userid: isLoggedIn ? userCurrentId : "", onSuccess: (response) => { setTotal(response.total); setView(response.total_clicks); const FeaturedListingData = response.data; setIsLoading(false); setGetFeaturedListing(FeaturedListingData); }, onError: (error) => { setIsLoading(false); console.log(error); } } ); }, [offsetdata, isLoggedIn, propertyIdToDelete, changeStatus]); useEffect(() => { }, [propertyId, propertyIdToDelete, propertyType, changeStatus]); useEffect(() => { setChangeStatus(false) }, [changeStatus]); const handlePageChange = (selectedPage) => { const newOffset = selectedPage.selected * limit; setOffsetdata(newOffset); window.scrollTo(0, 0); }; const handleShowIntrestedUser = (slug_id) => { router.push(`/user/intrested/${slug_id}`); } return (
{translate("hy")} {""} {userData}
{translate("manageYourProfile")}
{translate("totalProperty")}
{total > 0 ?
{total}
:
0
}
{translate("totalViews")}
{view > 0 ?
{view}
:
0
}
{translate("listingTitle")}
{translate("category")}
{translate("views")}
{translate("intrestedUsers")}
{translate("postedOn")}
{translate("status")}
{translate("action")}
{isLoading ? (
) : getFeaturedListing && getFeaturedListing.length > 0 ? ( getFeaturedListing.map((elem, index) => (
{elem.property_type}
{elem.title}
{elem.city} {elem.state} {elem.country}
{CurrencySymbol} {elem.price}
{elem.category.category}
{elem.total_view}
handleShowIntrestedUser(elem.slug_id)}>
{elem.post_created}
{elem.status === 1 ?
{translate("active")}
:
{translate("inactive")}
}
{ if (visible) { setAnchorEl(index); } else { setAnchorEl(null); } }} overlay={
handleClickEdit(elem.slug_id)}>
}> {translate("edit")}
{elem.status === 1 && elem.promoted === false ? (
handleFeatureClick(elem.id)}>
} > {translate("feature")}
) : null} {elem.status === 1 && elem.property_type !== 'sold' ? (
handleChangeStatusClick(elem.id, elem.property_type)}>
}> {translate("change status")}
) : null}
handleClickDelete(elem.id)}>
} > {translate("delete")}
} >
)) ) : (
{translate("noDataAvailabe")}
)}
setIsFeatureModalVisible(false)} propertyId={propertyId} />
setChangestatusModal(false)} propertyId={propertyId} propertyType={propertyType} setChangeStatus={setChangeStatus} /> {getFeaturedListing && getFeaturedListing.length > 0 ? (
) : null}
) } export default UserDashboard