diff --git a/frontend/client/src/components/AddMemberModal.js b/frontend/client/src/components/AddMemberModal.js index 1e41fd01..5a3e3e73 100644 --- a/frontend/client/src/components/AddMemberModal.js +++ b/frontend/client/src/components/AddMemberModal.js @@ -34,21 +34,23 @@ const ValidationRules = [ }, ] +const defaultState = { + firstName: '', + firstNameValidationFailed: false, + firstNameValidationMessage: '', + lastName: '', + lastNameValidationFailed: false, + lastNameValidationMessage: '', + email: '', + emailValidationFailed: false, + emailValidationMessage: '', + role: ROLES.NON_ADMIN_LABEL, + roleValidationFailed: false, + roleValidationMessage: '', +} + const AddMemberModalBase = observer((props) => { - const [state, setState] = useState({ - firstName: '', - firstNameValidationFailed: false, - firstNameValidationMessage: '', - lastName: '', - lastNameValidationFailed: false, - lastNameValidationMessage: '', - email: '', - emailValidationFailed: false, - emailValidationMessage: '', - role: ROLES.NON_ADMIN_LABEL, - roleValidationFailed: false, - roleValidationMessage: '', - }) + const [state, setState] = useState(defaultState) const tryCreateUser = () => { let newState = {} @@ -86,7 +88,10 @@ const AddMemberModalBase = observer((props) => { lastName: state.lastName, isAdmin: state.role === ROLES.ADMIN_LABEL, }) - .then(props.onSuccess, props.onFailure) + .then(() => { + props.onSuccess() + setState(defaultState) + }, props.onFailure) } function handleChange(e) { @@ -101,9 +106,14 @@ const AddMemberModalBase = observer((props) => { } } + const resetAndClose = () => { + props.onClose() + setState(defaultState) + } + // TODO needs to fail but not close on validation failure and high light invalid fields (can do that before touching the store) return ( -