This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): allow changing and toggling app password via dialogs
- Loading branch information
Showing
10 changed files
with
281 additions
and
87 deletions.
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 |
---|---|---|
@@ -1,48 +1,38 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { useFieldState, useFormState } from 'informed' | ||
import { useIntl } from 'react-intl' | ||
import { DataRow } from 'components/UI' | ||
import { PasswordInput, FieldLabelFactory, Toggle } from 'components/Form' | ||
import { FieldLabelFactory } from 'components/Form' | ||
import messages from './messages' | ||
import PasswordState from './Security/PasswordState' | ||
|
||
const FieldLabel = FieldLabelFactory(messages) | ||
|
||
const SettingsFieldsSecurity = ({ currentConfig }) => { | ||
const { value: isPasswordActive } = useFieldState('password.active') | ||
const { submits } = useFormState() | ||
const willValidateInline = submits > 0 | ||
const intl = useIntl() | ||
|
||
const SettingsFieldsSecurity = ({ | ||
currentConfig, | ||
changePassword, | ||
enablePassword, | ||
disablePassword, | ||
}) => { | ||
return ( | ||
<> | ||
<DataRow | ||
left={<FieldLabel itemKey="password.active" tooltip="password_tooltip" />} | ||
right={<Toggle field="password.active" initialValue={currentConfig.password.active} />} | ||
/> | ||
{isPasswordActive && ( | ||
<DataRow | ||
pt={0} | ||
right={ | ||
<PasswordInput | ||
description={intl.formatMessage({ ...messages.password_value_description })} | ||
field="password.value" | ||
initialValue={currentConfig.password.value} | ||
isRequired | ||
minLength={6} | ||
validateOnBlur={willValidateInline} | ||
validateOnChange={willValidateInline} | ||
width={200} | ||
/> | ||
} | ||
<DataRow | ||
left={<FieldLabel itemKey="password.active" tooltip="password_tooltip" />} | ||
right={ | ||
<PasswordState | ||
onChange={changePassword} | ||
onDisable={disablePassword} | ||
onEnable={enablePassword} | ||
value={currentConfig.password.active} | ||
/> | ||
)} | ||
</> | ||
} | ||
/> | ||
) | ||
} | ||
|
||
SettingsFieldsSecurity.propTypes = { | ||
changePassword: PropTypes.func.isRequired, | ||
currentConfig: PropTypes.object.isRequired, | ||
disablePassword: PropTypes.func.isRequired, | ||
enablePassword: PropTypes.func.isRequired, | ||
} | ||
|
||
export default SettingsFieldsSecurity |
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,27 @@ | ||
import { connect } from 'react-redux' | ||
import ChangePasswordDialog from 'components/Settings/Security/ChangePasswordDialog' | ||
import { | ||
changePassword as onChange, | ||
accountSelectors, | ||
clearLoginError, | ||
CHANGE_PASSWORD_DIALOG_ID, | ||
} from 'reducers/account' | ||
import { modalSelectors, closeDialog } from 'reducers/modal' | ||
|
||
const onCancel = () => closeDialog(CHANGE_PASSWORD_DIALOG_ID) | ||
|
||
const mapStateToProps = state => ({ | ||
isOpen: modalSelectors.isDialogOpen(state, CHANGE_PASSWORD_DIALOG_ID), | ||
loginError: accountSelectors.loginError(state), | ||
}) | ||
|
||
const mapDispatchToProps = { | ||
onChange, | ||
onCancel, | ||
clearLoginError, | ||
} | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(ChangePasswordDialog) |
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,27 @@ | ||
import { connect } from 'react-redux' | ||
import PasswordPromptDialog from 'components/Settings/Security/PasswordPromptDialog' | ||
import { | ||
accountSelectors, | ||
clearLoginError, | ||
disablePassword as onOk, | ||
PASSWORD_PROMPT_DIALOG_ID, | ||
} from 'reducers/account' | ||
import { modalSelectors, closeDialog } from 'reducers/modal' | ||
|
||
const onCancel = () => closeDialog(PASSWORD_PROMPT_DIALOG_ID) | ||
|
||
const mapStateToProps = state => ({ | ||
isOpen: modalSelectors.isDialogOpen(state, PASSWORD_PROMPT_DIALOG_ID), | ||
loginError: accountSelectors.loginError(state), | ||
}) | ||
|
||
const mapDispatchToProps = { | ||
onOk, | ||
onCancel, | ||
clearLoginError, | ||
} | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(PasswordPromptDialog) |
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,21 @@ | ||
import { connect } from 'react-redux' | ||
import PasswordPromptDialog from 'components/Settings/Security/PasswordPromptDialog' | ||
import { enablePassword as onOk, PASSWORD_SET_DIALOG_ID } from 'reducers/account' | ||
import { modalSelectors, closeDialog } from 'reducers/modal' | ||
|
||
const onCancel = () => closeDialog(PASSWORD_SET_DIALOG_ID) | ||
|
||
const mapStateToProps = state => ({ | ||
isOpen: modalSelectors.isDialogOpen(state, PASSWORD_SET_DIALOG_ID), | ||
isPromptMode: false, | ||
}) | ||
|
||
const mapDispatchToProps = { | ||
onOk, | ||
onCancel, | ||
} | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(PasswordPromptDialog) |
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,23 @@ | ||
import { connect } from 'react-redux' | ||
import SettingsFieldsSecurity from 'components/Settings/SettingsFieldsSecurity' | ||
import { openDialog } from 'reducers/modal' | ||
import { | ||
CHANGE_PASSWORD_DIALOG_ID, | ||
PASSWORD_PROMPT_DIALOG_ID, | ||
PASSWORD_SET_DIALOG_ID, | ||
} from 'reducers/account' | ||
|
||
const changePassword = () => openDialog(CHANGE_PASSWORD_DIALOG_ID) | ||
const disablePassword = () => openDialog(PASSWORD_PROMPT_DIALOG_ID) | ||
const enablePassword = () => openDialog(PASSWORD_SET_DIALOG_ID) | ||
|
||
const mapDispatchToProps = { | ||
changePassword, | ||
enablePassword, | ||
disablePassword, | ||
} | ||
|
||
export default connect( | ||
null, | ||
mapDispatchToProps | ||
)(SettingsFieldsSecurity) |
Oops, something went wrong.