Skip to content

Commit

Permalink
full completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rofiyev committed Sep 2, 2024
0 parents commit ddc5bec
Show file tree
Hide file tree
Showing 88 changed files with 10,261 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
27 changes: 27 additions & 0 deletions actions/getCurrentUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
import { getServerSession } from "next-auth/next";
import prisma from "@/libs/prismadb";

export async function getSession() {
return await getServerSession(authOptions);
}

export default async function getCurrentUser() {
try {
const session = await getSession();

if (!session?.user?.email) return null;

const currentUser = await prisma.user.findUnique({
where: {
email: session.user.email as string,
},
});

if (!currentUser) return null;

return currentUser;
} catch (error) {
return null;
}
}
20 changes: 20 additions & 0 deletions actions/getFavouriteListings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import prisma from "@/libs/prismadb";
import getCurrentUser from "./getCurrentUser";

export default async function getFavouriteListings() {
try {
const currentUser = await getCurrentUser();

if (!currentUser) return [];

const favourites = await prisma.listings.findMany({
where: {
id: { in: [...(currentUser.favoriteIds || [])] },
},
});

return favourites;
} catch (error: any) {
throw new Error(error);
}
}
24 changes: 24 additions & 0 deletions actions/getListingById.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import prisma from "@/libs/prismadb";

interface IParams {
listingId: string;
}

export default async function getListingById(params: IParams) {
try {
const { listingId } = params;

const listing = await prisma.listings.findUnique({
where: { id: listingId },
include: {
user: true,
},
});

if (!listing) return null;

return listing;
} catch (error: any) {
throw new Error(error);
}
}
63 changes: 63 additions & 0 deletions actions/getListings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import prisma from "@/libs/prismadb";

export interface IListingsParams {
userId?: string;
guestCount?: number;
roomCount?: number;
bathroomCount?: number;
startDate?: string;
endDate?: string;
locationValue?: string;
category?: string;
}

export default async function getListings(params: IListingsParams) {
try {
const {
userId,
roomCount,
guestCount,
bathroomCount,
startDate,
endDate,
locationValue,
category,
} = params;

let query: any = {};

if (userId) query.userId = userId;
if (category) query.category = category;
if (roomCount) query.roomCount = { gte: +roomCount };
if (guestCount) query.guestCount = { gte: +guestCount };
if (bathroomCount) query.bathroomCount = { gte: +bathroomCount };
if (locationValue) query.locationValue = locationValue;
if (startDate && endDate) {
query.NOT = {
reservation: {
some: {
OR: [
{
endDate: { gte: startDate },
startDate: { lte: endDate },
},
{
startDate: { lte: endDate },
endDate: { gte: startDate },
},
],
},
},
};
}

const listings = await prisma.listings.findMany({
where: query,
orderBy: { createdAt: "desc" },
});

return listings;
} catch (error: any) {
throw new Error(error);
}
}
31 changes: 31 additions & 0 deletions actions/getReservations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import prisma from "@/libs/prismadb";

interface IParams {
listingId?: string;
userId?: string;
authorId?: string;
}

export default async function getReservations(params: IParams) {
try {
const { listingId, authorId, userId } = params;

const query: any = {};

if (listingId) query.listingId = listingId;
if (userId) query.userId = userId;
if (authorId) query.listings = { userId: authorId };

const reservations = await prisma.reservations.findMany({
where: query,
include: { listings: true },
orderBy: {
createdAt: "desc",
},
});

return reservations;
} catch (error: any) {
throw new Error(error);
}
}
22 changes: 22 additions & 0 deletions app/_components/avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use client";

import { FC } from "react";
import Image from "next/image";

interface Props {
src: string | null | undefined;
}

const Avatar: FC<Props> = ({ src }) => {
return (
<Image
src={src || "/placeholder.png"}
className="rounded-full"
height="30"
width="30"
alt="avatar"
/>
);
};

export default Avatar;
43 changes: 43 additions & 0 deletions app/_components/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use client";

import { FC, MouseEvent } from "react";
import { IconType } from "react-icons";

interface Props {
label: string;
onClick: (e: MouseEvent<HTMLButtonElement>) => void;
disabled?: boolean;
outline?: boolean;
small?: boolean;
icon?: IconType;
}

const Button: FC<Props> = ({
label,
onClick,
disabled,
outline,
small,
icon: Icon,
}) => {
return (
<button
onClick={onClick}
disabled={disabled}
className={`relative disabled:opacity-70 disabled:cursor-not-allowed rounded-lg hover:opacity-80 hover:border-opacity-85 transition w-full
${outline ? "bg-white" : "bg-rose-500"}
${outline ? "border-black" : "border-rose-500"}
${outline ? "text-black" : "text-white"}
${small ? "py-1" : "py-3"}
${small ? "text-sm" : "text-md"}
${small ? "font-light" : "font-semibold"}
${small ? "border-[1px]" : "border-2"}
`}
>
{Icon && <Icon className="absolute left-4 top-3" size={24} />}
{label}
</button>
);
};

export default Button;
56 changes: 56 additions & 0 deletions app/_components/category-box.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"use client";

import { FC, useCallback } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import { IconType } from "react-icons";
import qs from "query-string";

interface Props {
label: string;
icon: IconType;
selected?: boolean;
}

const CategoryBox: FC<Props> = ({ icon: Icon, label, selected }) => {
const router = useRouter();
const params = useSearchParams();

const handleClick = useCallback(() => {
let currentQuery: {
category?: string;
} = {};

if (params) currentQuery = qs.parse(params.toString());

const updateQuery: {
category?: string;
} = {
...currentQuery,
category: label,
};

if (params?.get("category") === label) delete updateQuery.category;

const url = qs.stringifyUrl(
{ url: "/", query: updateQuery },
{ skipNull: true }
);

router.push(url);
}, [params, label, router]);

return (
<div
onClick={handleClick}
className={`flex flex-col items-center justify-center gap-2 p-2 border-b-2 hover:text-neutral-800 transition cursor-pointer
${selected ? "border-b-neutral-800" : "border-transparent"}
${selected ? "text-neutral-800" : "text-neutral-500"}
`}
>
<Icon size={26} />
<div className="font-semibold text-sm">{label}</div>
</div>
);
};

export default CategoryBox;
19 changes: 19 additions & 0 deletions app/_components/client-only.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use client";

import { FC, ReactNode, useEffect, useState } from "react";

interface Props {
children: ReactNode;
}

const ClientOnly: FC<Props> = ({ children }) => {
const [mouted, setMounted] = useState<boolean>(false);

useEffect(() => {
setMounted(true);
}, []);

return mouted ? children : null;
};

export default ClientOnly;
Loading

0 comments on commit ddc5bec

Please sign in to comment.