summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/containers/projects/NewProjectContainer.js
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-web/opendc-web-ui/src/containers/projects/NewProjectContainer.js')
-rw-r--r--opendc-web/opendc-web-ui/src/containers/projects/NewProjectContainer.js13
1 files changed, 9 insertions, 4 deletions
diff --git a/opendc-web/opendc-web-ui/src/containers/projects/NewProjectContainer.js b/opendc-web/opendc-web-ui/src/containers/projects/NewProjectContainer.js
index e03b5c07..c844fe2d 100644
--- a/opendc-web/opendc-web-ui/src/containers/projects/NewProjectContainer.js
+++ b/opendc-web/opendc-web-ui/src/containers/projects/NewProjectContainer.js
@@ -1,20 +1,25 @@
import React, { useState } from 'react'
-import { useDispatch } from 'react-redux'
-import { addProject } from '../../redux/actions/projects'
import TextInputModal from '../../components/modals/TextInputModal'
import { Button } from 'reactstrap'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faPlus } from '@fortawesome/free-solid-svg-icons'
+import { useMutation, useQueryClient } from 'react-query'
+import { addProject } from '../../api/projects'
+import { useAuth } from '../../auth'
/**
* A container for creating a new project.
*/
const NewProjectContainer = () => {
const [isVisible, setVisible] = useState(false)
- const dispatch = useDispatch()
+ const auth = useAuth()
+ const queryClient = useQueryClient()
+ const mutation = useMutation((data) => addProject(auth, data), {
+ onSuccess: (result) => queryClient.setQueryData('projects', (old) => [...(old || []), result]),
+ })
const callback = (text) => {
if (text) {
- dispatch(addProject(text))
+ mutation.mutate({ name: text })
}
setVisible(false)
}