Skip to content

Commit 9b7c693

Browse files
committed
updated: Epdated the controlflow and migrated the depriciated to nextJs latest
1 parent 835c02f commit 9b7c693

File tree

15 files changed

+132
-151
lines changed

15 files changed

+132
-151
lines changed

src/actions/bookingActions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export async function getAllBookingsForProperty(
129129
const bookingsRaw :any= await prisma.$queryRaw`
130130
SELECT b.* , c.checkInDate , c.checkOutDate
131131
FROM Booking as b
132-
JOIN Checkincheckout as c ON b.id = c.bookingId
132+
JOIN CheckInCheckOut as c ON b.id = c.bookingId
133133
WHERE b.propertyId = ${propertyId}
134134
`;
135135

@@ -262,7 +262,7 @@ export async function is_available(from: Date, to: Date, propertyId: string) {
262262
SELECT p.maxGuests
263263
FROM Property AS p
264264
LEFT JOIN Booking AS b ON b.propertyId = p.id
265-
LEFT JOIN Checkincheckout AS c ON c.bookingId = b.id
265+
LEFT JOIN CheckInCheckOut AS c ON c.bookingId = b.id
266266
WHERE p.id = ${propertyId}
267267
AND NOT (
268268
${from} >= c.checkoutDate OR

src/actions/favouritesAction.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ export default async function addLiked(
3838
}
3939

4040

41-
42-
4341
export async function deleteLiked(likedData: TFavourite) {
4442
try {
4543
const validatedFavorites = favouriteSchema.parse(likedData);

src/actions/listingActions.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isAuthenticatedUserInDb } from "./userActions";
44
import prisma from "@/lib/db";
55
import { revalidatePath } from "next/cache";
66
import cuid from "cuid"; // Import cuid for generating unique IDs
7+
import { Listing } from "@prisma/client";
78

89
export async function createListing(
910
listingValues: TListing
@@ -56,28 +57,22 @@ export async function getListing(
5657
): Promise<TListing | null> {
5758
try {
5859
if (!propertyId || !userId) {
59-
throw new Error("couldn't get the user or property");
60+
throw new Error("Couldn't get the user or property");
6061
}
62+
6163
console.log("property, userId:", propertyId, userId);
62-
const listing = await prisma.listing.findUnique({
63-
where: {
64-
userId_propertyId: {
65-
userId,
66-
propertyId},
67-
availabilityEnd: {
68-
gte: new Date(),
69-
},
70-
}
71-
}
72-
);
64+
65+
const listing = await prisma.$queryRaw<TListing[]>`
66+
SELECT * FROM Listing WHERE userId = ${userId} AND propertyId = ${propertyId}
67+
`;
68+
7369
console.log("Listing in getListing: ", listing);
7470

75-
const validatedListing = listingSchema.parse(listing);
71+
if (listing.length === 0) return null;
7672

77-
revalidatePath("/");
78-
return validatedListing;
73+
return listing[0]; // ✅ Return first item only
7974
} catch (error) {
8075
console.error("Error in finding the listing: ", error);
8176
return null;
8277
}
83-
}
78+
}

src/app/(main)/bookings/[kindeId]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
} from "@/components/ui/card";
1717
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
1818

19-
const Bookings = async ({ params }: { params: { kindeId: string } }) => {
19+
const Bookings = async (props: { params: Promise<{ kindeId: string }> }) => {
20+
const params = await props.params;
2021
const kindeId = params.kindeId;
2122
const bookings = (await getAllBookedProperties(kindeId)) as (TBooking & {
2223
property: TProperty;

src/app/(main)/get-all-bookings/[userId]/page.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ type BookingDetails = {
1818
};
1919

2020
type Props = {
21-
params: {
21+
params: Promise<{
2222
userId: string;
23-
};
23+
}>;
2424
};
2525

26-
export default async function AllBookings({ params }: Props) {
26+
export default async function AllBookings(props: Props) {
27+
const params = await props.params;
2728
const { userId } = params;
28-
// const router = useRouter();
29+
// const router = useRouter();
2930

3031
const user = await getUserByKindeId(userId);
3132
if (!user) {
3233
return <h1>User Not found</h1>;
3334
}
3435

35-
const all_booking_property_details: BookingDetails[] = await AllBookingPropertyDetails(user.id ?? "") || [];
36+
const all_booking_property_details: BookingDetails[] = (await AllBookingPropertyDetails(user.id ?? "")) || [];
3637

3738
// Redirect to '/' if there are no bookings
3839
if (all_booking_property_details.length === 0) {

src/app/(main)/page.tsx

Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
1313
import PropTypesSelect from "@/components/propertyTypes/propTypes";
1414
import Footer from "@/components/footer/footer";
1515
import AboutUs from "@/components/contents/Aboutus";
16-
import NoPropertyAvailable from "@/components/property/noProps";
1716

1817
export default async function Home({
19-
searchParams = {},
18+
searchParams,
2019
}: {
21-
searchParams?: { [key: string]: string | string[] | undefined };
20+
searchParams?: Promise<{ [key: string]: string | string[] | undefined }>;
2221
}) {
23-
// Handle undefined safely
22+
const resolvedParams = await searchParams;
23+
24+
// Helper to extract query parameters
2425
const getParam = (key: string): string | undefined => {
25-
const value = searchParams?.[key];
26+
const value = resolvedParams?.[key];
2627
if (Array.isArray(value)) return value[0]?.trim() || undefined;
2728
return value?.trim() || undefined;
2829
};
2930

31+
// Format date to YYYY-MM-DD or return undefined
3032
const toDateStringOrUndefined = (value?: string): string | undefined => {
3133
if (!value) return undefined;
3234
const date = new Date(value);
@@ -39,84 +41,81 @@ export default async function Home({
3941
const typeParam = getParam("type");
4042
const type = typeParam && typeParam !== "Any" ? typeParam : undefined;
4143

42-
console.log("Parsed search params:", {
43-
destination,
44-
checkIn,
45-
checkOut,
46-
type,
47-
});
48-
44+
// Fetch authenticated user (optional)
4945
let kindeUser: TKindeUser | null = null;
5046
try {
5147
const { getUser } = getKindeServerSession();
5248
kindeUser = (await getUser()) as TKindeUser;
5349
console.log("User:", kindeUser);
5450
} catch (error) {
55-
console.log("Finding User Error", error);
51+
console.warn("Failed to fetch user:", error);
5652
}
5753

58-
// Fetch listings
59-
const properties =
60-
destination || checkIn || checkOut || type
61-
? await getFilteredListings(destination, checkIn, checkOut, type)
62-
: await getAllListedProperties();
63-
64-
console.log("Fetched properties:", properties);
65-
66-
if (!properties || properties.length === 0) {
67-
return <NoPropertyAvailable />;
68-
}
54+
// Get property listings based on filters (if any)
55+
const properties = destination || checkIn || checkOut || type
56+
? await getFilteredListings(destination, checkIn, checkOut, type)
57+
: await getAllListedProperties();
6958

59+
// Prepare property cards
7060
const propertyCards = await Promise.all(
7161
properties.map(async (property) => {
7262
if (!property?.id || !property?.locationId) {
73-
console.warn("Skipping invalid property:", property);
63+
console.warn("Skipping property with missing ID or location:", property);
7464
return null;
7565
}
7666

77-
const [reviews, amenities, images, location, user] = await Promise.all([
78-
getAllReviewsById(property.id),
79-
getAllAmenitiesForProperty(property.id),
80-
getAllImagesbyId(property.id),
81-
getLocationById(property.locationId),
82-
getUserById(property.userId),
83-
]);
67+
try {
68+
const [reviews, amenities, images, location, user] = await Promise.all([
69+
getAllReviewsById(property.id),
70+
getAllAmenitiesForProperty(property.id),
71+
getAllImagesbyId(property.id),
72+
getLocationById(property.locationId),
73+
getUserById(property.userId),
74+
]);
8475

85-
if (!amenities || !location || !user) {
86-
console.error("Couldn't fetch all details for property:", property);
76+
if (!location || !amenities || !user) {
77+
console.error("Incomplete data for property:", property.id);
78+
return null;
79+
}
80+
81+
return (
82+
<PropertyCard
83+
key={property.id}
84+
property={property}
85+
location={location}
86+
reviews={reviews}
87+
amenities={amenities}
88+
images={images}
89+
type="book"
90+
hostName={user.name}
91+
hostKindeId={property.userId}
92+
favorites=""
93+
status={null}
94+
/>
95+
);
96+
} catch (error) {
97+
console.error("Failed to fetch property details:", property.id, error);
8798
return null;
8899
}
89-
90-
return (
91-
<PropertyCard
92-
key={property.id}
93-
property={property}
94-
location={location}
95-
reviews={reviews}
96-
amenities={amenities}
97-
images={images}
98-
type="book"
99-
hostName={user.name}
100-
hostKindeId={property.userId}
101-
favorites=""
102-
status={null}
103-
/>
104-
);
105100
})
106101
);
107102

103+
const validCards = propertyCards.filter(Boolean);
104+
108105
return (
109106
<>
110107
<PropTypesSelect />
111-
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 p-6">
112-
{propertyCards.filter(Boolean).length > 0 ? (
113-
propertyCards.filter(Boolean)
108+
109+
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 p-6 min-h-[50vh]">
110+
{validCards.length > 0 ? (
111+
validCards
114112
) : (
115-
<div className="text-red-600 text-center font-semibold text-lg w-full mt-8">
113+
<div className="text-red-600 text-center font-semibold text-lg w-full mt-8 col-span-full">
116114
No property available
117115
</div>
118116
)}
119117
</div>
118+
120119
<AboutUs />
121120
<Footer />
122121
</>

src/app/(main)/properties/[propertyId]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
1111
// import { useRouter } from "next/navigation";
1212
import React from "react";
1313

14-
const page = async ({ params }: { params: { propertyId: string } }) => {
14+
const page = async (props: { params: Promise<{ propertyId: string }> }) => {
15+
const params = await props.params;
1516
// const router=useRouter()
1617
// const {toast}=useToast()
1718
const property = await getPropertyById(params.propertyId);

src/app/(main)/user/[userId]/delete-logs/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { Card, CardHeader, CardTitle, CardContent, CardDescription } from "@/com
44
import { Table, TableHeader, TableRow, TableCell, TableBody } from "@/components/ui/table";
55

66
type Props = {
7-
params: { userId: string };
7+
params: Promise<{ userId: string }>;
88
};
99

10-
export default async function AllBookingsdelLogs({ params }: Props) {
10+
export default async function AllBookingsdelLogs(props: Props) {
11+
const params = await props.params;
1112
const { userId } = params;
1213
const user = await getUserByKindeId(userId);
1314

src/app/(main)/user/[userId]/edit-property/[propertyId]/DeleteProps/page.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import { getKindeServerSession } from '@kinde-oss/kinde-auth-nextjs/server';
66
import React from 'react'
77

88
type Props = {
9-
params: {
9+
params: Promise<{
1010
kindeUserId: string;
1111
propertyId: string;
12-
};
12+
}>;
1313
};
14-
export default async function Deleteprops({ params }: Props){
14+
export default async function Deleteprops(props: Props) {
15+
const params = await props.params;
1516
const {kindeUserId,propertyId}=params
1617
const { getUser } = getKindeServerSession();
1718
const kindeUser = (await getUser()) as TKindeUser;
@@ -22,7 +23,7 @@ export default async function Deleteprops({ params }: Props){
2223
if(!user){
2324
return(<h1>Sorry..Something went wrong</h1>)
2425
}
25-
26+
2627
const bookings=await getBookingDetailsByPropertyId(propertyId)
2728
return(
2829
<>

src/app/(main)/user/[userId]/edit-property/[propertyId]/page.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server";
55
import React from "react";
66

77
type Props = {
8-
params: {
8+
params: Promise<{
99
kindeUserId: string;
1010
propertyId: string;
11-
};
11+
}>;
1212
};
1313

14-
export default async function AddPropertyPage({ params }: Props) {
14+
export default async function AddPropertyPage(props: Props) {
15+
const params = await props.params;
1516
const { kindeUserId, propertyId } = params; // Access both parameters here
1617
console.log(kindeUserId+'sdkncdsbbvh445@#$54f')
1718
const { getUser } = getKindeServerSession();

0 commit comments

Comments
 (0)