@arch-cadre/blog-module 1.0.7 → 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 (100) hide show
  1. package/dist/actions/index.d.ts +38 -5
  2. package/dist/actions/index.js +149 -0
  3. package/dist/components/BlogStatsWidget.d.ts +1 -2
  4. package/dist/components/BlogStatsWidget.js +17 -0
  5. package/dist/components/RecentCommentsWidget.d.ts +1 -2
  6. package/dist/components/RecentCommentsWidget.js +24 -0
  7. package/dist/components/RecentPostsWidget.d.ts +1 -2
  8. package/dist/components/RecentPostsWidget.js +24 -0
  9. package/dist/components/ui/button.d.ts +1 -1
  10. package/dist/components/ui/button.js +33 -0
  11. package/dist/components/ui/card.js +12 -0
  12. package/dist/components/ui/input.js +8 -0
  13. package/dist/components/ui/table.js +16 -0
  14. package/dist/components/ui/textarea.js +8 -0
  15. package/dist/index.js +98 -0
  16. package/dist/lib/{utils.mjs → utils.js} +1 -1
  17. package/dist/lib/validation.d.ts +2 -2
  18. package/dist/lib/validation.js +11 -0
  19. package/dist/navigation.js +21 -0
  20. package/dist/routes.js +55 -0
  21. package/dist/schema.js +60 -0
  22. package/dist/ui/views.d.ts +5 -6
  23. package/dist/ui/views.js +119 -0
  24. package/package.json +11 -17
  25. package/src/actions/index.d.ts +67 -0
  26. package/src/actions/index.js +149 -0
  27. package/src/actions/index.ts +157 -0
  28. package/src/components/BlogStatsWidget.d.ts +1 -0
  29. package/src/components/BlogStatsWidget.js +17 -0
  30. package/src/components/BlogStatsWidget.tsx +46 -0
  31. package/src/components/RecentCommentsWidget.d.ts +1 -0
  32. package/src/components/RecentCommentsWidget.js +24 -0
  33. package/src/components/RecentCommentsWidget.tsx +71 -0
  34. package/src/components/RecentPostsWidget.d.ts +1 -0
  35. package/src/components/RecentPostsWidget.js +24 -0
  36. package/src/components/RecentPostsWidget.tsx +68 -0
  37. package/src/components/ui/button.d.ts +11 -0
  38. package/src/components/ui/button.js +33 -0
  39. package/src/components/ui/button.tsx +56 -0
  40. package/src/components/ui/card.d.ts +6 -0
  41. package/src/components/ui/card.js +12 -0
  42. package/src/components/ui/card.tsx +51 -0
  43. package/src/components/ui/input.d.ts +5 -0
  44. package/src/components/ui/input.js +8 -0
  45. package/{dist/components/ui/input.mjs → src/components/ui/input.tsx} +17 -13
  46. package/src/components/ui/table.d.ts +8 -0
  47. package/src/components/ui/table.js +16 -0
  48. package/src/components/ui/table.tsx +83 -0
  49. package/src/components/ui/textarea.d.ts +5 -0
  50. package/src/components/ui/textarea.js +8 -0
  51. package/{dist/components/ui/textarea.mjs → src/components/ui/textarea.tsx} +16 -12
  52. package/src/index.d.ts +3 -0
  53. package/src/index.js +98 -0
  54. package/{dist/index.mjs → src/index.ts} +44 -18
  55. package/src/lib/utils.d.ts +2 -0
  56. package/src/lib/utils.js +5 -0
  57. package/src/lib/utils.ts +6 -0
  58. package/src/lib/validation.d.ts +24 -0
  59. package/src/lib/validation.js +11 -0
  60. package/{dist/lib/validation.mjs → src/lib/validation.ts} +5 -2
  61. package/src/navigation.d.ts +2 -0
  62. package/src/navigation.js +21 -0
  63. package/{dist/navigation.mjs → src/navigation.ts} +9 -7
  64. package/src/routes.d.ts +3 -0
  65. package/src/routes.js +55 -0
  66. package/{dist/routes.mjs → src/routes.tsx} +30 -24
  67. package/src/schema.d.ts +736 -0
  68. package/src/schema.js +60 -0
  69. package/src/schema.ts +67 -0
  70. package/src/styles/globals.css +123 -0
  71. package/src/ui/views.d.ts +15 -0
  72. package/src/ui/views.js +119 -0
  73. package/src/ui/views.tsx +538 -0
  74. package/dist/actions/index.cjs +0 -158
  75. package/dist/actions/index.mjs +0 -121
  76. package/dist/components/BlogStatsWidget.cjs +0 -45
  77. package/dist/components/BlogStatsWidget.mjs +0 -13
  78. package/dist/components/RecentCommentsWidget.cjs +0 -47
  79. package/dist/components/RecentCommentsWidget.mjs +0 -28
  80. package/dist/components/RecentPostsWidget.cjs +0 -47
  81. package/dist/components/RecentPostsWidget.mjs +0 -28
  82. package/dist/components/ui/button.cjs +0 -53
  83. package/dist/components/ui/button.mjs +0 -44
  84. package/dist/components/ui/card.cjs +0 -46
  85. package/dist/components/ui/card.mjs +0 -35
  86. package/dist/components/ui/input.cjs +0 -23
  87. package/dist/components/ui/table.cjs +0 -66
  88. package/dist/components/ui/table.mjs +0 -59
  89. package/dist/components/ui/textarea.cjs +0 -21
  90. package/dist/index.cjs +0 -100
  91. package/dist/lib/utils.cjs +0 -11
  92. package/dist/lib/validation.cjs +0 -16
  93. package/dist/navigation.cjs +0 -23
  94. package/dist/routes.cjs +0 -74
  95. package/dist/schema.cjs +0 -62
  96. package/dist/schema.mjs +0 -53
  97. package/dist/styles/globals.css +0 -1
  98. package/dist/ui/views.cjs +0 -448
  99. package/dist/ui/views.mjs +0 -232
  100. /package/{dist → src}/intl.d.ts +0 -0
@@ -1,16 +1,15 @@
1
- import * as React from "react";
2
1
  export declare function BlogListPage({ posts }: {
3
2
  posts?: any[];
4
- }): React.JSX.Element;
3
+ }): import("react/jsx-runtime").JSX.Element;
5
4
  export declare function PostDetailPage({ post, comments, currentUser, }: {
6
5
  post: any;
7
6
  comments: any[];
8
7
  currentUser?: any;
9
- }): React.JSX.Element;
8
+ }): import("react/jsx-runtime").JSX.Element;
10
9
  export declare function BlogAdminPage({ posts }: {
11
10
  posts: any[];
12
- }): React.JSX.Element;
13
- export declare function CreatePostForm(): React.JSX.Element;
11
+ }): import("react/jsx-runtime").JSX.Element;
12
+ export declare function CreatePostForm(): import("react/jsx-runtime").JSX.Element;
14
13
  export declare function EditPostForm({ post }: {
15
14
  post: any;
16
- }): React.JSX.Element;
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
+ }
package/package.json CHANGED
@@ -1,23 +1,16 @@
1
1
  {
2
2
  "name": "@arch-cadre/blog-module",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "A sample module for Kryo framework",
5
5
  "type": "module",
6
+ "types": "./dist/index.d.ts",
6
7
  "exports": {
7
8
  "./package.json": "./package.json",
8
- ".": {
9
- "types": "./dist/index.d.ts",
10
- "import": "./dist/index.mjs",
11
- "require": "./dist/index.cjs"
12
- },
13
- "./actions": {
14
- "types": "./dist/actions/index.d.ts",
15
- "import": "./dist/actions/index.mjs",
16
- "require": "./dist/actions/index.cjs"
17
- }
9
+ ".": "./dist/index.js"
18
10
  },
19
11
  "files": [
20
12
  "dist",
13
+ "src",
21
14
  "locales",
22
15
  "manifest.json"
23
16
  ],
@@ -26,11 +19,12 @@
26
19
  "clean": "rm -rf ./dist",
27
20
  "switch:dev": "node scripts/switchToSrc.js",
28
21
  "switch:prod": "node scripts/switchToDist.js",
29
- "build": "unbuild",
30
- "devs": "unbuild --stub"
22
+ "builds": "unbuild",
23
+ "devs": "unbuild --stub",
24
+ "build": "pnpm clean && tsc --module esnext"
31
25
  },
32
26
  "dependencies": {
33
- "@arch-cadre/modules": "^0.0.73",
27
+ "@arch-cadre/modules": "^0.0.78",
34
28
  "@hookform/resolvers": "^3.10.0",
35
29
  "@radix-ui/react-slot": "^1.2.3",
36
30
  "class-variance-authority": "^0.7.1",
@@ -53,9 +47,9 @@
53
47
  "unbuild": "^3.6.1"
54
48
  },
55
49
  "peerDependencies": {
56
- "@arch-cadre/core": "^0.0.47",
57
- "@arch-cadre/intl": "^0.0.47",
58
- "@arch-cadre/ui": "^0.0.47",
50
+ "@arch-cadre/core": "^0.0.52",
51
+ "@arch-cadre/intl": "^0.0.52",
52
+ "@arch-cadre/ui": "^0.0.52",
59
53
  "react": "^19.0.0"
60
54
  },
61
55
  "main": "./dist/index.mjs"
@@ -0,0 +1,67 @@
1
+ import type { z } from "zod";
2
+ import { commentSchema, postSchema } from "../lib/validation.js";
3
+ export declare function createPost(data: z.infer<typeof postSchema>): Promise<{
4
+ success: boolean;
5
+ error?: undefined;
6
+ } | {
7
+ success: boolean;
8
+ error: any;
9
+ }>;
10
+ export declare function getPosts(): Promise<{
11
+ id: string;
12
+ title: string;
13
+ slug: string;
14
+ content: string;
15
+ createdAt: Date;
16
+ author: {
17
+ name: string;
18
+ };
19
+ }[]>;
20
+ export declare function getPostBySlug(slug: string): Promise<{
21
+ id: string;
22
+ title: string;
23
+ slug: string;
24
+ content: string;
25
+ createdAt: Date;
26
+ author: {
27
+ name: string;
28
+ };
29
+ }>;
30
+ export declare function getPostById(id: string): Promise<{
31
+ id: string;
32
+ title: string;
33
+ slug: string;
34
+ content: string;
35
+ authorId: string;
36
+ createdAt: Date;
37
+ }>;
38
+ export declare function getComments(postId: string): Promise<{
39
+ id: string;
40
+ content: string;
41
+ createdAt: Date;
42
+ author: {
43
+ name: string;
44
+ image: string | null;
45
+ };
46
+ }[]>;
47
+ export declare function createComment(data: z.infer<typeof commentSchema>): Promise<{
48
+ success: boolean;
49
+ error?: undefined;
50
+ } | {
51
+ success: boolean;
52
+ error: any;
53
+ }>;
54
+ export declare function deletePost(id: string): Promise<{
55
+ success: boolean;
56
+ error?: undefined;
57
+ } | {
58
+ success: boolean;
59
+ error: any;
60
+ }>;
61
+ export declare function updatePost(id: string, data: z.infer<typeof postSchema>): Promise<{
62
+ success: boolean;
63
+ error?: undefined;
64
+ } | {
65
+ success: boolean;
66
+ error: any;
67
+ }>;
@@ -0,0 +1,149 @@
1
+ "use server";
2
+ import { db, getCurrentSession, userTable } from "@arch-cadre/core/server";
3
+ import { desc, eq } from "drizzle-orm";
4
+ import { revalidatePath } from "next/cache";
5
+ import { commentSchema, postSchema } from "../lib/validation.js";
6
+ import { commentsTable, postsTable } from "../schema.js";
7
+ // --- Posts ---
8
+ export async function createPost(data) {
9
+ try {
10
+ const { user } = await getCurrentSession();
11
+ if (!user)
12
+ throw new Error("Unauthorized");
13
+ const validated = postSchema.parse(data);
14
+ await db.insert(postsTable).values({
15
+ ...validated,
16
+ authorId: user.id,
17
+ });
18
+ revalidatePath("/blog");
19
+ return { success: true };
20
+ }
21
+ catch (error) {
22
+ console.error("[BlogModule:Actions] createPost failed:", error);
23
+ return { success: false, error: error.message };
24
+ }
25
+ }
26
+ export async function getPosts() {
27
+ try {
28
+ return await db
29
+ .select({
30
+ id: postsTable.id,
31
+ title: postsTable.title,
32
+ slug: postsTable.slug,
33
+ content: postsTable.content,
34
+ createdAt: postsTable.createdAt,
35
+ author: {
36
+ name: userTable.name,
37
+ },
38
+ })
39
+ .from(postsTable)
40
+ .innerJoin(userTable, eq(postsTable.authorId, userTable.id))
41
+ .orderBy(desc(postsTable.createdAt));
42
+ }
43
+ catch (error) {
44
+ console.error("[BlogModule:Actions] getPosts failed:", error);
45
+ throw error;
46
+ }
47
+ }
48
+ export async function getPostBySlug(slug) {
49
+ try {
50
+ const [post] = await db
51
+ .select({
52
+ id: postsTable.id,
53
+ title: postsTable.title,
54
+ slug: postsTable.slug,
55
+ content: postsTable.content,
56
+ createdAt: postsTable.createdAt,
57
+ author: {
58
+ name: userTable.name,
59
+ },
60
+ })
61
+ .from(postsTable)
62
+ .innerJoin(userTable, eq(postsTable.authorId, userTable.id))
63
+ .where(eq(postsTable.slug, slug));
64
+ return post || null;
65
+ }
66
+ catch (error) {
67
+ console.error("[BlogModule:Actions] getPostBySlug failed:", error);
68
+ throw error;
69
+ }
70
+ }
71
+ export async function getPostById(id) {
72
+ try {
73
+ const [post] = await db
74
+ .select()
75
+ .from(postsTable)
76
+ .where(eq(postsTable.id, id));
77
+ return post || null;
78
+ }
79
+ catch (error) {
80
+ console.error("[BlogModule:Actions] getPostById failed:", error);
81
+ throw error;
82
+ }
83
+ }
84
+ // --- Comments ---
85
+ export async function getComments(postId) {
86
+ try {
87
+ return await db
88
+ .select({
89
+ id: commentsTable.id,
90
+ content: commentsTable.content,
91
+ createdAt: commentsTable.createdAt,
92
+ author: {
93
+ name: userTable.name,
94
+ image: userTable.image,
95
+ },
96
+ })
97
+ .from(commentsTable)
98
+ .innerJoin(userTable, eq(commentsTable.authorId, userTable.id))
99
+ .where(eq(commentsTable.postId, postId))
100
+ .orderBy(desc(commentsTable.createdAt));
101
+ }
102
+ catch (error) {
103
+ console.error("[BlogModule:Actions] getComments failed:", error);
104
+ throw error;
105
+ }
106
+ }
107
+ export async function createComment(data) {
108
+ try {
109
+ const { user } = await getCurrentSession();
110
+ if (!user)
111
+ throw new Error("Must be logged in to comment");
112
+ const validated = commentSchema.parse(data);
113
+ await db.insert(commentsTable).values({
114
+ content: validated.content,
115
+ postId: validated.postId,
116
+ authorId: user.id,
117
+ });
118
+ revalidatePath(`/blog`);
119
+ return { success: true };
120
+ }
121
+ catch (error) {
122
+ console.error("[BlogModule:Actions] createComment failed:", error);
123
+ return { success: false, error: error.message };
124
+ }
125
+ }
126
+ export async function deletePost(id) {
127
+ try {
128
+ await db.delete(postsTable).where(eq(postsTable.id, id));
129
+ revalidatePath("/blog");
130
+ return { success: true };
131
+ }
132
+ catch (error) {
133
+ console.error("[BlogModule:Actions] deletePost failed:", error);
134
+ return { success: false, error: error.message };
135
+ }
136
+ }
137
+ export async function updatePost(id, data) {
138
+ try {
139
+ const validated = postSchema.parse(data);
140
+ await db.update(postsTable).set(validated).where(eq(postsTable.id, id));
141
+ revalidatePath("/blog");
142
+ revalidatePath(`/blog/${validated.slug}`);
143
+ return { success: true };
144
+ }
145
+ catch (error) {
146
+ console.error("[BlogModule:Actions] updatePost failed:", error);
147
+ return { success: false, error: error.message };
148
+ }
149
+ }
@@ -0,0 +1,157 @@
1
+ "use server";
2
+
3
+ import { db, getCurrentSession, userTable } from "@arch-cadre/core/server";
4
+ import { desc, eq } from "drizzle-orm";
5
+ import { revalidatePath } from "next/cache";
6
+ import type { z } from "zod";
7
+ import { commentSchema, postSchema } from "../lib/validation.js";
8
+ import { commentsTable, postsTable } from "../schema.js";
9
+
10
+ // --- Posts ---
11
+ export async function createPost(data: z.infer<typeof postSchema>) {
12
+ try {
13
+ const { user } = await getCurrentSession();
14
+ if (!user) throw new Error("Unauthorized");
15
+
16
+ const validated = postSchema.parse(data);
17
+
18
+ await db.insert(postsTable).values({
19
+ ...validated,
20
+ authorId: user.id,
21
+ });
22
+
23
+ revalidatePath("/blog");
24
+ return { success: true };
25
+ } catch (error: any) {
26
+ console.error("[BlogModule:Actions] createPost failed:", error);
27
+ return { success: false, error: error.message };
28
+ }
29
+ }
30
+
31
+ export async function getPosts() {
32
+ try {
33
+ return await db
34
+ .select({
35
+ id: postsTable.id,
36
+ title: postsTable.title,
37
+ slug: postsTable.slug,
38
+ content: postsTable.content,
39
+ createdAt: postsTable.createdAt,
40
+ author: {
41
+ name: userTable.name,
42
+ },
43
+ })
44
+ .from(postsTable)
45
+ .innerJoin(userTable, eq(postsTable.authorId, userTable.id))
46
+ .orderBy(desc(postsTable.createdAt));
47
+ } catch (error: any) {
48
+ console.error("[BlogModule:Actions] getPosts failed:", error);
49
+ throw error;
50
+ }
51
+ }
52
+
53
+ export async function getPostBySlug(slug: string) {
54
+ try {
55
+ const [post] = await db
56
+ .select({
57
+ id: postsTable.id,
58
+ title: postsTable.title,
59
+ slug: postsTable.slug,
60
+ content: postsTable.content,
61
+ createdAt: postsTable.createdAt,
62
+ author: {
63
+ name: userTable.name,
64
+ },
65
+ })
66
+ .from(postsTable)
67
+ .innerJoin(userTable, eq(postsTable.authorId, userTable.id))
68
+ .where(eq(postsTable.slug, slug));
69
+
70
+ return post || null;
71
+ } catch (error: any) {
72
+ console.error("[BlogModule:Actions] getPostBySlug failed:", error);
73
+ throw error;
74
+ }
75
+ }
76
+
77
+ export async function getPostById(id: string) {
78
+ try {
79
+ const [post] = await db
80
+ .select()
81
+ .from(postsTable)
82
+ .where(eq(postsTable.id, id));
83
+ return post || null;
84
+ } catch (error: any) {
85
+ console.error("[BlogModule:Actions] getPostById failed:", error);
86
+ throw error;
87
+ }
88
+ }
89
+
90
+ // --- Comments ---
91
+ export async function getComments(postId: string) {
92
+ try {
93
+ return await db
94
+ .select({
95
+ id: commentsTable.id,
96
+ content: commentsTable.content,
97
+ createdAt: commentsTable.createdAt,
98
+ author: {
99
+ name: userTable.name,
100
+ image: userTable.image,
101
+ },
102
+ })
103
+ .from(commentsTable)
104
+ .innerJoin(userTable, eq(commentsTable.authorId, userTable.id))
105
+ .where(eq(commentsTable.postId, postId))
106
+ .orderBy(desc(commentsTable.createdAt));
107
+ } catch (error: any) {
108
+ console.error("[BlogModule:Actions] getComments failed:", error);
109
+ throw error;
110
+ }
111
+ }
112
+
113
+ export async function createComment(data: z.infer<typeof commentSchema>) {
114
+ try {
115
+ const { user } = await getCurrentSession();
116
+ if (!user) throw new Error("Must be logged in to comment");
117
+
118
+ const validated = commentSchema.parse(data);
119
+
120
+ await db.insert(commentsTable).values({
121
+ content: validated.content,
122
+ postId: validated.postId,
123
+ authorId: user.id,
124
+ });
125
+
126
+ revalidatePath(`/blog`);
127
+ return { success: true };
128
+ } catch (error: any) {
129
+ console.error("[BlogModule:Actions] createComment failed:", error);
130
+ return { success: false, error: error.message };
131
+ }
132
+ }
133
+
134
+ export async function deletePost(id: string) {
135
+ try {
136
+ await db.delete(postsTable).where(eq(postsTable.id, id));
137
+ revalidatePath("/blog");
138
+ return { success: true };
139
+ } catch (error: any) {
140
+ console.error("[BlogModule:Actions] deletePost failed:", error);
141
+ return { success: false, error: error.message };
142
+ }
143
+ }
144
+
145
+ export async function updatePost(id: string, data: z.infer<typeof postSchema>) {
146
+ try {
147
+ const validated = postSchema.parse(data);
148
+
149
+ await db.update(postsTable).set(validated).where(eq(postsTable.id, id));
150
+ revalidatePath("/blog");
151
+ revalidatePath(`/blog/${validated.slug}`);
152
+ return { success: true };
153
+ } catch (error: any) {
154
+ console.error("[BlogModule:Actions] updatePost failed:", error);
155
+ return { success: false, error: error.message };
156
+ }
157
+ }
@@ -0,0 +1 @@
1
+ export default function BlogStatsWidget(): Promise<import("react/jsx-runtime").JSX.Element>;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { db } from "@arch-cadre/core/server";
3
+ import { getTranslation } from "@arch-cadre/intl/server";
4
+ import { Card, CardContent, CardHeader, CardTitle } from "@arch-cadre/ui";
5
+ import { sql } from "drizzle-orm";
6
+ import { FileText, MessageSquare } from "lucide-react";
7
+ import { commentsTable, postsTable } from "../schema.js";
8
+ export default async function BlogStatsWidget() {
9
+ const { t } = await getTranslation();
10
+ const [postsCount] = await db
11
+ .select({ count: sql `count(*)` })
12
+ .from(postsTable);
13
+ const [commentsCount] = await db
14
+ .select({ count: sql `count(*)` })
15
+ .from(commentsTable);
16
+ return (_jsxs("div", { className: "grid gap-4 md:grid-cols-2 lg:grid-cols-2", children: [_jsxs(Card, { children: [_jsxs(CardHeader, { className: "flex flex-row items-center justify-between space-y-0 pb-2", children: [_jsx(CardTitle, { className: "text-sm font-medium", children: t("Total Posts") }), _jsx(FileText, { className: "h-4 w-4 text-muted-foreground" })] }), _jsx(CardContent, { children: _jsx("div", { className: "text-2xl font-bold", children: postsCount?.count || 0 }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "flex flex-row items-center justify-between space-y-0 pb-2", children: [_jsx(CardTitle, { className: "text-sm font-medium", children: t("Total Comments") }), _jsx(MessageSquare, { className: "h-4 w-4 text-muted-foreground" })] }), _jsx(CardContent, { children: _jsx("div", { className: "text-2xl font-bold", children: commentsCount?.count || 0 }) })] })] }));
17
+ }
@@ -0,0 +1,46 @@
1
+ import { db } from "@arch-cadre/core/server";
2
+ import { getTranslation } from "@arch-cadre/intl/server";
3
+ import { Card, CardContent, CardHeader, CardTitle } from "@arch-cadre/ui";
4
+ import { sql } from "drizzle-orm";
5
+ import { FileText, MessageSquare } from "lucide-react";
6
+ import * as React from "react";
7
+ import { commentsTable, postsTable } from "../schema.js";
8
+
9
+ export default async function BlogStatsWidget() {
10
+ const { t } = await getTranslation();
11
+
12
+ const [postsCount] = await db
13
+ .select({ count: sql<number>`count(*)` })
14
+ .from(postsTable);
15
+
16
+ const [commentsCount] = await db
17
+ .select({ count: sql<number>`count(*)` })
18
+ .from(commentsTable);
19
+
20
+ return (
21
+ <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-2">
22
+ <Card>
23
+ <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
24
+ <CardTitle className="text-sm font-medium">
25
+ {t("Total Posts")}
26
+ </CardTitle>
27
+ <FileText className="h-4 w-4 text-muted-foreground" />
28
+ </CardHeader>
29
+ <CardContent>
30
+ <div className="text-2xl font-bold">{postsCount?.count || 0}</div>
31
+ </CardContent>
32
+ </Card>
33
+ <Card>
34
+ <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
35
+ <CardTitle className="text-sm font-medium">
36
+ {t("Total Comments")}
37
+ </CardTitle>
38
+ <MessageSquare className="h-4 w-4 text-muted-foreground" />
39
+ </CardHeader>
40
+ <CardContent>
41
+ <div className="text-2xl font-bold">{commentsCount?.count || 0}</div>
42
+ </CardContent>
43
+ </Card>
44
+ </div>
45
+ );
46
+ }
@@ -0,0 +1 @@
1
+ export default function RecentCommentsWidget(): Promise<import("react/jsx-runtime").JSX.Element>;