mirror of
https://github.com/traberph/short.git
synced 2026-11-22 22:55:12 +00:00
add oauth
This commit is contained in:
@@ -22,10 +22,6 @@ WORKDIR /app
|
|||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
## WORKAROUND:
|
|
||||||
RUN rm -rf src/app/~/dash
|
|
||||||
RUN rm -rf src/app/actions
|
|
||||||
|
|
||||||
# Next.js collects completely anonymous telemetry data about general usage.
|
# Next.js collects completely anonymous telemetry data about general usage.
|
||||||
# Learn more here: https://nextjs.org/telemetry
|
# Learn more here: https://nextjs.org/telemetry
|
||||||
# Uncomment the following line in case you want to disable telemetry during the build.
|
# Uncomment the following line in case you want to disable telemetry during the build.
|
||||||
|
|||||||
+3
-1
@@ -13,4 +13,6 @@ services:
|
|||||||
web:
|
web:
|
||||||
build: .
|
build: .
|
||||||
ports:
|
ports:
|
||||||
- 3000:3000
|
- 3000:3000
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
Generated
+155
-1
@@ -12,6 +12,8 @@
|
|||||||
"@prisma/client": "^5.18.0",
|
"@prisma/client": "^5.18.0",
|
||||||
"js-sha256": "^0.11.0",
|
"js-sha256": "^0.11.0",
|
||||||
"next": "^15.0.0-canary.195",
|
"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",
|
"ua-parser-js": "^1.0.38",
|
||||||
"zod": "^3.23.8"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
@@ -40,6 +42,37 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"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": {
|
"node_modules/@emnapi/runtime": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz",
|
||||||
@@ -810,6 +843,15 @@
|
|||||||
"node": ">=12.4.0"
|
"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": {
|
"node_modules/@pkgjs/parseargs": {
|
||||||
"version": "0.11.0",
|
"version": "0.11.0",
|
||||||
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
|
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
|
||||||
@@ -911,6 +953,12 @@
|
|||||||
"tslib": "^2.4.0"
|
"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": {
|
"node_modules/@types/json5": {
|
||||||
"version": "0.0.29",
|
"version": "0.0.29",
|
||||||
"resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz",
|
"resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz",
|
||||||
@@ -1657,6 +1705,15 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"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": {
|
"node_modules/cross-spawn": {
|
||||||
"version": "7.0.3",
|
"version": "7.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
||||||
@@ -1689,7 +1746,6 @@
|
|||||||
"version": "3.1.3",
|
"version": "3.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
|
||||||
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
|
"integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/damerau-levenshtein": {
|
"node_modules/damerau-levenshtein": {
|
||||||
@@ -2952,6 +3008,15 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"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": {
|
"node_modules/gopd": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz",
|
||||||
@@ -3627,6 +3692,15 @@
|
|||||||
"jiti": "bin/jiti.js"
|
"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": {
|
"node_modules/js-sha256": {
|
||||||
"version": "0.11.0",
|
"version": "0.11.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.11.0.tgz",
|
"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": {
|
"node_modules/next/node_modules/postcss": {
|
||||||
"version": "8.4.31",
|
"version": "8.4.31",
|
||||||
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
|
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
|
||||||
@@ -3998,6 +4099,15 @@
|
|||||||
"node": ">=0.10.0"
|
"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": {
|
"node_modules/object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||||
@@ -4493,6 +4603,28 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"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": {
|
"node_modules/prelude-ls": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
|
||||||
@@ -4503,6 +4635,12 @@
|
|||||||
"node": ">= 0.8.0"
|
"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": {
|
"node_modules/prisma": {
|
||||||
"version": "5.19.0",
|
"version": "5.19.0",
|
||||||
"resolved": "https://registry.npmjs.org/prisma/-/prisma-5.19.0.tgz",
|
"resolved": "https://registry.npmjs.org/prisma/-/prisma-5.19.0.tgz",
|
||||||
@@ -4593,6 +4731,22 @@
|
|||||||
"react": "^18.3.1"
|
"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": {
|
"node_modules/react-is": {
|
||||||
"version": "16.13.1",
|
"version": "16.13.1",
|
||||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
"@prisma/client": "^5.18.0",
|
"@prisma/client": "^5.18.0",
|
||||||
"js-sha256": "^0.11.0",
|
"js-sha256": "^0.11.0",
|
||||||
"next": "^15.0.0-canary.195",
|
"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",
|
"ua-parser-js": "^1.0.38",
|
||||||
"zod": "^3.23.8"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
"use server"
|
"use server"
|
||||||
|
|
||||||
import { z } from "zod";
|
import { set, z } from "zod";
|
||||||
import prisma from "../../prisma/prisma";
|
import prisma from "../../prisma/prisma";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
export async function createLinkBlock(prevState: any, formData: FormData) {
|
export async function createLinkBlock(prevState: any, formData: FormData) {
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ export async function createLinkBlock(prevState: any, formData: FormData) {
|
|||||||
});
|
});
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return {
|
return {
|
||||||
message: "Error creating link block",
|
message: "Error adding link to page",
|
||||||
error: e.message
|
error: e.message
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -73,7 +74,7 @@ export async function createLinkBlock(prevState: any, formData: FormData) {
|
|||||||
revalidatePath(`/${customPage.page.shortcode}`);
|
revalidatePath(`/${customPage.page.shortcode}`);
|
||||||
|
|
||||||
return {
|
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({
|
try {
|
||||||
where: {
|
await prisma.linkBlock.delete({
|
||||||
uuid: data.data.uuid
|
where: {
|
||||||
}
|
uuid: data.data.uuid
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} catch (e: any) {
|
||||||
|
return {
|
||||||
|
message: "Cant delete link from page",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
revalidatePath("/~/dash");
|
revalidatePath("/~/dash");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
message: "Link block deleted"
|
message: "Removed link from page"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+42
-20
@@ -49,7 +49,7 @@ export async function createCustomPage(prevState: any, fromData: FormData) {
|
|||||||
message: "Shortcode already exists",
|
message: "Shortcode already exists",
|
||||||
error: {
|
error: {
|
||||||
shortcode: ["Shortcode already exists"]
|
shortcode: ["Shortcode already exists"]
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -149,13 +149,16 @@ export async function deletePage(prevState: any, fromData: FormData) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function pinPageToRoot(prevState: any, fromData: FormData) {
|
export async function pinPageToRoot(prevState: any, fromData: FormData) {
|
||||||
const schema = z.object({
|
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({
|
const data = schema.safeParse({
|
||||||
uuid: fromData.get("uuid")
|
uuid: fromData.get("uuid"),
|
||||||
|
unpin: fromData.get("unpin")
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!data.success) {
|
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 {
|
console.log(data.data.unpin);
|
||||||
message: "Page pinned",
|
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",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
import { handlers } from "@/auth" // Referring to the auth.ts we just created
|
||||||
|
export const { GET, POST } = handlers
|
||||||
+62
-8
@@ -2,17 +2,16 @@
|
|||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@apply text-gray-300 bg-gray-900
|
@apply text-gray-300 bg-gray-900;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
@apply text-5xl font-bold mb-6
|
@apply text-5xl font-bold mb-6;
|
||||||
}
|
}
|
||||||
|
|
||||||
h2 {
|
h2 {
|
||||||
@apply text-2xl font-bold mb-4
|
@apply text-2xl font-bold mb-4;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-group {
|
.form-group {
|
||||||
@@ -44,13 +43,68 @@ label {
|
|||||||
}
|
}
|
||||||
|
|
||||||
button {
|
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 {
|
.zebra {
|
||||||
@apply odd:bg-slate-800 p-2 rounded
|
@apply odd:bg-slate-800 p-2 rounded;
|
||||||
}
|
}
|
||||||
|
|
||||||
.common-red {
|
.common-red {
|
||||||
@apply text-red-500
|
@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;
|
||||||
|
}
|
||||||
|
|||||||
+7
-5
@@ -5,18 +5,20 @@ import { redirect } from "next/navigation";
|
|||||||
|
|
||||||
export default async function Home() {
|
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) {
|
if (pinnedPage) {
|
||||||
redirect(pinnedPage.page.shortcode);
|
redirect(pinnedPage.page.shortcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
(<>
|
(<div className="vcenter">
|
||||||
<h1>Home</h1>
|
<h1>Welcome</h1>
|
||||||
<p>This is a url shortner</p>
|
<p>This is a url shortner</p>
|
||||||
<Link href="~/dash">Dashboard</Link>
|
<p>Currently there is no default root page defined</p>
|
||||||
</>
|
<Link href="/~/dash" className="mt-5 hover:underline">Set pin a page in the dashboard</Link>
|
||||||
|
<Link href="https:github.com/traberph/short" className="hover:underline">Or check out the project page</Link>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import CustomPageDashboard from "@/components/CustomPageDashboard";
|
|||||||
import LinkFavicon from "@/components/LinkFavicon";
|
import LinkFavicon from "@/components/LinkFavicon";
|
||||||
import { hashToColor } from "@/utils";
|
import { hashToColor } from "@/utils";
|
||||||
import PinPageToRootForm from "@/components/forms/pinPageToRootForm";
|
import PinPageToRootForm from "@/components/forms/pinPageToRootForm";
|
||||||
|
import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/solid";
|
||||||
|
|
||||||
interface PageProps {
|
interface PageProps {
|
||||||
params: Promise<{
|
params: Promise<{
|
||||||
@@ -14,8 +15,8 @@ interface PageProps {
|
|||||||
}>
|
}>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function DetailedStats({ params } : PageProps) {
|
export default async function DetailedStats({ params }: PageProps) {
|
||||||
|
|
||||||
const { uuid } = await params;
|
const { uuid } = await params;
|
||||||
|
|
||||||
const page = await prisma.page.findUnique({
|
const page = await prisma.page.findUnique({
|
||||||
@@ -87,13 +88,13 @@ export default async function DetailedStats({ params } : PageProps) {
|
|||||||
<p><a className="underline" href={page.redirectPage[0].dest}>{page.redirectPage[0].dest}</a></p> : ""}
|
<p><a className="underline" href={page.redirectPage[0].dest}>{page.redirectPage[0].dest}</a></p> : ""}
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-5">
|
<div className="ml-5">
|
||||||
{page.pinnedPage ? <p className="common-red">Pinned to root</p> : ""}
|
{page.pinnedPage ? <p className="common-red">Pinned to root</p> : ""}
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-auto">
|
<div className="ml-auto">
|
||||||
<Link href={`/${page.shortcode}`}><button>View</button></Link>
|
<Link href={`/${page.shortcode}`}><button><ArrowTopRightOnSquareIcon className="button-icon" /></button></Link>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-5">
|
<div className="ml-5">
|
||||||
<PinPageToRootForm pageUuid={page.uuid} disabled={!!page.pinnedPage} />
|
<PinPageToRootForm pageUuid={page.uuid} pinned={!!page.pinnedPage} />
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-5">
|
<div className="ml-5">
|
||||||
<DeletePageForm uuid={page.uuid} />
|
<DeletePageForm uuid={page.uuid} />
|
||||||
|
|||||||
@@ -2,14 +2,36 @@
|
|||||||
|
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import React, { ReactNode } from 'react';
|
import React, { ReactNode } from 'react';
|
||||||
|
import { Toaster } from "react-hot-toast";
|
||||||
|
import { auth } from "@/auth";
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
import SignOutButton from '@/components/forms/signOutButton';
|
||||||
|
|
||||||
|
|
||||||
export default function Dashboard({ children }: { children: ReactNode }) {
|
export default async function Dashboard({ children }: { children: ReactNode }) {
|
||||||
|
|
||||||
|
const session = await auth();
|
||||||
|
const awSession = await session;
|
||||||
|
const user = awSession?.user;
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
redirect("/~/");
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='p-10 max-w-7xl mx-auto'>
|
<div className='p-10 max-w-7xl mx-auto'>
|
||||||
<Link href="/~/dash/">
|
<div className='flex justify-top'>
|
||||||
<h1>Dashboard</h1>
|
|
||||||
</Link>
|
<Link href="/~/dash/">
|
||||||
|
<h1>Dashboard</h1>
|
||||||
|
</Link>
|
||||||
|
<div className="ml-auto flex flex-col">
|
||||||
|
{user?.name ? <>
|
||||||
|
<div>{user?.name || user.email}</div>
|
||||||
|
<SignOutButton /></> : ""}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Toaster position='top-right' />
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export default async function Dashboard() {
|
|||||||
|
|
||||||
const redirectPages = pages.filter((page) => page.redirectPage.length > 0);
|
const redirectPages = pages.filter((page) => page.redirectPage.length > 0);
|
||||||
const customPages = pages.filter((page) => page.customPage.length > 0);
|
const customPages = pages.filter((page) => page.customPage.length > 0);
|
||||||
|
const pinnedPage = await prisma.pinnedPage.findFirst({ where: { id: 1 } });
|
||||||
|
|
||||||
return (<>
|
return (<>
|
||||||
<h2>Redirect Pages</h2>
|
<h2>Redirect Pages</h2>
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { auth } from "@/auth";
|
||||||
|
import SignInButton from "@/components/forms/signInButton";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
|
export default async function AdminRoot() {
|
||||||
|
|
||||||
|
const session = await auth();
|
||||||
|
const awSession = await session;
|
||||||
|
const user = awSession?.user;
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
redirect("/~/dash/");
|
||||||
|
}
|
||||||
|
|
||||||
|
return (<div className="vcenter">
|
||||||
|
|
||||||
|
<Link href="https://github.com/traberph/short"><h1>traberph/short</h1></Link>
|
||||||
|
<SignInButton />
|
||||||
|
<Link href="/" className="mt-3 hover:underline">or back to root</Link>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import NextAuth from "next-auth"
|
||||||
|
import Authentik from "next-auth/providers/authentik"
|
||||||
|
|
||||||
|
export const { handlers, signIn, signOut, auth } = NextAuth({
|
||||||
|
providers: [Authentik],
|
||||||
|
})
|
||||||
@@ -19,20 +19,24 @@ export default async function CustomPageComponent(params: { customPage: CustomPa
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center justify-center min-h-screen">
|
<div className="vcenter">
|
||||||
<Image
|
<Image
|
||||||
src={`data:image/png;base64,${customPage.image}`}
|
src={`data:image/png;base64,${customPage.image}`}
|
||||||
alt=" "
|
alt=" "
|
||||||
width={100}
|
width={100}
|
||||||
height={100}
|
height={100}
|
||||||
className="rounded-full"
|
className="rounded-full zoom-animated"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<h1 className="mt-5 text-center">{customPage.title}</h1>
|
<h1 className="mt-5 text-center zoom-animated">{customPage.title}</h1>
|
||||||
<div className="w-full max-w-96 mb-40 p-2">
|
<div className="w-full max-w-96 p-2">
|
||||||
|
|
||||||
{linkBlocks.map((block) => (
|
{linkBlocks.map((block, index) => (
|
||||||
<button key={block.uuid} className="bg-slate-600 hover:bg-slate-500 w-full my-2">
|
<button
|
||||||
|
key={block.uuid}
|
||||||
|
className="bg-slate-600 hover:bg-slate-500 w-full my-2 slide-animated"
|
||||||
|
style={{ animationDelay: `${1.5 + index * 0.1}s` }}
|
||||||
|
>
|
||||||
<a href={`/${block.redirectPage.page.shortcode}`}>
|
<a href={`/${block.redirectPage.page.shortcode}`}>
|
||||||
<div className="relative flex items-center">
|
<div className="relative flex items-center">
|
||||||
<div className="flex-shrink-0"><LinkFavicon url={block.redirectPage.dest} /></div>
|
<div className="flex-shrink-0"><LinkFavicon url={block.redirectPage.dest} /></div>
|
||||||
@@ -42,7 +46,12 @@ export default async function CustomPageComponent(params: { customPage: CustomPa
|
|||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className="text-slate-700"><a className="underline" target="blank" href="https://github.com/traberph/short">traberph/short</a> by me running on <a className="underline" href="https://k3s.io/" target="blank">K3s</a></div>
|
<div
|
||||||
|
className="text-slate-700 mt-10 fade-animated"
|
||||||
|
style={{ animationDelay: `${1.5 + linkBlocks.length * 0.1}s`, opacity: 0 }}
|
||||||
|
>
|
||||||
|
<a className="underline" target="blank" href="https://github.com/traberph/short">traberph/short</a> by me running on <a className="underline" href="https://k3s.io/" target="blank">K3s</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ import { CustomPage } from "@prisma/client"
|
|||||||
import prisma from "../../prisma/prisma"
|
import prisma from "../../prisma/prisma"
|
||||||
import CreateLinkBlockForm from "./forms/createLinkBlockForm"
|
import CreateLinkBlockForm from "./forms/createLinkBlockForm"
|
||||||
import DeleteLinkBlockForm from "./forms/deleteLinkBlockForm"
|
import DeleteLinkBlockForm from "./forms/deleteLinkBlockForm"
|
||||||
|
import { ArrowTopRightOnSquareIcon, ArrowTrendingUpIcon, ArrowUpCircleIcon, ArrowUpRightIcon } from "@heroicons/react/24/solid"
|
||||||
|
|
||||||
export default async function CustomPageDashboard(params: { customPage: CustomPage }) {
|
export default async function CustomPageDashboard(params: { customPage: CustomPage }) {
|
||||||
|
|
||||||
@@ -30,12 +31,12 @@ export default async function CustomPageDashboard(params: { customPage: CustomPa
|
|||||||
<div>connected link page: <span className="font-bold">{block.redirectPage.page.shortcode}</span></div>
|
<div>connected link page: <span className="font-bold">{block.redirectPage.page.shortcode}</span></div>
|
||||||
<div className="ml-auto">
|
<div className="ml-auto">
|
||||||
<button>
|
<button>
|
||||||
<a href={`/${block.redirectPage.page.shortcode}`} className="btn btn-primary">Visit</a>
|
<a href={`/${block.redirectPage.page.shortcode}`} className="btn btn-primary"><ArrowTopRightOnSquareIcon className="button-icon" /></a>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-5">
|
<div className="ml-5">
|
||||||
<button>
|
<button>
|
||||||
<a href={`/~/dash/${block.redirectPage.page.uuid}`} className="btn btn-primary">Details</a>
|
<a href={`/~/dash/${block.redirectPage.page.uuid}`} className="btn btn-primary"><ArrowTrendingUpIcon className="button-icon" /></a>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-5">
|
<div className="ml-5">
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { createCustomPage } from "@/actions/page_actions";
|
import { createCustomPage } from "@/actions/page_actions";
|
||||||
import { useActionState } from "react";
|
import { useActionState, useEffect } from "react";
|
||||||
import SubmitButton from "../SubmitButton";
|
import SubmitButton from "../SubmitButton";
|
||||||
|
import { handleToast } from "@/utils";
|
||||||
|
|
||||||
|
|
||||||
export default function CreateCustomPageForm() {
|
export default function CreateCustomPageForm() {
|
||||||
@@ -13,6 +14,8 @@ export default function CreateCustomPageForm() {
|
|||||||
|
|
||||||
const [state, formAction] = useActionState(createCustomPage, initialState);
|
const [state, formAction] = useActionState(createCustomPage, initialState);
|
||||||
|
|
||||||
|
useEffect(() => { handleToast(state); }, [state]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form action={formAction}>
|
<form action={formAction}>
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { createLinkBlock } from "@/actions/block_actions"
|
import { createLinkBlock } from "@/actions/block_actions"
|
||||||
import { useActionState } from "react";
|
import { useActionState, useEffect } from "react";
|
||||||
import SubmitButton from "../SubmitButton";
|
import SubmitButton from "../SubmitButton";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import { handleToast } from "@/utils";
|
||||||
|
import { LinkIcon } from "@heroicons/react/24/solid";
|
||||||
|
|
||||||
|
|
||||||
export default function CreateLinkBlockForm({ customPage, shortcodes }: { customPage: string, shortcodes: string[] }) {
|
export default function CreateLinkBlockForm({ customPage, shortcodes }: { customPage: string, shortcodes: string[] }) {
|
||||||
@@ -13,6 +16,8 @@ export default function CreateLinkBlockForm({ customPage, shortcodes }: { custom
|
|||||||
|
|
||||||
const [state, formAction] = useActionState(createLinkBlock, initialState);
|
const [state, formAction] = useActionState(createLinkBlock, initialState);
|
||||||
|
|
||||||
|
useEffect(() => { handleToast(state); }, [state]);
|
||||||
|
|
||||||
return (<form action={formAction}>
|
return (<form action={formAction}>
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label htmlFor="redirectPageShortcode">Redirect Page</label>
|
<label htmlFor="redirectPageShortcode">Redirect Page</label>
|
||||||
@@ -32,8 +37,7 @@ export default function CreateLinkBlockForm({ customPage, shortcodes }: { custom
|
|||||||
<p className="form-label-error">{state.error?.order}</p>
|
<p className="form-label-error">{state.error?.order}</p>
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" name="customPageUuid" value={customPage} />
|
<input type="hidden" name="customPageUuid" value={customPage} />
|
||||||
<p className="mb-2">{state.message}</p>
|
<SubmitButton>add to page <LinkIcon className="ml-2 button-icon" /></SubmitButton>
|
||||||
<SubmitButton>add to page</SubmitButton>
|
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { createRedirectPage } from "@/actions/page_actions";
|
import { createRedirectPage } from "@/actions/page_actions";
|
||||||
import { useActionState } from "react";
|
import { useActionState, useEffect } from "react";
|
||||||
import SubmitButton from "../SubmitButton";
|
import SubmitButton from "../SubmitButton";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
import { handleToast } from "@/utils";
|
||||||
|
|
||||||
export default function CreateRedirectPageForm() {
|
export default function CreateRedirectPageForm() {
|
||||||
const initialState = {
|
const initialState = {
|
||||||
@@ -11,6 +13,8 @@ export default function CreateRedirectPageForm() {
|
|||||||
};
|
};
|
||||||
const [state, formAction] = useActionState(createRedirectPage, initialState);
|
const [state, formAction] = useActionState(createRedirectPage, initialState);
|
||||||
|
|
||||||
|
useEffect(() => { handleToast(state); }, [state]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form action={formAction}>
|
<form action={formAction}>
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
@@ -23,7 +27,6 @@ export default function CreateRedirectPageForm() {
|
|||||||
<input type='text' name='dest' id='dest' className={state.error?.dest ? "border-red-400" : ""} />
|
<input type='text' name='dest' id='dest' className={state.error?.dest ? "border-red-400" : ""} />
|
||||||
<p className="form-label-error">{state.error?.dest}</p>
|
<p className="form-label-error">{state.error?.dest}</p>
|
||||||
</div>
|
</div>
|
||||||
<p>{state.message}</p>
|
|
||||||
<SubmitButton />
|
<SubmitButton />
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { deleteLinkBlock } from "@/actions/block_actions";
|
import { deleteLinkBlock } from "@/actions/block_actions";
|
||||||
import { useActionState } from "react";
|
import { useActionState, useEffect } from "react";
|
||||||
import SubmitButton from "../SubmitButton";
|
import SubmitButton from "../SubmitButton";
|
||||||
|
import { handleToast } from "@/utils";
|
||||||
|
import { LinkSlashIcon } from "@heroicons/react/24/solid";
|
||||||
|
|
||||||
export default function DeleteLinkBlockForm({linkBlockUuid}: {linkBlockUuid:string}) {
|
export default function DeleteLinkBlockForm({ linkBlockUuid }: { linkBlockUuid: string }) {
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
message: "",
|
message: "",
|
||||||
@@ -13,11 +15,14 @@ export default function DeleteLinkBlockForm({linkBlockUuid}: {linkBlockUuid:stri
|
|||||||
|
|
||||||
const [state, formAction] = useActionState(deleteLinkBlock, initialState);
|
const [state, formAction] = useActionState(deleteLinkBlock, initialState);
|
||||||
|
|
||||||
return (<form action={formAction}>
|
useEffect(() => { handleToast(state); }, [state]);
|
||||||
|
|
||||||
<input type="hidden" name="uuid" id="uuid" value={linkBlockUuid}/>
|
return (<form action={formAction}>
|
||||||
<SubmitButton>unlink</SubmitButton>
|
<input type="hidden" name="uuid" id="uuid" value={linkBlockUuid} />
|
||||||
|
<SubmitButton>
|
||||||
|
<LinkSlashIcon className="button-icon" />
|
||||||
|
</SubmitButton>
|
||||||
</form>
|
</form>
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,26 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { deletePage } from "@/actions/page_actions";
|
import { deletePage } from "@/actions/page_actions";
|
||||||
import { useActionState } from "react";
|
import { useActionState, useEffect } from "react";
|
||||||
import SubmitButton from "../SubmitButton";
|
import SubmitButton from "../SubmitButton";
|
||||||
import { redirect } from "next/navigation";
|
import toast from "react-hot-toast";
|
||||||
|
import { handleToast } from "@/utils";
|
||||||
|
import { TrashIcon } from "@heroicons/react/24/solid";
|
||||||
|
|
||||||
export default function DeletePageForm({uuid}: {uuid: string}) {
|
export default function DeletePageForm({ uuid }: { uuid: string }) {
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
message: "",
|
message: "",
|
||||||
error: {},
|
error: {},
|
||||||
};
|
};
|
||||||
const [state, formAction] = useActionState(deletePage, initialState);
|
const [state, formAction] = useActionState(deletePage, initialState);
|
||||||
|
|
||||||
|
useEffect(() => { handleToast(state); }, [state]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form action={formAction}>
|
<form action={formAction}>
|
||||||
<input type="hidden" name="uuid" value={uuid}/>
|
<input type="hidden" name="uuid" value={uuid} />
|
||||||
<SubmitButton>Delete</SubmitButton>
|
<SubmitButton><TrashIcon className="button-icon" /></SubmitButton>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { pinPageToRoot } from "@/actions/page_actions";
|
import { pinPageToRoot } from "@/actions/page_actions";
|
||||||
import { BookmarkIcon } from "@heroicons/react/24/solid";
|
import { handleToast } from "@/utils";
|
||||||
import { useActionState, useState } from "react";
|
import { BookmarkIcon, BookmarkSlashIcon } from "@heroicons/react/24/solid";
|
||||||
|
import { use, useActionState, useEffect, useState } from "react";
|
||||||
|
import { toast } from 'react-hot-toast';
|
||||||
|
|
||||||
export default function PinPageToRootForm({ pageUuid, disabled }: { pageUuid: string, disabled: boolean }) {
|
export default function PinPageToRootForm({ pageUuid, pinned }: { pageUuid: string, pinned: boolean }) {
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
message: "",
|
message: "",
|
||||||
@@ -12,10 +14,17 @@ export default function PinPageToRootForm({ pageUuid, disabled }: { pageUuid: st
|
|||||||
|
|
||||||
const [state, formAction] = useActionState(pinPageToRoot, initialState);
|
const [state, formAction] = useActionState(pinPageToRoot, initialState);
|
||||||
|
|
||||||
|
useEffect(() => { handleToast(state); }, [state]);
|
||||||
|
|
||||||
return ( <form action={formAction}>
|
return (<form action={formAction}>
|
||||||
<input type="hidden" name="uuid" value={pageUuid} />
|
<input type="hidden" name="uuid" value={pageUuid} />
|
||||||
{/* <p>{state.message}</p> */}
|
<input type="hidden" name="unpin" value={"" + pinned} />
|
||||||
<button type="submit" className="btn btn-primary" disabled={disabled}><BookmarkIcon className="h-5 w-5 inline-block align-middle"/></button>
|
<button type="submit" className="btn btn-primary">
|
||||||
|
{pinned ?
|
||||||
|
<BookmarkSlashIcon className="h-5 w-5 inline-block align-middle" />
|
||||||
|
:
|
||||||
|
<BookmarkIcon className="h-5 w-5 inline-block align-middle" />
|
||||||
|
}
|
||||||
|
</button>
|
||||||
</form>)
|
</form>)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { signIn } from "@/auth"
|
||||||
|
|
||||||
|
export default function SignInButton() {
|
||||||
|
return (<div>
|
||||||
|
<form
|
||||||
|
action={async () => {
|
||||||
|
"use server"
|
||||||
|
await signIn("authentik")
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<button type="submit">Sign In</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import { signOut } from "@/auth"
|
||||||
|
|
||||||
|
export default function SignOutButton() {
|
||||||
|
return (
|
||||||
|
<form
|
||||||
|
className="flex"
|
||||||
|
action={async () => {
|
||||||
|
"use server"
|
||||||
|
await signOut()
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<button className='ml-auto bg-transparent p-1 hover:underline hover:bg-transparent' type="submit">logout</button>
|
||||||
|
</form>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { auth as middleware } from "@/auth"
|
||||||
+14
-1
@@ -1,4 +1,6 @@
|
|||||||
export function hashToColor(hash: string|null): string {
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
|
export function hashToColor(hash: string | null): string {
|
||||||
if (!hash) {
|
if (!hash) {
|
||||||
return "black";
|
return "black";
|
||||||
}
|
}
|
||||||
@@ -7,4 +9,15 @@ export function hashToColor(hash: string|null): string {
|
|||||||
const b = parseInt(hash.slice(4, 6), 16);
|
const b = parseInt(hash.slice(4, 6), 16);
|
||||||
const color = `rgb(${r}, ${g}, ${b})`;
|
const color = `rgb(${r}, ${g}, ${b})`;
|
||||||
return color;
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handleToast(state: { message: string, error?: any }) {
|
||||||
|
if (state.message) {
|
||||||
|
console.log(state);
|
||||||
|
if (state.error) {
|
||||||
|
toast.error(state.message);
|
||||||
|
} else {
|
||||||
|
toast.success(state.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user