-
Notifications
You must be signed in to change notification settings - Fork 481
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
New student deletion flow #23651
Merged
Merged
New student deletion flow #23651
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6b00909
Add DeleteAccount placeholder component, replace rails content
maddiedierker 25245e5
Add type prop to BootstrapButton to handle 'danger' buttons
maddiedierker 8913701
Add basic dialog with warning information
maddiedierker f8df2a3
Add dialog fields and style
maddiedierker 62315e5
Add password/deleteVerification to state and validate
maddiedierker dacaca5
Merge branch 'staging' into new-student-deletion-flow
maddiedierker 747ab8c
Move state from DeleteAccountDialog to DeleteAccount component
maddiedierker 87db2b6
Merge branch 'refactor-user-destroy' into new-student-deletion-flow
maddiedierker d095bbd
Merge branch 'refactor-user-destroy' into new-student-deletion-flow
maddiedierker 43c0ebb
Add error handling
maddiedierker 24447a2
Reset state to default state on modal open/close
maddiedierker 720f1de
Remove password field for users who don't have passwords
maddiedierker 6d5846d
Test DeleteAccount and DeleteAccountDialog integration
maddiedierker c12dc76
Simplify setState in onFailure
maddiedierker 7dceaff
Implement PR feedback
maddiedierker File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import React, {PropTypes} from 'react'; | ||
import $ from 'jquery'; | ||
import i18n from '@cdo/locale'; | ||
import color from '@cdo/apps/util/color'; | ||
import {navigateToHref} from '@cdo/apps/utils'; | ||
import BootstrapButton from './BootstrapButton'; | ||
import DeleteAccountDialog from './DeleteAccountDialog'; | ||
|
||
export const DELETE_VERIFICATION_STRING = i18n.deleteAccountDialog_verificationString(); | ||
const styles = { | ||
container: { | ||
paddingTop: 20, | ||
}, | ||
hr: { | ||
borderColor: color.red, | ||
}, | ||
header: { | ||
fontSize: 22, | ||
color: color.red, | ||
}, | ||
warning: { | ||
marginTop: 10, | ||
marginBottom: 10, | ||
}, | ||
buttonContainer: { | ||
display: 'flex', | ||
justifyContent: 'flex-end', | ||
}, | ||
}; | ||
const DEFAULT_STATE = { | ||
isDialogOpen: false, | ||
password: '', | ||
passwordError: '', | ||
deleteVerification: '', | ||
deleteError: '', | ||
}; | ||
|
||
export default class DeleteAccount extends React.Component { | ||
static propTypes = { | ||
isPasswordRequired: PropTypes.bool.isRequired, | ||
}; | ||
|
||
state = DEFAULT_STATE; | ||
|
||
toggleDialog = () => { | ||
this.setState(state => { | ||
return { | ||
...DEFAULT_STATE, | ||
isDialogOpen: !state.isDialogOpen | ||
}; | ||
}); | ||
}; | ||
|
||
onPasswordChange = (event) => { | ||
this.setState({ | ||
password: event.target.value | ||
}); | ||
}; | ||
|
||
onDeleteVerificationChange = (event) => { | ||
this.setState({ | ||
deleteVerification: event.target.value | ||
}); | ||
}; | ||
|
||
isValid = () => { | ||
const {password, deleteVerification} = this.state; | ||
const isPasswordValid = this.props.isPasswordRequired ? (password.length > 0) : true; | ||
return isPasswordValid && deleteVerification === DELETE_VERIFICATION_STRING; | ||
}; | ||
|
||
deleteUser = () => { | ||
const payload = { | ||
new_destroy_flow: true, | ||
password_confirmation: this.state.password | ||
}; | ||
|
||
$.ajax({ | ||
url: '/users', | ||
method: 'DELETE', | ||
data: payload | ||
}).done(result => { | ||
navigateToHref('/'); | ||
}).fail((jqXhr, _) => { | ||
this.onFailure(jqXhr); | ||
}); | ||
}; | ||
|
||
onFailure = (xhr) => { | ||
const responseJSON = xhr.responseJSON; | ||
let newState; | ||
if (responseJSON && responseJSON.error) { | ||
const passwordErrors = responseJSON.error.current_password; | ||
newState = {passwordError: passwordErrors[0]}; | ||
} else { | ||
newState = {deleteError: `Unexpected error: ${xhr.status}`}; | ||
} | ||
|
||
this.setState(newState); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div style={styles.container}> | ||
<hr style={styles.hr} /> | ||
<h2 style={styles.header}> | ||
{i18n.deleteAccount()} | ||
</h2> | ||
<div style={styles.warning}> | ||
{i18n.deleteAccount_warning()} | ||
</div> | ||
<div style={styles.buttonContainer}> | ||
{/* This button intentionally uses BootstrapButton to match other account page buttons */} | ||
<BootstrapButton | ||
type="danger" | ||
text={i18n.deleteAccount()} | ||
onClick={this.toggleDialog} | ||
/> | ||
</div> | ||
<DeleteAccountDialog | ||
isOpen={this.state.isDialogOpen} | ||
isPasswordRequired={this.props.isPasswordRequired} | ||
password={this.state.password} | ||
passwordError={this.state.passwordError} | ||
deleteVerification={this.state.deleteVerification} | ||
onPasswordChange={this.onPasswordChange} | ||
onDeleteVerificationChange={this.onDeleteVerificationChange} | ||
onCancel={this.toggleDialog} | ||
disableConfirm={!this.isValid()} | ||
deleteUser={this.deleteUser} | ||
deleteError={this.state.deleteError} | ||
/> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import React, {PropTypes} from 'react'; | ||
import i18n from '@cdo/locale'; | ||
import color from '@cdo/apps/util/color'; | ||
import BaseDialog from '@cdo/apps/templates/BaseDialog'; | ||
import {Header, Field, ConfirmCancelFooter} from '../SystemDialog/SystemDialog'; | ||
import FontAwesome from '@cdo/apps/templates/FontAwesome'; | ||
import Button from '@cdo/apps/templates/Button'; | ||
|
||
const GUTTER = 20; | ||
const styles = { | ||
container: { | ||
margin: GUTTER, | ||
color: color.charcoal, | ||
}, | ||
bodyContainer: { | ||
display: 'flex', | ||
alignItems: 'center', | ||
paddingBottom: GUTTER, | ||
}, | ||
icon: { | ||
color: color.red, | ||
fontSize: 100, | ||
}, | ||
text: { | ||
fontSize: 16, | ||
paddingLeft: GUTTER, | ||
}, | ||
dangerText: { | ||
color: color.red, | ||
}, | ||
input: { | ||
width: 490 | ||
}, | ||
}; | ||
|
||
export default class DeleteAccountDialog extends React.Component { | ||
static propTypes = { | ||
isOpen: PropTypes.bool.isRequired, | ||
isPasswordRequired: PropTypes.bool.isRequired, | ||
password: PropTypes.string.isRequired, | ||
passwordError: PropTypes.string, | ||
deleteVerification: PropTypes.string.isRequired, | ||
onPasswordChange: PropTypes.func.isRequired, | ||
onDeleteVerificationChange: PropTypes.func.isRequired, | ||
onCancel: PropTypes.func.isRequired, | ||
disableConfirm: PropTypes.bool.isRequired, | ||
deleteUser: PropTypes.func.isRequired, | ||
deleteError: PropTypes.string, | ||
}; | ||
|
||
render() { | ||
const { | ||
isOpen, | ||
isPasswordRequired, | ||
password, | ||
passwordError, | ||
deleteVerification, | ||
onPasswordChange, | ||
onDeleteVerificationChange, | ||
onCancel, | ||
disableConfirm, | ||
deleteUser, | ||
deleteError, | ||
} = this.props; | ||
|
||
return ( | ||
<BaseDialog | ||
useUpdatedStyles | ||
fixedWidth={550} | ||
isOpen={isOpen} | ||
handleClose={onCancel} | ||
> | ||
<div style={styles.container}> | ||
<Header text={i18n.deleteAccountDialog_header()}/> | ||
<div style={styles.bodyContainer}> | ||
<FontAwesome | ||
icon="exclamation-triangle" | ||
style={styles.icon} | ||
/> | ||
<div style={styles.text}> | ||
<strong>{i18n.deleteAccountDialog_body1()}</strong> | ||
{i18n.deleteAccountDialog_body2()} | ||
<strong style={styles.dangerText}>{i18n.deleteAccountDialog_body3()}</strong> | ||
{i18n.deleteAccountDialog_body4()} | ||
</div> | ||
</div> | ||
{isPasswordRequired && | ||
<Field | ||
label={i18n.deleteAccountDialog_currentPassword()} | ||
error={passwordError} | ||
> | ||
<input | ||
type="password" | ||
style={styles.input} | ||
value={password} | ||
onChange={onPasswordChange} | ||
/> | ||
</Field> | ||
} | ||
<Field | ||
label={i18n.deleteAccountDialog_verification({verificationString: i18n.deleteAccountDialog_verificationString()})} | ||
> | ||
<input | ||
type="text" | ||
style={styles.input} | ||
value={deleteVerification} | ||
onChange={onDeleteVerificationChange} | ||
/> | ||
</Field> | ||
<div> | ||
{i18n.deleteAccountDialog_emailUs()} | ||
</div> | ||
<ConfirmCancelFooter | ||
confirmText={i18n.deleteAccountDialog_button()} | ||
confirmColor={Button.ButtonColor.red} | ||
onConfirm={deleteUser} | ||
onCancel={onCancel} | ||
disableConfirm={disableConfirm} | ||
tabIndex="1" | ||
> | ||
<span | ||
id="uitest-delete-error" | ||
style={styles.dangerText} | ||
> | ||
{deleteError} | ||
</span> | ||
</ConfirmCancelFooter> | ||
</div> | ||
</BaseDialog> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to check if the mount point actually exists - it's possible it won't be rendered if the user doesn't have permission to delete their own account.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right! i'll add that check.