@arch-cadre/blog-module 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/package.json +6 -5
  2. package/src/actions/index.d.ts +67 -0
  3. package/src/actions/index.js +149 -0
  4. package/src/actions/index.ts +157 -0
  5. package/src/components/BlogStatsWidget.d.ts +1 -0
  6. package/src/components/BlogStatsWidget.js +17 -0
  7. package/src/components/BlogStatsWidget.tsx +46 -0
  8. package/src/components/RecentCommentsWidget.d.ts +1 -0
  9. package/src/components/RecentCommentsWidget.js +24 -0
  10. package/src/components/RecentCommentsWidget.tsx +71 -0
  11. package/src/components/RecentPostsWidget.d.ts +1 -0
  12. package/src/components/RecentPostsWidget.js +24 -0
  13. package/src/components/RecentPostsWidget.tsx +68 -0
  14. package/src/components/ui/button.d.ts +11 -0
  15. package/src/components/ui/button.js +33 -0
  16. package/src/components/ui/button.tsx +56 -0
  17. package/src/components/ui/card.d.ts +6 -0
  18. package/src/components/ui/card.js +12 -0
  19. package/src/components/ui/card.tsx +51 -0
  20. package/src/components/ui/input.d.ts +5 -0
  21. package/src/components/ui/input.js +8 -0
  22. package/src/components/ui/input.tsx +24 -0
  23. package/src/components/ui/table.d.ts +8 -0
  24. package/src/components/ui/table.js +16 -0
  25. package/src/components/ui/table.tsx +83 -0
  26. package/src/components/ui/textarea.d.ts +5 -0
  27. package/src/components/ui/textarea.js +8 -0
  28. package/src/components/ui/textarea.tsx +23 -0
  29. package/src/index.d.ts +3 -0
  30. package/src/index.js +98 -0
  31. package/src/index.ts +121 -0
  32. package/src/intl.d.ts +7 -0
  33. package/src/lib/utils.d.ts +2 -0
  34. package/src/lib/utils.js +5 -0
  35. package/src/lib/utils.ts +6 -0
  36. package/src/lib/validation.d.ts +24 -0
  37. package/src/lib/validation.js +11 -0
  38. package/src/lib/validation.ts +13 -0
  39. package/src/navigation.d.ts +2 -0
  40. package/src/navigation.js +21 -0
  41. package/src/navigation.ts +23 -0
  42. package/src/routes.d.ts +3 -0
  43. package/src/routes.js +55 -0
  44. package/src/routes.tsx +74 -0
  45. package/src/schema.d.ts +736 -0
  46. package/src/schema.js +60 -0
  47. package/src/schema.ts +67 -0
  48. package/src/styles/globals.css +123 -0
  49. package/src/ui/views.d.ts +15 -0
  50. package/src/ui/views.js +119 -0
  51. package/src/ui/views.tsx +538 -0
package/src/schema.js ADDED
@@ -0,0 +1,60 @@
1
+ import { userTable } from "@arch-cadre/core";
2
+ import { defineRelations } from "drizzle-orm";
3
+ import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
4
+ export const postsTable = pgTable("blog_posts", {
5
+ id: text("id")
6
+ .primaryKey()
7
+ .$defaultFn(() => crypto.randomUUID()),
8
+ title: text("title").notNull(),
9
+ slug: text("slug").unique().notNull(),
10
+ content: text("content").notNull(),
11
+ authorId: text("author_id")
12
+ .references(() => userTable.id, { onDelete: "cascade" })
13
+ .notNull(),
14
+ createdAt: timestamp("created_at").defaultNow().notNull(),
15
+ });
16
+ export const commentsTable = pgTable("blog_comments", {
17
+ id: text("id")
18
+ .primaryKey()
19
+ .$defaultFn(() => crypto.randomUUID()),
20
+ postId: text("post_id")
21
+ .references(() => postsTable.id, { onDelete: "cascade" })
22
+ .notNull(),
23
+ authorId: text("author_id")
24
+ .references(() => userTable.id, { onDelete: "cascade" })
25
+ .notNull(),
26
+ content: text("content").notNull(),
27
+ createdAt: timestamp("created_at").defaultNow().notNull(),
28
+ });
29
+ export const blogSchema = {
30
+ postsTable,
31
+ commentsTable,
32
+ };
33
+ export const relations = defineRelations({
34
+ user: userTable,
35
+ post: postsTable,
36
+ comment: commentsTable,
37
+ }, (r) => ({
38
+ user: {
39
+ posts: r.many.post({
40
+ from: r.user.id,
41
+ to: r.post.authorId,
42
+ }),
43
+ comments: r.many.comment({
44
+ from: r.user.id,
45
+ to: r.comment.authorId,
46
+ }),
47
+ },
48
+ post: {
49
+ comments: r.many.comment({
50
+ from: r.post.id,
51
+ to: r.comment.postId,
52
+ }),
53
+ },
54
+ comment: {
55
+ post: r.one.post({
56
+ from: r.comment.postId,
57
+ to: r.post.id,
58
+ }),
59
+ },
60
+ }));
package/src/schema.ts ADDED
@@ -0,0 +1,67 @@
1
+ import { userTable } from "@arch-cadre/core";
2
+ import { defineRelations } from "drizzle-orm";
3
+ import { pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core";
4
+
5
+ export const postsTable = pgTable("blog_posts", {
6
+ id: text("id")
7
+ .primaryKey()
8
+ .$defaultFn(() => crypto.randomUUID()),
9
+ title: text("title").notNull(),
10
+ slug: text("slug").unique().notNull(),
11
+ content: text("content").notNull(),
12
+ authorId: text("author_id")
13
+ .references(() => userTable.id, { onDelete: "cascade" })
14
+ .notNull(),
15
+ createdAt: timestamp("created_at").defaultNow().notNull(),
16
+ });
17
+
18
+ export const commentsTable = pgTable("blog_comments", {
19
+ id: text("id")
20
+ .primaryKey()
21
+ .$defaultFn(() => crypto.randomUUID()),
22
+ postId: text("post_id")
23
+ .references(() => postsTable.id, { onDelete: "cascade" })
24
+ .notNull(),
25
+ authorId: text("author_id")
26
+ .references(() => userTable.id, { onDelete: "cascade" })
27
+ .notNull(),
28
+ content: text("content").notNull(),
29
+ createdAt: timestamp("created_at").defaultNow().notNull(),
30
+ });
31
+
32
+ export const blogSchema = {
33
+ postsTable,
34
+ commentsTable,
35
+ };
36
+
37
+ export const relations = defineRelations(
38
+ {
39
+ user: userTable,
40
+ post: postsTable,
41
+ comment: commentsTable,
42
+ },
43
+ (r) => ({
44
+ user: {
45
+ posts: r.many.post({
46
+ from: r.user.id,
47
+ to: r.post.authorId,
48
+ }),
49
+ comments: r.many.comment({
50
+ from: r.user.id,
51
+ to: r.comment.authorId,
52
+ }),
53
+ },
54
+ post: {
55
+ comments: r.many.comment({
56
+ from: r.post.id,
57
+ to: r.comment.postId,
58
+ }),
59
+ },
60
+ comment: {
61
+ post: r.one.post({
62
+ from: r.comment.postId,
63
+ to: r.post.id,
64
+ }),
65
+ },
66
+ }),
67
+ );
@@ -0,0 +1,123 @@
1
+ @import "tailwindcss";
2
+ @import "tw-animate-css";
3
+
4
+ @custom-variant dark (&:is(.dark *));
5
+
6
+ :root {
7
+ --background: oklch(1 0 0);
8
+ --foreground: oklch(0.145 0 0);
9
+ --card: oklch(1 0 0);
10
+ --card-foreground: oklch(0.145 0 0);
11
+ --popover: oklch(1 0 0);
12
+ --popover-foreground: oklch(0.145 0 0);
13
+ --primary: oklch(0.205 0 0);
14
+ --primary-foreground: oklch(0.985 0 0);
15
+ --secondary: oklch(0.97 0 0);
16
+ --secondary-foreground: oklch(0.205 0 0);
17
+ --muted: oklch(0.97 0 0);
18
+ --muted-foreground: oklch(0.556 0 0);
19
+ --accent: oklch(0.97 0 0);
20
+ --accent-foreground: oklch(0.205 0 0);
21
+ --destructive: oklch(0.577 0.245 27.325);
22
+ --destructive-foreground: oklch(0.577 0.245 27.325);
23
+ --border: oklch(0.922 0 0);
24
+ --input: oklch(0.922 0 0);
25
+ --ring: oklch(0.708 0 0);
26
+ --chart-1: oklch(0.646 0.222 41.116);
27
+ --chart-2: oklch(0.6 0.118 184.704);
28
+ --chart-3: oklch(0.398 0.07 227.392);
29
+ --chart-4: oklch(0.828 0.189 84.429);
30
+ --chart-5: oklch(0.769 0.188 70.08);
31
+ --radius: 0.625rem;
32
+ --sidebar: oklch(0.985 0 0);
33
+ --sidebar-foreground: oklch(0.145 0 0);
34
+ --sidebar-primary: oklch(0.205 0 0);
35
+ --sidebar-primary-foreground: oklch(0.985 0 0);
36
+ --sidebar-accent: oklch(0.97 0 0);
37
+ --sidebar-accent-foreground: oklch(0.205 0 0);
38
+ --sidebar-border: oklch(0.922 0 0);
39
+ --sidebar-ring: oklch(0.708 0 0);
40
+ }
41
+
42
+ .dark {
43
+ --background: oklch(0.145 0 0);
44
+ --foreground: oklch(0.985 0 0);
45
+ --card: oklch(0.145 0 0);
46
+ --card-foreground: oklch(0.985 0 0);
47
+ --popover: oklch(0.145 0 0);
48
+ --popover-foreground: oklch(0.985 0 0);
49
+ --primary: oklch(0.985 0 0);
50
+ --primary-foreground: oklch(0.205 0 0);
51
+ --secondary: oklch(0.269 0 0);
52
+ --secondary-foreground: oklch(0.985 0 0);
53
+ --muted: oklch(0.269 0 0);
54
+ --muted-foreground: oklch(0.708 0 0);
55
+ --accent: oklch(0.269 0 0);
56
+ --accent-foreground: oklch(0.985 0 0);
57
+ --destructive: oklch(0.396 0.141 25.723);
58
+ --destructive-foreground: oklch(0.637 0.237 25.331);
59
+ --border: oklch(0.269 0 0);
60
+ --input: oklch(0.269 0 0);
61
+ --ring: oklch(0.439 0 0);
62
+ --chart-1: oklch(0.488 0.243 264.376);
63
+ --chart-2: oklch(0.696 0.17 162.48);
64
+ --chart-3: oklch(0.769 0.188 70.08);
65
+ --chart-4: oklch(0.627 0.265 303.9);
66
+ --chart-5: oklch(0.645 0.246 16.439);
67
+ --sidebar: oklch(0.205 0 0);
68
+ --sidebar-foreground: oklch(0.985 0 0);
69
+ --sidebar-primary: oklch(0.488 0.243 264.376);
70
+ --sidebar-primary-foreground: oklch(0.985 0 0);
71
+ --sidebar-accent: oklch(0.269 0 0);
72
+ --sidebar-accent-foreground: oklch(0.985 0 0);
73
+ --sidebar-border: oklch(0.269 0 0);
74
+ --sidebar-ring: oklch(0.439 0 0);
75
+ }
76
+
77
+ @theme inline {
78
+ --color-background: var(--background);
79
+ --color-foreground: var(--foreground);
80
+ --color-card: var(--card);
81
+ --color-card-foreground: var(--card-foreground);
82
+ --color-popover: var(--popover);
83
+ --color-popover-foreground: var(--popover-foreground);
84
+ --color-primary: var(--primary);
85
+ --color-primary-foreground: var(--primary-foreground);
86
+ --color-secondary: var(--secondary);
87
+ --color-secondary-foreground: var(--secondary-foreground);
88
+ --color-muted: var(--muted);
89
+ --color-muted-foreground: var(--muted-foreground);
90
+ --color-accent: var(--accent);
91
+ --color-accent-foreground: var(--accent-foreground);
92
+ --color-destructive: var(--destructive);
93
+ --color-destructive-foreground: var(--destructive-foreground);
94
+ --color-border: var(--border);
95
+ --color-input: var(--input);
96
+ --color-ring: var(--ring);
97
+ --color-chart-1: var(--chart-1);
98
+ --color-chart-2: var(--chart-2);
99
+ --color-chart-3: var(--chart-3);
100
+ --color-chart-4: var(--chart-4);
101
+ --color-chart-5: var(--chart-5);
102
+ --radius-sm: calc(var(--radius) - 4px);
103
+ --radius-md: calc(var(--radius) - 2px);
104
+ --radius-lg: var(--radius);
105
+ --radius-xl: calc(var(--radius) + 4px);
106
+ --color-sidebar: var(--sidebar);
107
+ --color-sidebar-foreground: var(--sidebar-foreground);
108
+ --color-sidebar-primary: var(--sidebar-primary);
109
+ --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
110
+ --color-sidebar-accent: var(--sidebar-accent);
111
+ --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
112
+ --color-sidebar-border: var(--sidebar-border);
113
+ --color-sidebar-ring: var(--sidebar-ring);
114
+ }
115
+
116
+ @layer base {
117
+ * {
118
+ @apply border-border outline-ring/50;
119
+ }
120
+ body {
121
+ @apply bg-background text-foreground;
122
+ }
123
+ }
@@ -0,0 +1,15 @@
1
+ export declare function BlogListPage({ posts }: {
2
+ posts?: any[];
3
+ }): import("react/jsx-runtime").JSX.Element;
4
+ export declare function PostDetailPage({ post, comments, currentUser, }: {
5
+ post: any;
6
+ comments: any[];
7
+ currentUser?: any;
8
+ }): import("react/jsx-runtime").JSX.Element;
9
+ export declare function BlogAdminPage({ posts }: {
10
+ posts: any[];
11
+ }): import("react/jsx-runtime").JSX.Element;
12
+ export declare function CreatePostForm(): import("react/jsx-runtime").JSX.Element;
13
+ export declare function EditPostForm({ post }: {
14
+ post: any;
15
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,119 @@
1
+ /** biome-ignore-all lint/a11y/noLabelWithoutControl: <explanation> */
2
+ "use client";
3
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
+ import { useTranslation } from "@arch-cadre/intl/client";
5
+ import { zodResolver } from "@hookform/resolvers/zod";
6
+ import { ArrowLeft, Eye, MessageSquare, Pencil, Plus, Trash2, User as UserIcon, } from "lucide-react";
7
+ import Link from "next/link";
8
+ import { useRouter } from "next/navigation";
9
+ import { useForm } from "react-hook-form";
10
+ import { toast } from "sonner";
11
+ import { createComment, createPost, deletePost, updatePost } from "../actions/index.js";
12
+ import { Button } from "../components/ui/button.js";
13
+ import { Card, CardContent, CardHeader, CardTitle, } from "../components/ui/card.js";
14
+ import { Input } from "../components/ui/input.js";
15
+ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "../components/ui/table.js";
16
+ import { Textarea } from "../components/ui/textarea.js";
17
+ import { commentSchema, postSchema } from "../lib/validation.js";
18
+ export function BlogListPage({ posts = [] }) {
19
+ const { t } = useTranslation();
20
+ return (_jsxs("div", { className: "max-w-4xl mx-auto p-6 space-y-8", children: [_jsxs("header", { className: "border-b pb-6", children: [_jsx("h1", { className: "text-4xl font-black tracking-tighter text-primary", children: t("Blog Posts") }), _jsx("p", { className: "text-muted-foreground mt-2", children: t("Reading your blog posts") })] }), _jsx("div", { className: "grid gap-6", children: posts.map((post) => (_jsx(Link, { href: `/blog/${post.slug}`, children: _jsxs(Card, { className: "group hover:shadow-lg transition-all cursor-pointer overflow-hidden border-primary/5", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "text-2xl group-hover:text-primary transition-colors", children: post.title }), _jsxs("div", { className: "flex items-center gap-2 text-xs text-muted-foreground mt-1", children: [_jsx(UserIcon, { className: "size-3" }), _jsx("span", { children: post.author?.name }), _jsx("span", { children: "\u2022" }), _jsx("span", { children: new Date(post.createdAt).toLocaleDateString() })] })] }), _jsx(CardContent, { children: _jsx("p", { className: "text-secondary-foreground line-clamp-2", children: post.content }) })] }) }, post.id))) })] }));
21
+ }
22
+ // --- Comment Form Component ---
23
+ function CommentForm({ postId }) {
24
+ const router = useRouter();
25
+ const { t } = useTranslation();
26
+ const { register, handleSubmit, reset, formState: { errors, isSubmitting }, } = useForm({
27
+ resolver: zodResolver(commentSchema.omit({ postId: true })),
28
+ });
29
+ const onSubmit = async (data) => {
30
+ const result = await createComment({ ...data, postId });
31
+ if (result.success) {
32
+ toast.success(t("Comment added"));
33
+ reset();
34
+ router.refresh();
35
+ }
36
+ else {
37
+ toast.error(result.error);
38
+ }
39
+ };
40
+ return (_jsxs("form", { onSubmit: handleSubmit(onSubmit), className: "space-y-4", children: [_jsxs("div", { className: "space-y-1", children: [_jsx(Textarea, { ...register("content"), placeholder: t("Add your comment here..."), className: errors.content ? "border-destructive" : "" }), errors.content && (_jsx("p", { className: "text-xs text-destructive", children: errors.content.message }))] }), _jsx(Button, { type: "submit", disabled: isSubmitting, size: "sm", children: isSubmitting ? t("Please wait...") : t("Create Comment") })] }));
41
+ }
42
+ // --- Detail View ---
43
+ export function PostDetailPage({ post, comments = [], currentUser, }) {
44
+ const { t } = useTranslation();
45
+ if (!post)
46
+ return _jsx("div", { className: "p-20 text-center", children: t("Post not found") });
47
+ return (_jsxs("div", { className: "max-w-3xl mx-auto p-6 space-y-10 pb-20", children: [_jsx(Button, { asChild: true, variant: "ghost", size: "sm", className: "gap-2", children: _jsxs(Link, { href: "/blog", children: [_jsx(ArrowLeft, { className: "size-4" }), " ", t("Back to posts")] }) }), _jsxs("article", { className: "space-y-6", children: [_jsxs("div", { className: "space-y-2", children: [_jsx("h1", { className: "text-5xl font-black tracking-tighter leading-tight", children: post.title }), _jsxs("div", { className: "flex items-center gap-3 text-muted-foreground", children: [_jsx("div", { className: "size-8 rounded-full bg-primary/10 flex items-center justify-center", children: _jsx(UserIcon, { className: "size-4 text-primary" }) }), _jsxs("div", { className: "text-sm", children: [_jsx("p", { className: "font-bold text-foreground leading-none", children: post.author?.name }), _jsx("p", { className: "text-xs", children: new Date(post.createdAt).toLocaleDateString() })] })] })] }), _jsx("div", { className: "prose prose-lg dark:prose-invert max-w-none whitespace-pre-wrap pt-4 border-t", children: post.content })] }), _jsxs("section", { className: "pt-10 border-t space-y-8", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(MessageSquare, { className: "size-5" }), _jsxs("h3", { className: "text-2xl font-bold tracking-tight", children: [t("Comments"), " (", comments.length, ")"] })] }), currentUser ? (_jsxs("div", { className: "bg-muted/30 p-6 rounded-2xl border", children: [_jsx("p", { className: "text-sm font-bold mb-4", children: t("Leave a comment") }), _jsx(CommentForm, { postId: post.id })] })) : (_jsx("div", { className: "p-6 bg-amber-50 border border-amber-100 rounded-2xl text-center", children: _jsxs("p", { className: "text-sm font-medium text-amber-800", children: ["Please", " ", _jsx(Link, { href: "/signin", className: "underline font-bold", children: t("Sign in") }), " ", t("to join the conversation.")] }) })), _jsxs("div", { className: "space-y-6", children: [comments.map((comment) => (_jsxs("div", { className: "flex gap-4", children: [_jsx("div", { className: "size-10 rounded-full bg-muted flex items-center justify-center shrink-0", children: _jsx(UserIcon, { className: "size-5 opacity-40" }) }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "font-bold text-sm", children: comment.author?.name }), _jsx("span", { className: "text-[10px] opacity-50", children: new Date(comment.createdAt).toLocaleDateString() })] }), _jsx("p", { className: "text-sm text-secondary-foreground leading-relaxed", children: comment.content })] })] }, comment.id))), comments.length === 0 && (_jsx("p", { className: "text-center text-muted-foreground text-sm py-10 italic", children: t("No comments yet. Be the first to comment!") }))] })] })] }));
48
+ }
49
+ // --- Admin View Components ---
50
+ export function BlogAdminPage({ posts = [] }) {
51
+ const router = useRouter();
52
+ const { t } = useTranslation();
53
+ const handleDelete = async (id) => {
54
+ if (!confirm(t("Confirm deletion of this post?")))
55
+ return;
56
+ const result = await deletePost(id);
57
+ if (result.success) {
58
+ toast.success(t("Post deleted"));
59
+ router.refresh();
60
+ }
61
+ else {
62
+ toast.error(t("UnexpectedError") + result.error);
63
+ }
64
+ };
65
+ return (_jsxs("div", { className: "p-6 space-y-6", children: [_jsxs("div", { className: "flex justify-between items-center", children: [_jsx("h1", { className: "text-3xl font-black tracking-tight text-foreground", children: t("Blog posts") }), _jsx(Button, { asChild: true, size: "sm", className: "gap-2", children: _jsxs(Link, { href: "/kryo/blog/new", children: [_jsx(Plus, { className: "size-4" }), " ", t("New Post")] }) })] }), _jsx(Card, { className: "border-primary/10 shadow-sm overflow-hidden", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { className: "w-[40%]", children: t("Title") }), _jsx(TableHead, { children: t("Author") }), _jsx(TableHead, { children: t("Date") }), _jsx(TableHead, { className: "text-right", children: t("Actions") })] }) }), _jsxs(TableBody, { children: [posts.length === 0 && (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 4, className: "h-24 text-center text-muted-foreground italic", children: t("No posts found. Create your first post!") }) })), posts.map((post) => (_jsxs(TableRow, { className: "transition-colors", children: [_jsx(TableCell, { className: "font-bold", children: post.title }), _jsx(TableCell, { className: "text-xs", children: post.author?.name }), _jsx(TableCell, { className: "text-muted-foreground text-xs", children: new Date(post.createdAt).toLocaleDateString() }), _jsx(TableCell, { className: "text-right", children: _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { asChild: true, variant: "ghost", size: "icon", className: "size-8", children: _jsx(Link, { href: `/blog/${post.slug}`, target: "_blank", children: _jsx(Eye, { className: "size-4" }) }) }), _jsx(Button, { asChild: true, variant: "ghost", size: "icon", className: "size-8", children: _jsx(Link, { href: `/kryo/blog/edit/${post.id}`, children: _jsx(Pencil, { className: "size-4" }) }) }), _jsx(Button, { variant: "ghost", size: "icon", className: "size-8 text-destructive hover:text-destructive hover:bg-destructive/10", onClick: () => handleDelete(post.id), children: _jsx(Trash2, { className: "size-4" }) })] }) })] }, post.id)))] })] }) })] }));
66
+ }
67
+ export function CreatePostForm() {
68
+ const router = useRouter();
69
+ const { t } = useTranslation();
70
+ const { register, handleSubmit, formState: { errors, isSubmitting }, } = useForm({
71
+ resolver: zodResolver(postSchema.omit({ slug: true })),
72
+ });
73
+ const onSubmit = async (data) => {
74
+ const slug = data.title
75
+ .toLowerCase()
76
+ .replace(/ /g, "-")
77
+ .replace(/[^\w-]+/g, "");
78
+ const result = await createPost({ ...data, slug });
79
+ if (result.success) {
80
+ toast.success(t("Post created"));
81
+ router.push("/kryo/blog");
82
+ router.refresh();
83
+ }
84
+ else {
85
+ toast.error(t("UnexpectedError") + result.error);
86
+ }
87
+ };
88
+ return (_jsxs("div", { className: "max-w-2xl mx-auto p-6 space-y-6", children: [_jsxs("div", { className: "flex items-center gap-4", children: [_jsx(Button, { asChild: true, variant: "outline", size: "icon", className: "rounded-lg", children: _jsx(Link, { href: "/kryo/blog", children: _jsx(ArrowLeft, { className: "size-4" }) }) }), _jsx("h1", { className: "text-2xl font-black text-foreground", children: t("New Post") })] }), _jsx(Card, { className: "border-primary/10 shadow-lg", children: _jsx(CardContent, { className: "pt-6", children: _jsxs("form", { onSubmit: handleSubmit(onSubmit), className: "space-y-6", children: [_jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "text-xs font-black uppercase tracking-widest opacity-50 px-1", children: t("Title") }), _jsx(Input, { ...register("title"), className: errors.title ? "border-destructive font-bold" : "font-bold", placeholder: t("Title of your post") }), errors.title && (_jsx("p", { className: "text-xs text-destructive font-bold", children: errors.title.message }))] }), _jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "text-xs font-black uppercase tracking-widest opacity-50 px-1", children: t("Content") }), _jsx(Textarea, { ...register("content"), rows: 12, className: errors.content
89
+ ? "border-destructive resize-none"
90
+ : "resize-none", placeholder: t("Content of your post") }), errors.content && (_jsx("p", { className: "text-xs text-destructive font-bold", children: errors.content.message }))] }), _jsx(Button, { type: "submit", disabled: isSubmitting, className: "w-full text-sm uppercase tracking-widest transition-all", children: isSubmitting ? t("Please wait...") : t("Publish") })] }) }) })] }));
91
+ }
92
+ export function EditPostForm({ post }) {
93
+ const router = useRouter();
94
+ const { t } = useTranslation();
95
+ const { register, handleSubmit, formState: { errors, isSubmitting }, } = useForm({
96
+ resolver: zodResolver(postSchema),
97
+ defaultValues: {
98
+ title: post.title,
99
+ content: post.content,
100
+ slug: post.slug,
101
+ },
102
+ });
103
+ const onSubmit = async (data) => {
104
+ const result = await updatePost(post.id, data);
105
+ if (result.success) {
106
+ toast.success(t("Post updated"));
107
+ router.push("/kryo/blog");
108
+ router.refresh();
109
+ }
110
+ else {
111
+ toast.error(t("UnexpectedError") + result.error);
112
+ }
113
+ };
114
+ return (_jsxs("div", { className: "max-w-2xl mx-auto p-6 space-y-6", children: [_jsxs("div", { className: "flex items-center gap-4", children: [_jsx(Button, { asChild: true, variant: "outline", size: "icon", className: "rounded-lg", children: _jsx(Link, { href: "/kryo/blog", children: _jsx(ArrowLeft, { className: "size-4" }) }) }), _jsx("h1", { className: "text-2xl font-black text-foreground", children: t("Edit Post") })] }), _jsx(Card, { className: "border-primary/10 shadow-lg", children: _jsx(CardContent, { className: "pt-6", children: _jsxs("form", { onSubmit: handleSubmit(onSubmit), className: "space-y-6", children: [_jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "text-xs font-black uppercase tracking-widest opacity-50 px-1", children: t("Title") }), _jsx(Input, { ...register("title"), className: errors.title ? "border-destructive font-bold" : "font-bold", placeholder: t("Title of your post") }), errors.title && (_jsx("p", { className: "text-xs text-destructive font-bold", children: errors.title.message }))] }), _jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "text-xs font-black uppercase tracking-widest opacity-50 px-1", children: t("Slug") }), _jsx(Input, { ...register("slug"), className: errors.slug
115
+ ? "border-destructive font-mono text-sm"
116
+ : "font-mono text-sm", placeholder: t("Slug URL") }), errors.slug && (_jsx("p", { className: "text-xs text-destructive font-bold", children: errors.slug.message }))] }), _jsxs("div", { className: "space-y-2", children: [_jsx("label", { className: "text-xs font-black uppercase tracking-widest opacity-50 px-1", children: t("Content") }), _jsx(Textarea, { ...register("content"), rows: 12, className: errors.content
117
+ ? "border-destructive resize-none"
118
+ : "resize-none", placeholder: t("Content of your post") }), errors.content && (_jsx("p", { className: "text-xs text-destructive font-bold", children: errors.content.message }))] }), _jsx(Button, { type: "submit", disabled: isSubmitting, className: "w-full text-sm uppercase tracking-widest transition-all", children: isSubmitting ? t("Please wait...") : t("Update") })] }) }) })] }));
119
+ }