npm install -g nextui-cli
nextui init your-project-name
cd your-project-name
npm install
npm uninstall framer-motion
npm install framer-motion@10
npm install framer
// tailwind.config.js
// import { nextui } from '@nextui-org/theme';
const { nextui } = require("@nextui-org/theme");
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./layouts/**/*.{js,ts,jsx,tsx,mdx}",
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {
fontFamily: {
sans: ["var(--font-sans)"],
mono: ["var(--font-mono)"],
},
},
},
darkMode: "class",
plugins: [nextui()],
};
npm run dev
npx create-payload-app@latest
Follow the installation prompts. Name your Payload app (e.g., 'payload') and use in the installation the connection string to your Database, for example your MongoDB or MongoDB Atlas connection string.
For example the Conexion String with MongoDB Atlas String is like this:
mongodb+srv://<user>:<password>@cluster0.hfwosz5.mongodb.net/<data_base_name>?retryWrites=true&w=majority&appName=Cluster0
npm install --save @payloadcms/richtext-slate
import path from "path";
import { payloadCloud } from "@payloadcms/plugin-cloud";
import { mongooseAdapter } from "@payloadcms/db-mongodb";
import { webpackBundler } from "@payloadcms/bundler-webpack";
// Import of the Editor
import { slateEditor } from "@payloadcms/richtext-slate";
import { buildConfig } from "payload/config";
import Users from "./collections/Users";
// Import of the New Collection Cards
import Cards from "./collections/Cards";
export default buildConfig({
admin: {
user: Users.slug,
bundler: webpackBundler(),
},
// I add it the Editor and the Editor Options
editor: slateEditor({
admin: {
elements: [
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"blockquote",
"link",
"ol",
"ul",
"textAlign",
"indent",
"relationship",
],
leaves: ["bold", "italic", "underline", "strikethrough", "code"],
},
}),
// I add it the New Collection Cards
collections: [Users, Cards],
typescript: {
outputFile: path.resolve(__dirname, "payload-types.ts"),
},
graphQL: {
schemaOutputFile: path.resolve(__dirname, "generated-schema.graphql"),
},
plugins: [payloadCloud()],
db: mongooseAdapter({
url: process.env.DATABASE_URI,
}),
});
npm run dev
Access the Payload admin panel at http://localhost:3000/admin to set up your first admin user. (CHECK THAT http://localhost:3000 IST FREE)
Create a component (e.g., a Card component) to display information from the Cards database collection.
In the pages/api directory, create an API route to get all cards (e.g., getAllCards.ts):
import type { NextApiRequest, NextApiResponse } from "next";
import { ApiResponse, ApiCard } from "../../types";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<ApiCard[] | { message: string }>
) {
try {
const response = await fetch("http://localhost:3000/api/cards");
if (!response.ok) {
return res.status(response.status).json({ message: response.statusText });
}
const apiResponse: ApiResponse = await response.json();
return res.status(200).json(apiResponse.docs);
} catch (error) {
console.log("Error :", error);
return res.status(500).json({ message: "Error fetching data" });
}
}
import { useEffect, useState } from "react";
import { CardProps } from "../types/index";
import Card from "./../components/Card";
import DefaultLayout from "@/layouts/default";
export default function IndexPage() {
const [cards, setCards] = useState<CardProps[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
async function fetchCards() {
try {
const response = await fetch("/api/getAllCards");
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data: CardProps[] = await response.json();
setCards(data);
} catch (error) {
setError(
error instanceof Error ? error.message : "An unknown error occurred"
);
} finally {
setLoading(false);
}
}
fetchCards();
}, []);
if (loading) {
return <div>Loading...</div>;
}
if (error) {
return <div>Error: {error}</div>;
}
return (
<DefaultLayout>
<section className="flex flex-col items-center justify-center gap-4 py-8 md:py-10">
<h2>Python Cards</h2>
<div className="container mx-auto p-4">
{cards.map((card) => (
<Card
key={card.id}
category={card.category}
codeExample={card.codeExample}
description={card.description}
id={card.id}
title={card.title}
/>
))}
</div>
</section>
</DefaultLayout>
);
}
Go to the /payload/ directory and run 'npm run dev' for PAYLOAD in a terminal. Then, open http://localhost:3000/admin in a browser and log in. Create some Cards Items in the Collection Cards.
In another terminal, remeins in the root directory and run 'npm run dev' for NEXTUI. Open in your browser, the recomended localhost port you see in terminal. Now you should see the Cards info in Browser.
Licensed nextui under the MIT license.