forked from pets-oss/pets-front
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create organization tasks page, resolves pets-oss#151
1 parent
5523a59
commit 32ff5d2
Showing
9 changed files
with
851 additions
and
542 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
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,66 @@ | ||
import React from 'react'; | ||
|
||
import { Box, Card, CardHeader, Typography } from '@material-ui/core'; | ||
import { Theme } from '@material-ui/core/styles'; | ||
import makeStyles from '@material-ui/core/styles/makeStyles'; | ||
import { OrganizationTask } from '../../graphql/types'; | ||
|
||
const DONE = 'Task is done'; | ||
const TODO = 'Task to be taken'; | ||
|
||
export default function TaskCard({ task }: TaskCardProps) { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<Box my={2}> | ||
<Card> | ||
<CardHeader | ||
title={ | ||
<Typography component="h6" className={classes.headerText} noWrap> | ||
{task.title} | ||
</Typography> | ||
} | ||
subheader={<Typography className={classes.subHeaderText}>{task.description}</Typography>} | ||
/> | ||
<Box display="flex" className={task.isDone ? classes.done : classes.todo}> | ||
<Box my={1} mx="auto" py={1} color="white"> | ||
{task.isDone ? DONE : TODO} | ||
</Box> | ||
</Box> | ||
</Card> | ||
</Box> | ||
); | ||
} | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
root: { | ||
width: '100%', | ||
}, | ||
headerText: { | ||
maxWidth: 150, | ||
[theme.breakpoints.up('md')]: { | ||
maxWidth: 350, | ||
}, | ||
[theme.breakpoints.up('lg')]: { | ||
maxWidth: 600, | ||
}, | ||
fontSize: 20, | ||
lineHeight: '24px', | ||
fontWeight: 600, | ||
}, | ||
done: { | ||
color: theme.palette.success.contrastText, | ||
backgroundColor: theme.palette.success.main, | ||
}, | ||
todo: { | ||
backgroundColor: theme.palette.error.light, | ||
color: theme.palette.error.contrastText, | ||
}, | ||
subHeaderText: { | ||
color: theme.palette.grey['600'], | ||
}, | ||
})); | ||
|
||
interface TaskCardProps { | ||
task: OrganizationTask; | ||
} |
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,19 @@ | ||
import React from 'react'; | ||
|
||
import { Box } from '@material-ui/core'; | ||
import { OrganizationTask } from '../../graphql/types'; | ||
import TaskCard from './TaskCard'; | ||
|
||
interface TaskListProps { | ||
tasks: OrganizationTask[]; | ||
} | ||
|
||
export default function TaskList({ tasks }: TaskListProps) { | ||
return ( | ||
<Box component="ul"> | ||
{tasks.map(task => ( | ||
<TaskCard task={task} key={task.id} /> | ||
))} | ||
</Box> | ||
); | ||
} |
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,28 @@ | ||
import { loader } from 'graphql.macro'; | ||
import React from 'react'; | ||
|
||
import { useQuery } from '@apollo/client'; | ||
import { Skeleton } from '@material-ui/lab'; | ||
import TaskList from './TaskList'; | ||
|
||
const GET_ORGANIZATION_TASKS_QUERY = loader('src/graphql/queries/organization-tasks.graphql'); | ||
|
||
export default function TaskListContainer() { | ||
const { loading, data, error } = useQuery(GET_ORGANIZATION_TASKS_QUERY); | ||
|
||
if (loading) { | ||
return <Skeleton animation="wave" variant="rect" height="70vh" />; | ||
} | ||
|
||
if (error) { | ||
// TODO: replace with proper UI elements | ||
return <p>Error!</p>; | ||
} | ||
|
||
if (!data?.organizationTasks?.length) { | ||
// TODO: replace with proper UI elements | ||
return <p>No data!</p>; | ||
} | ||
|
||
return <TaskList tasks={data.organizationTasks} />; | ||
} |
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,8 @@ | ||
query getOrganizationTasks { | ||
organizationTasks { | ||
id, | ||
title, | ||
description, | ||
isDone | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { loader } from 'graphql.macro'; | ||
import React from 'react'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
import { screen } from '@testing-library/react'; | ||
import { renderWithMockProvider } from '../test-utils/render-mock-provider'; | ||
import OrganizationTasksPage from './OrganizationTasksPage'; | ||
|
||
jest.mock('@material-ui/lab/Skeleton', () => () => <div>Loading...</div>); | ||
|
||
const GET_ORGANIZATION_TASKS_QUERY = loader('src/graphql/queries/organization-tasks.graphql'); | ||
|
||
test('should have loading state', () => { | ||
renderWithMockProvider(<OrganizationTasksPage />, { query: GET_ORGANIZATION_TASKS_QUERY }); | ||
expect(screen.getByText(/Loading.../i)).toBeInTheDocument(); | ||
}); | ||
|
||
test('should handle error state', async () => { | ||
renderWithMockProvider(<OrganizationTasksPage />, { | ||
query: GET_ORGANIZATION_TASKS_QUERY, | ||
error: new Error('Something went wrong'), | ||
}); | ||
// Wait for the application to update | ||
await act(async () => new Promise(resolve => setTimeout(resolve, 0))); | ||
expect(screen.getByText(/Error!/i)).toBeInTheDocument(); | ||
}); | ||
|
||
test('should load organization task list', async () => { | ||
renderWithMockProvider(<OrganizationTasksPage />, { | ||
query: GET_ORGANIZATION_TASKS_QUERY, | ||
data: { | ||
organizationTasks: [ | ||
{ | ||
id: 1, | ||
title: 'Vet for Murkė', | ||
description: 'Place: Kaunakiemio g. 15a', | ||
isDone: false, | ||
}, | ||
], | ||
}, | ||
}); | ||
// Wait for the application to update | ||
await act(async () => new Promise(resolve => setTimeout(resolve, 0))); | ||
expect(screen.getByText(/Organization Tasks/i)).toBeInTheDocument(); | ||
}); |
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,14 @@ | ||
import React from 'react'; | ||
|
||
import TaskListContainer from '../components/task/TaskListContainer'; | ||
import Page from './Page'; | ||
|
||
function OrganizationTasksPage() { | ||
return ( | ||
<Page title="Organization Tasks"> | ||
<TaskListContainer /> | ||
</Page> | ||
); | ||
} | ||
|
||
export default OrganizationTasksPage; |