From 45a86275a85937a03376d06f06573d572b672bc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Go=CC=81mez=20Bachiller?= Date: Wed, 22 Nov 2023 14:54:12 +0100 Subject: [PATCH] feat: add book mockups --- .../20231122133945_book/migration.sql | 9 ++++ prisma/schema.prisma | 7 +++ src/app/settings/profile/page.tsx | 8 ++- src/components/Book/Book.tsx | 25 ++++++++++ src/components/BookForm/BookForm.tsx | 49 +++++++++++++++++++ .../user/domain/model/name.value-object.ts | 2 +- .../services/users-in-memory.repository.ts | 4 ++ stories/components/Book.stories.ts | 19 +++++++ stories/components/BookForm.stories.ts | 13 +++++ 9 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 prisma/migrations/20231122133945_book/migration.sql create mode 100644 src/components/Book/Book.tsx create mode 100644 src/components/BookForm/BookForm.tsx create mode 100644 stories/components/Book.stories.ts create mode 100644 stories/components/BookForm.stories.ts diff --git a/prisma/migrations/20231122133945_book/migration.sql b/prisma/migrations/20231122133945_book/migration.sql new file mode 100644 index 0000000..3dab7cd --- /dev/null +++ b/prisma/migrations/20231122133945_book/migration.sql @@ -0,0 +1,9 @@ +-- CreateTable +CREATE TABLE "Book" ( + "id" TEXT NOT NULL, + "authors" TEXT[], + "image" TEXT NOT NULL, + "title" TEXT NOT NULL, + + CONSTRAINT "Book_pkey" PRIMARY KEY ("id") +); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index ca9b8fd..1096274 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -53,3 +53,10 @@ model VerificationToken { @@unique([identifier, token]) } + +model Book { + id String @id @default(cuid()) + authors String[] + image String + title String +} \ No newline at end of file diff --git a/src/app/settings/profile/page.tsx b/src/app/settings/profile/page.tsx index d74b058..37266c5 100644 --- a/src/app/settings/profile/page.tsx +++ b/src/app/settings/profile/page.tsx @@ -1,16 +1,20 @@ import { redirect } from 'next/navigation' import EditProfileForm from '@/components/EditProfileForm/EditProfileForm' +import { FindUserResponse } from '@/core/user/application/types' import { findUser, updateUser } from '@/core/user/infrastructure/actions' import { auth } from '@/lib/auth/auth' export default async function Page() { const session = await auth() - if (!session) { + const email = session?.user?.email + if (!email) { return redirect('/') } - const user = await findUser(session.user?.email as string) + const user = (await findUser( + session.user?.email as string, + )) as FindUserResponse return ( <> diff --git a/src/components/Book/Book.tsx b/src/components/Book/Book.tsx new file mode 100644 index 0000000..dbbbf0b --- /dev/null +++ b/src/components/Book/Book.tsx @@ -0,0 +1,25 @@ +import { Card, CardBody, CardFooter, Image } from '@nextui-org/react' + +export interface BookProps { + authors: string[] + image: string + title: string +} + +export default function Book(props: BookProps) { + const { authors, image, title } = props + + return ( + <> + + + {title} + + +
{title}
+
{authors.join(', ')}
+
+
+ + ) +} diff --git a/src/components/BookForm/BookForm.tsx b/src/components/BookForm/BookForm.tsx new file mode 100644 index 0000000..bb7c7c5 --- /dev/null +++ b/src/components/BookForm/BookForm.tsx @@ -0,0 +1,49 @@ +'use client' + +import { Divider, Input } from '@nextui-org/react' + +import SubmitButton from '@/components/SubmitButton/SubmitButton' + +export default function BookForm() { + return ( + <> +
+
+ + + + +
+
+ +
+
+ + ) +} diff --git a/src/core/user/domain/model/name.value-object.ts b/src/core/user/domain/model/name.value-object.ts index 9aa7635..4e86967 100644 --- a/src/core/user/domain/model/name.value-object.ts +++ b/src/core/user/domain/model/name.value-object.ts @@ -1,5 +1,5 @@ export default class Name { - private constructor(public readonly value: string) {} + constructor(public readonly value: string) {} static create(name: string): Name { const trimmedName = name.trim() diff --git a/src/core/user/infrastructure/services/users-in-memory.repository.ts b/src/core/user/infrastructure/services/users-in-memory.repository.ts index d82abfc..4e2c775 100644 --- a/src/core/user/infrastructure/services/users-in-memory.repository.ts +++ b/src/core/user/infrastructure/services/users-in-memory.repository.ts @@ -11,4 +11,8 @@ export default class UsersInMemory implements Users { async save(user: User): Promise { this.users.set(user.email, user) } + + purge(): void { + this.users = new Map() + } } diff --git a/stories/components/Book.stories.ts b/stories/components/Book.stories.ts new file mode 100644 index 0000000..865f4a2 --- /dev/null +++ b/stories/components/Book.stories.ts @@ -0,0 +1,19 @@ +import { Meta, StoryObj } from '@storybook/react' + +import Book from '@/components/Book/Book' + +const meta = { + component: Book, + title: 'Components/Book', +} satisfies Meta + +export default meta +type Story = StoryObj + +export const Basic: Story = { + args: { + authors: ['Martin Kleppmann'], + image: 'https://m.media-amazon.com/images/I/91YfNb49PLL._SL1500_.jpg', + title: 'Designing Data-Intensive Applications', + }, +} diff --git a/stories/components/BookForm.stories.ts b/stories/components/BookForm.stories.ts new file mode 100644 index 0000000..def561f --- /dev/null +++ b/stories/components/BookForm.stories.ts @@ -0,0 +1,13 @@ +import { Meta, StoryObj } from '@storybook/react' + +import BookForm from '@/components/BookForm/BookForm' + +const meta = { + component: BookForm, + title: 'Components/BookForm', +} satisfies Meta + +export default meta +type Story = StoryObj + +export const Basic: Story = {}