1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2025-03-11 02:57:39 +00:00
pds-2021-g2-nest/nest_frontend/components/interactive/BoxRepositoryCreate.js

110 lines
3.6 KiB
JavaScript
Raw Normal View History

2021-05-07 17:42:20 +02:00
import React from "react"
2021-05-07 17:30:10 +02:00
import BoxFull from "../base/BoxFull"
import FormLabelled from "../base/FormLabelled"
import FormLabel from "../base/formparts/FormLabel"
import InputWithIcon from "../base/InputWithIcon"
2021-05-11 18:05:01 +02:00
import { faBackward, faFolder, faPencilAlt, faPlus } from "@fortawesome/free-solid-svg-icons"
2021-05-07 17:30:10 +02:00
import Radio from "../base/Radio"
import Button from "../base/Button"
import useRepositoryEditor from "../../hooks/useRepositoryEditor"
2021-05-08 01:40:49 +02:00
import FormAlert from "../base/formparts/FormAlert"
import goToOnSuccess from "../../utils/goToOnSuccess"
import { useHistory } from "react-router"
2021-05-07 17:30:10 +02:00
2021-05-10 15:22:07 +02:00
/**
* A {@link BoxFull} allowing the user to save the changes made in the current {@link RepositoryEditor}.
*
* @param props
* @returns {JSX.Element}
* @constructor
*/
2021-05-07 17:30:10 +02:00
export default function BoxRepositoryCreate({ ...props }) {
const {
2021-05-10 15:22:07 +02:00
id,
2021-05-07 17:30:10 +02:00
evaluationMode,
setEvaluationMode,
name,
setName,
save,
2021-05-11 18:05:01 +02:00
revert,
2021-05-08 01:40:49 +02:00
error,
2021-05-07 17:30:10 +02:00
} = useRepositoryEditor()
const history = useHistory()
2021-05-07 17:30:10 +02:00
return (
2021-05-13 18:24:52 +02:00
<BoxFull header={"Crea repository"} {...props}>
2021-05-11 16:37:15 +02:00
<FormLabelled
onSubmit={e => {
e.preventDefault()
save()
}}
>
2021-05-15 17:19:45 +02:00
<FormLabel htmlFor={"repo-name"} text={"Nome repository"}>
2021-05-07 17:30:10 +02:00
<InputWithIcon
id={"repo-name"}
icon={faFolder}
value={name}
onChange={e => setName(e.target.value)}
/>
</FormLabel>
2021-05-15 17:19:45 +02:00
<FormLabel htmlFor={"filter-mode"} text={"Richiedi"}>
2021-05-07 17:30:10 +02:00
<label>
<Radio
name={"filter-mode"}
2021-05-10 14:13:45 +02:00
onChange={() => setEvaluationMode(0)}
2021-05-07 17:30:10 +02:00
checked={evaluationMode === 0}
/>
2021-05-15 17:19:45 +02:00
Almeno una cond.
2021-05-07 17:30:10 +02:00
</label>
&nbsp;
<label>
<Radio
name={"filter-mode"}
2021-05-10 14:13:45 +02:00
onChange={() => setEvaluationMode(1)}
2021-05-07 17:30:10 +02:00
checked={evaluationMode === 1}
/>
2021-05-15 17:19:45 +02:00
Tutte le cond.
2021-05-07 17:30:10 +02:00
</label>
</FormLabel>
2021-05-08 01:40:49 +02:00
{error ?
2021-05-11 16:37:15 +02:00
<FormAlert color={"Red"}>
{error.toString()}
</FormAlert>
: null}
2021-05-10 15:22:07 +02:00
{id ?
2021-05-11 18:05:01 +02:00
<>
<Button
style={{ "gridColumn": "1" }}
icon={faBackward}
color={"Red"}
2021-05-11 18:05:18 +02:00
onClick={() => revert()}
2021-05-11 18:05:01 +02:00
>
2021-05-15 17:19:45 +02:00
Annulla modifiche
2021-05-11 18:05:01 +02:00
</Button>
<Button
style={{ "gridColumn": "2" }}
icon={faPencilAlt}
color={"Green"}
onClick={_ => goToOnSuccess(save, history, "/repositories")()}
>
2021-05-15 17:19:45 +02:00
Salva modifiche
2021-05-11 18:05:01 +02:00
</Button>
</>
2021-05-11 16:37:15 +02:00
:
<Button
style={{ "gridColumn": "1 / 3" }}
icon={faPlus}
color={"Green"}
2021-05-11 18:05:01 +02:00
onClick={_ => goToOnSuccess(save, history, "/repositories")()}
2021-05-11 16:37:15 +02:00
>
2021-05-13 18:24:52 +02:00
Crea repository
2021-05-11 16:37:15 +02:00
</Button>
2021-05-10 15:22:07 +02:00
}
2021-05-07 17:30:10 +02:00
</FormLabelled>
</BoxFull>
)
}