From 42a5dabec1cd213c8389f4ff25bfd3de8a9b1e1b Mon Sep 17 00:00:00 2001 From: Sonny Date: Wed, 10 Apr 2024 18:26:23 +0200 Subject: [PATCH] feat: add optionnal category description --- .../migration.sql | 2 ++ prisma/schema.prisma | 15 ++++++----- public/locales/en/common.json | 3 ++- public/locales/fr/common.json | 3 ++- src/components/Links/Links.tsx | 5 ++++ src/components/Links/links.module.scss | 27 ++++++++++--------- src/lib/category/categoryValidationSchema.ts | 1 + src/pages/api/category/[cid].ts | 5 +++- src/pages/api/category/index.ts | 4 +-- src/pages/category/create.tsx | 14 ++++++++-- src/pages/category/edit/[cid].tsx | 24 ++++++++++++----- src/pages/link/edit/[lid].tsx | 4 ++- 12 files changed, 73 insertions(+), 34 deletions(-) create mode 100644 prisma/migrations/20240410162021_add_category_description/migration.sql diff --git a/prisma/migrations/20240410162021_add_category_description/migration.sql b/prisma/migrations/20240410162021_add_category_description/migration.sql new file mode 100644 index 0000000..ecac8f6 --- /dev/null +++ b/prisma/migrations/20240410162021_add_category_description/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE `category` ADD COLUMN `description` VARCHAR(255) NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 449a587..93a323f 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -29,9 +29,10 @@ model User { } model Category { - id Int @id @default(autoincrement()) - name String @db.VarChar(255) - links Link[] + id Int @id @default(autoincrement()) + name String @db.VarChar(255) + description String? @db.VarChar(255) + links Link[] author User @relation(fields: [authorId], references: [id]) authorId Int @@ -45,10 +46,10 @@ model Category { } model Link { - id Int @id @default(autoincrement()) - name String @db.VarChar(255) - description String? @db.VarChar(255) - url String @db.Text + id Int @id @default(autoincrement()) + name String @db.VarChar(255) + description String @db.VarChar(255) + url String @db.Text category Category @relation(fields: [categoryId], references: [id]) categoryId Int diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 8b28e2f..33858ac 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -18,6 +18,7 @@ "categories": "Categories", "category": "Category", "name": "Category name", + "description": "Category description", "create": "Create a category", "edit": "Edit a category", "remove": "Delete a category", @@ -46,4 +47,4 @@ "footer": { "made_by": "Made with ❤\uFE0F by" } -} +} \ No newline at end of file diff --git a/public/locales/fr/common.json b/public/locales/fr/common.json index 3a312ac..18c3b3c 100644 --- a/public/locales/fr/common.json +++ b/public/locales/fr/common.json @@ -18,6 +18,7 @@ "categories": "Catégories", "category": "Catégorie", "name": "Nom de la catégorie", + "description": "Description de la catégorie", "create": "Créer une catégorie", "edit": "Modifier une catégorie", "remove": "Supprimer une catégorie", @@ -46,4 +47,4 @@ "footer": { "made_by": "Fait avec ❤\uFE0F par" } -} +} \ No newline at end of file diff --git a/src/components/Links/Links.tsx b/src/components/Links/Links.tsx index d3d2631..f1135e0 100644 --- a/src/components/Links/Links.tsx +++ b/src/components/Links/Links.tsx @@ -66,6 +66,11 @@ export default function Links({ /> + {activeCategory.description && ( +

+ {activeCategory.description} +

+ )} {links.length !== 0 ? (