diff --git a/src/features/Posts/pages/CreatePostPage/Components/DraftsContainer/DraftContainer.stories.tsx b/src/features/Posts/pages/CreatePostPage/Components/DraftsContainer/DraftContainer.stories.tsx new file mode 100644 index 0000000..05d2fc1 --- /dev/null +++ b/src/features/Posts/pages/CreatePostPage/Components/DraftsContainer/DraftContainer.stories.tsx @@ -0,0 +1,30 @@ +import { ComponentStory, ComponentMeta } from '@storybook/react'; +import { Post_Type } from 'src/graphql'; +import { WithModals, WrapForm } from 'src/utils/storybook/decorators'; +import { IStoryFormInputs } from '../../CreateStoryPage/CreateStoryPage'; + +import DraftsContainer from './DraftsContainer'; + +export default { + title: 'Posts/Create Post Page/Drafts Container', + component: DraftsContainer, + argTypes: { + backgroundColor: { control: 'color' }, + }, + decorators: [WithModals, WrapForm({ + defaultValues: { + tags: [], + cover_image: [], + } + })] +} as ComponentMeta; + + +const Template: ComponentStory = (args) =>
+ +export const Default = Template.bind({}); +Default.args = { + type: Post_Type.Story +} + + diff --git a/src/features/Posts/pages/CreatePostPage/Components/DraftsContainer/DraftsContainer.tsx b/src/features/Posts/pages/CreatePostPage/Components/DraftsContainer/DraftsContainer.tsx index 5cedbb1..48ed624 100644 --- a/src/features/Posts/pages/CreatePostPage/Components/DraftsContainer/DraftsContainer.tsx +++ b/src/features/Posts/pages/CreatePostPage/Components/DraftsContainer/DraftsContainer.tsx @@ -94,7 +94,7 @@ export default function DraftsContainer({ type, onDraftLoad }: Props) { <> {(!myDraftsQuery.loading && myDraftsQuery.data?.getMyDrafts && myDraftsQuery.data.getMyDrafts.length > 0) && -
+

Saved Drafts

    {myDraftsQuery.data.getMyDrafts.map(draft => @@ -107,7 +107,7 @@ export default function DraftsContainer({ type, onDraftLoad }: Props) { {draft.title}

    -

    Last edited {getDateDifference(draft.updatedAt)} ago

    +

    Last edited {getDateDifference(draft.updatedAt, { dense: true })} ago

    )} diff --git a/src/features/Posts/pages/CreatePostPage/Components/StoryForm/StoryForm.stories.tsx b/src/features/Posts/pages/CreatePostPage/Components/StoryForm/StoryForm.stories.tsx index 6217b32..ea4d469 100644 --- a/src/features/Posts/pages/CreatePostPage/Components/StoryForm/StoryForm.stories.tsx +++ b/src/features/Posts/pages/CreatePostPage/Components/StoryForm/StoryForm.stories.tsx @@ -1,5 +1,6 @@ import { ComponentStory, ComponentMeta } from '@storybook/react'; -import { WithModals } from 'src/utils/storybook/decorators'; +import { WithModals, WrapForm } from 'src/utils/storybook/decorators'; +import { IStoryFormInputs } from '../../CreateStoryPage/CreateStoryPage'; import StoryForm from './StoryForm'; @@ -9,7 +10,12 @@ export default { argTypes: { backgroundColor: { control: 'color' }, }, - decorators: [WithModals] + decorators: [WithModals, WrapForm({ + defaultValues: { + tags: [], + cover_image: [], + } + })] } as ComponentMeta; diff --git a/src/mocks/handlers.ts b/src/mocks/handlers.ts index f90c1c0..a1fb79b 100644 --- a/src/mocks/handlers.ts +++ b/src/mocks/handlers.ts @@ -1,6 +1,6 @@ import { graphql } from 'msw' -import { allCategories, getAllHackathons, getCategory, getFeed, getPostById, getProject, getTrendingPosts, hottestProjects, me, newProjects, popularTags, profile, projectsByCategory, searchProjects } from './resolvers' +import { allCategories, getAllHackathons, getCategory, getFeed, getMyDrafts, getPostById, getProject, getTrendingPosts, hottestProjects, me, newProjects, popularTags, profile, projectsByCategory, searchProjects } from './resolvers' import { NavCategoriesQuery, ExploreProjectsQuery, @@ -28,6 +28,7 @@ import { DonationsStatsQuery, MeQuery, ProfileQuery, + GetMyDraftsQuery, } from 'src/graphql' const delay = (ms = 1000) => new Promise((res) => setTimeout(res, ms + Math.random() * 1000)) @@ -212,4 +213,14 @@ export const handlers = [ ) }), + graphql.query('GetMyDrafts', async (req, res, ctx) => { + await delay() + + return res( + ctx.data({ + getMyDrafts: getMyDrafts() + }) + ) + }), + ] \ No newline at end of file diff --git a/src/mocks/resolvers.ts b/src/mocks/resolvers.ts index 028d54b..c3e5ccc 100644 --- a/src/mocks/resolvers.ts +++ b/src/mocks/resolvers.ts @@ -77,4 +77,8 @@ export function me() { export function profile() { return MOCK_DATA['user'] +} + +export function getMyDrafts(): Query['getMyDrafts'] { + return MOCK_DATA['posts'].stories; } \ No newline at end of file diff --git a/src/utils/storybook/decorators.tsx b/src/utils/storybook/decorators.tsx index f70e2b1..7533f8b 100644 --- a/src/utils/storybook/decorators.tsx +++ b/src/utils/storybook/decorators.tsx @@ -113,10 +113,9 @@ export const centerDecorator: DecoratorFn = (Story) => {
} - -export const WrapForm: (options?: Partial) => DecoratorFn = options => { +export function WrapForm(options?: Partial>): DecoratorFn { const Func: DecoratorFn = (Story) => { - const methods = useForm(options); + const methods = useForm(options); return