refactor mylistings and my rentals
This commit is contained in:
@@ -36,7 +36,7 @@ const EarningsDashboard: React.FC = () => {
|
||||
const fetchEarningsData = async () => {
|
||||
try {
|
||||
// Get completed rentals where user is the owner
|
||||
const response = await rentalAPI.getMyListings();
|
||||
const response = await rentalAPI.getListings();
|
||||
const rentals = response.data || [];
|
||||
|
||||
// Filter for completed rentals with earnings data
|
||||
|
||||
@@ -173,7 +173,7 @@ const EditItem: React.FC = () => {
|
||||
|
||||
const fetchAcceptedRentals = async () => {
|
||||
try {
|
||||
const response = await rentalAPI.getMyListings();
|
||||
const response = await rentalAPI.getListings();
|
||||
const rentals: Rental[] = response.data;
|
||||
// Filter for accepted rentals for this specific item
|
||||
const itemRentals = rentals.filter(
|
||||
|
||||
@@ -48,7 +48,7 @@ const ItemDetail: React.FC = () => {
|
||||
|
||||
const checkIfAlreadyRenting = async () => {
|
||||
try {
|
||||
const response = await rentalAPI.getMyRentals();
|
||||
const response = await rentalAPI.getRentals();
|
||||
const rentals: Rental[] = response.data;
|
||||
// Check if user has an active rental for this item
|
||||
const hasActiveRental = rentals.some(
|
||||
|
||||
@@ -10,7 +10,7 @@ import DeclineRentalModal from "../components/DeclineRentalModal";
|
||||
import ConditionCheckModal from "../components/ConditionCheckModal";
|
||||
import ReturnStatusModal from "../components/ReturnStatusModal";
|
||||
|
||||
const MyListings: React.FC = () => {
|
||||
const Owning: React.FC = () => {
|
||||
// Helper function to format time
|
||||
const formatTime = (timeString?: string) => {
|
||||
if (!timeString || timeString.trim() === "") return "";
|
||||
@@ -66,12 +66,12 @@ const MyListings: React.FC = () => {
|
||||
const [rentalForReturn, setRentalForReturn] = useState<Rental | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetchMyListings();
|
||||
fetchListings();
|
||||
fetchOwnerRentals();
|
||||
fetchAvailableChecks();
|
||||
}, [user]);
|
||||
|
||||
const fetchMyListings = async () => {
|
||||
const fetchListings = async () => {
|
||||
if (!user) return;
|
||||
|
||||
try {
|
||||
@@ -124,7 +124,7 @@ const MyListings: React.FC = () => {
|
||||
|
||||
const fetchOwnerRentals = async () => {
|
||||
try {
|
||||
const response = await rentalAPI.getMyListings();
|
||||
const response = await rentalAPI.getListings();
|
||||
setOwnerRentals(response.data);
|
||||
} catch (err: any) {
|
||||
console.error("Failed to fetch owner rentals:", err);
|
||||
@@ -698,4 +698,4 @@ const MyListings: React.FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default MyListings;
|
||||
export default Owning;
|
||||
@@ -155,7 +155,7 @@ const Profile: React.FC = () => {
|
||||
);
|
||||
|
||||
// Fetch rentals where user is the owner (rentals on user's items)
|
||||
const ownerRentalsResponse = await rentalAPI.getMyListings();
|
||||
const ownerRentalsResponse = await rentalAPI.getListings();
|
||||
const ownerRentals: Rental[] = ownerRentalsResponse.data;
|
||||
|
||||
const acceptedRentals = ownerRentals.filter((r) =>
|
||||
@@ -194,14 +194,14 @@ const Profile: React.FC = () => {
|
||||
const fetchRentalHistory = async () => {
|
||||
try {
|
||||
// Fetch past rentals as a renter
|
||||
const renterResponse = await rentalAPI.getMyRentals();
|
||||
const renterResponse = await rentalAPI.getRentals();
|
||||
const pastRenterRentals = renterResponse.data.filter((r: Rental) =>
|
||||
["completed", "cancelled"].includes(r.status)
|
||||
);
|
||||
setPastRenterRentals(pastRenterRentals);
|
||||
|
||||
// Fetch past rentals as an owner
|
||||
const ownerResponse = await rentalAPI.getMyListings();
|
||||
const ownerResponse = await rentalAPI.getListings();
|
||||
const pastOwnerRentals = ownerResponse.data.filter((r: Rental) =>
|
||||
["completed", "cancelled"].includes(r.status)
|
||||
);
|
||||
|
||||
@@ -223,7 +223,7 @@ const RentItem: React.FC = () => {
|
||||
<div className="d-grid gap-2 d-md-block">
|
||||
<button
|
||||
className="btn btn-primary me-2"
|
||||
onClick={() => navigate("/my-rentals")}
|
||||
onClick={() => navigate("/renting")}
|
||||
>
|
||||
View My Rentals
|
||||
</button>
|
||||
|
||||
@@ -7,7 +7,7 @@ import ReviewItemModal from "../components/ReviewModal";
|
||||
import RentalCancellationModal from "../components/RentalCancellationModal";
|
||||
import ConditionCheckModal from "../components/ConditionCheckModal";
|
||||
|
||||
const MyRentals: React.FC = () => {
|
||||
const Renting: React.FC = () => {
|
||||
// Helper function to format time
|
||||
const formatTime = (timeString?: string) => {
|
||||
if (!timeString || timeString.trim() === "") return "";
|
||||
@@ -66,7 +66,7 @@ const MyRentals: React.FC = () => {
|
||||
|
||||
const fetchRentals = async () => {
|
||||
try {
|
||||
const response = await rentalAPI.getMyRentals();
|
||||
const response = await rentalAPI.getRentals();
|
||||
setRentals(response.data);
|
||||
} catch (err: any) {
|
||||
setError(err.response?.data?.message || "Failed to fetch rentals");
|
||||
@@ -470,4 +470,4 @@ const MyRentals: React.FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export default MyRentals;
|
||||
export default Renting;
|
||||
Reference in New Issue
Block a user