Skip to content

Commit

Permalink
Merge pull request #3 from NIAEFEUP/feature/payload-setup
Browse files Browse the repository at this point in the history
Database and payload setup
  • Loading branch information
thePeras authored Aug 5, 2024
2 parents c594429 + 00cd663 commit 18cf866
Show file tree
Hide file tree
Showing 19 changed files with 13,376 additions and 83 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PAYLOAD_SECRET=jawliejfilwajefSEANlawefawfewag349jwgo3gj4d
POSTGRES_URL=postgresql://postgres:<your-password>@127.0.0.1:5432/<database-name>
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
.next/
.next/
.env
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
- Nextjs 13
- React 18
- TypeScript
- Node 20 (use [NVM](https://github.com/nvm-sh/nvm) to manage node versions)

## Packages

- Payload CMS
- Framer Motion
- Lucide Icons

Expand All @@ -17,21 +19,31 @@
Here are the steps you need to follow to install the dependencies.

```bash
npm install
pnpm install
```

Setup your environment variables with a database name and a password.

Now you just need to create the database with docker or use directly your local database. Thats up to you.

```bash
./start-database.sh
```

You can start the project on the local server

```bash
npm run dev
pnpm run dev
```

It’ll start the template on [localhost:3000](http://localhost:3000).
It’ll start the template on [localhost:3000](http://localhost:3000).

## Project structure

- The `pages` directory contains all the pages of the project with app routing, as each file in this directory corresponds to a page.

- The `components` directory contains all the components used in the project.

- The `public` directory contains all the static files used in the project like images.
- The `public` directory contains all the static files used in the project like images.

- The `collections` directory defines the schemas for the collections that will be managed in the Paylode dashboard.
22 changes: 22 additions & 0 deletions app/(payload)/admin/[[...segments]]/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
import type { Metadata } from 'next'

import config from '@payload-config'
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
import { NotFoundPage, generatePageMetadata } from '@payloadcms/next/views'

type Args = {
params: {
segments: string[]
}
searchParams: {
[key: string]: string | string[]
}
}

export const generateMetadata = ({ params, searchParams }: Args): Promise<Metadata> =>
generatePageMetadata({ config, params, searchParams })

const NotFound = ({ params, searchParams }: Args) => NotFoundPage({ config, params, searchParams })

export default NotFound
22 changes: 22 additions & 0 deletions app/(payload)/admin/[[...segments]]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
import type { Metadata } from 'next'

import config from '@payload-config'
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
import { RootPage, generatePageMetadata } from '@payloadcms/next/views'

type Args = {
params: {
segments: string[]
}
searchParams: {
[key: string]: string | string[]
}
}

export const generateMetadata = ({ params, searchParams }: Args): Promise<Metadata> =>
generatePageMetadata({ config, params, searchParams })

const Page = ({ params, searchParams }: Args) => RootPage({ config, params, searchParams })

export default Page
10 changes: 10 additions & 0 deletions app/(payload)/api/[...slug]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
/* DO NOT MODIFY it because it could be re-written at any time. */
import config from '@payload-config'
import { REST_DELETE, REST_GET, REST_OPTIONS, REST_PATCH, REST_POST } from '@payloadcms/next/routes'

export const GET = REST_GET(config)
export const POST = REST_POST(config)
export const DELETE = REST_DELETE(config)
export const PATCH = REST_PATCH(config)
export const OPTIONS = REST_OPTIONS(config)
Empty file added app/(payload)/custom.scss
Empty file.
16 changes: 16 additions & 0 deletions app/(payload)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* THIS FILE WAS GENERATED AUTOMATICALLY BY PAYLOAD. */
import configPromise from '@payload-config'
import '@payloadcms/next/css'
import { RootLayout } from '@payloadcms/next/layouts'
/* DO NOT MODIFY IT BECAUSE IT COULD BE REWRITTEN AT ANY TIME. */
import React from 'react'

import './custom.scss'

type Args = {
children: React.ReactNode
}

const Layout = ({ children }: Args) => <RootLayout config={configPromise}>{children}</RootLayout>

export default Layout
14 changes: 14 additions & 0 deletions app/my-route/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import configPromise from '@payload-config'
import { getPayload } from 'payload'

export const GET = async () => {
const payload = await getPayload({
config: configPromise,
})

const data = await payload.find({
collection: 'users',
})

return Response.json(data)
}
16 changes: 16 additions & 0 deletions collections/Media.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { CollectionConfig } from 'payload'

export const Media: CollectionConfig = {
slug: 'media',
access: {
read: () => true,
},
fields: [
{
name: 'alt',
type: 'text',
required: true,
},
],
upload: true,
}
13 changes: 13 additions & 0 deletions collections/Users.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { CollectionConfig } from 'payload'

export const Users: CollectionConfig = {
slug: 'users',
admin: {
useAsTitle: 'email',
},
auth: true,
fields: [
// Email added by default
// Add more fields as needed
],
}
3 changes: 2 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { withPayload } = require("@payloadcms/next/withPayload");
/** @type {import('next').NextConfig} */

const nextConfig = {
Expand All @@ -15,4 +16,4 @@ const nextConfig = {
},
};

module.exports = nextConfig;
module.exports = withPayload(nextConfig);
58 changes: 39 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,48 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"payload": "cross-env NODE_OPTIONS=--no-deprecation payload"
},
"dependencies": {
"@types/bcrypt": "^5.0.1",
"@types/node": "^20.8.9",
"@types/react": "^18.2.32",
"@types/react-dom": "^18.2.14",
"autoprefixer": "^10.4.16",
"eslint": "8.41.0",
"eslint-config-next": "13.4.4",
"framer-motion": "^10.12.16",
"lucide-react": "^0.417.0",
"next": "^14.2.5",
"next-themes": "^0.2.1",
"postcss": "^8.4.31",
"prettier": "^3.0.3",
"prettier-plugin-tailwindcss": "^0.5.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@payloadcms/db-mongodb": "3.0.0-beta.71",
"@payloadcms/db-postgres": "3.0.0-beta.71",
"@payloadcms/next": "3.0.0-beta.71",
"@payloadcms/richtext-lexical": "3.0.0-beta.71",
"@payloadcms/richtext-slate": "3.0.0-beta.71",
"@payloadcms/ui": "3.0.0-beta.71",
"autoprefixer": "^10.4.19",
"babel-plugin-react-compiler": "^0.0.0-experimental-592953e-20240517",
"cross-env": "^7.0.3",
"framer-motion": "^11.3.19",
"graphql": "^16.8.2",
"next": "15.0.0-canary.77",
"next-themes": "^0.3.0",
"payload": "3.0.0-beta.71",
"react": "19.0.0-rc-6230622a1a-20240610",
"react-dom": "19.0.0-rc-6230622a1a-20240610",
"react-hot-toast": "^2.4.1",
"sharp": "0.32.6",
"swiper": "^9.3.2",
"tailwindcss": "^3.3.5",
"typescript": "^5.2.2"
"tailwindcss": "^3.4.7"
},
"devDependencies": {
"@payloadcms/graphql": "3.0.0-beta.71",
"@types/node": "^20.14.9",
"@types/react": "npm:types-react@19.0.0-rc.0",
"@types/react-dom": "npm:types-react-dom@19.0.0-rc.0",
"eslint": "^8.57.0",
"eslint-config-next": "15.0.0-rc.0",
"typescript": "5.5.3"
},
"pnpm": {
"overrides": {
"@types/react": "npm:types-react@19.0.0-rc.0",
"@types/react-dom": "npm:types-react-dom@19.0.0-rc.0"
}
},
"overrides": {
"@types/react": "npm:types-react@19.0.0-rc.0",
"@types/react-dom": "npm:types-react-dom@19.0.0-rc.0"
}
}
125 changes: 125 additions & 0 deletions payload-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/* tslint:disable */
/* eslint-disable */
/**
* This file was automatically generated by Payload.
* DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,
* and re-run `payload generate:types` to regenerate this file.
*/

export interface Config {
auth: {
users: UserAuthOperations;
};
collections: {
users: User;
media: Media;
'payload-preferences': PayloadPreference;
'payload-migrations': PayloadMigration;
};
db: {
defaultIDType: number;
};
globals: {};
locale: null;
user: User & {
collection: 'users';
};
}
export interface UserAuthOperations {
forgotPassword: {
email: string;
};
login: {
email: string;
password: string;
};
registerFirstUser: {
email: string;
password: string;
};
unlock: {
email: string;
};
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users".
*/
export interface User {
id: number;
updatedAt: string;
createdAt: string;
email: string;
resetPasswordToken?: string | null;
resetPasswordExpiration?: string | null;
salt?: string | null;
hash?: string | null;
loginAttempts?: number | null;
lockUntil?: string | null;
password?: string | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "media".
*/
export interface Media {
id: number;
alt: string;
updatedAt: string;
createdAt: string;
url?: string | null;
thumbnailURL?: string | null;
filename?: string | null;
mimeType?: string | null;
filesize?: number | null;
width?: number | null;
height?: number | null;
focalX?: number | null;
focalY?: number | null;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-preferences".
*/
export interface PayloadPreference {
id: number;
user: {
relationTo: 'users';
value: number | User;
};
key?: string | null;
value?:
| {
[k: string]: unknown;
}
| unknown[]
| string
| number
| boolean
| null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-migrations".
*/
export interface PayloadMigration {
id: number;
name?: string | null;
batch?: number | null;
updatedAt: string;
createdAt: string;
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "auth".
*/
export interface Auth {
[k: string]: unknown;
}


declare module 'payload' {
export interface GeneratedTypes extends Config {}
}
Loading

0 comments on commit 18cf866

Please sign in to comment.