@carlonicora/nextjs-jsonapi 5.3.0 → 5.4.0

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 (173) hide show
  1. package/dist/{BlockNoteEditor-UJ6363LC.js → BlockNoteEditor-4YCAIEPT.js} +23 -22
  2. package/dist/BlockNoteEditor-4YCAIEPT.js.map +1 -0
  3. package/dist/{BlockNoteEditor-WTSQANKI.mjs → BlockNoteEditor-YQL2SGFR.mjs} +8 -7
  4. package/dist/BlockNoteEditor-YQL2SGFR.mjs.map +1 -0
  5. package/dist/{BlockNoteViewer-JVKWJZ6J.mjs → BlockNoteViewer-AEJKJ27Q.mjs} +2 -2
  6. package/dist/{BlockNoteViewer-EL4JFB6P.js → BlockNoteViewer-YL3J7J2Y.js} +3 -3
  7. package/dist/{BlockNoteViewer-EL4JFB6P.js.map → BlockNoteViewer-YL3J7J2Y.js.map} +1 -1
  8. package/dist/BlogCategoryFields-DO48vOTE.d.mts +14 -0
  9. package/dist/BlogCategoryFields-DO48vOTE.d.ts +14 -0
  10. package/dist/BlogPostInterface-BB_4wcDR.d.mts +124 -0
  11. package/dist/BlogPostInterface-bWAT1rfR.d.ts +124 -0
  12. package/dist/billing/index.js +441 -441
  13. package/dist/billing/index.mjs +3 -3
  14. package/dist/blog-public.types-BbrzsC1c.d.mts +30 -0
  15. package/dist/blog-public.types-BbrzsC1c.d.ts +30 -0
  16. package/dist/{chunk-3BAM23VA.js → chunk-3NLAXVIN.js} +860 -849
  17. package/dist/chunk-3NLAXVIN.js.map +1 -0
  18. package/dist/{chunk-QKZUE5OF.mjs → chunk-3YW35YHQ.mjs} +1 -101
  19. package/dist/chunk-3YW35YHQ.mjs.map +1 -0
  20. package/dist/{chunk-QQQE3N2X.js → chunk-5PPG6PL7.js} +3 -3
  21. package/dist/{chunk-QQQE3N2X.js.map → chunk-5PPG6PL7.js.map} +1 -1
  22. package/dist/{chunk-FNTQQFLH.mjs → chunk-6DC2WVVB.mjs} +2 -2
  23. package/dist/{chunk-MIZTWBPX.mjs → chunk-EUKTBOI2.mjs} +19 -8
  24. package/dist/chunk-EUKTBOI2.mjs.map +1 -0
  25. package/dist/{chunk-XGTQWBDJ.js → chunk-KSYQEKJX.js} +11 -111
  26. package/dist/chunk-KSYQEKJX.js.map +1 -0
  27. package/dist/{chunk-CRI4T47Y.js → chunk-NFBOSPNJ.js} +756 -41
  28. package/dist/chunk-NFBOSPNJ.js.map +1 -0
  29. package/dist/{chunk-6WU74VFU.mjs → chunk-QMYQRPQC.mjs} +2 -2
  30. package/dist/{chunk-JQWI62NV.mjs → chunk-WC63PJSC.mjs} +716 -1
  31. package/dist/chunk-WC63PJSC.mjs.map +1 -0
  32. package/dist/chunk-XCHSX3VC.mjs +107 -0
  33. package/dist/chunk-XCHSX3VC.mjs.map +1 -0
  34. package/dist/{chunk-EO75CV76.js → chunk-YNCQSWQW.js} +8 -8
  35. package/dist/{chunk-EO75CV76.js.map → chunk-YNCQSWQW.js.map} +1 -1
  36. package/dist/chunk-YW4ZCEWB.js +107 -0
  37. package/dist/chunk-YW4ZCEWB.js.map +1 -0
  38. package/dist/client/index.js +4 -4
  39. package/dist/client/index.mjs +3 -3
  40. package/dist/components/index.d.mts +13 -2
  41. package/dist/components/index.d.ts +13 -2
  42. package/dist/components/index.js +4 -4
  43. package/dist/components/index.mjs +3 -3
  44. package/dist/contexts/index.js +4 -4
  45. package/dist/contexts/index.mjs +3 -3
  46. package/dist/core/index.d.mts +214 -3
  47. package/dist/core/index.d.ts +214 -3
  48. package/dist/core/index.js +36 -2
  49. package/dist/core/index.js.map +1 -1
  50. package/dist/core/index.mjs +35 -1
  51. package/dist/email-automations/index.js +92 -92
  52. package/dist/email-automations/index.mjs +3 -3
  53. package/dist/features/analytics/index.js +122 -122
  54. package/dist/features/analytics/index.mjs +4 -4
  55. package/dist/features/analytics/server.js +6 -5
  56. package/dist/features/analytics/server.js.map +1 -1
  57. package/dist/features/analytics/server.mjs +4 -3
  58. package/dist/features/analytics/server.mjs.map +1 -1
  59. package/dist/features/blog/index.css +30 -0
  60. package/dist/features/blog/index.css.map +1 -0
  61. package/dist/features/blog/index.d.mts +266 -0
  62. package/dist/features/blog/index.d.ts +266 -0
  63. package/dist/features/blog/index.js +1799 -0
  64. package/dist/features/blog/index.js.map +1 -0
  65. package/dist/features/blog/index.mjs +1799 -0
  66. package/dist/features/blog/index.mjs.map +1 -0
  67. package/dist/features/blog/server.d.mts +33 -0
  68. package/dist/features/blog/server.d.ts +33 -0
  69. package/dist/features/blog/server.js +139 -0
  70. package/dist/features/blog/server.js.map +1 -0
  71. package/dist/features/blog/server.mjs +139 -0
  72. package/dist/features/blog/server.mjs.map +1 -0
  73. package/dist/features/help/index.js +37 -37
  74. package/dist/features/help/index.mjs +3 -3
  75. package/dist/features/tokenusage/index.js +125 -125
  76. package/dist/features/tokenusage/index.mjs +4 -4
  77. package/dist/index.d.mts +4 -2
  78. package/dist/index.d.ts +4 -2
  79. package/dist/index.js +37 -3
  80. package/dist/index.js.map +1 -1
  81. package/dist/index.mjs +36 -2
  82. package/dist/{s3.service-CY-jgOAM.d.ts → s3.service-Bz_K-tjz.d.ts} +11 -0
  83. package/dist/{s3.service-Sri0QP7Z.d.mts → s3.service-D5zNCEW3.d.mts} +11 -0
  84. package/dist/server/index.d.mts +1 -1
  85. package/dist/server/index.d.ts +1 -1
  86. package/dist/server/index.js +8 -6
  87. package/dist/server/index.js.map +1 -1
  88. package/dist/server/index.mjs +12 -10
  89. package/messages/en.json +93 -0
  90. package/messages/it.json +93 -0
  91. package/package.json +11 -1
  92. package/src/components/editors/BlockNoteEditor.tsx +13 -3
  93. package/src/components/forms/FormBlockNote.tsx +4 -0
  94. package/src/components/navigations/ContentTitle.tsx +14 -3
  95. package/src/core/index.ts +4 -0
  96. package/src/core/registry/ModuleRegistry.ts +6 -0
  97. package/src/features/blog/BlogModules.ts +49 -0
  98. package/src/features/blog/components/admin/BlogAdminContainer.tsx +32 -0
  99. package/src/features/blog/components/admin/BlogCategoriesList.tsx +56 -0
  100. package/src/features/blog/components/admin/BlogCategoryEditor.tsx +230 -0
  101. package/src/features/blog/components/admin/BlogCoverImageField.tsx +123 -0
  102. package/src/features/blog/components/admin/BlogLayoutSetting.tsx +86 -0
  103. package/src/features/blog/components/admin/BlogPostComparison.tsx +54 -0
  104. package/src/features/blog/components/admin/BlogPostContainer.tsx +102 -0
  105. package/src/features/blog/components/admin/BlogPostDeleter.tsx +35 -0
  106. package/src/features/blog/components/admin/BlogPostEditor.tsx +207 -0
  107. package/src/features/blog/components/admin/BlogPostPublishButton.tsx +50 -0
  108. package/src/features/blog/components/admin/BlogPostTranslationEditor.tsx +110 -0
  109. package/src/features/blog/components/admin/BlogPostTranslationPanel.tsx +136 -0
  110. package/src/features/blog/components/admin/BlogPostsList.tsx +58 -0
  111. package/src/features/blog/components/admin/BlogTranslationStatus.tsx +104 -0
  112. package/src/features/blog/components/admin/__tests__/BlogPostTranslationPanel.spec.tsx +100 -0
  113. package/src/features/blog/components/admin/__tests__/BlogPostsList.spec.tsx +30 -0
  114. package/src/features/blog/components/admin/index.ts +14 -0
  115. package/src/features/blog/components/public/BlogCategoryChips.tsx +59 -0
  116. package/src/features/blog/components/public/BlogList.tsx +21 -0
  117. package/src/features/blog/components/public/BlogListColumn.tsx +53 -0
  118. package/src/features/blog/components/public/BlogListFeatured.tsx +57 -0
  119. package/src/features/blog/components/public/BlogListParts.tsx +74 -0
  120. package/src/features/blog/components/public/BlogListRail.tsx +62 -0
  121. package/src/features/blog/components/public/BlogPostCard.tsx +132 -0
  122. package/src/features/blog/components/public/BlogPostMeta.tsx +49 -0
  123. package/src/features/blog/components/public/BlogPostView.tsx +74 -0
  124. package/src/features/blog/components/public/BlogSearchBox.tsx +52 -0
  125. package/src/features/blog/components/public/__tests__/BlogList.spec.tsx +173 -0
  126. package/src/features/blog/components/public/__tests__/BlogPostView.spec.tsx +128 -0
  127. package/src/features/blog/components/public/blogPublicHelpers.ts +30 -0
  128. package/src/features/blog/components/public/index.ts +3 -0
  129. package/src/features/blog/contexts/BlogPostContext.tsx +66 -0
  130. package/src/features/blog/contexts/index.ts +1 -0
  131. package/src/features/blog/data/BlogCategory.ts +93 -0
  132. package/src/features/blog/data/BlogCategoryFields.ts +4 -0
  133. package/src/features/blog/data/BlogCategoryInterface.ts +24 -0
  134. package/src/features/blog/data/BlogCategoryService.ts +54 -0
  135. package/src/features/blog/data/BlogCategoryTranslation.ts +90 -0
  136. package/src/features/blog/data/BlogCategoryTranslationInterface.ts +22 -0
  137. package/src/features/blog/data/BlogCategoryTranslationService.ts +30 -0
  138. package/src/features/blog/data/BlogPost.spec.ts +123 -0
  139. package/src/features/blog/data/BlogPost.ts +159 -0
  140. package/src/features/blog/data/BlogPostFields.ts +7 -0
  141. package/src/features/blog/data/BlogPostInterface.ts +39 -0
  142. package/src/features/blog/data/BlogPostService.ts +82 -0
  143. package/src/features/blog/data/BlogPostTranslation.spec.ts +73 -0
  144. package/src/features/blog/data/BlogPostTranslation.ts +110 -0
  145. package/src/features/blog/data/BlogPostTranslationInterface.ts +27 -0
  146. package/src/features/blog/data/BlogPostTranslationService.ts +30 -0
  147. package/src/features/blog/data/BlogSettings.ts +37 -0
  148. package/src/features/blog/data/BlogSettingsInterface.ts +11 -0
  149. package/src/features/blog/data/BlogSettingsService.ts +24 -0
  150. package/src/features/blog/data/index.ts +17 -0
  151. package/src/features/blog/hooks/index.ts +3 -0
  152. package/src/features/blog/hooks/useBlogCategoryNames.ts +34 -0
  153. package/src/features/blog/hooks/useBlogCategoryTableStructure.tsx +84 -0
  154. package/src/features/blog/hooks/useBlogPostTableStructure.tsx +126 -0
  155. package/src/features/blog/index.ts +15 -0
  156. package/src/features/blog/server/fetchers.ts +120 -0
  157. package/src/features/blog/server/toPublic.spec.ts +91 -0
  158. package/src/features/blog/server/toPublic.ts +36 -0
  159. package/src/features/blog/server-entry.ts +17 -0
  160. package/src/features/blog/types/blog-public.types.ts +34 -0
  161. package/src/features/blog/types/blog.constants.ts +40 -0
  162. package/src/features/s3/data/s3.service.ts +17 -0
  163. package/dist/BlockNoteEditor-UJ6363LC.js.map +0 -1
  164. package/dist/BlockNoteEditor-WTSQANKI.mjs.map +0 -1
  165. package/dist/chunk-3BAM23VA.js.map +0 -1
  166. package/dist/chunk-CRI4T47Y.js.map +0 -1
  167. package/dist/chunk-JQWI62NV.mjs.map +0 -1
  168. package/dist/chunk-MIZTWBPX.mjs.map +0 -1
  169. package/dist/chunk-QKZUE5OF.mjs.map +0 -1
  170. package/dist/chunk-XGTQWBDJ.js.map +0 -1
  171. /package/dist/{BlockNoteViewer-JVKWJZ6J.mjs.map → BlockNoteViewer-AEJKJ27Q.mjs.map} +0 -0
  172. /package/dist/{chunk-FNTQQFLH.mjs.map → chunk-6DC2WVVB.mjs.map} +0 -0
  173. /package/dist/{chunk-6WU74VFU.mjs.map → chunk-QMYQRPQC.mjs.map} +0 -0
@@ -0,0 +1,110 @@
1
+ "use client";
2
+
3
+ import { zodResolver } from "@hookform/resolvers/zod";
4
+ import { useTranslations } from "next-intl";
5
+ import { ReactNode, useCallback, useMemo, useState } from "react";
6
+ import { useForm } from "react-hook-form";
7
+ import { z } from "zod";
8
+ import { EditorSheet, FormBlockNote, FormInput, FormTextarea } from "../../../../components";
9
+ import { Modules } from "../../../../core";
10
+ import { BlogPostTranslationInterface, BlogPostTranslationService } from "../../data";
11
+ import { useBlogLanguageName } from "./BlogTranslationStatus";
12
+ import { BLOG_POST_UPLOAD_PREFIX } from "../../types/blog.constants";
13
+
14
+ type BlogPostTranslationEditorProps = {
15
+ translation: BlogPostTranslationInterface;
16
+ trigger?: ReactNode;
17
+ onSuccess?: () => void | Promise<void>;
18
+ };
19
+
20
+ const isBodyEmpty = (body: any) => !body || (Array.isArray(body) && body.length === 0);
21
+
22
+ const buildFormSchema = (t: (key: string) => string) =>
23
+ z.object({
24
+ id: z.string().uuid(),
25
+ title: z.string().min(1, { message: t("blog.errors.title") }),
26
+ slug: z.string().optional(),
27
+ summary: z.string().optional(),
28
+ body: z.any(),
29
+ coverImageAlt: z.string().optional(),
30
+ });
31
+
32
+ /**
33
+ * Edits one non-original translation by hand. Saving marks it `manual` and
34
+ * re-runs nothing. Mirrors features/how-to/components/forms/HowToEditor.tsx.
35
+ */
36
+ export function BlogPostTranslationEditor({ translation, trigger, onSuccess }: BlogPostTranslationEditorProps) {
37
+ const t = useTranslations();
38
+ const formSchema = useMemo(() => buildFormSchema(t), [t]);
39
+ const languageName = useBlogLanguageName();
40
+ const [isBodyEmptyState, setIsBodyEmptyState] = useState<boolean>(isBodyEmpty(translation.body));
41
+
42
+ const getDefaultValues = useCallback(
43
+ () => ({
44
+ id: translation.id,
45
+ title: translation.title ?? "",
46
+ slug: translation.slug ?? "",
47
+ summary: translation.summary ?? "",
48
+ body: translation.body || [],
49
+ coverImageAlt: translation.coverImageAlt ?? "",
50
+ }),
51
+ [translation],
52
+ );
53
+
54
+ const form = useForm<z.infer<typeof formSchema>>({
55
+ resolver: zodResolver(formSchema),
56
+ defaultValues: getDefaultValues(),
57
+ });
58
+
59
+ const { dirtyFields } = form.formState;
60
+ const isFormDirty = useCallback(() => {
61
+ const dirty: Record<string, unknown> = { ...dirtyFields };
62
+ if (dirty.body && isBodyEmptyState) delete dirty.body;
63
+ return Object.keys(dirty).length > 0;
64
+ }, [dirtyFields, isBodyEmptyState]);
65
+
66
+ return (
67
+ <EditorSheet
68
+ form={form}
69
+ entityType={t("blog.entities.post")}
70
+ entityName={translation.title}
71
+ title={`${t("blog.admin.editPost")} · ${languageName(translation.language)}`}
72
+ isEdit
73
+ module={Modules.BlogPostTranslation}
74
+ size="lg"
75
+ isFormDirty={isFormDirty}
76
+ onSubmit={async (values) =>
77
+ BlogPostTranslationService.update({
78
+ id: values.id,
79
+ title: values.title,
80
+ slug: values.slug || undefined,
81
+ summary: values.summary,
82
+ body: values.body,
83
+ coverImageAlt: values.coverImageAlt,
84
+ })
85
+ }
86
+ onReset={() => {
87
+ setIsBodyEmptyState(isBodyEmpty(translation.body));
88
+ return getDefaultValues();
89
+ }}
90
+ onSuccess={onSuccess ?? (() => {})}
91
+ trigger={trigger}
92
+ >
93
+ <div className="flex w-full flex-col gap-y-4">
94
+ <FormInput form={form} id="title" name={t("blog.fields.title")} isRequired />
95
+ <FormInput form={form} id="slug" name={t("blog.fields.slug")} description={t("blog.fields.slugHelp")} />
96
+ <FormTextarea form={form} id="summary" name={t("blog.fields.summary")} />
97
+ <FormInput form={form} id="coverImageAlt" name={t("blog.fields.coverImageAlt")} />
98
+ <FormBlockNote
99
+ uploadKeyPrefix={BLOG_POST_UPLOAD_PREFIX}
100
+ form={form}
101
+ id="body"
102
+ name={t("blog.fields.body")}
103
+ type="blog-post"
104
+ isRequired
105
+ onEmptyChange={setIsBodyEmptyState}
106
+ />
107
+ </div>
108
+ </EditorSheet>
109
+ );
110
+ }
@@ -0,0 +1,136 @@
1
+ "use client";
2
+
3
+ import { PencilIcon } from "lucide-react";
4
+ import { useTranslations } from "next-intl";
5
+ import Image from "next/image";
6
+ import { useState } from "react";
7
+ import { DetailField } from "../../../../components";
8
+ import { Alert, AlertDescription, Badge, Button } from "../../../../shadcnui";
9
+ import { isRemoteImageSrc } from "../../../../utils";
10
+ import { BlogPostInterface, BlogPostTranslationInterface, BlogPostTranslationService } from "../../data";
11
+ import { BlogPostComparison, BlogPostTranslationFields } from "./BlogPostComparison";
12
+ import { BlogPostEditor } from "./BlogPostEditor";
13
+ import { BlogPostTranslationEditor } from "./BlogPostTranslationEditor";
14
+ import { useBlogCategoryNames } from "../../hooks/useBlogCategoryNames";
15
+ import { BlogTranslationStatus, useBlogDateFormatter, useBlogLanguageName } from "./BlogTranslationStatus";
16
+
17
+ type BlogPostTranslationPanelProps = {
18
+ post: BlogPostInterface;
19
+ translation: BlogPostTranslationInterface;
20
+ /** Re-reads the post after an edit or a re-translation request. */
21
+ onChanged?: () => Promise<void>;
22
+ };
23
+
24
+ /**
25
+ * One language tab of the admin post page (approved mockup A).
26
+ * - Original tab: cover image, categories, status, the text fields and an Edit
27
+ * that opens BlogPostEditor (which re-translates every other language).
28
+ * - Translation tab: where the text came from, whether it was edited by hand,
29
+ * the overwrite warning, "Compare with original", the job status, the text
30
+ * fields and an Edit that opens BlogPostTranslationEditor.
31
+ */
32
+ export function BlogPostTranslationPanel({ post, translation, onChanged }: BlogPostTranslationPanelProps) {
33
+ const t = useTranslations();
34
+ const categoryName = useBlogCategoryNames();
35
+ const languageName = useBlogLanguageName();
36
+ const formatDate = useBlogDateFormatter();
37
+ const [isComparing, setIsComparing] = useState<boolean>(false);
38
+
39
+ const original = post.original;
40
+ const reload = onChanged ?? (async () => {});
41
+
42
+ const editTrigger = (
43
+ <Button render={<div />} nativeButton={false} size="sm" variant="outline">
44
+ <PencilIcon />
45
+ {t("blog.actions.edit")}
46
+ </Button>
47
+ );
48
+
49
+ if (translation.isOriginal) {
50
+ const statusLabel = {
51
+ draft: t("blog.status.draft"),
52
+ published: t("blog.status.published"),
53
+ unpublished: t("blog.status.unpublished"),
54
+ }[post.status];
55
+
56
+ return (
57
+ <div className="flex w-full flex-col gap-y-6 p-4">
58
+ <div className="flex items-center justify-between gap-x-4">
59
+ <Badge variant="softGray">{t("blog.translation.original")}</Badge>
60
+ <BlogPostEditor post={post} trigger={editTrigger} onSuccess={reload} />
61
+ </div>
62
+ {post.coverImage && (
63
+ <Image
64
+ src={post.coverImage}
65
+ alt={translation.coverImageAlt ?? translation.title}
66
+ width={640}
67
+ height={360}
68
+ className="h-auto max-h-72 w-auto rounded-lg object-cover"
69
+ unoptimized={isRemoteImageSrc(post.coverImage)}
70
+ />
71
+ )}
72
+ <div className="grid grid-cols-1 gap-4 md:grid-cols-3">
73
+ <DetailField label={t("blog.fields.status")} value={statusLabel} />
74
+ <DetailField label={t("blog.fields.publishedAt")} value={formatDate(post.publishedAt) || "—"} />
75
+ <DetailField
76
+ label={t("blog.fields.categories")}
77
+ value={
78
+ post.categories
79
+ .map((category) => categoryName(category.id))
80
+ .filter(Boolean)
81
+ .join(", ") || "—"
82
+ }
83
+ />
84
+ </div>
85
+ <BlogPostTranslationFields translation={translation} />
86
+ </div>
87
+ );
88
+ }
89
+
90
+ const isWorking = translation.aiStatus === "pending" || translation.aiStatus === "in_progress";
91
+
92
+ return (
93
+ <div className="flex w-full flex-col gap-y-6 p-4">
94
+ <Alert>
95
+ <AlertDescription className="flex flex-col gap-y-2">
96
+ <div className="flex flex-wrap items-center gap-2">
97
+ {translation.source === "manual" && <Badge variant="softAmber">{t("blog.translation.editedByHand")}</Badge>}
98
+ {original && translation.translatedAt && (
99
+ <span>
100
+ {t("blog.translation.translatedFrom", {
101
+ language: languageName(original.language),
102
+ date: formatDate(translation.translatedAt),
103
+ })}
104
+ </span>
105
+ )}
106
+ </div>
107
+ <span>{t("blog.translation.overwriteWarning")}</span>
108
+ {original && (
109
+ <div>
110
+ <Button type="button" size="sm" variant="ghost" onClick={() => setIsComparing((value) => !value)}>
111
+ {isComparing ? t("blog.actions.hideComparison") : t("blog.actions.compareWithOriginal")}
112
+ </Button>
113
+ </div>
114
+ )}
115
+ </AlertDescription>
116
+ </Alert>
117
+
118
+ <div className="flex items-center justify-between gap-x-4">
119
+ <BlogTranslationStatus
120
+ aiStatus={translation.aiStatus}
121
+ onRetranslate={async () => {
122
+ await BlogPostTranslationService.retranslate({ id: translation.id });
123
+ await reload();
124
+ }}
125
+ />
126
+ {!isWorking && <BlogPostTranslationEditor translation={translation} trigger={editTrigger} onSuccess={reload} />}
127
+ </div>
128
+
129
+ {isComparing && original ? (
130
+ <BlogPostComparison original={original} translation={translation} />
131
+ ) : (
132
+ <BlogPostTranslationFields translation={translation} />
133
+ )}
134
+ </div>
135
+ );
136
+ }
@@ -0,0 +1,58 @@
1
+ "use client";
2
+
3
+ import { NewspaperIcon } from "lucide-react";
4
+ import { useTranslations } from "next-intl";
5
+ import { ReactNode } from "react";
6
+ import { ContentListTable } from "../../../../components";
7
+ import { Modules } from "../../../../core";
8
+ import { DataListRetriever, useDataListRetriever } from "../../../../hooks";
9
+ import { Button, EmptyState } from "../../../../shadcnui";
10
+ import { BlogPostFields, BlogPostInterface, BlogPostService } from "../../data";
11
+ import "../../hooks/useBlogPostTableStructure";
12
+ import { BlogPostEditor } from "./BlogPostEditor";
13
+
14
+ type BlogPostsListProps = {
15
+ /** Pass when the list is the page's own content inside a `RoundPageContainer fullWidth`. */
16
+ fullWidth?: boolean;
17
+ };
18
+
19
+ /** Admin posts table. Mirrors features/email-automation/components/lists/EmailAutomationsList.tsx. */
20
+ export function BlogPostsList({ fullWidth }: BlogPostsListProps = {}) {
21
+ const t = useTranslations();
22
+
23
+ const data: DataListRetriever<BlogPostInterface> = useDataListRetriever({
24
+ retriever: (params) => BlogPostService.findMany(params),
25
+ retrieverParams: {},
26
+ module: Modules.BlogPost,
27
+ });
28
+
29
+ // Creating navigates to the new post's page (EditorSheet's default without onSuccess).
30
+ const functions: ReactNode[] = [
31
+ <BlogPostEditor
32
+ key="create-blog-post"
33
+ trigger={
34
+ <Button render={<div />} nativeButton={false} size="sm" variant="outline">
35
+ {t("blog.admin.newPost")}
36
+ </Button>
37
+ }
38
+ />,
39
+ ];
40
+
41
+ return (
42
+ <ContentListTable
43
+ data={data}
44
+ fields={[
45
+ BlogPostFields.title,
46
+ BlogPostFields.status,
47
+ BlogPostFields.categories,
48
+ BlogPostFields.publishedAt,
49
+ BlogPostFields.languages,
50
+ ]}
51
+ tableGeneratorType={Modules.BlogPost}
52
+ functions={functions}
53
+ fullWidth={fullWidth}
54
+ title={t("blog.entities.posts")}
55
+ emptyState={<EmptyState icon={NewspaperIcon} title={t("blog.admin.empty")} />}
56
+ />
57
+ );
58
+ }
@@ -0,0 +1,104 @@
1
+ "use client";
2
+
3
+ import { LoaderCircleIcon, RotateCcwIcon } from "lucide-react";
4
+ import { useTranslations } from "next-intl";
5
+ import { useCallback, useMemo, useState } from "react";
6
+ import { errorToast } from "../../../../components";
7
+ import { useI18nLocale } from "../../../../i18n";
8
+ import { Badge, Button } from "../../../../shadcnui";
9
+ import { BlogCategoryInterface } from "../../data";
10
+ import { BlogAiStatus } from "../../types/blog.constants";
11
+
12
+ /** Status pill colours for a post, shared by the post header and the admin posts table. */
13
+ export const BLOG_STATUS_BADGE = {
14
+ draft: "softGray",
15
+ published: "softGreen",
16
+ unpublished: "softAmber",
17
+ } as const;
18
+
19
+ /** The category label in the admin: the category's own original-language name. */
20
+ export function blogCategoryAdminName(category: BlogCategoryInterface): string {
21
+ return category.original?.name ?? category.name ?? "";
22
+ }
23
+
24
+ /**
25
+ * Language names come from `Intl.DisplayNames` in the viewer's locale: there is
26
+ * no per-language message key. An unknown code falls back to the code itself.
27
+ */
28
+ export function useBlogLanguageName(): (language: string) => string {
29
+ const locale = useI18nLocale();
30
+ const names = useMemo(() => {
31
+ try {
32
+ return new Intl.DisplayNames([locale], { type: "language" });
33
+ } catch {
34
+ return undefined;
35
+ }
36
+ }, [locale]);
37
+
38
+ return useCallback(
39
+ (language: string) => {
40
+ const name = names?.of(language);
41
+ if (!name) return language;
42
+ return name.charAt(0).toLocaleUpperCase(locale) + name.slice(1);
43
+ },
44
+ [names, locale],
45
+ );
46
+ }
47
+
48
+ /** Formats a date for the admin pages in the viewer's locale. */
49
+ export function useBlogDateFormatter(): (date?: Date) => string {
50
+ const locale = useI18nLocale();
51
+ return useCallback((date?: Date) => (date ? date.toLocaleDateString(locale, { dateStyle: "medium" }) : ""), [locale]);
52
+ }
53
+
54
+ type BlogTranslationStatusProps = {
55
+ aiStatus: BlogAiStatus;
56
+ /** Re-queues the translation of this one language. Shown only when the job failed. */
57
+ onRetranslate?: () => Promise<void>;
58
+ };
59
+
60
+ /**
61
+ * The translation state of one language. Nothing is rendered once the
62
+ * translation is `completed`; `failed` adds the "Translate again" action.
63
+ */
64
+ export function BlogTranslationStatus({ aiStatus, onRetranslate }: BlogTranslationStatusProps) {
65
+ const t = useTranslations();
66
+ const [isRetrying, setIsRetrying] = useState<boolean>(false);
67
+
68
+ if (aiStatus === "completed") return null;
69
+
70
+ if (aiStatus === "pending" || aiStatus === "in_progress") {
71
+ return (
72
+ <div className="flex items-center gap-x-2">
73
+ <Badge variant="softBlue">
74
+ <LoaderCircleIcon className="animate-spin" />
75
+ {aiStatus === "pending" ? t("blog.translation.pending") : t("blog.translation.translating")}
76
+ </Badge>
77
+ </div>
78
+ );
79
+ }
80
+
81
+ const retranslate = async () => {
82
+ if (!onRetranslate) return;
83
+ setIsRetrying(true);
84
+ try {
85
+ await onRetranslate();
86
+ } catch (error) {
87
+ errorToast({ title: t("common.errors.error"), error });
88
+ } finally {
89
+ setIsRetrying(false);
90
+ }
91
+ };
92
+
93
+ return (
94
+ <div className="flex items-center gap-x-2">
95
+ <Badge variant="softRed">{t("blog.translation.failed")}</Badge>
96
+ {onRetranslate && (
97
+ <Button type="button" size="sm" variant="outline" onClick={() => void retranslate()} disabled={isRetrying}>
98
+ <RotateCcwIcon />
99
+ {t("blog.actions.translateAgain")}
100
+ </Button>
101
+ )}
102
+ </div>
103
+ );
104
+ }
@@ -0,0 +1,100 @@
1
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
2
+ import { describe, expect, it, vi } from "vitest";
3
+
4
+ import type { BlogPostInterface, BlogPostTranslationInterface } from "../../../data";
5
+ import { BlogPostTranslationPanel } from "../BlogPostTranslationPanel";
6
+
7
+ const { retranslate } = vi.hoisted(() => ({ retranslate: vi.fn() }));
8
+
9
+ vi.mock("next-intl", () => ({ useTranslations: () => (key: string) => key }));
10
+ vi.mock("../../../data", () => ({ BlogPostTranslationService: { retranslate } }));
11
+ vi.mock("../../../hooks/useBlogCategoryNames", () => ({ useBlogCategoryNames: () => () => "" }));
12
+ // Editors and the BlockNote field display are not under test.
13
+ vi.mock("../BlogPostEditor", () => ({ BlogPostEditor: () => <span>post-editor</span> }));
14
+ vi.mock("../BlogPostTranslationEditor", () => ({
15
+ BlogPostTranslationEditor: () => <span>translation-editor</span>,
16
+ }));
17
+ vi.mock("../BlogPostComparison", () => ({
18
+ BlogPostTranslationFields: () => <div data-testid="fields" />,
19
+ BlogPostComparison: () => <div data-testid="comparison" />,
20
+ }));
21
+
22
+ const english = {
23
+ id: "t-en",
24
+ language: "en",
25
+ isOriginal: true,
26
+ source: "original",
27
+ aiStatus: "completed",
28
+ title: "Prep situations, not plots",
29
+ slug: "prep-situations-not-plots",
30
+ summary: "Why a scene that can go three ways beats one that must go one way.",
31
+ body: [],
32
+ readingMinutes: 6,
33
+ } as unknown as BlogPostTranslationInterface;
34
+
35
+ const translation = (overrides: Record<string, unknown>) =>
36
+ ({
37
+ id: "t-it",
38
+ language: "it",
39
+ isOriginal: false,
40
+ source: "ai",
41
+ aiStatus: "completed",
42
+ title: "Prepara situazioni, non trame",
43
+ slug: "prepara-situazioni-non-trame",
44
+ body: [],
45
+ readingMinutes: 6,
46
+ translatedAt: new Date("2026-10-12T09:00:00.000Z"),
47
+ ...overrides,
48
+ }) as unknown as BlogPostTranslationInterface;
49
+
50
+ const manualItalian = translation({ source: "manual" });
51
+
52
+ const post = {
53
+ id: "p1",
54
+ status: "published",
55
+ originalLanguage: "en",
56
+ publishedAt: new Date("2026-10-12T09:00:00.000Z"),
57
+ categories: [],
58
+ translations: [english, manualItalian],
59
+ original: english,
60
+ categoryIds: [],
61
+ } as unknown as BlogPostInterface;
62
+
63
+ describe("BlogPostTranslationPanel", () => {
64
+ it("warns that editing the original replaces hand edits", () => {
65
+ render(<BlogPostTranslationPanel post={post} translation={manualItalian} />);
66
+ expect(screen.getByText("blog.translation.editedByHand")).toBeInTheDocument();
67
+ expect(screen.getByText("blog.translation.overwriteWarning")).toBeInTheDocument();
68
+ expect(screen.getByText("blog.translation.translatedFrom")).toBeInTheDocument();
69
+ });
70
+
71
+ it("opens the comparison with the original on demand", () => {
72
+ render(<BlogPostTranslationPanel post={post} translation={manualItalian} />);
73
+ expect(screen.queryByTestId("comparison")).not.toBeInTheDocument();
74
+ fireEvent.click(screen.getByText("blog.actions.compareWithOriginal"));
75
+ expect(screen.getByTestId("comparison")).toBeInTheDocument();
76
+ expect(screen.getByText("blog.actions.hideComparison")).toBeInTheDocument();
77
+ });
78
+
79
+ it("failed translation shows Translate again, which re-queues that language", async () => {
80
+ const onChanged = vi.fn().mockResolvedValue(undefined);
81
+ retranslate.mockResolvedValue(undefined);
82
+ render(
83
+ <BlogPostTranslationPanel post={post} translation={translation({ aiStatus: "failed" })} onChanged={onChanged} />,
84
+ );
85
+
86
+ expect(screen.getByText("blog.translation.failed")).toBeInTheDocument();
87
+ fireEvent.click(screen.getByText("blog.actions.translateAgain"));
88
+
89
+ await waitFor(() => expect(retranslate).toHaveBeenCalledWith({ id: "t-it" }));
90
+ await waitFor(() => expect(onChanged).toHaveBeenCalled());
91
+ });
92
+
93
+ it("original tab shows the Original badge and no overwrite warning", () => {
94
+ render(<BlogPostTranslationPanel post={post} translation={english} />);
95
+ expect(screen.getByText("blog.translation.original")).toBeInTheDocument();
96
+ expect(screen.getByText("post-editor")).toBeInTheDocument();
97
+ expect(screen.queryByText("blog.translation.overwriteWarning")).not.toBeInTheDocument();
98
+ expect(screen.queryByText("blog.translation.editedByHand")).not.toBeInTheDocument();
99
+ });
100
+ });
@@ -0,0 +1,30 @@
1
+ import { render, screen } from "@testing-library/react";
2
+ import { ReactNode } from "react";
3
+ import { beforeAll, describe, expect, it, vi } from "vitest";
4
+
5
+ import { ModuleRegistry } from "../../../../../core/registry/ModuleRegistry";
6
+ import { BlogPostsList } from "../BlogPostsList";
7
+
8
+ vi.mock("../../../../../hooks", async (importOriginal) => ({
9
+ ...(await importOriginal<typeof import("../../../../../hooks")>()),
10
+ useDataListRetriever: () => ({ data: [], refresh: vi.fn(), search: vi.fn() }),
11
+ }));
12
+ vi.mock("../../../../../components/tables/ContentListTable", () => ({
13
+ ContentListTable: ({ functions }: { functions: ReactNode[] }) => <div data-testid="functions">{functions}</div>,
14
+ }));
15
+ vi.mock("next-intl", () => ({ useTranslations: () => (key: string) => key }));
16
+ // The editor sheet itself is not under test: render only the trigger the list hands it.
17
+ vi.mock("../BlogPostEditor", () => ({
18
+ BlogPostEditor: ({ trigger }: { trigger?: ReactNode }) => <>{trigger}</>,
19
+ }));
20
+
21
+ beforeAll(() => {
22
+ ModuleRegistry.register("BlogPost" as any, { name: "blog-posts" } as any);
23
+ });
24
+
25
+ describe("BlogPostsList", () => {
26
+ it("offers the new-post editor", () => {
27
+ render(<BlogPostsList />);
28
+ expect(screen.getByText("blog.admin.newPost")).toBeInTheDocument();
29
+ });
30
+ });
@@ -0,0 +1,14 @@
1
+ export * from "./BlogAdminContainer";
2
+ export * from "./BlogPostContainer";
3
+ export * from "./BlogPostsList";
4
+ export * from "./BlogCategoriesList";
5
+ export * from "./BlogLayoutSetting";
6
+ export * from "./BlogPostTranslationPanel";
7
+ export * from "./BlogPostComparison";
8
+ export * from "./BlogTranslationStatus";
9
+ export * from "./BlogPostEditor";
10
+ export * from "./BlogPostTranslationEditor";
11
+ export * from "./BlogCategoryEditor";
12
+ export * from "./BlogPostPublishButton";
13
+ export * from "./BlogPostDeleter";
14
+ export * from "./BlogCoverImageField";
@@ -0,0 +1,59 @@
1
+ "use client";
2
+
3
+ import { useTranslations } from "next-intl";
4
+ import { Badge, Link } from "../../../../shadcnui";
5
+ import type { PublicBlogCategory } from "../../types/blog-public.types";
6
+ import { blogListHref } from "./blogPublicHelpers";
7
+
8
+ /**
9
+ * Category filter: "All" plus one link per category. Every link keeps the
10
+ * search query and drops the page, so a new filter starts from page one.
11
+ * `chips` is the horizontal pill row; `list` is the vertical rail list.
12
+ */
13
+ export function BlogCategoryChips(props: {
14
+ categories: PublicBlogCategory[];
15
+ basePath: string;
16
+ activeCategorySlug?: string;
17
+ query?: string;
18
+ variant?: "chips" | "list";
19
+ className?: string;
20
+ }) {
21
+ const { categories, basePath, activeCategorySlug, query, variant = "chips", className } = props;
22
+ const t = useTranslations();
23
+
24
+ const items = [
25
+ {
26
+ key: "all",
27
+ label: t("blog.public.all"),
28
+ href: blogListHref(basePath, { q: query }),
29
+ active: !activeCategorySlug,
30
+ },
31
+ ...categories.map((category) => ({
32
+ key: category.id,
33
+ label: category.name,
34
+ href: blogListHref(basePath, { category: category.slug, q: query }),
35
+ active: category.slug === activeCategorySlug,
36
+ })),
37
+ ];
38
+
39
+ // Pills are Badges rendered as links: the active one is the filled default
40
+ // variant, the rest are outline (chips row) or ghost (rail list).
41
+ const inactiveVariant = variant === "chips" ? "outline" : "ghost";
42
+
43
+ return (
44
+ <nav aria-label={t("blog.entities.categories")} className={className}>
45
+ <ul className={variant === "chips" ? "flex flex-wrap items-center gap-2" : "flex flex-col items-start gap-2"}>
46
+ {items.map((item) => (
47
+ <li key={item.key}>
48
+ <Badge
49
+ variant={item.active ? "default" : inactiveVariant}
50
+ render={<Link href={item.href} aria-current={item.active ? "page" : undefined} />}
51
+ >
52
+ {item.label}
53
+ </Badge>
54
+ </li>
55
+ ))}
56
+ </ul>
57
+ </nav>
58
+ );
59
+ }
@@ -0,0 +1,21 @@
1
+ "use client";
2
+
3
+ import { BlogListColumn } from "./BlogListColumn";
4
+ import { BlogListFeatured } from "./BlogListFeatured";
5
+ import type { BlogListProps } from "./BlogListParts";
6
+ import { BlogListRail } from "./BlogListRail";
7
+
8
+ /** Public blog list in the layout an administrator picked (BlogSettings.listLayout). */
9
+ export function BlogList(props: BlogListProps) {
10
+ switch (props.layout) {
11
+ case "column":
12
+ return <BlogListColumn {...props} />;
13
+ case "rail":
14
+ return <BlogListRail {...props} />;
15
+ case "featured":
16
+ default:
17
+ return <BlogListFeatured {...props} />;
18
+ }
19
+ }
20
+
21
+ export type { BlogListProps };