From be0c5b7783381cf9f53e4a934126eeefeddc806a Mon Sep 17 00:00:00 2001 From: Gabriel Collares <98597812+GabrielCollares@users.noreply.github.com> Date: Wed, 17 Jul 2024 01:01:49 -0300 Subject: [PATCH] feat: create the speaker-section component --- .../SpeakerSection/SpeakerSection.stories.tsx | 87 +++++++++++++++++++ .../SpeakerSection/SpeakerSection.test.tsx | 24 +++++ .../SpeakerSection/SpeakerSection.tsx | 32 +++++++ src/components/SpeakerSection/index.ts | 3 + src/components/SpeakerSection/types.ts | 8 ++ 5 files changed, 154 insertions(+) create mode 100644 src/components/SpeakerSection/SpeakerSection.stories.tsx create mode 100644 src/components/SpeakerSection/SpeakerSection.test.tsx create mode 100644 src/components/SpeakerSection/SpeakerSection.tsx create mode 100644 src/components/SpeakerSection/index.ts create mode 100644 src/components/SpeakerSection/types.ts diff --git a/src/components/SpeakerSection/SpeakerSection.stories.tsx b/src/components/SpeakerSection/SpeakerSection.stories.tsx new file mode 100644 index 0000000..d3d2081 --- /dev/null +++ b/src/components/SpeakerSection/SpeakerSection.stories.tsx @@ -0,0 +1,87 @@ +import type { Meta, StoryObj } from "@storybook/react"; +import { SpeakerSection } from "./SpeakerSection"; + +export type Story = StoryObj; + +const meta: Meta = { + title: "Components/SpeakerSection", + tags: ["autodocs"], + component: SpeakerSection, + argTypes: { + handleCardModeChange: { action: "handleCardModeChange" }, + liveTalk: { control: "object" }, + savedCardIds: { control: undefined }, + sectionTitle: { control: "text" }, + }, +} satisfies Meta; + +export default meta; + +export const FrontEndCE: Story = { + args: { + liveTalk: { + id: 1, + hour: "10:00", + title: "Como se tornar um desenvolvedor Front-End", + tags: ["Javascript", "React", "Carreira"], + room: "Test Room", + speaker: { + image: "test.jpg", + title: "Jean Livino", + role: "CEO Hackaton", + company: "FrontEnd CE", + bio: "Test bio", + social_link: "https://test.com", + id: 1, + }, + }, + savedCardIds: [], + sectionTitle: "Front-End CE", + }, +}; + +export const Comunidade: Story = { + args: { + liveTalk: { + id: 1, + hour: "11:00", + title: "Como entrar na comunidade!", + tags: ["Javascript", "React", "Carreira"], + room: "Test Room", + speaker: { + image: "test.jpg", + title: "Andressa Morais", + role: "CEO Hackaton", + company: "FrontEnd CE", + bio: "Test bio", + social_link: "https://test.com", + id: 1, + }, + }, + savedCardIds: [], + sectionTitle: "Comunidade", + }, +}; + +export const Convida: Story = { + args: { + liveTalk: { + id: 1, + hour: "11:00", + title: "Fui convidado para um evento, e agora?", + tags: ["Javascript", "React", "Carreira"], + room: "Test Room", + speaker: { + image: "test.jpg", + title: "Bruno Oliveira", + role: "CEO Hackaton", + company: "FrontEnd CE", + bio: "Test bio", + social_link: "https://test.com", + id: 1, + }, + }, + savedCardIds: [], + sectionTitle: "Convida", + }, +}; \ No newline at end of file diff --git a/src/components/SpeakerSection/SpeakerSection.test.tsx b/src/components/SpeakerSection/SpeakerSection.test.tsx new file mode 100644 index 0000000..75b572d --- /dev/null +++ b/src/components/SpeakerSection/SpeakerSection.test.tsx @@ -0,0 +1,24 @@ +import { render } from '@testing-library/react'; +import { SpeakerSection } from './SpeakerSection'; + +test('renders SpeakerComponent', () => { + const liveTalk = { + id: 1, + hour: '10:00', + title: 'Test Talk', + tags: ['tag1', 'tag2'], + room: 'Test Room', + speaker: { + image: 'test.jpg', + title: 'Test Speaker', + role: 'Test Role', + company: 'Test Company', + bio: 'Test Bio', + social_link: 'https://test.com', + id: 1, + }, + }; + const { getByText } = render( {}} liveTalk={liveTalk} savedCardIds={[]} sectionTitle="Test Section" />); + const element = getByText(/Test Section/i); + expect(element).toBeInTheDocument(); +}); \ No newline at end of file diff --git a/src/components/SpeakerSection/SpeakerSection.tsx b/src/components/SpeakerSection/SpeakerSection.tsx new file mode 100644 index 0000000..c92889e --- /dev/null +++ b/src/components/SpeakerSection/SpeakerSection.tsx @@ -0,0 +1,32 @@ +import { SpeakerCard } from "@/components/SpeakerCard"; +import { Button } from "@/components/ui/button"; +import { SpeakerSectionProps } from "./types"; + +export const SpeakerSection = ({ sectionTitle, liveTalk, savedCardIds, handleCardModeChange }: SpeakerSectionProps) => { + + return ( +
+ {liveTalk && ( +
+ +
+ handleCardModeChange(liveTalk.id, mode)} + key={liveTalk.id} + hour={liveTalk.hour} + label={liveTalk.title} + tags={liveTalk.tags} + imageUrl={liveTalk.speaker.image} + imageFallback={liveTalk.speaker.title[0]} + name={liveTalk.speaker.title} + role={liveTalk.speaker.role} + /> +
+
+ )} +
+ ); +}; \ No newline at end of file diff --git a/src/components/SpeakerSection/index.ts b/src/components/SpeakerSection/index.ts new file mode 100644 index 0000000..22f99d5 --- /dev/null +++ b/src/components/SpeakerSection/index.ts @@ -0,0 +1,3 @@ +import { SpeakerSection } from "./SpeakerSection" + +export { SpeakerSection } \ No newline at end of file diff --git a/src/components/SpeakerSection/types.ts b/src/components/SpeakerSection/types.ts new file mode 100644 index 0000000..f70baae --- /dev/null +++ b/src/components/SpeakerSection/types.ts @@ -0,0 +1,8 @@ +import { Palestra } from "@/api/types"; + +export interface SpeakerSectionProps { + liveTalk: Palestra | undefined; + savedCardIds: number[]; + sectionTitle: string; + handleCardModeChange: (cardId: number, newMode: boolean) => void; +} \ No newline at end of file