summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/projects/NewProject.js
blob: 4f5d79cfb4db1213abd245d4d21eaf6a06a7f590 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import React, { useState } from 'react'
import TextInputModal from '../../components/modals/TextInputModal'
import { Button } from '@patternfly/react-core'
import { useMutation } from 'react-query'
import { PlusIcon } from '@patternfly/react-icons'
import { buttonContainer } from './NewProject.module.scss'

/**
 * A container for creating a new project.
 */
const NewProject = () => {
    const [isVisible, setVisible] = useState(false)
    const { mutate: addProject } = useMutation('addProject')

    const onSubmit = (name) => {
        if (name) {
            addProject({ name })
        }
        setVisible(false)
    }

    return (
        <>
            <div className={buttonContainer}>
                <Button
                    icon={<PlusIcon />}
                    color="primary"
                    className="pf-u-float-right"
                    onClick={() => setVisible(true)}
                >
                    New Project
                </Button>
            </div>
            <TextInputModal title="New Project" label="Project name" isOpen={isVisible} callback={onSubmit} />
        </>
    )
}

export default NewProject