Implement add toy and edit toy functions to sqlite database
This commit is contained in:
@@ -1,58 +1,55 @@
|
||||
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { ListOrdered, Check, X } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Image from "next/image";
|
||||
import type { Toy } from "@/types";
|
||||
import { mockToys } from "@/lib/mockData";
|
||||
import type { Toy, RentalRequest } from "@/types";
|
||||
import { getAllToys } from "@/data/operations";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
interface RentalRequest {
|
||||
id: string;
|
||||
toy: Toy;
|
||||
requesterName: string;
|
||||
requesterId: string;
|
||||
requestedDates: string; // e.g., "Aug 5, 2024 - Aug 10, 2024"
|
||||
status: 'pending' | 'approved' | 'declined';
|
||||
message?: string;
|
||||
dataAiHint?: string;
|
||||
// This is still mock data. In a real app, this would come from the database.
|
||||
function getMockRequests(): RentalRequest[] {
|
||||
const allToys = getAllToys();
|
||||
const myToys = allToys.filter(t => t.ownerId === 1);
|
||||
|
||||
if (myToys.length === 0) return [];
|
||||
|
||||
const rentalRequests: RentalRequest[] = [
|
||||
{
|
||||
id: 'req1',
|
||||
toy: myToys[0],
|
||||
requesterName: 'Charlie Brown',
|
||||
requesterId: 4,
|
||||
requestedDates: 'August 10, 2024 - August 17, 2024',
|
||||
status: 'pending',
|
||||
message: 'My son would love to play with these for his birthday week!',
|
||||
dataAiHint: myToys[0]?.category.toLowerCase(),
|
||||
},
|
||||
{
|
||||
id: 'req2',
|
||||
toy: myToys.length > 1 ? myToys[1] : myToys[0],
|
||||
requesterName: 'Diana Prince',
|
||||
requesterId: 5,
|
||||
requestedDates: 'September 1, 2024 - September 5, 2024',
|
||||
status: 'approved',
|
||||
dataAiHint: (myToys.length > 1 ? myToys[1] : myToys[0])?.category.toLowerCase(),
|
||||
},
|
||||
{
|
||||
id: 'req3',
|
||||
toy: myToys[0],
|
||||
requesterName: 'Edward Nigma',
|
||||
requesterId: 6,
|
||||
requestedDates: 'July 20, 2024 - July 22, 2024',
|
||||
status: 'declined',
|
||||
message: 'Looking for a weekend rental.',
|
||||
dataAiHint: myToys[0]?.category.toLowerCase(),
|
||||
},
|
||||
];
|
||||
return rentalRequests;
|
||||
}
|
||||
|
||||
// Mock data: rental requests for the current user's toys
|
||||
const rentalRequests: RentalRequest[] = [
|
||||
{
|
||||
id: 'req1',
|
||||
toy: mockToys[0], // Colorful Building Blocks Set (owned by user1)
|
||||
requesterName: 'Charlie Brown',
|
||||
requesterId: 'user4',
|
||||
requestedDates: 'August 10, 2024 - August 17, 2024',
|
||||
status: 'pending',
|
||||
message: 'My son would love to play with these for his birthday week!',
|
||||
dataAiHint: mockToys[0]?.category.toLowerCase(),
|
||||
},
|
||||
{
|
||||
id: 'req2',
|
||||
toy: mockToys[3], // Plush Teddy Bear (owned by user1)
|
||||
requesterName: 'Diana Prince',
|
||||
requesterId: 'user5',
|
||||
requestedDates: 'September 1, 2024 - September 5, 2024',
|
||||
status: 'approved',
|
||||
dataAiHint: mockToys[3]?.category.toLowerCase(),
|
||||
},
|
||||
{
|
||||
id: 'req3',
|
||||
toy: mockToys[0],
|
||||
requesterName: 'Edward Nigma',
|
||||
requesterId: 'user6',
|
||||
requestedDates: 'July 20, 2024 - July 22, 2024',
|
||||
status: 'declined',
|
||||
message: 'Looking for a weekend rental.',
|
||||
dataAiHint: mockToys[0]?.category.toLowerCase(),
|
||||
},
|
||||
];
|
||||
|
||||
// Assuming current user is user1 for whom these requests are relevant
|
||||
const currentUserToyRequests = rentalRequests.filter(req => req.toy.ownerId === 'user1');
|
||||
const currentUserToyRequests = getMockRequests();
|
||||
|
||||
|
||||
export default function RentalRequestsPage() {
|
||||
|
||||
Reference in New Issue
Block a user