From c145c49403ce97cf44dd88bfe5411cfd3f3c13d4 Mon Sep 17 00:00:00 2001 From: leon-i Date: Tue, 28 Jul 2020 15:22:07 -0400 Subject: [PATCH 1/2] Closing modal now resets state --- .../client/src/components/AddMemberModal.js | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/frontend/client/src/components/AddMemberModal.js b/frontend/client/src/components/AddMemberModal.js index 1e41fd01..6a3d60a1 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 = {} @@ -101,9 +103,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 ( -