diff --git a/app/autofill.js b/app/autofill.js index 33623d0a247..3f39ec9290c 100644 --- a/app/autofill.js +++ b/app/autofill.js @@ -32,13 +32,13 @@ module.exports.removeAutofillAddress = (guid) => { session.defaultSession.autofill.removeProfile(guid) } -module.exports.addAutofillCreditCard = (detail, guid) => { +module.exports.addAutofillCreditCard = (detail) => { session.defaultSession.autofill.addCreditCard({ - name: detail.name, - card_number: detail.card, - expiration_month: detail.month, - expiration_year: detail.year, - guid: guid + name: detail.get('name'), + card_number: detail.get('card'), + expiration_month: detail.get('month'), + expiration_year: detail.get('year'), + guid: detail.get('guid') }) } diff --git a/app/renderer/components/autofill/autofillCreditCardPanel.js b/app/renderer/components/autofill/autofillCreditCardPanel.js index 1ba303beeb0..064ec72e443 100644 --- a/app/renderer/components/autofill/autofillCreditCardPanel.js +++ b/app/renderer/components/autofill/autofillCreditCardPanel.js @@ -3,17 +3,13 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ const React = require('react') -const ImmutableComponent = require('../immutableComponent') -const Dialog = require('../common/dialog') -const Button = require('../common/button') -const windowActions = require('../../../../js/actions/windowActions') -const appActions = require('../../../../js/actions/appActions') -const KeyCodes = require('../../../common/constants/keyCodes') - +const Immutable = require('immutable') const {StyleSheet, css} = require('aphrodite/no-important') -const commonStyles = require('../styles/commonStyles') -const globalStyles = require('../styles/global') +// Component +const ReduxComponent = require('../reduxComponent') +const Dialog = require('../common/dialog') +const Button = require('../common/button') const { CommonForm, CommonFormSection, @@ -24,81 +20,113 @@ const { commonFormStyles } = require('../common/commonForm') -class AutofillCreditCardPanel extends ImmutableComponent { - constructor () { - super() - this.onNameChange = this.onNameChange.bind(this) - this.onCardChange = this.onCardChange.bind(this) - this.onExpMonthChange = this.onExpMonthChange.bind(this) - this.onExpYearChange = this.onExpYearChange.bind(this) +// Actions +const windowActions = require('../../../../js/actions/windowActions') +const appActions = require('../../../../js/actions/appActions') + +// Constants +const KeyCodes = require('../../../common/constants/keyCodes') + +// Styles +const commonStyles = require('../styles/commonStyles') +const globalStyles = require('../styles/global') + +class AutofillCreditCardPanel extends React.Component { + constructor (props) { + super(props) this.onKeyDown = this.onKeyDown.bind(this) this.onSave = this.onSave.bind(this) - this.onClick = this.onClick.bind(this) } + onNameChange (e) { - let currentDetail = this.props.currentDetail - currentDetail = currentDetail.set('name', e.target.value) - if (this.nameOnCard.value !== e.target.value) { - this.nameOnCard.value = e.target.value - } - windowActions.setAutofillCreditCardDetail(currentDetail, this.props.originalDetail) + windowActions.setAutofillCreditCardDetail('name', e.target.value) } + onCardChange (e) { - let currentDetail = this.props.currentDetail - currentDetail = currentDetail.set('card', e.target.value) - windowActions.setAutofillCreditCardDetail(currentDetail, this.props.originalDetail) + windowActions.setAutofillCreditCardDetail('card', e.target.value) } + onExpMonthChange (e) { - let currentDetail = this.props.currentDetail - currentDetail = currentDetail.set('month', e.target.value) - windowActions.setAutofillCreditCardDetail(currentDetail, this.props.originalDetail) + windowActions.setAutofillCreditCardDetail('month', e.target.value) } + onExpYearChange (e) { - let currentDetail = this.props.currentDetail - currentDetail = currentDetail.set('year', e.target.value) - windowActions.setAutofillCreditCardDetail(currentDetail, this.props.originalDetail) + windowActions.setAutofillCreditCardDetail('year', e.target.value) } + onKeyDown (e) { switch (e.keyCode) { case KeyCodes.ENTER: this.onSave() break case KeyCodes.ESC: - this.props.onHide() + this.onHide() break } } + onSave () { - appActions.addAutofillCreditCard(this.props.currentDetail, this.props.originalDetail) - this.props.onHide() + appActions.addAutofillCreditCard(Immutable.fromJS({ + name: this.props.name, + card: this.props.card, + month: this.props.month, + year: this.props.year, + guid: this.props.guid + })) + this.onHide() } + onClick (e) { e.stopPropagation() } - get disableSaveButton () { - let currentDetail = this.props.currentDetail - if (!currentDetail.size) return true - if (!currentDetail.get('name') && !currentDetail.get('card')) return true - return false - } + componentDidMount () { this.nameOnCard.focus() - this.nameOnCard.value = this.props.currentDetail.get('name') || '' } - render () { - var ExpMonth = [] + + onHide () { + windowActions.setAutofillCreditCardDetail() + } + + get expirationMonths () { + const expMonth = [] for (let i = 1; i <= 12; ++i) { let mon = i < 10 ? '0' + i.toString() : i.toString() - ExpMonth.push() + expMonth.push() } - var ExpYear = [] - var today = new Date() - var year = today.getFullYear() + + return expMonth + } + + get expirationYears () { + const expYear = [] + const today = new Date() + const year = today.getFullYear() for (let i = year; i <= year + 9; ++i) { - ExpYear.push() + expYear.push() } - return + return expYear + } + + mergeProps (state, ownProps) { + const currentWindow = state.get('currentWindow') + const detail = currentWindow.get('autofillCreditCardDetail', Immutable.Map()) + + const props = {} + props.name = detail.get('name', '') + props.card = detail.get('card', '') + props.month = detail.get('month') + props.year = detail.get('year') + props.guid = detail.get('guid', '-1') + props.disableSaveButton = detail.isEmpty() || + (!detail.get('name') && !detail.get('card')) + + return props + } + + render () { + return
{ this.nameOnCard = nameOnCard }} + defaultValue={this.props.name} + type='text' data-test-id='creditCardName' spellCheck='false' onKeyDown={this.onKeyDown} onChange={this.onNameChange} - ref={(nameOnCard) => { this.nameOnCard = nameOnCard }} />
@@ -154,17 +184,19 @@ class AutofillCreditCardPanel extends ImmutableComponent { styles.expirationDate__dropdowns )}> - {ExpMonth} + data-test-id='expMonthSelect' + > + {this.expirationMonths}
- {ExpYear} + data-test-id='expYearSelect' + > + {this.expirationYears}
@@ -174,10 +206,10 @@ class AutofillCreditCardPanel extends ImmutableComponent {