Skip to content

Commit

Permalink
Prefill Name field when creating cases or studies (#165)
Browse files Browse the repository at this point in the history
* Prefill Name field when creating cases or studies

Signed-off-by: Ayoub LABIDI <[email protected]>

* Fix issue : Case Name prefilled after cancelling study creation

Signed-off-by: Ayoub LABIDI <[email protected]>

* Code refactoring of create-study-dialog

Signed-off-by: Ayoub LABIDI <[email protected]>

* Code Refactoring : callback removed and if statement simplified

Signed-off-by: Ayoub LABIDI <[email protected]>

* Fix bug : validate button clickable when import parameters fail

Signed-off-by: Ayoub LABIDI <[email protected]>

Signed-off-by: Ayoub LABIDI <[email protected]>
  • Loading branch information
ayolab authored Nov 18, 2022
1 parent 9b55d44 commit c5445b3
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 165 deletions.
25 changes: 21 additions & 4 deletions src/components/dialogs/create-case-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import React, { useState } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import PropTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux';
Expand All @@ -16,7 +16,12 @@ import Alert from '@mui/material/Alert';
import DialogActions from '@mui/material/DialogActions';
import Button from '@mui/material/Button';
import { ElementType } from '../../utils/elementType';
import { useFileValue, useNameField, useTextValue } from './field-hook';
import {
useFileValue,
useNameField,
useTextValue,
usePrefillNameField,
} from './field-hook';
import { createCase } from '../../utils/rest-api';
import { useSnackbarMessage } from '../../utils/messages';
import {
Expand All @@ -37,7 +42,7 @@ export function CreateCaseDialog({ onClose, open }) {
const dispatch = useDispatch();
const intl = useIntl();
const [triggerReset, setTriggerReset] = useState(true);
const [name, NameField, nameError, nameOk] = useNameField({
const [name, NameField, nameError, nameOk, setCaseName] = useNameField({
label: 'nameProperty',
autoFocus: true,
elementType: ElementType.CASE,
Expand Down Expand Up @@ -65,6 +70,18 @@ export function CreateCaseDialog({ onClose, open }) {
return file && nameOk && isFileOk;
}

const nameRef = useRef(name);

useEffect(() => {
nameRef.current = name;
}, [name]);

usePrefillNameField({
nameRef,
selectedFile: file,
setValue: setCaseName,
});

const snackbarMessage = useSnackbarMessage();

const handleCreateNewCase = () => {
Expand Down Expand Up @@ -106,7 +123,7 @@ export function CreateCaseDialog({ onClose, open }) {

const handleKeyPressed = (event) => {
if (event.key === 'Enter') {
handleCreateNewCase(name, file);
handleCreateNewCase();
}
};

Expand Down
Loading

0 comments on commit c5445b3

Please sign in to comment.