Skip to content

Commit

Permalink
feat: add book mockups
Browse files Browse the repository at this point in the history
  • Loading branch information
sgomez committed Nov 22, 2023
1 parent 051c587 commit 45a8627
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 3 deletions.
9 changes: 9 additions & 0 deletions prisma/migrations/20231122133945_book/migration.sql
Original file line number Diff line number Diff line change
@@ -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")
);
7 changes: 7 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ model VerificationToken {
@@unique([identifier, token])
}

model Book {
id String @id @default(cuid())
authors String[]
image String
title String
}
8 changes: 6 additions & 2 deletions src/app/settings/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
Expand Down
25 changes: 25 additions & 0 deletions src/components/Book/Book.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<Card className="max-w-[320px]">
<CardBody>
<Image alt={title} width={297} height={387} src={image} />
</CardBody>
<CardFooter className="flex flex-col items-start">
<div className="text-xl font-bold">{title}</div>
<div className="text-sm">{authors.join(', ')}</div>
</CardFooter>
</Card>
</>
)
}
49 changes: 49 additions & 0 deletions src/components/BookForm/BookForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use client'

import { Divider, Input } from '@nextui-org/react'

import SubmitButton from '@/components/SubmitButton/SubmitButton'

export default function BookForm() {
return (
<>
<form className="flex flex-col gap-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-6 mt-4 w-full">
<Input
label="Título"
labelPlacement="outside"
name="title"
placeholder="Título"
radius="none"
size="lg"
isRequired
/>
<Input
label="Autores"
labelPlacement="outside"
name="authors"
placeholder="Autores"
radius="none"
size="lg"
isRequired
description="Separados por comas"
/>
<Input
label="Imagen"
labelPlacement="outside"
name="image"
placeholder="Imagen"
radius="none"
size="lg"
isRequired
description="Introduzca la url de la portada del libro"
/>
<Divider className="col-span-1 md:col-span-2" />
</div>
<div className="flex flex-row-reverse">
<SubmitButton />
</div>
</form>
</>
)
}
2 changes: 1 addition & 1 deletion src/core/user/domain/model/name.value-object.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ export default class UsersInMemory implements Users {
async save(user: User): Promise<void> {
this.users.set(user.email, user)
}

purge(): void {
this.users = new Map()
}
}
19 changes: 19 additions & 0 deletions stories/components/Book.stories.ts
Original file line number Diff line number Diff line change
@@ -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<typeof Book>

export default meta
type Story = StoryObj<typeof meta>

export const Basic: Story = {
args: {
authors: ['Martin Kleppmann'],
image: 'https://m.media-amazon.com/images/I/91YfNb49PLL._SL1500_.jpg',
title: 'Designing Data-Intensive Applications',
},
}
13 changes: 13 additions & 0 deletions stories/components/BookForm.stories.ts
Original file line number Diff line number Diff line change
@@ -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<typeof BookForm>

export default meta
type Story = StoryObj<typeof meta>

export const Basic: Story = {}

0 comments on commit 45a8627

Please sign in to comment.