Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closing Add Member Modal Now Resets State #418

Merged
merged 2 commits into from
Jul 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions frontend/client/src/components/AddMemberModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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) {
Expand All @@ -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 (
<Modal hidden={props.hidden} onClose={props.onClose} containerClass="add-member-modal-container">
<Modal hidden={props.hidden} onClose={resetAndClose} containerClass="add-member-modal-container">
<h3>Add Member</h3>
<div className="add-member-form">
<label htmlFor="firstName">
Expand Down