-
Notifications
You must be signed in to change notification settings - Fork 9
Display blogs in terslated language #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 17 commits
ffb4dcb
f30b119
ce19789
5a5a785
5f627d1
50c4c0e
09d41d4
f3c7843
7b2b4f2
b440491
12dfff9
5dc1f46
f6634db
26ee5c4
8f9aac7
5dfc006
29bc8ba
7a2d0b3
2c66e01
785efb4
56b8e5c
afd3ea4
6a7bf75
5241150
f45fabb
709df19
9e183b8
d045d75
a16bd05
cbc7742
ccd94d7
e865d2e
89011a7
4d01705
efb7571
05d797b
121c6c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| Warnings: | ||
|
|
||
| - You are about to drop the column `slug` on the `Post` table. All the data in the column will be lost. | ||
| - You are about to drop the column `title` on the `Post` table. All the data in the column will be lost. | ||
| - Added the required column `slugen` to the `Post` table without a default value. This is not possible if the table is not empty. | ||
| - Added the required column `slugfr` to the `Post` table without a default value. This is not possible if the table is not empty. | ||
| - Added the required column `titleen` to the `Post` table without a default value. This is not possible if the table is not empty. | ||
| - Added the required column `titlefr` to the `Post` table without a default value. This is not possible if the table is not empty. | ||
|
|
||
| */ | ||
| -- RedefineTables | ||
| PRAGMA defer_foreign_keys=ON; | ||
| PRAGMA foreign_keys=OFF; | ||
| CREATE TABLE "new_Post" ( | ||
| "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
| "titlefr" TEXT NOT NULL, | ||
| "titleen" TEXT NOT NULL, | ||
| "locale" TEXT NOT NULL, | ||
| "slugfr" TEXT NOT NULL, | ||
| "slugen" TEXT NOT NULL, | ||
| "content" TEXT NOT NULL, | ||
| "validated" BOOLEAN NOT NULL DEFAULT false, | ||
| "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" DATETIME NOT NULL | ||
| ); | ||
| INSERT INTO "new_Post" ("content", "createdAt", "id", "locale", "updatedAt", "validated") SELECT "content", "createdAt", "id", "locale", "updatedAt", "validated" FROM "Post"; | ||
| DROP TABLE "Post"; | ||
| ALTER TABLE "new_Post" RENAME TO "Post"; | ||
| CREATE UNIQUE INDEX "Post_id_key" ON "Post"("id"); | ||
| CREATE UNIQUE INDEX "Post_slugfr_key" ON "Post"("slugfr"); | ||
| CREATE UNIQUE INDEX "Post_slugen_key" ON "Post"("slugen"); | ||
| PRAGMA foreign_keys=ON; | ||
| PRAGMA defer_foreign_keys=OFF; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| -- This is an empty migration. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,37 +15,40 @@ import { useState } from "react"; | |
| import { getBlog, renameBlog } from "@/db/blogs"; | ||
| import { updatePostLabels } from "@/db/labels"; | ||
| import { Locale } from "@/locales/config"; | ||
| import { getDictionary } from "@/locales/dictionaries"; | ||
| import { usePathname } from "next/navigation"; | ||
| import { isLocale } from "@/locales/config"; | ||
|
|
||
| function Rename({ title, id, router }: { title: string; id: number; router: AppRouterInstance }) { | ||
| function Rename({ title, id, router, t, locale }: { title: string; id: number; router: AppRouterInstance; t: any; locale: Locale }) { | ||
|
||
| return ( | ||
| <Dialog> | ||
| <DialogTrigger asChild> | ||
| <Button variant="outline"> | ||
| <span className="flex items-center space-x-2"> | ||
| <p>Renommer</p> | ||
| <p>{t.rename.rename}</p> | ||
| <FaPencil /> | ||
| </span> | ||
| </Button> | ||
| </DialogTrigger> | ||
| <DialogContent> | ||
| <DialogHeader> | ||
| <DialogTitle>Modification du titre du post</DialogTitle> | ||
| <DialogTitle>{t.rename.modifytitle}</DialogTitle> | ||
| <form | ||
| className="flex flex-col items-center w-full space-y-10" | ||
| onSubmit={e => { | ||
| const formData = new FormData(e.target as HTMLFormElement); | ||
| const title = formData.get("title") as string; | ||
| renameBlog(id, title).finally(() => { | ||
| renameBlog(id, title, locale).finally(() => { | ||
| router.refresh(); | ||
| }); | ||
| }} | ||
| > | ||
| <Label htmlFor="title" className="w-full"> | ||
| Titre | ||
| {t.rename.title} | ||
| </Label> | ||
| <Input defaultValue={title} className="w-full" type="text" name="title" id="title" /> | ||
| <Button variant="call2action" type="submit"> | ||
| Renommer | ||
| {t.rename.rename} | ||
| </Button> | ||
| </form> | ||
| </DialogHeader> | ||
|
|
@@ -54,36 +57,36 @@ function Rename({ title, id, router }: { title: string; id: number; router: AppR | |
| ); | ||
| } | ||
|
|
||
| function AddLabel({ getLabels, addRemoveLabel, dbLabels }: { getLabels: string[]; addRemoveLabel: (x: string) => void; dbLabels: string[] }) { | ||
| function AddLabel({ getLabels, addRemoveLabel, dbLabels, t }: { getLabels: string[]; addRemoveLabel: (x: string) => void; dbLabels: string[]; t: any }) { | ||
|
||
| return ( | ||
| <ManyComboBox | ||
| selected={getLabels} | ||
| addRemove={addRemoveLabel} | ||
| items={dbLabels} | ||
| vocab={{ | ||
| title: "Modifier les labels", | ||
| selectorMessage: "Selectionner au plus 6 labels", | ||
| empty: "Aucun filtre ne correspond à cette recherche", | ||
| title: t.labels.modifylabels, | ||
| selectorMessage: t.labels.selectlabels, | ||
| empty: t.labels.empty, | ||
| }} | ||
| limit={6} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| function OpenSave({ saving }: { saving: boolean }) { | ||
| function OpenSave({ saving, t }: { saving: boolean; t: any }) { | ||
|
||
| return ( | ||
| <Dialog> | ||
| <DialogTrigger asChild> | ||
| <Button variant="outline"> | ||
| <span className="flex items-center space-x-2"> | ||
| {saving ? ( | ||
| <> | ||
| <p>Sauvegarde en cours</p> | ||
| <p>{t.save.saving}</p> | ||
| <AiOutlineLoading3Quarters className="animate-spin" /> | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <p>Sauvegardé</p> | ||
| <p>{t.save.saved}</p> | ||
| <FaCheck /> | ||
| </> | ||
| )} | ||
|
|
@@ -92,16 +95,9 @@ function OpenSave({ saving }: { saving: boolean }) { | |
| </DialogTrigger> | ||
| <DialogContent> | ||
| <DialogHeader className="space-y-6"> | ||
| <DialogTitle>Sauvegarde automatique des posts</DialogTitle> | ||
| <DialogDescription className="flex items-center flex-col"> | ||
| Une sauvegarde automatique s'effectue en permanence pour éviter les pertes de données. Comme elles peuvent prendre du temps, vous | ||
| pouvez faire une sauvegarde manuelle avant de quitter la page avec le bouton “Sauvegarder”. Spammer ce bouton ne sert à | ||
| rien, juste peut entraîner des crash. | ||
| </DialogDescription> | ||
| <DialogFooter className="text-destructive"> | ||
| ATTENTION: ne quittez pas la page tant que le status n'est pas marqué en “Sauvegardé” au risque de perdre votre | ||
| contenu... | ||
| </DialogFooter> | ||
| <DialogTitle>{t.save.automaticsave}</DialogTitle> | ||
| <DialogDescription className="flex items-center flex-col">{t.save.savedescription}</DialogDescription> | ||
| <DialogFooter className="text-destructive">{t.save.savewarning}</DialogFooter> | ||
| </DialogHeader> | ||
| </DialogContent> | ||
| </Dialog> | ||
|
|
@@ -120,6 +116,8 @@ interface ActionProps { | |
| } | ||
|
|
||
| export function Actions({ setToBeChanged, content, value, title, id, dbLabels, blogLabels, locale }: ActionProps) { | ||
| const localepage = usePathname().split("/")[1] as Locale; | ||
|
||
| const t = getDictionary(localepage).navigation.admin.editblog; | ||
| const [getLabels, setLabels] = useState<string[]>(blogLabels); | ||
| const addRemoveLabel = (label: string) => { | ||
| var newLabels = getLabels; | ||
|
|
@@ -150,15 +148,15 @@ export function Actions({ setToBeChanged, content, value, title, id, dbLabels, b | |
| }} | ||
| > | ||
| <span className="flex items-center space-x-2"> | ||
| <p>Sauvergarder</p> | ||
| <p>{t.save.save}</p> | ||
| <FaSave /> | ||
| </span> | ||
| </Button> | ||
| <Rename id={id} title={title} router={router} /> | ||
| <AddLabel addRemoveLabel={addRemoveLabel} dbLabels={dbLabels} getLabels={getLabels} /> | ||
| <Rename id={id} title={title} router={router} t={t} locale={locale} /> | ||
| <AddLabel addRemoveLabel={addRemoveLabel} dbLabels={dbLabels} getLabels={getLabels} t={t} /> | ||
| </div> | ||
| <div> | ||
| <OpenSave saving={JSON.stringify(content) !== value} /> | ||
| <OpenSave saving={JSON.stringify(content) !== value} t={t} /> | ||
| </div> | ||
| </div> | ||
| {/* <div className="pb-4"> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,10 +14,11 @@ interface PageProps extends LocaleParams { | |
|
|
||
| export default async function Validation({ params: { locale }, validate }: PageProps) { | ||
| const posts = await getAllBlog(); | ||
| const allData: ValidationBlogType[] = posts.map(({ id, validated, authors, title, content, createdAt, updatedAt }) => ({ | ||
| const allData: ValidationBlogType[] = posts.map(({ id, validated, authors, locale, title, content, createdAt, updatedAt }) => ({ | ||
| id, | ||
| validated, | ||
| emails: authors.map(author => author.email), | ||
| locale, | ||
| title, | ||
| content, | ||
| createdAt, | ||
|
|
@@ -33,7 +34,7 @@ export default async function Validation({ params: { locale }, validate }: PageP | |
| <ResizablePanel defaultSize={100}> | ||
| <div className="p-10 h-full"> | ||
| <DataTable | ||
| search_column="title" | ||
| search_column={"title"} | ||
|
||
| data={isAdmin ? allData : allData.filter(post => post.emails.includes(session?.email!))} | ||
| columns={columns} | ||
| filters={[]} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ import { BtnLink, EmailBtn } from "@/components/telecom-etude/contact"; | |
| import { getUserName } from "@/lib/users"; | ||
| import { Checkbox } from "@/components/ui/checkbox"; | ||
| import Link from "next/link"; | ||
| import { usePathname } from "next/navigation"; | ||
| import { Locale } from "@/locales/config"; | ||
|
||
|
|
||
| function Delete({ row }: { row: Row<ValidationBlogType> }) { | ||
| const router = useRouter(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the prisma extension + formatOnSave.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed