diff --git a/client/src/apollo/queries/todos/todos.js b/client/src/apollo/queries/todos/todos.js index f5f29e9..03088d2 100644 --- a/client/src/apollo/queries/todos/todos.js +++ b/client/src/apollo/queries/todos/todos.js @@ -9,6 +9,7 @@ const GET_TODOS = gql` status deadline category { + id title } } diff --git a/client/src/apollo/queries/todos/todosByCategory.js b/client/src/apollo/queries/todos/todosByCategory.js index ce084cf..8f2af9c 100644 --- a/client/src/apollo/queries/todos/todosByCategory.js +++ b/client/src/apollo/queries/todos/todosByCategory.js @@ -3,7 +3,6 @@ import gql from 'graphql-tag' const GET_TODOS_BY_CATEGORY = gql` query getTodosByCategory($id: ID!) { category(id: $id) { - id title todos { id @@ -12,6 +11,7 @@ query getTodosByCategory($id: ID!) { status deadline category { + id title } } diff --git a/client/src/components/Modals/Todo/CreateTodoModal.js b/client/src/components/Modals/Todo/CreateTodoModal.js index 7e8cde3..f3dff37 100644 --- a/client/src/components/Modals/Todo/CreateTodoModal.js +++ b/client/src/components/Modals/Todo/CreateTodoModal.js @@ -3,7 +3,8 @@ import useStyles from '../styles' import { Dialog, DialogContent, DialogTitle, DialogActions, Button, TextField, Select, MenuItem, InputLabel, FormControl } from '@material-ui/core' import AddIcon from '@material-ui/icons/Add' -import { useQuery, useMutation } from '@apollo/react-hooks' +import { Query } from 'react-apollo' +import { useMutation } from '@apollo/react-hooks' import CREATE_TODO from '../../../apollo/mutations/todos/createTodo'; import GET_TODOS from '../../../apollo/queries/todos/todos'; @@ -62,83 +63,87 @@ const CreateTodoModal = ({ isModalOpen, handleCloseModal }) => { deadline: target.name === 'deadline' ? target.value : fieldsData.deadline }) } - - const { loading, error, data } = useQuery(GET_CATEGORIES); - - if (loading) return null; - if (error) return `Error! ${error.message}`; - + return ( -
- - - Добавить новую запись - - -
- - - - Категория - - - - - - - - -
-
-
+ + {({ loading, error, data }) => { + if (loading) return null; + if (error) return `Error! ${error.message}`; + + return ( +
+ + + Добавить новую запись + + +
+ + + + Категория + + + + + + + + +
+
+
+ ) + }} +
) } diff --git a/client/src/components/Modals/Todo/UpdateTodoModal.js b/client/src/components/Modals/Todo/UpdateTodoModal.js index ff2182e..9f95e8e 100644 --- a/client/src/components/Modals/Todo/UpdateTodoModal.js +++ b/client/src/components/Modals/Todo/UpdateTodoModal.js @@ -3,7 +3,9 @@ import useStyles from '../styles' import { Dialog, DialogContent, DialogTitle, DialogActions, Button, TextField, Select, MenuItem, InputLabel, FormControl } from '@material-ui/core' import EditIcon from '@material-ui/icons/Edit' -import categories from '../../../db/categories.json' +import { Query } from 'react-apollo' +import { useQuery } from '@apollo/react-hooks' +import GET_CATEGORIES from '../../../apollo/queries/categories/categories' const UpdateTodoModal = ({ isModalOpen, handleCloseModal, selectedTodo, setSelectedTodo }) => { const classes = useStyles() @@ -32,6 +34,9 @@ const UpdateTodoModal = ({ isModalOpen, handleCloseModal, selectedTodo, setSelec }) } + const { loading, error, data } = useQuery(GET_CATEGORIES) + if (loading) return null + if (error) return `Error: ${error}` return (
@@ -77,7 +82,7 @@ const UpdateTodoModal = ({ isModalOpen, handleCloseModal, selectedTodo, setSelec onChange={handleFieldChange} label="Категория" > - {categories.map((category, i) => {category.title})} + {data.categories.map((category, i) => {category.title})} { id: todo.id, title: todo.title, description: todo.description, - category: todo.category, + category: todo.category.id, deadline: todo.deadline }