Skip to content

Commit

Permalink
Notification Story
Browse files Browse the repository at this point in the history
  • Loading branch information
casesandberg committed Jul 18, 2024
1 parent 9436db9 commit 4c617b0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
39 changes: 38 additions & 1 deletion packages/database/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ import Decimal from 'decimal.js'
import _ from 'lodash'
import { ExtendedMarket } from '@play-money/markets/components/MarketOverviewPage'
import type { TransactionWithItems } from '@play-money/transactions/lib/getTransactions'
import { Market, User, Account, TransactionItem, Currency, MarketOption, Comment, MarketResolution } from './zod'
import {
Market,
User,
Account,
TransactionItem,
Currency,
MarketOption,
Comment,
MarketResolution,
Notification,
} from './zod'

export function mockUser(overrides?: Partial<User>): User {
const firstName = faker.person.firstName()
Expand Down Expand Up @@ -169,3 +179,30 @@ export function mockComment(overrides?: Partial<Comment>): Comment {
...overrides,
}
}

type ExtendedNotification = Notification & { actor: User; recipient: User; market: Market; comment: Comment }
export function mockNotification(overrides?: Partial<Notification>): ExtendedNotification {
return {
id: faker.string.uuid(),
recipientId: faker.string.uuid(),
recipient: mockUser(),
actorId: faker.string.uuid(),
actor: mockUser(),
type: faker.helpers.arrayElement(['MARKET_COMMENT']),
marketId: faker.string.uuid(),
market: mockMarket(),
commentId: faker.string.uuid(),
comment: mockComment(),
transactionId: faker.string.uuid(),
marketOptionId: faker.string.uuid(),
marketResolutionId: faker.string.uuid(),
parentCommentId: faker.string.uuid(),
commentReactionId: faker.string.uuid(),
content: null,
actionUrl: '/market/1',
readAt: null,
createdAt: faker.date.past(),
updatedAt: faker.date.past(),
...overrides,
}
}
27 changes: 27 additions & 0 deletions packages/notifications/components/NotificationItem.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Meta, StoryObj } from '@storybook/react'
import React from 'react'
import { mockNotification } from '@play-money/database/mocks'
import { NotificationItem } from './NotificationItem'

const meta = {
component: NotificationItem,
tags: ['autodocs'],
decorators: [
(Story) => (
<div className="w-[400px]">
<Story />
</div>
),
],
} satisfies Meta<typeof NotificationItem>

export default meta
type Story = StoryObj<typeof meta>

export const Default: Story = {
args: {
notification: mockNotification() as unknown as Story['args']['notification'],
unread: true,
count: 1,
},
}

0 comments on commit 4c617b0

Please sign in to comment.