From 18161f4604870e5a160277991823d13b23bd681b Mon Sep 17 00:00:00 2001 From: Ivan Rezchikov Date: Sat, 11 Jul 2026 21:20:57 +0300 Subject: [PATCH] prod --- .drone.yml | 75 +++++++ Dockerfile | 19 ++ app/[type]/[slug]/archive-button.tsx | 10 +- app/[type]/[slug]/edit/client.tsx | 66 ++---- app/[type]/[slug]/edit/page.tsx | 8 +- app/[type]/[slug]/page.tsx | 80 ++++--- app/[type]/[slug]/pin-toggle-button.tsx | 20 +- app/account/account-menu.tsx | 2 +- app/account/citizenship/apply/form.tsx | 7 +- .../citizenship/apply/image-upload-field.tsx | 131 ++++++++--- app/account/citizenship/apply/page.tsx | 50 ++--- app/account/citizenship/has-citizenship.tsx | 6 +- app/account/citizenship/no-citizenship.tsx | 8 +- app/account/citizenship/page.tsx | 40 ++-- .../citizenship/renunciation-dialog.tsx | 2 +- .../citizenship/review/application-card.tsx | 32 +-- app/account/citizenship/review/client.tsx | 2 +- app/account/citizenship/review/page.tsx | 14 +- app/account/page.tsx | 81 +++---- app/create/client.tsx | 69 ++---- app/create/page.tsx | 8 +- app/error.tsx | 16 ++ app/favicon.ico | Bin 25931 -> 6083 bytes app/globals.css | 45 +++- app/layout.tsx | 9 +- app/news/page.tsx | 42 ++-- app/not-found.tsx | 14 ++ app/page.tsx | 113 ++++++---- bun.lock | 46 ++++ components/drafts-dialog.tsx | 59 ++--- components/editor.tsx | 25 ++- components/footer.tsx | 11 +- components/header.tsx | 45 ++-- components/identity-card.tsx | 31 ++- components/image-uploader.tsx | 210 ++++++++++++++++++ components/mobile-nav.tsx | 53 +++++ components/news-card.tsx | 10 +- components/ui/button.tsx | 4 +- components/ui/field.tsx | 12 +- components/ui/input.tsx | 2 +- components/ui/select.tsx | 2 +- components/ui/tooltip.tsx | 57 +++++ docker-compose.yml | 36 +++ lib/citizenship/actions.ts | 59 +++-- lib/citizenship/repository.ts | 10 +- lib/citizenship/types.ts | 2 - lib/image.ts | 46 ++-- lib/navlinks/actions.ts | 26 ++- lib/pages/actions.ts | 59 +++-- lib/pages/repository.ts | 14 +- lib/user/actions.ts | 6 +- next.config.ts | 2 +- package.json | 5 + prisma/schema.prisma | 17 +- public/profile.png | Bin 188935 -> 0 bytes public/signature.png | Bin 23559 -> 0 bytes todo | 8 - 57 files changed, 1211 insertions(+), 615 deletions(-) create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 app/error.tsx create mode 100644 app/not-found.tsx create mode 100644 components/image-uploader.tsx create mode 100644 components/mobile-nav.tsx create mode 100644 components/ui/tooltip.tsx create mode 100644 docker-compose.yml delete mode 100644 public/profile.png delete mode 100644 public/signature.png delete mode 100644 todo diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..90eb1d9 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,75 @@ +kind: pipeline +type: docker +name: default + +steps: + - name: lint frontend + image: node:20-alpine + commands: + - npm install + - npm run lint + + - name: build and push frontend + image: docker:24 + volumes: + - name: dockersock + path: /var/run/docker.sock + commands: + - docker build + -t localhost:5000/eu:latest + -f ./Dockerfile + eu + - docker push localhost:5000/eu:latest + + - name: deploy + image: docker:24 + volumes: + - name: dockersock + path: /var/run/docker.sock + - name: appdir + path: /opt/app + environment: + PUBLIC_URL: + from_secret: PUBLIC_URL + DATABASE_URL: + from_secret: DATABASE_URL + KOTOSOFT_ID_API_URL: + from_secret: KOTOSOFT_ID_API_URL + KOTOSOFT_CLIENT_ID: + from_secret: KOTOSOFT_CLIENT_ID + KOTOSOFT_CLIENT_SECRET: + from_secret: KOTOSOFT_CLIENT_SECRET + JWT_SECRET: + from_secret: JWT_SECRET + MINIO_URL: + from_secret: MINIO_URL + MINIO_ACCESS_KEY: + from_secret: MINIO_ACCESS_KEY + MINIO_SECRET_KEY: + from_secret: MINIO_SECRET_KEY + MINIO_PUBLIC_URL: + from_secret: MINIO_PUBLIC_URL + VIRTUAL_HOST: + from_secret: API_DOMAIN + LETSENCRYPT_HOST: + from_secret: API_DOMAIN + LETSENCRYPT_EMAIL: + from_secret: LETSENCRYPT_EMAIL + commands: + - apk add --no-cache docker-cli-compose + - cp docker-compose.yml /opt/app/docker-compose.yml + - cd /opt/app + - docker compose pull + - docker compose up -d --remove-orphans + +volumes: + - name: dockersock + host: + path: /var/run/docker.sock + - name: appdir + host: + path: /opt/drone/eu + +trigger: + branch: + - main \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7f6710a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM node:20 AS builder +WORKDIR /app +COPY package.json package-lock.json* ./ +RUN npm install --include=dev +COPY . . +RUN npm run build + +FROM node:20 AS production +WORKDIR /app +COPY package.json package-lock.json* ./ +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/public ./public +COPY --from=builder /app/messages ./messages +RUN npm prune --omit=dev +EXPOSE 80 +CMD ["npm", "start", "--", "-p", "3000", "-H", "0.0.0.0"] +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD wget -q --spider http://localhost:3000/ || exit 1 \ No newline at end of file diff --git a/app/[type]/[slug]/archive-button.tsx b/app/[type]/[slug]/archive-button.tsx index a6f4e36..45b1357 100644 --- a/app/[type]/[slug]/archive-button.tsx +++ b/app/[type]/[slug]/archive-button.tsx @@ -1,23 +1,25 @@ "use client"; -import { useTransition } from "react"; import { Button } from "@/components/ui/button"; import { ArchiveIcon } from "lucide-react"; import { Spinner } from "@/components/ui/spinner"; import { archivePageAction } from "@/lib/pages/actions"; import { PageType } from "@/lib/pages/types"; +import { useAction } from "@/hooks/useAction"; export function ArchiveButton({ pageId, slug, type }: { pageId: string, slug: string, type: PageType }) { - const [isPending, startTransition] = useTransition(); + const { run, isPending } = useAction(archivePageAction, { + successMessage: "Page archived", + }); return ( ); -} \ No newline at end of file +} diff --git a/app/[type]/[slug]/edit/client.tsx b/app/[type]/[slug]/edit/client.tsx index 66632f4..c22cd0e 100644 --- a/app/[type]/[slug]/edit/client.tsx +++ b/app/[type]/[slug]/edit/client.tsx @@ -1,14 +1,13 @@ "use client"; -import { useRef, useState, useTransition } from "react"; +import { useRef } from "react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import Editor, { EditorData } from "@/components/editor"; import { savePageAction } from "@/lib/pages/actions"; -import { validatePage } from "@/lib/pages/validation"; import { Block, Page, PageMeta, PageType } from "@/lib/pages/types"; -import { Loader2 } from "lucide-react"; -import { toast } from "sonner"; +import { Spinner } from "@/components/ui/spinner"; +import { useAction } from "@/hooks/useAction"; type Props = { page: Page | null; @@ -18,8 +17,10 @@ type Props = { export default function EditPageClient({ page, pageType, initialBlocks = [] }: Props) { const router = useRouter(); - const [isPending, startTransition] = useTransition(); - const [fieldErrors, setFieldErrors] = useState<{ title?: string[]; slug?: string[] }>({}); + const { run, isPending } = useAction(savePageAction, { + successMessage: "Page saved", + onSuccess: () => router.push(`/${pageType.toLowerCase()}/${dataRef.current.slug}`), + }); const dataRef = useRef({ title: page?.title ?? "", @@ -31,47 +32,20 @@ export default function EditPageClient({ page, pageType, initialBlocks = [] }: P }); function handleSave(status: "DRAFT" | "PUBLISHED") { - startTransition(async () => { - const data = dataRef.current; - const payload = { - id: page?.id ?? null, - slug: data.slug || data.title.toLowerCase().replace(/\s+/g, "-"), - title: data.title, - type: pageType, - status, - blocks: data.blocks, - meta: { location: data.location, tags: data.tags }, - }; - - const parsed = validatePage(payload); - if (!parsed.success) { - const errors: { title?: string[]; slug?: string[] } = {}; - for (const msg of parsed.errors) { - if (msg.toLowerCase().includes("title")) { - (errors.title ??= []).push(msg); - } else if (msg.toLowerCase().includes("slug")) { - (errors.slug ??= []).push(msg); - } - } - setFieldErrors(errors); - toast.error(parsed.errors.join(", ")); - return; - } - - setFieldErrors({}); - - try { - await savePageAction(payload); - toast.success("Page saved"); - router.push(`/${pageType.toLowerCase()}/${data.slug}`); - } catch (e) { - toast.error(e instanceof Error ? e.message : "Failed to save page"); - } + const data = dataRef.current; + run({ + id: page?.id ?? null, + slug: data.slug || data.title.toLowerCase().replace(/\s+/g, "-"), + title: data.title, + type: pageType, + status, + blocks: data.blocks, + meta: { location: data.location, tags: data.tags }, }); } return ( -
+

Edit page

@@ -79,7 +53,7 @@ export default function EditPageClient({ page, pageType, initialBlocks = [] }: P disabled={isPending} onClick={() => handleSave("PUBLISHED")} > - {isPending && } + {isPending && } Save
@@ -88,12 +62,10 @@ export default function EditPageClient({ page, pageType, initialBlocks = [] }: P page={page} type={pageType} initialBlocks={initialBlocks} - errors={fieldErrors} onChange={(data) => { dataRef.current = data; - setFieldErrors({}); }} />
); -} \ No newline at end of file +} diff --git a/app/[type]/[slug]/edit/page.tsx b/app/[type]/[slug]/edit/page.tsx index 2798a5c..edbacfb 100644 --- a/app/[type]/[slug]/edit/page.tsx +++ b/app/[type]/[slug]/edit/page.tsx @@ -1,5 +1,3 @@ -import Header from "@/components/header"; -import Footer from "@/components/footer"; import { getPageBySlug, getBlocksByPageId } from "@/lib/pages/repository"; import { getCurrentUser } from "@/lib/user"; import { redirect, notFound } from "next/navigation"; @@ -20,10 +18,6 @@ export default async function EditPage({ params }: { params: Promise<{ type: str const blocks = page ? await getBlocksByPageId(page.id) : []; return ( - <> -
- -