-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FS-268]: Project Documents Add A New Document (#137)
This PR projects documents add a new document. --------- Co-authored-by: Alireza Safaierad <frontendmonster@gmail.com>
- Loading branch information
1 parent
e8a9672
commit a62b7d5
Showing
30 changed files
with
524 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ents/CreateProjectDocument/CreateProjectDocumentButton/CreateProjectDocumentButton.cy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { CreateProjectDocumentButton } from './CreateProjectDocumentButton'; | ||
import { createProjectDocumentButtonId } from './CreateProjectDocumentButton.ids'; | ||
|
||
describe('Create Project Button', () => { | ||
beforeEach(() => { | ||
cy.mount(<CreateProjectDocumentButton />); | ||
}); | ||
|
||
it('should be visible to users', () => { | ||
cy.findByTestId(createProjectDocumentButtonId).should('exist'); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
...ents/CreateProjectDocument/CreateProjectDocumentButton/CreateProjectDocumentButton.ids.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const createProjectDocumentButtonId = 'create-document'; |
11 changes: 11 additions & 0 deletions
11
...CreateProjectDocument/CreateProjectDocumentButton/CreateProjectDocumentButton.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { CreateProjectDocumentButton } from './CreateProjectDocumentButton'; | ||
|
||
export default { | ||
component: CreateProjectDocumentButton, | ||
} as Meta<typeof CreateProjectDocumentButton>; | ||
|
||
type Story = StoryObj<typeof CreateProjectDocumentButton>; | ||
|
||
export const Default: Story = {}; |
23 changes: 23 additions & 0 deletions
23
...ponents/CreateProjectDocument/CreateProjectDocumentButton/CreateProjectDocumentButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { PlusIcon } from '@camp/icons'; | ||
import { messages } from '@camp/messages'; | ||
import { tid } from '@camp/test'; | ||
import { Button } from '@mantine/core'; | ||
|
||
import { openCreateProjectDocumentModal } from '../CreateProjectDocumentModal'; | ||
import { createProjectDocumentButtonId as id } from './CreateProjectDocumentButton.ids'; | ||
|
||
export const CreateProjectDocumentButton = () => { | ||
const t = messages.projectDetail.addDocument; | ||
|
||
return ( | ||
<Button | ||
variant="outline" | ||
size="sm" | ||
{...tid(id)} | ||
onClick={openCreateProjectDocumentModal} | ||
leftIcon={<PlusIcon size={16} />} | ||
> | ||
{t.addDocBtn} | ||
</Button> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
...ects/ProjectDetail/_components/CreateProjectDocument/CreateProjectDocumentButton/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './CreateProjectDocumentButton'; |
10 changes: 10 additions & 0 deletions
10
...mponents/CreateProjectDocument/CreateProjectDocumentForm/CreateProjectDocumentForm.ids.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const createProjectDocumentFormIds = { | ||
form: 'create-project-document-form', | ||
dateInput: 'project-document-date', | ||
descriptionInput: 'project-description-input', | ||
submitBtn: 'submit-button', | ||
notification: { | ||
success: 'create-project-document-success-notification', | ||
failure: 'create-project-document-failure-notification', | ||
}, | ||
} as const; |
143 changes: 143 additions & 0 deletions
143
..._components/CreateProjectDocument/CreateProjectDocumentForm/CreateProjectDocumentForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { debug, DebugScopes } from '@camp/debug'; | ||
import { | ||
ControlledDateInput, | ||
ControlledFileUpload, | ||
FileUpload, | ||
Check warning on line 5 in app/Dashboard/Projects/ProjectDetail/_components/CreateProjectDocument/CreateProjectDocumentForm/CreateProjectDocumentForm.tsx GitHub Actions / verify
|
||
showNotification, | ||
} from '@camp/design'; | ||
import { | ||
createResolver, | ||
documentFileValidator, | ||
documentSchema, | ||
} from '@camp/domain'; | ||
import { messages } from '@camp/messages'; | ||
import { tid } from '@camp/test'; | ||
import { Button, createStyles, Group, Stack, TextInput } from '@mantine/core'; | ||
import { Controller, useForm } from 'react-hook-form'; | ||
Check warning on line 16 in app/Dashboard/Projects/ProjectDetail/_components/CreateProjectDocument/CreateProjectDocumentForm/CreateProjectDocumentForm.tsx GitHub Actions / verify
|
||
import type { SafeParseError, SafeParseSuccess } from 'zod'; | ||
|
||
import { createProjectDocumentFormIds as ids } from './CreateProjectDocumentForm.ids'; | ||
|
||
interface FormSchema { | ||
date: Date; | ||
description: string; | ||
documents: File[]; | ||
} | ||
|
||
interface Props { | ||
dismiss: () => void; | ||
} | ||
|
||
const resolver = createResolver<FormSchema>({ | ||
date: documentSchema.date(), | ||
description: documentSchema.description(), | ||
documents: documentSchema.documents(), | ||
}); | ||
|
||
const useStyle = createStyles(theme => ({ | ||
label: { | ||
label: { | ||
color: theme.colors.fg[6], | ||
}, | ||
}, | ||
})); | ||
|
||
// FIXME replace with actual upload | ||
|
||
// eslint-disable-next-line fp/no-let | ||
let x = 0; | ||
|
||
const uploadDocument = () => { | ||
return new Promise<void>((res, rej) => { | ||
Check warning on line 51 in app/Dashboard/Projects/ProjectDetail/_components/CreateProjectDocument/CreateProjectDocumentForm/CreateProjectDocumentForm.tsx GitHub Actions / verify
|
||
setTimeout(() => { | ||
x++; | ||
if (x === 3) rej(); | ||
else res(); | ||
}, 1000); | ||
}); | ||
}; | ||
|
||
const unUploadDocument = () => { | ||
return uploadDocument(); | ||
}; | ||
|
||
export const CreateProjectDocumentForm = ({ dismiss }: Props) => { | ||
const t = messages.projectDetail.addDocument.form; | ||
const { handleSubmit, register, formState, control } = useForm<FormSchema>({ | ||
resolver, | ||
mode: 'onChange', | ||
}); | ||
|
||
const onSubmit = handleSubmit(data => { | ||
debug.log(DebugScopes.All, data); | ||
}); | ||
|
||
const { classes } = useStyle(); | ||
return ( | ||
<form onSubmit={onSubmit} {...tid(ids.form)}> | ||
<Stack spacing={40}> | ||
<ControlledDateInput | ||
name="date" | ||
control={control} | ||
className={classes.label} | ||
wrapperProps={tid(ids.dateInput)} | ||
label={t.dateInput.label} | ||
placeholder={t.dateInput.placeholder} | ||
error={formState.errors.date?.message} | ||
/> | ||
<TextInput | ||
wrapperProps={tid(ids.descriptionInput)} | ||
required | ||
{...register('description')} | ||
label={t.descriptionInput.label} | ||
placeholder={t.descriptionInput.placeholder} | ||
error={formState.errors.description?.message} | ||
/> | ||
<ControlledFileUpload | ||
control={control} | ||
name="documents" | ||
defaultValue={[]} | ||
required | ||
label={t.documentsInput.label} | ||
helper={t.documentsInput.maxSize} | ||
upload={uploadDocument} | ||
unUpload={unUploadDocument} | ||
filter={(files): File[] => { | ||
const res = files.map(f => documentFileValidator.safeParse(f)); | ||
const firstError = res.find( | ||
r => !r.success, | ||
) as SafeParseError<File> | null; | ||
|
||
if (firstError != null) | ||
showNotification({ | ||
message: firstError.error.issues[0]!.message, | ||
type: 'failure', | ||
}); | ||
return res | ||
.filter((r): r is SafeParseSuccess<File> => r.success) | ||
.map(r => r.data); | ||
}} | ||
/> | ||
|
||
<Group spacing={10} position="right"> | ||
<Button | ||
size="sm" | ||
variant="filled" | ||
color="secondary" | ||
onClick={dismiss} | ||
> | ||
{messages.actions.dismiss} | ||
</Button> | ||
<Button | ||
type="submit" | ||
size="sm" | ||
disabled={!formState.isValid} | ||
{...tid(ids.submitBtn)} | ||
> | ||
{t.submitBtn} | ||
</Button> | ||
</Group> | ||
</Stack> | ||
</form> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
...ojects/ProjectDetail/_components/CreateProjectDocument/CreateProjectDocumentForm/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './CreateProjectDocumentForm'; |
1 change: 1 addition & 0 deletions
1
...onents/CreateProjectDocument/CreateProjectDocumentModal/CreateProjectDocumentModal.ids.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const createProjectDocumentModalId = 'create-project-document-modal'; |
39 changes: 39 additions & 0 deletions
39
...s/CreateProjectDocument/CreateProjectDocumentModal/CreateProjectDocumentModal.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ModalsProvider } from '@mantine/modals'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { useEffect } from 'react'; | ||
|
||
import { | ||
CreateProjectDocumentModal, | ||
openCreateProjectDocumentModal, | ||
} from './CreateProjectDocumentModal'; | ||
|
||
export default { | ||
argTypes: { | ||
opened: { | ||
defaultValue: true, | ||
type: 'boolean', | ||
description: 'Mounts modal if true', | ||
}, | ||
}, | ||
component: CreateProjectDocumentModal, | ||
decorators: [ | ||
Story => ( | ||
<ModalsProvider> | ||
<Story /> | ||
</ModalsProvider> | ||
), | ||
], | ||
chromatic: { delay: 500 }, | ||
} as Meta<typeof CreateProjectDocumentModal>; | ||
|
||
type Story = StoryObj<typeof CreateProjectDocumentModal>; | ||
|
||
export const Default: Story = { | ||
render: () => { | ||
useEffect(() => { | ||
openCreateProjectDocumentModal(); | ||
}, []); | ||
|
||
return <></>; | ||
}, | ||
}; |
21 changes: 21 additions & 0 deletions
21
...omponents/CreateProjectDocument/CreateProjectDocumentModal/CreateProjectDocumentModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { messages } from '@camp/messages'; | ||
import { tid } from '@camp/test'; | ||
import { closeModal, openModal } from '@mantine/modals'; | ||
|
||
import { CreateProjectDocumentForm } from '../CreateProjectDocumentForm'; | ||
import { createProjectDocumentModalId as id } from './CreateProjectDocumentModal.ids'; | ||
|
||
export const CreateProjectDocumentModal = () => ( | ||
<CreateProjectDocumentForm dismiss={() => closeModal(id)} /> | ||
); | ||
|
||
export const openCreateProjectDocumentModal = () => | ||
openModal({ | ||
modalId: id, | ||
children: <CreateProjectDocumentModal />, | ||
title: messages.projectDetail.addDocument.title, | ||
size: '490', | ||
padding: '30px', | ||
centered: true, | ||
...tid(id), | ||
}); |
1 change: 1 addition & 0 deletions
1
...jects/ProjectDetail/_components/CreateProjectDocument/CreateProjectDocumentModal/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './CreateProjectDocumentModal'; |
1 change: 1 addition & 0 deletions
1
app/Dashboard/Projects/ProjectDetail/_components/CreateProjectDocument/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './CreateProjectDocumentButton'; |
18 changes: 18 additions & 0 deletions
18
app/Dashboard/Projects/ProjectDetail/_components/ProjectDocuments/ProjectDocuments.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DashboardTitle } from '@camp/design'; | ||
import { messages } from '@camp/messages'; | ||
import { Group, Stack } from '@mantine/core'; | ||
|
||
import { CreateProjectDocumentButton } from '../CreateProjectDocument'; | ||
|
||
export const ProjectDocuments = () => { | ||
const t = messages.projectDetail.addDocument; | ||
|
||
return ( | ||
<Stack spacing={25} sx={{ position: 'relative' }}> | ||
<Group position="apart" mih="100%"> | ||
<DashboardTitle>{t.title}</DashboardTitle> | ||
<CreateProjectDocumentButton /> | ||
</Group> | ||
</Stack> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
app/Dashboard/Projects/ProjectDetail/_components/ProjectDocuments/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ProjectDocuments'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,3 +51,4 @@ huskyrc | |
indexify | ||
pkey | ||
alian | ||
Prray |
Oops, something went wrong.