From 3798a3345235b24ce22b402240d4114bfaaf577c Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi <256895@studenti.unimore.it> Date: Mon, 10 May 2021 17:24:32 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20Fix=20minor=20bugs=20in=20BoxRep?= =?UTF-8?q?ositoryCreate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/interactive/BoxRepositoryCreate.js | 10 ++++++---- .../src/components/providers/RepositoryEditor.js | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/code/frontend/src/components/interactive/BoxRepositoryCreate.js b/code/frontend/src/components/interactive/BoxRepositoryCreate.js index 088784d..83a18fe 100644 --- a/code/frontend/src/components/interactive/BoxRepositoryCreate.js +++ b/code/frontend/src/components/interactive/BoxRepositoryCreate.js @@ -8,6 +8,8 @@ import Radio from "../base/Radio" import Button from "../base/Button" import useRepositoryEditor from "../../hooks/useRepositoryEditor" import FormAlert from "../base/formparts/FormAlert" +import goToOnSuccess from "../../utils/goToOnSuccess" +import { useHistory } from "react-router" /** @@ -28,6 +30,8 @@ export default function BoxRepositoryCreate({ ...props }) { error, } = useRepositoryEditor() + const history = useHistory() + return ( {e.preventDefault(); save()}}> @@ -68,8 +72,7 @@ export default function BoxRepositoryCreate({ ...props }) { style={{"gridColumn": "1 / 3"}} icon={faPencilAlt} color={"Green"} - goTo={"/repositories"} - onClick={e => save()} + onClick={e => goToOnSuccess(save, history, "/repositories")} > Edit repository @@ -78,8 +81,7 @@ export default function BoxRepositoryCreate({ ...props }) { style={{"gridColumn": "1 / 3"}} icon={faPlus} color={"Green"} - goTo={"/repositories"} - onClick={e => save()} + onClick={e => goToOnSuccess(save, history, "/repositories")} > Create repository diff --git a/code/frontend/src/components/providers/RepositoryEditor.js b/code/frontend/src/components/providers/RepositoryEditor.js index b0a55c9..269ceb5 100644 --- a/code/frontend/src/components/providers/RepositoryEditor.js +++ b/code/frontend/src/components/providers/RepositoryEditor.js @@ -24,16 +24,16 @@ export default function RepositoryEditor({ className, }) { /** The repository name. */ - const [_name, setName] = useState(name) + const [_name, setName] = useState(name ?? "") /** The repository state (active / archived). */ - const [_isActive, setActive] = useState(isActive) + const [_isActive, setActive] = useState(isActive ?? true) /** The start date of the data gathering. */ - const [_start, setStart] = useState(start) + const [_start, setStart] = useState(start ?? new Date().toISOString()) /** The end date of the data gathering. */ - const [_end, setEnd] = useState(end) + const [_end, setEnd] = useState(end ?? new Date().toISOString()) /** The conditions of the data gathering. */ const {