replaced vague notes with specific intended use, also fixed modal on top of modal for reviews
This commit is contained in:
210
backend/migrations/20241124000005-create-rentals.js
Normal file
210
backend/migrations/20241124000005-create-rentals.js
Normal file
@@ -0,0 +1,210 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
up: async (queryInterface, Sequelize) => {
|
||||||
|
await queryInterface.createTable("Rentals", {
|
||||||
|
id: {
|
||||||
|
type: Sequelize.UUID,
|
||||||
|
defaultValue: Sequelize.UUIDV4,
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
itemId: {
|
||||||
|
type: Sequelize.UUID,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: "Items",
|
||||||
|
key: "id",
|
||||||
|
},
|
||||||
|
onUpdate: "CASCADE",
|
||||||
|
onDelete: "CASCADE",
|
||||||
|
},
|
||||||
|
renterId: {
|
||||||
|
type: Sequelize.UUID,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: "Users",
|
||||||
|
key: "id",
|
||||||
|
},
|
||||||
|
onUpdate: "CASCADE",
|
||||||
|
onDelete: "CASCADE",
|
||||||
|
},
|
||||||
|
ownerId: {
|
||||||
|
type: Sequelize.UUID,
|
||||||
|
allowNull: false,
|
||||||
|
references: {
|
||||||
|
model: "Users",
|
||||||
|
key: "id",
|
||||||
|
},
|
||||||
|
onUpdate: "CASCADE",
|
||||||
|
onDelete: "CASCADE",
|
||||||
|
},
|
||||||
|
startDateTime: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
endDateTime: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
totalAmount: {
|
||||||
|
type: Sequelize.DECIMAL(10, 2),
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
platformFee: {
|
||||||
|
type: Sequelize.DECIMAL(10, 2),
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
payoutAmount: {
|
||||||
|
type: Sequelize.DECIMAL(10, 2),
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: Sequelize.ENUM(
|
||||||
|
"pending",
|
||||||
|
"confirmed",
|
||||||
|
"declined",
|
||||||
|
"active",
|
||||||
|
"completed",
|
||||||
|
"cancelled",
|
||||||
|
"returned_late",
|
||||||
|
"returned_late_and_damaged",
|
||||||
|
"damaged",
|
||||||
|
"lost"
|
||||||
|
),
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
paymentStatus: {
|
||||||
|
type: Sequelize.ENUM("pending", "paid", "refunded", "not_required"),
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
payoutStatus: {
|
||||||
|
type: Sequelize.ENUM("pending", "completed", "failed"),
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
payoutProcessedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
},
|
||||||
|
stripeTransferId: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
refundAmount: {
|
||||||
|
type: Sequelize.DECIMAL(10, 2),
|
||||||
|
},
|
||||||
|
refundProcessedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
},
|
||||||
|
refundReason: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
},
|
||||||
|
stripeRefundId: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
cancelledBy: {
|
||||||
|
type: Sequelize.ENUM("renter", "owner"),
|
||||||
|
},
|
||||||
|
cancelledAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
},
|
||||||
|
declineReason: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
},
|
||||||
|
stripePaymentMethodId: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
stripePaymentIntentId: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
paymentMethodBrand: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
paymentMethodLast4: {
|
||||||
|
type: Sequelize.STRING,
|
||||||
|
},
|
||||||
|
chargedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
},
|
||||||
|
deliveryMethod: {
|
||||||
|
type: Sequelize.ENUM("pickup", "delivery"),
|
||||||
|
defaultValue: "pickup",
|
||||||
|
},
|
||||||
|
deliveryAddress: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
},
|
||||||
|
intendedUse: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
},
|
||||||
|
itemRating: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
itemReview: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
},
|
||||||
|
itemReviewSubmittedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
},
|
||||||
|
itemReviewVisible: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
|
renterRating: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
renterReview: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
},
|
||||||
|
renterReviewSubmittedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
},
|
||||||
|
renterReviewVisible: {
|
||||||
|
type: Sequelize.BOOLEAN,
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
|
itemPrivateMessage: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
},
|
||||||
|
renterPrivateMessage: {
|
||||||
|
type: Sequelize.TEXT,
|
||||||
|
},
|
||||||
|
actualReturnDateTime: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
},
|
||||||
|
lateFees: {
|
||||||
|
type: Sequelize.DECIMAL(10, 2),
|
||||||
|
defaultValue: 0.0,
|
||||||
|
},
|
||||||
|
damageFees: {
|
||||||
|
type: Sequelize.DECIMAL(10, 2),
|
||||||
|
defaultValue: 0.0,
|
||||||
|
},
|
||||||
|
replacementFees: {
|
||||||
|
type: Sequelize.DECIMAL(10, 2),
|
||||||
|
defaultValue: 0.0,
|
||||||
|
},
|
||||||
|
itemLostReportedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
},
|
||||||
|
damageAssessment: {
|
||||||
|
type: Sequelize.JSONB,
|
||||||
|
defaultValue: {},
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
updatedAt: {
|
||||||
|
type: Sequelize.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add indexes
|
||||||
|
await queryInterface.addIndex("Rentals", ["itemId"]);
|
||||||
|
await queryInterface.addIndex("Rentals", ["renterId"]);
|
||||||
|
await queryInterface.addIndex("Rentals", ["ownerId"]);
|
||||||
|
await queryInterface.addIndex("Rentals", ["status"]);
|
||||||
|
},
|
||||||
|
|
||||||
|
down: async (queryInterface, Sequelize) => {
|
||||||
|
await queryInterface.dropTable("Rentals");
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -124,7 +124,7 @@ const Rental = sequelize.define("Rental", {
|
|||||||
deliveryAddress: {
|
deliveryAddress: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
},
|
},
|
||||||
notes: {
|
intendedUse: {
|
||||||
type: DataTypes.TEXT,
|
type: DataTypes.TEXT,
|
||||||
},
|
},
|
||||||
// Renter's review of the item (existing fields renamed for clarity)
|
// Renter's review of the item (existing fields renamed for clarity)
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ router.post("/", authenticateToken, requireVerifiedEmail, async (req, res) => {
|
|||||||
endDateTime,
|
endDateTime,
|
||||||
deliveryMethod,
|
deliveryMethod,
|
||||||
deliveryAddress,
|
deliveryAddress,
|
||||||
notes,
|
intendedUse,
|
||||||
stripePaymentMethodId,
|
stripePaymentMethodId,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ router.post("/", authenticateToken, requireVerifiedEmail, async (req, res) => {
|
|||||||
status: "pending",
|
status: "pending",
|
||||||
deliveryMethod,
|
deliveryMethod,
|
||||||
deliveryAddress,
|
deliveryAddress,
|
||||||
notes,
|
intendedUse,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only add stripePaymentMethodId if it's provided (for paid rentals)
|
// Only add stripePaymentMethodId if it's provided (for paid rentals)
|
||||||
@@ -1099,7 +1099,7 @@ router.post("/:id/cancel", authenticateToken, async (req, res) => {
|
|||||||
// Mark item return status (owner only)
|
// Mark item return status (owner only)
|
||||||
router.post("/:id/mark-return", authenticateToken, async (req, res) => {
|
router.post("/:id/mark-return", authenticateToken, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { status, actualReturnDateTime, notes, statusOptions } = req.body;
|
const { status, actualReturnDateTime, statusOptions } = req.body;
|
||||||
const rentalId = req.params.id;
|
const rentalId = req.params.id;
|
||||||
const userId = req.user.id;
|
const userId = req.user.id;
|
||||||
|
|
||||||
@@ -1133,7 +1133,6 @@ router.post("/:id/mark-return", authenticateToken, async (req, res) => {
|
|||||||
status: "completed",
|
status: "completed",
|
||||||
payoutStatus: "pending",
|
payoutStatus: "pending",
|
||||||
actualReturnDateTime: actualReturnDateTime || rental.endDateTime,
|
actualReturnDateTime: actualReturnDateTime || rental.endDateTime,
|
||||||
notes: notes || null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch full rental details with associations for email
|
// Fetch full rental details with associations for email
|
||||||
@@ -1177,15 +1176,13 @@ router.post("/:id/mark-return", authenticateToken, async (req, res) => {
|
|||||||
status: "damaged",
|
status: "damaged",
|
||||||
payoutStatus: "pending",
|
payoutStatus: "pending",
|
||||||
actualReturnDateTime: actualReturnDateTime || rental.endDateTime,
|
actualReturnDateTime: actualReturnDateTime || rental.endDateTime,
|
||||||
notes: notes || null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if ALSO returned late
|
// Check if ALSO returned late
|
||||||
if (statusOptions?.returned_late && actualReturnDateTime) {
|
if (statusOptions?.returned_late && actualReturnDateTime) {
|
||||||
const lateReturnDamaged = await LateReturnService.processLateReturn(
|
const lateReturnDamaged = await LateReturnService.processLateReturn(
|
||||||
rentalId,
|
rentalId,
|
||||||
actualReturnDateTime,
|
actualReturnDateTime
|
||||||
notes
|
|
||||||
);
|
);
|
||||||
damageUpdates.status = "returned_late_and_damaged";
|
damageUpdates.status = "returned_late_and_damaged";
|
||||||
damageUpdates.lateFees = lateReturnDamaged.lateCalculation.lateFee;
|
damageUpdates.lateFees = lateReturnDamaged.lateCalculation.lateFee;
|
||||||
@@ -1207,8 +1204,7 @@ router.post("/:id/mark-return", authenticateToken, async (req, res) => {
|
|||||||
|
|
||||||
const lateReturn = await LateReturnService.processLateReturn(
|
const lateReturn = await LateReturnService.processLateReturn(
|
||||||
rentalId,
|
rentalId,
|
||||||
actualReturnDateTime,
|
actualReturnDateTime
|
||||||
notes
|
|
||||||
);
|
);
|
||||||
|
|
||||||
updatedRental = lateReturn.rental;
|
updatedRental = lateReturn.rental;
|
||||||
@@ -1221,7 +1217,6 @@ router.post("/:id/mark-return", authenticateToken, async (req, res) => {
|
|||||||
status: "lost",
|
status: "lost",
|
||||||
payoutStatus: "pending",
|
payoutStatus: "pending",
|
||||||
itemLostReportedAt: new Date(),
|
itemLostReportedAt: new Date(),
|
||||||
notes: notes || null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send notification to customer service
|
// Send notification to customer service
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ class TemplateManager {
|
|||||||
<p><strong>Total Amount:</strong> ${{totalAmount}}</p>
|
<p><strong>Total Amount:</strong> ${{totalAmount}}</p>
|
||||||
<p><strong>Your Earnings:</strong> ${{payoutAmount}}</p>
|
<p><strong>Your Earnings:</strong> ${{payoutAmount}}</p>
|
||||||
<p><strong>Delivery Method:</strong> {{deliveryMethod}}</p>
|
<p><strong>Delivery Method:</strong> {{deliveryMethod}}</p>
|
||||||
<p><strong>Renter Notes:</strong> {{rentalNotes}}</p>
|
<p><strong>Intended Use:</strong> {{intendedUse}}</p>
|
||||||
<p><a href="{{approveUrl}}" class="button">Review & Respond</a></p>
|
<p><a href="{{approveUrl}}" class="button">Review & Respond</a></p>
|
||||||
<p>Please respond to this request within 24 hours.</p>
|
<p>Please respond to this request within 24 hours.</p>
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ class RentalFlowEmailService {
|
|||||||
* @param {string} rental.totalAmount - Total rental amount
|
* @param {string} rental.totalAmount - Total rental amount
|
||||||
* @param {string} rental.payoutAmount - Owner's payout amount
|
* @param {string} rental.payoutAmount - Owner's payout amount
|
||||||
* @param {string} rental.deliveryMethod - Delivery method
|
* @param {string} rental.deliveryMethod - Delivery method
|
||||||
* @param {string} rental.notes - Rental notes from renter
|
|
||||||
* @returns {Promise<{success: boolean, messageId?: string, error?: string}>}
|
* @returns {Promise<{success: boolean, messageId?: string, error?: string}>}
|
||||||
*/
|
*/
|
||||||
async sendRentalRequestEmail(owner, renter, rental) {
|
async sendRentalRequestEmail(owner, renter, rental) {
|
||||||
@@ -88,7 +87,7 @@ class RentalFlowEmailService {
|
|||||||
? parseFloat(rental.payoutAmount).toFixed(2)
|
? parseFloat(rental.payoutAmount).toFixed(2)
|
||||||
: "0.00",
|
: "0.00",
|
||||||
deliveryMethod: rental.deliveryMethod || "Not specified",
|
deliveryMethod: rental.deliveryMethod || "Not specified",
|
||||||
rentalNotes: rental.notes || "No additional notes provided",
|
intendedUse: rental.intendedUse || "Not specified",
|
||||||
approveUrl: approveUrl,
|
approveUrl: approveUrl,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -60,10 +60,9 @@ class LateReturnService {
|
|||||||
* Process late return and update rental with fees
|
* Process late return and update rental with fees
|
||||||
* @param {string} rentalId - Rental ID
|
* @param {string} rentalId - Rental ID
|
||||||
* @param {Date} actualReturnDateTime - When item was returned
|
* @param {Date} actualReturnDateTime - When item was returned
|
||||||
* @param {string} notes - Optional notes about the return
|
|
||||||
* @returns {Object} - Updated rental with late fee information
|
* @returns {Object} - Updated rental with late fee information
|
||||||
*/
|
*/
|
||||||
static async processLateReturn(rentalId, actualReturnDateTime, notes = null) {
|
static async processLateReturn(rentalId, actualReturnDateTime) {
|
||||||
const rental = await Rental.findByPk(rentalId, {
|
const rental = await Rental.findByPk(rentalId, {
|
||||||
include: [{ model: Item, as: "item" }],
|
include: [{ model: Item, as: "item" }],
|
||||||
});
|
});
|
||||||
@@ -84,10 +83,6 @@ class LateReturnService {
|
|||||||
payoutStatus: "pending",
|
payoutStatus: "pending",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (notes) {
|
|
||||||
updates.notes = notes;
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedRental = await rental.update(updates);
|
const updatedRental = await rental.update(updates);
|
||||||
|
|
||||||
// Send notification to customer service if late return detected
|
// Send notification to customer service if late return detected
|
||||||
|
|||||||
@@ -295,8 +295,8 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="info-box">
|
<div class="info-box">
|
||||||
<p><strong>Renter's Notes:</strong></p>
|
<p><strong>Intended Use:</strong></p>
|
||||||
<p>{{rentalNotes}}</p>
|
<p>{{intendedUse}}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="text-align: center">
|
<div style="text-align: center">
|
||||||
|
|||||||
@@ -289,7 +289,6 @@ describe('Rentals Routes', () => {
|
|||||||
endDateTime: '2024-01-15T18:00:00.000Z',
|
endDateTime: '2024-01-15T18:00:00.000Z',
|
||||||
deliveryMethod: 'pickup',
|
deliveryMethod: 'pickup',
|
||||||
deliveryAddress: null,
|
deliveryAddress: null,
|
||||||
notes: 'Test rental',
|
|
||||||
stripePaymentMethodId: 'pm_test123',
|
stripePaymentMethodId: 'pm_test123',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -449,7 +449,6 @@ describe('EmailService', () => {
|
|||||||
totalAmount: 150.00,
|
totalAmount: 150.00,
|
||||||
payoutAmount: 135.00,
|
payoutAmount: 135.00,
|
||||||
deliveryMethod: 'pickup',
|
deliveryMethod: 'pickup',
|
||||||
notes: 'Please have it ready by 9am',
|
|
||||||
item: { name: 'Power Drill' }
|
item: { name: 'Power Drill' }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -522,7 +521,6 @@ describe('EmailService', () => {
|
|||||||
totalAmount: 0,
|
totalAmount: 0,
|
||||||
payoutAmount: 0,
|
payoutAmount: 0,
|
||||||
deliveryMethod: 'pickup',
|
deliveryMethod: 'pickup',
|
||||||
notes: null,
|
|
||||||
item: { name: 'Free Item' }
|
item: { name: 'Free Item' }
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -531,39 +529,6 @@ describe('EmailService', () => {
|
|||||||
expect(result.success).toBe(true);
|
expect(result.success).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle missing rental notes', async () => {
|
|
||||||
const mockOwner = {
|
|
||||||
email: 'owner@example.com',
|
|
||||||
firstName: 'John'
|
|
||||||
};
|
|
||||||
const mockRenter = {
|
|
||||||
firstName: 'Jane',
|
|
||||||
lastName: 'Doe'
|
|
||||||
};
|
|
||||||
|
|
||||||
User.findByPk
|
|
||||||
.mockResolvedValueOnce(mockOwner)
|
|
||||||
.mockResolvedValueOnce(mockRenter);
|
|
||||||
|
|
||||||
const rental = {
|
|
||||||
id: 1,
|
|
||||||
ownerId: 10,
|
|
||||||
renterId: 20,
|
|
||||||
startDateTime: new Date('2024-12-01T10:00:00Z'),
|
|
||||||
endDateTime: new Date('2024-12-03T10:00:00Z'),
|
|
||||||
totalAmount: 100,
|
|
||||||
payoutAmount: 90,
|
|
||||||
deliveryMethod: 'delivery',
|
|
||||||
notes: null, // No notes
|
|
||||||
item: { name: 'Test Item' }
|
|
||||||
};
|
|
||||||
|
|
||||||
const result = await emailService.sendRentalRequestEmail(rental);
|
|
||||||
|
|
||||||
expect(result.success).toBe(true);
|
|
||||||
expect(mockSend).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should generate correct approval URL', async () => {
|
it('should generate correct approval URL', async () => {
|
||||||
const mockOwner = {
|
const mockOwner = {
|
||||||
email: 'owner@example.com',
|
email: 'owner@example.com',
|
||||||
@@ -589,7 +554,6 @@ describe('EmailService', () => {
|
|||||||
totalAmount: 100,
|
totalAmount: 100,
|
||||||
payoutAmount: 90,
|
payoutAmount: 90,
|
||||||
deliveryMethod: 'pickup',
|
deliveryMethod: 'pickup',
|
||||||
notes: 'Test notes',
|
|
||||||
item: { name: 'Test Item' }
|
item: { name: 'Test Item' }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ const ReturnStatusModal: React.FC<ReturnStatusModalProps> = ({
|
|||||||
lost: false,
|
lost: false,
|
||||||
});
|
});
|
||||||
const [actualReturnDateTime, setActualReturnDateTime] = useState("");
|
const [actualReturnDateTime, setActualReturnDateTime] = useState("");
|
||||||
const [notes, setNotes] = useState("");
|
|
||||||
const [conditionNotes, setConditionNotes] = useState("");
|
const [conditionNotes, setConditionNotes] = useState("");
|
||||||
const [photos, setPhotos] = useState<File[]>([]);
|
const [photos, setPhotos] = useState<File[]>([]);
|
||||||
const [processing, setProcessing] = useState(false);
|
const [processing, setProcessing] = useState(false);
|
||||||
@@ -56,7 +55,6 @@ const ReturnStatusModal: React.FC<ReturnStatusModalProps> = ({
|
|||||||
lost: false,
|
lost: false,
|
||||||
});
|
});
|
||||||
setActualReturnDateTime("");
|
setActualReturnDateTime("");
|
||||||
setNotes("");
|
|
||||||
setConditionNotes("");
|
setConditionNotes("");
|
||||||
setPhotos([]);
|
setPhotos([]);
|
||||||
setError(null);
|
setError(null);
|
||||||
@@ -71,13 +69,13 @@ const ReturnStatusModal: React.FC<ReturnStatusModalProps> = ({
|
|||||||
|
|
||||||
// Create blob URLs for photo previews and clean them up
|
// Create blob URLs for photo previews and clean them up
|
||||||
const photoBlobUrls = useMemo(() => {
|
const photoBlobUrls = useMemo(() => {
|
||||||
return photos.map(photo => URL.createObjectURL(photo));
|
return photos.map((photo) => URL.createObjectURL(photo));
|
||||||
}, [photos]);
|
}, [photos]);
|
||||||
|
|
||||||
// Cleanup blob URLs when photos change or component unmounts
|
// Cleanup blob URLs when photos change or component unmounts
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
photoBlobUrls.forEach(url => URL.revokeObjectURL(url));
|
photoBlobUrls.forEach((url) => URL.revokeObjectURL(url));
|
||||||
};
|
};
|
||||||
}, [photoBlobUrls]);
|
}, [photoBlobUrls]);
|
||||||
|
|
||||||
@@ -202,6 +200,7 @@ const ReturnStatusModal: React.FC<ReturnStatusModalProps> = ({
|
|||||||
);
|
);
|
||||||
if (!hasSelection) {
|
if (!hasSelection) {
|
||||||
setError("Please select at least one return status option");
|
setError("Please select at least one return status option");
|
||||||
|
setProcessing(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,7 +315,6 @@ const ReturnStatusModal: React.FC<ReturnStatusModalProps> = ({
|
|||||||
const data: any = {
|
const data: any = {
|
||||||
status: primaryStatus,
|
status: primaryStatus,
|
||||||
statusOptions, // Send all selected options
|
statusOptions, // Send all selected options
|
||||||
notes: notes.trim() || undefined,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (statusOptions.returned_late) {
|
if (statusOptions.returned_late) {
|
||||||
@@ -346,7 +344,6 @@ const ReturnStatusModal: React.FC<ReturnStatusModalProps> = ({
|
|||||||
lost: false,
|
lost: false,
|
||||||
});
|
});
|
||||||
setActualReturnDateTime("");
|
setActualReturnDateTime("");
|
||||||
setNotes("");
|
|
||||||
setConditionNotes("");
|
setConditionNotes("");
|
||||||
setPhotos([]);
|
setPhotos([]);
|
||||||
setError(null);
|
setError(null);
|
||||||
@@ -950,7 +947,7 @@ const ReturnStatusModal: React.FC<ReturnStatusModalProps> = ({
|
|||||||
>
|
>
|
||||||
<span className="visually-hidden">Loading...</span>
|
<span className="visually-hidden">Loading...</span>
|
||||||
</div>
|
</div>
|
||||||
Processing...
|
Submitting...
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
"Submit"
|
"Submit"
|
||||||
|
|||||||
@@ -69,6 +69,18 @@ const ReviewItemModal: React.FC<ReviewItemModalProps> = ({
|
|||||||
|
|
||||||
if (!show) return null;
|
if (!show) return null;
|
||||||
|
|
||||||
|
// Show success modal instead of review modal after successful submission
|
||||||
|
if (showSuccessModal) {
|
||||||
|
return (
|
||||||
|
<SuccessModal
|
||||||
|
show={true}
|
||||||
|
onClose={handleSuccessModalClose}
|
||||||
|
title="Thank you for your review!"
|
||||||
|
message={successMessage}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="modal d-block"
|
className="modal d-block"
|
||||||
@@ -212,13 +224,6 @@ const ReviewItemModal: React.FC<ReviewItemModalProps> = ({
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<SuccessModal
|
|
||||||
show={showSuccessModal}
|
|
||||||
onClose={handleSuccessModalClose}
|
|
||||||
title="Thank you for your review!"
|
|
||||||
message={successMessage}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -69,6 +69,18 @@ const ReviewRenterModal: React.FC<ReviewRenterModalProps> = ({
|
|||||||
|
|
||||||
if (!show) return null;
|
if (!show) return null;
|
||||||
|
|
||||||
|
// Show success modal instead of review modal after successful submission
|
||||||
|
if (showSuccessModal) {
|
||||||
|
return (
|
||||||
|
<SuccessModal
|
||||||
|
show={true}
|
||||||
|
onClose={handleSuccessModalClose}
|
||||||
|
title="Thank you for your review!"
|
||||||
|
message={successMessage}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="modal d-block"
|
className="modal d-block"
|
||||||
@@ -212,13 +224,6 @@ const ReviewRenterModal: React.FC<ReviewRenterModalProps> = ({
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<SuccessModal
|
|
||||||
show={showSuccessModal}
|
|
||||||
onClose={handleSuccessModalClose}
|
|
||||||
title="Thank you for your review!"
|
|
||||||
message={successMessage}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -359,6 +359,14 @@ const Owning: React.FC = () => {
|
|||||||
<strong>Total:</strong> ${rental.totalAmount}
|
<strong>Total:</strong> ${rental.totalAmount}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
{rental.intendedUse && rental.status === "pending" && (
|
||||||
|
<div className="alert alert-light mt-2 mb-2 p-2 small">
|
||||||
|
<strong>Intended Use:</strong>
|
||||||
|
<br />
|
||||||
|
{rental.intendedUse}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{rental.status === "cancelled" &&
|
{rental.status === "cancelled" &&
|
||||||
rental.refundAmount !== undefined && (
|
rental.refundAmount !== undefined && (
|
||||||
<div className="alert alert-info mt-2 mb-2 p-2 small">
|
<div className="alert alert-info mt-2 mb-2 p-2 small">
|
||||||
@@ -620,9 +628,7 @@ const Owning: React.FC = () => {
|
|||||||
onClick={() => toggleAvailability(item)}
|
onClick={() => toggleAvailability(item)}
|
||||||
className="btn btn-sm btn-outline-info"
|
className="btn btn-sm btn-outline-info"
|
||||||
>
|
>
|
||||||
{item.isAvailable
|
{item.isAvailable ? "Mark Unavailable" : "Mark Available"}
|
||||||
? "Mark Unavailable"
|
|
||||||
: "Mark Available"}
|
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => handleDelete(item.id)}
|
onClick={() => handleDelete(item.id)}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const RentItem: React.FC = () => {
|
|||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
deliveryMethod: "pickup" as "pickup" | "delivery",
|
deliveryMethod: "pickup" as "pickup" | "delivery",
|
||||||
deliveryAddress: "",
|
deliveryAddress: "",
|
||||||
|
intendedUse: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const [manualSelection, setManualSelection] = useState({
|
const [manualSelection, setManualSelection] = useState({
|
||||||
@@ -143,6 +144,7 @@ const RentItem: React.FC = () => {
|
|||||||
endDateTime,
|
endDateTime,
|
||||||
deliveryMethod: formData.deliveryMethod,
|
deliveryMethod: formData.deliveryMethod,
|
||||||
deliveryAddress: formData.deliveryAddress,
|
deliveryAddress: formData.deliveryAddress,
|
||||||
|
intendedUse: formData.intendedUse || undefined,
|
||||||
totalAmount: totalCost,
|
totalAmount: totalCost,
|
||||||
};
|
};
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -261,6 +263,26 @@ const RentItem: React.FC = () => {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<div className="mb-3">
|
||||||
|
<label htmlFor="intendedUse" className="form-label">
|
||||||
|
What will you use this for?{" "}
|
||||||
|
<span className="text-muted">(Optional)</span>
|
||||||
|
</label>
|
||||||
|
<textarea
|
||||||
|
id="intendedUse"
|
||||||
|
name="intendedUse"
|
||||||
|
className="form-control"
|
||||||
|
rows={3}
|
||||||
|
value={formData.intendedUse}
|
||||||
|
onChange={handleChange}
|
||||||
|
placeholder="Let the owner know how you plan to use their item..."
|
||||||
|
maxLength={500}
|
||||||
|
/>
|
||||||
|
<div className="form-text">
|
||||||
|
{formData.intendedUse.length}/500 characters
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{!manualSelection.startDate ||
|
{!manualSelection.startDate ||
|
||||||
!manualSelection.endDate ||
|
!manualSelection.endDate ||
|
||||||
!getRentalData() ? (
|
!getRentalData() ? (
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ export const rentalAPI = {
|
|||||||
// Return status marking
|
// Return status marking
|
||||||
markReturn: (
|
markReturn: (
|
||||||
id: string,
|
id: string,
|
||||||
data: { status: string; actualReturnDateTime?: string; notes?: string }
|
data: { status: string; actualReturnDateTime?: string }
|
||||||
) => api.post(`/rentals/${id}/mark-return`, data),
|
) => api.post(`/rentals/${id}/mark-return`, data),
|
||||||
reportDamage: (id: string, data: any) =>
|
reportDamage: (id: string, data: any) =>
|
||||||
api.post(`/rentals/${id}/report-damage`, data),
|
api.post(`/rentals/${id}/report-damage`, data),
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ export interface Rental {
|
|||||||
stripeTransferId?: string;
|
stripeTransferId?: string;
|
||||||
deliveryMethod: "pickup" | "delivery";
|
deliveryMethod: "pickup" | "delivery";
|
||||||
deliveryAddress?: string;
|
deliveryAddress?: string;
|
||||||
notes?: string;
|
intendedUse?: string;
|
||||||
rating?: number;
|
rating?: number;
|
||||||
review?: string;
|
review?: string;
|
||||||
declineReason?: string;
|
declineReason?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user