diff --git a/Dockerfile b/Dockerfile index 84ffe76..fda97af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,10 +22,6 @@ WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . -## WORKAROUND: -RUN rm -rf src/app/~/dash -RUN rm -rf src/app/actions - # Next.js collects completely anonymous telemetry data about general usage. # Learn more here: https://nextjs.org/telemetry # Uncomment the following line in case you want to disable telemetry during the build. diff --git a/docker-compose.yml b/docker-compose.yml index 3e238b2..cf74934 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,4 +13,6 @@ services: web: build: . ports: - - 3000:3000 \ No newline at end of file + - 3000:3000 + env_file: + - .env \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 324b178..ba1b1ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,8 @@ "@prisma/client": "^5.18.0", "js-sha256": "^0.11.0", "next": "^15.0.0-canary.195", + "next-auth": "^5.0.0-beta.22", + "react-hot-toast": "^2.4.1", "ua-parser-js": "^1.0.38", "zod": "^3.23.8" }, @@ -40,6 +42,37 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/@auth/core": { + "version": "0.35.3", + "resolved": "https://registry.npmjs.org/@auth/core/-/core-0.35.3.tgz", + "integrity": "sha512-g6qfiqU4OtyvIEZ8J7UoIwAxEnNnLJV0/f/DW41U+4G5nhBlaCrnKhawJIJpU0D3uavXLeDT3B0BkjtiimvMDA==", + "license": "ISC", + "dependencies": { + "@panva/hkdf": "^1.1.1", + "@types/cookie": "0.6.0", + "cookie": "0.6.0", + "jose": "^5.1.3", + "oauth4webapi": "^2.10.4", + "preact": "10.11.3", + "preact-render-to-string": "5.2.3" + }, + "peerDependencies": { + "@simplewebauthn/browser": "^9.0.1", + "@simplewebauthn/server": "^9.0.2", + "nodemailer": "^6.8.0" + }, + "peerDependenciesMeta": { + "@simplewebauthn/browser": { + "optional": true + }, + "@simplewebauthn/server": { + "optional": true + }, + "nodemailer": { + "optional": true + } + } + }, "node_modules/@emnapi/runtime": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz", @@ -810,6 +843,15 @@ "node": ">=12.4.0" } }, + "node_modules/@panva/hkdf": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.2.1.tgz", + "integrity": "sha512-6oclG6Y3PiDFcoyk8srjLfVKyMfVCKJ27JwNPViuXziFpmdz+MZnZN/aKY0JGXgYuO/VghU0jcOAZgWXZ1Dmrw==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -911,6 +953,12 @@ "tslib": "^2.4.0" } }, + "node_modules/@types/cookie": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA==", + "license": "MIT" + }, "node_modules/@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", @@ -1657,6 +1705,15 @@ "dev": true, "license": "MIT" }, + "node_modules/cookie": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", + "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -1689,7 +1746,6 @@ "version": "3.1.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", - "dev": true, "license": "MIT" }, "node_modules/damerau-levenshtein": { @@ -2952,6 +3008,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/goober": { + "version": "2.1.16", + "resolved": "https://registry.npmjs.org/goober/-/goober-2.1.16.tgz", + "integrity": "sha512-erjk19y1U33+XAMe1VTvIONHYoSqE4iS7BYUZfHaqeohLmnC0FdxEh7rQU+6MZ4OajItzjZFSRtVANrQwNq6/g==", + "license": "MIT", + "peerDependencies": { + "csstype": "^3.0.10" + } + }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -3627,6 +3692,15 @@ "jiti": "bin/jiti.js" } }, + "node_modules/jose": { + "version": "5.9.4", + "resolved": "https://registry.npmjs.org/jose/-/jose-5.9.4.tgz", + "integrity": "sha512-WBBl6au1qg6OHj67yCffCgFR3BADJBXN8MdRvCgJDuMv3driV2nHr7jdGvaKX9IolosAsn+M0XRArqLXUhyJHQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/js-sha256": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.11.0.tgz", @@ -3960,6 +4034,33 @@ } } }, + "node_modules/next-auth": { + "version": "5.0.0-beta.22", + "resolved": "https://registry.npmjs.org/next-auth/-/next-auth-5.0.0-beta.22.tgz", + "integrity": "sha512-QGBo9HGOjmnJBHGXvtFztl0tM5tL0porDlk74HVoCCzXd986ApOlIW3EmiCuho7YzEopgkFiwwmcXpoCrHAtYw==", + "license": "ISC", + "dependencies": { + "@auth/core": "0.35.3" + }, + "peerDependencies": { + "@simplewebauthn/browser": "^9.0.1", + "@simplewebauthn/server": "^9.0.2", + "next": "^14.0.0-0 || ^15.0.0-0", + "nodemailer": "^6.6.5", + "react": "^18.2.0 || ^19.0.0-0" + }, + "peerDependenciesMeta": { + "@simplewebauthn/browser": { + "optional": true + }, + "@simplewebauthn/server": { + "optional": true + }, + "nodemailer": { + "optional": true + } + } + }, "node_modules/next/node_modules/postcss": { "version": "8.4.31", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", @@ -3998,6 +4099,15 @@ "node": ">=0.10.0" } }, + "node_modules/oauth4webapi": { + "version": "2.17.0", + "resolved": "https://registry.npmjs.org/oauth4webapi/-/oauth4webapi-2.17.0.tgz", + "integrity": "sha512-lbC0Z7uzAFNFyzEYRIC+pkSVvDHJTbEW+dYlSBAlCYDe6RxUkJ26bClhk8ocBZip1wfI9uKTe0fm4Ib4RHn6uQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -4493,6 +4603,28 @@ "dev": true, "license": "MIT" }, + "node_modules/preact": { + "version": "10.11.3", + "resolved": "https://registry.npmjs.org/preact/-/preact-10.11.3.tgz", + "integrity": "sha512-eY93IVpod/zG3uMF22Unl8h9KkrcKIRs2EGar8hwLZZDU1lkjph303V9HZBwufh2s736U6VXuhD109LYqPoffg==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/preact" + } + }, + "node_modules/preact-render-to-string": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.2.3.tgz", + "integrity": "sha512-aPDxUn5o3GhWdtJtW0svRC2SS/l8D9MAgo2+AWml+BhDImb27ALf04Q2d+AHqUUOc6RdSXFIBVa2gxzgMKgtZA==", + "license": "MIT", + "dependencies": { + "pretty-format": "^3.8.0" + }, + "peerDependencies": { + "preact": ">=10" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -4503,6 +4635,12 @@ "node": ">= 0.8.0" } }, + "node_modules/pretty-format": { + "version": "3.8.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-3.8.0.tgz", + "integrity": "sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew==", + "license": "MIT" + }, "node_modules/prisma": { "version": "5.19.0", "resolved": "https://registry.npmjs.org/prisma/-/prisma-5.19.0.tgz", @@ -4593,6 +4731,22 @@ "react": "^18.3.1" } }, + "node_modules/react-hot-toast": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/react-hot-toast/-/react-hot-toast-2.4.1.tgz", + "integrity": "sha512-j8z+cQbWIM5LY37pR6uZR6D4LfseplqnuAO4co4u8917hBUvXlEqyP1ZzqVLcqoyUesZZv/ImreoCeHVDpE5pQ==", + "license": "MIT", + "dependencies": { + "goober": "^2.1.10" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "react": ">=16", + "react-dom": ">=16" + } + }, "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", diff --git a/package.json b/package.json index 2229bc3..320555d 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "@prisma/client": "^5.18.0", "js-sha256": "^0.11.0", "next": "^15.0.0-canary.195", + "next-auth": "^5.0.0-beta.22", + "react-hot-toast": "^2.4.1", "ua-parser-js": "^1.0.38", "zod": "^3.23.8" }, diff --git a/src/actions/block_actions.ts b/src/actions/block_actions.ts index 318fa27..444a47a 100644 --- a/src/actions/block_actions.ts +++ b/src/actions/block_actions.ts @@ -1,8 +1,9 @@ "use server" -import { z } from "zod"; +import { set, z } from "zod"; import prisma from "../../prisma/prisma"; import { revalidatePath } from "next/cache"; +import toast from "react-hot-toast"; export async function createLinkBlock(prevState: any, formData: FormData) { @@ -63,7 +64,7 @@ export async function createLinkBlock(prevState: any, formData: FormData) { }); } catch (e: any) { return { - message: "Error creating link block", + message: "Error adding link to page", error: e.message }; } @@ -73,7 +74,7 @@ export async function createLinkBlock(prevState: any, formData: FormData) { revalidatePath(`/${customPage.page.shortcode}`); return { - message: "Link block created" + message: "Adding link to page" }; } @@ -93,16 +94,22 @@ export async function deleteLinkBlock(prevState: any, formData: FormData) { }; } - await prisma.linkBlock.delete({ - where: { - uuid: data.data.uuid - } - }); + try { + await prisma.linkBlock.delete({ + where: { + uuid: data.data.uuid + } + }); + } catch (e: any) { + return { + message: "Cant delete link from page", + }; + } revalidatePath("/~/dash"); return { - message: "Link block deleted" + message: "Removed link from page" }; } diff --git a/src/actions/page_actions.ts b/src/actions/page_actions.ts index 50843d4..728885a 100644 --- a/src/actions/page_actions.ts +++ b/src/actions/page_actions.ts @@ -49,7 +49,7 @@ export async function createCustomPage(prevState: any, fromData: FormData) { message: "Shortcode already exists", error: { shortcode: ["Shortcode already exists"] - + } }; } @@ -149,13 +149,16 @@ export async function deletePage(prevState: any, fromData: FormData) { } + export async function pinPageToRoot(prevState: any, fromData: FormData) { const schema = z.object({ - uuid: z.string().uuid() + uuid: z.string().uuid(), + unpin: z.enum(['true', 'false']).transform((value) => value === 'true').optional() }); const data = schema.safeParse({ - uuid: fromData.get("uuid") + uuid: fromData.get("uuid"), + unpin: fromData.get("unpin") }); if (!data.success) { @@ -165,24 +168,43 @@ export async function pinPageToRoot(prevState: any, fromData: FormData) { }; } - await prisma.pinnedPage.upsert({ - where: { - id: 1 - }, - update: { - pageUuid: data.data.uuid - }, - create: { - id: 1, - pageUuid: data.data.uuid - } - }); - revalidatePath("/~/dash"); - revalidatePath("/"); - return { - message: "Page pinned", - }; + console.log(data.data.unpin); + if (data.data.unpin) { + + console.log + + await prisma.pinnedPage.delete({ + where: { + id: 1 + } + }); + revalidatePath("/~/dash"); + revalidatePath("/"); + return { + message: "Page unpinned", + }; + } else { + await prisma.pinnedPage.upsert({ + where: { + id: 1 + }, + update: { + pageUuid: data.data.uuid + }, + create: { + id: 1, + pageUuid: data.data.uuid + } + }); + + revalidatePath("/~/dash"); + revalidatePath("/"); + + return { + message: "Page pinned", + }; + } } \ No newline at end of file diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts new file mode 100644 index 0000000..0cf1408 --- /dev/null +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -0,0 +1,2 @@ +import { handlers } from "@/auth" // Referring to the auth.ts we just created +export const { GET, POST } = handlers \ No newline at end of file diff --git a/src/app/globals.css b/src/app/globals.css index d38c1e0..e88ed0d 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -2,17 +2,16 @@ @tailwind components; @tailwind utilities; - body { - @apply text-gray-300 bg-gray-900 + @apply text-gray-300 bg-gray-900; } h1 { - @apply text-5xl font-bold mb-6 + @apply text-5xl font-bold mb-6; } h2 { - @apply text-2xl font-bold mb-4 + @apply text-2xl font-bold mb-4; } .form-group { @@ -44,13 +43,68 @@ label { } button { - @apply rounded bg-green-600 hover:bg-green-700 text-white py-2 px-4 disabled:opacity-50 + @apply rounded bg-green-600 hover:bg-green-700 text-white py-2 px-4 disabled:opacity-50; +} + +.button-icon { + @apply h-5 w-5 inline-block align-middle; } .zebra { - @apply odd:bg-slate-800 p-2 rounded + @apply odd:bg-slate-800 p-2 rounded; } .common-red { - @apply text-red-500 -} \ No newline at end of file + @apply text-red-500; +} + +@keyframes slide-in { + 0% { + transform: translateY(-30px); + opacity: 0; + } + 100% { + transform: translateY(0); + opacity: 1; + } +} + +.slide-animated { + animation: slide-in 0.7s ease forwards; + opacity: 0; +} + +@keyframes zoom-in { + 0% { + transform: scale(0.7); + opacity: 0; + } + 100% { + transform: scale(1); + opacity: 1; + } +} + +.zoom-animated { + animation: zoom-in 1.5s ease forwards; + transform: scale(0.7); +} + +@keyframes fade-in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} + +.fade-animated { + animation: fade-in 0.7s ease forwards; + opacity: 0; +} + +.vcenter { + @apply flex items-center flex-col justify-center mt-5; + min-height: 80vh; +} diff --git a/src/app/page.tsx b/src/app/page.tsx index 96a6cea..1b8f6df 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -5,18 +5,20 @@ import { redirect } from "next/navigation"; export default async function Home() { - const pinnedPage = await prisma.pinnedPage.findFirst({where: {id: 1}, include: {page: true}}); + const pinnedPage = await prisma.pinnedPage.findFirst({ where: { id: 1 }, include: { page: true } }); if (pinnedPage) { redirect(pinnedPage.page.shortcode); } return ( - (<> -
This is a url shortner
- Dashboard - > +Currently there is no default root page defined
+ Set pin a page in the dashboard + Or check out the project page +Pinned to root
: ""} + {page.pinnedPage ?Pinned to root
: ""}