removed cron job that made rentals active. Now whether or not the rental is active is determined on the fly
This commit is contained in:
@@ -41,11 +41,13 @@ const RentalCancellationModal: React.FC<RentalCancellationModalProps> = ({
|
||||
setError(null);
|
||||
|
||||
// Check if rental status allows cancellation before making API call
|
||||
if (rental.status !== "pending" && rental.status !== "confirmed") {
|
||||
// Use displayStatus as it includes computed "active" status
|
||||
const effectiveStatus = rental.displayStatus || rental.status;
|
||||
if (effectiveStatus !== "pending" && effectiveStatus !== "confirmed") {
|
||||
let errorMessage = "This rental cannot be cancelled";
|
||||
if (rental.status === "active") {
|
||||
if (effectiveStatus === "active") {
|
||||
errorMessage = "Cannot cancel rental - the rental period has already started";
|
||||
} else if (rental.status === "completed") {
|
||||
} else if (effectiveStatus === "completed") {
|
||||
errorMessage = "Cannot cancel rental - the rental has already been completed";
|
||||
} else if (rental.status === "cancelled") {
|
||||
errorMessage = "This rental has already been cancelled";
|
||||
|
||||
@@ -318,13 +318,16 @@ const Owning: React.FC = () => {
|
||||
};
|
||||
|
||||
// Filter owner rentals - exclude cancelled (shown in Rental History)
|
||||
// Use displayStatus for filtering/sorting as it includes computed "active" status
|
||||
const allOwnerRentals = ownerRentals
|
||||
.filter((r) => ["pending", "confirmed", "active"].includes(r.status))
|
||||
.filter((r) => ["pending", "confirmed", "active"].includes(r.displayStatus || r.status))
|
||||
.sort((a, b) => {
|
||||
const statusOrder = { pending: 0, confirmed: 1, active: 2 };
|
||||
const aStatus = a.displayStatus || a.status;
|
||||
const bStatus = b.displayStatus || b.status;
|
||||
return (
|
||||
statusOrder[a.status as keyof typeof statusOrder] -
|
||||
statusOrder[b.status as keyof typeof statusOrder]
|
||||
statusOrder[aStatus as keyof typeof statusOrder] -
|
||||
statusOrder[bStatus as keyof typeof statusOrder]
|
||||
);
|
||||
});
|
||||
|
||||
@@ -401,17 +404,17 @@ const Owning: React.FC = () => {
|
||||
<div className="mb-2">
|
||||
<span
|
||||
className={`badge ${
|
||||
rental.status === "active"
|
||||
(rental.displayStatus || rental.status) === "active"
|
||||
? "bg-success"
|
||||
: rental.status === "pending"
|
||||
: (rental.displayStatus || rental.status) === "pending"
|
||||
? "bg-warning"
|
||||
: rental.status === "confirmed"
|
||||
: (rental.displayStatus || rental.status) === "confirmed"
|
||||
? "bg-info"
|
||||
: "bg-danger"
|
||||
}`}
|
||||
>
|
||||
{rental.status.charAt(0).toUpperCase() +
|
||||
rental.status.slice(1)}
|
||||
{(rental.displayStatus || rental.status).charAt(0).toUpperCase() +
|
||||
(rental.displayStatus || rental.status).slice(1)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -512,7 +515,7 @@ const Owning: React.FC = () => {
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{rental.status === "confirmed" && (
|
||||
{(rental.displayStatus || rental.status) === "confirmed" && (
|
||||
<button
|
||||
className="btn btn-sm btn-outline-danger"
|
||||
onClick={() => handleCancelClick(rental)}
|
||||
@@ -520,7 +523,7 @@ const Owning: React.FC = () => {
|
||||
Cancel
|
||||
</button>
|
||||
)}
|
||||
{rental.status === "active" && (
|
||||
{(rental.displayStatus || rental.status) === "active" && (
|
||||
<button
|
||||
className="btn btn-sm btn-success"
|
||||
onClick={() => handleCompleteClick(rental)}
|
||||
|
||||
@@ -182,8 +182,9 @@ const Renting: React.FC = () => {
|
||||
};
|
||||
|
||||
// Filter rentals - show only active rentals (declined go to history)
|
||||
// Use displayStatus for filtering as it includes computed "active" status
|
||||
const renterActiveRentals = rentals.filter((r) =>
|
||||
["pending", "confirmed", "active"].includes(r.status)
|
||||
["pending", "confirmed", "active"].includes(r.displayStatus || r.status)
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
@@ -268,25 +269,25 @@ const Renting: React.FC = () => {
|
||||
<div className="mb-2">
|
||||
<span
|
||||
className={`badge ${
|
||||
rental.status === "active"
|
||||
(rental.displayStatus || rental.status) === "active"
|
||||
? "bg-success"
|
||||
: rental.status === "pending"
|
||||
: (rental.displayStatus || rental.status) === "pending"
|
||||
? "bg-warning"
|
||||
: rental.status === "confirmed"
|
||||
: (rental.displayStatus || rental.status) === "confirmed"
|
||||
? "bg-info"
|
||||
: rental.status === "declined"
|
||||
: (rental.displayStatus || rental.status) === "declined"
|
||||
? "bg-secondary"
|
||||
: "bg-danger"
|
||||
}`}
|
||||
>
|
||||
{rental.status === "pending"
|
||||
{(rental.displayStatus || rental.status) === "pending"
|
||||
? "Awaiting Owner Approval"
|
||||
: rental.status === "confirmed"
|
||||
: (rental.displayStatus || rental.status) === "confirmed"
|
||||
? "Confirmed & Paid"
|
||||
: rental.status === "declined"
|
||||
: (rental.displayStatus || rental.status) === "declined"
|
||||
? "Declined by Owner"
|
||||
: rental.status.charAt(0).toUpperCase() +
|
||||
rental.status.slice(1)}
|
||||
: (rental.displayStatus || rental.status).charAt(0).toUpperCase() +
|
||||
(rental.displayStatus || rental.status).slice(1)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -362,8 +363,8 @@ const Renting: React.FC = () => {
|
||||
|
||||
<div className="d-flex flex-column gap-2 mt-3">
|
||||
<div className="d-flex gap-2">
|
||||
{(rental.status === "pending" ||
|
||||
rental.status === "confirmed") && (
|
||||
{((rental.displayStatus || rental.status) === "pending" ||
|
||||
(rental.displayStatus || rental.status) === "confirmed") && (
|
||||
<button
|
||||
className="btn btn-sm btn-danger"
|
||||
onClick={() => handleCancelClick(rental)}
|
||||
@@ -371,7 +372,7 @@ const Renting: React.FC = () => {
|
||||
Cancel
|
||||
</button>
|
||||
)}
|
||||
{rental.status === "active" &&
|
||||
{(rental.displayStatus || rental.status) === "active" &&
|
||||
!rental.itemRating &&
|
||||
!rental.itemReviewSubmittedAt && (
|
||||
<button
|
||||
|
||||
@@ -106,6 +106,18 @@ export interface Item {
|
||||
updatedAt: string;
|
||||
}
|
||||
|
||||
export type RentalStatus =
|
||||
| "pending"
|
||||
| "confirmed"
|
||||
| "declined"
|
||||
| "active"
|
||||
| "completed"
|
||||
| "cancelled"
|
||||
| "returned_late"
|
||||
| "returned_late_and_damaged"
|
||||
| "damaged"
|
||||
| "lost";
|
||||
|
||||
export interface Rental {
|
||||
id: string;
|
||||
itemId: string;
|
||||
@@ -117,17 +129,9 @@ export interface Rental {
|
||||
// Fee tracking fields
|
||||
platformFee?: number;
|
||||
payoutAmount?: number;
|
||||
status:
|
||||
| "pending"
|
||||
| "confirmed"
|
||||
| "declined"
|
||||
| "active"
|
||||
| "completed"
|
||||
| "cancelled"
|
||||
| "returned_late"
|
||||
| "returned_late_and_damaged"
|
||||
| "damaged"
|
||||
| "lost";
|
||||
status: RentalStatus;
|
||||
// Computed status (includes "active" when confirmed + start time passed)
|
||||
displayStatus?: RentalStatus;
|
||||
paymentStatus: "pending" | "paid" | "refunded";
|
||||
// Refund tracking fields
|
||||
refundAmount?: number;
|
||||
|
||||
Reference in New Issue
Block a user