2018-10-18 08:28:08 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { Text, TouchableOpacity } from 'react-native';
|
|
|
|
|
|
|
|
import { translate } from '../../../i18n';
|
2019-03-21 16:38:29 +00:00
|
|
|
import { connect } from '../../../redux';
|
2019-01-22 10:35:28 +00:00
|
|
|
import { StyleType } from '../../../styles';
|
|
|
|
|
|
|
|
import { _abstractMapStateToProps } from '../../functions';
|
2018-10-18 08:28:08 +00:00
|
|
|
|
|
|
|
import { type Props as BaseProps } from './BaseDialog';
|
|
|
|
import BaseSubmitDialog from './BaseSubmitDialog';
|
|
|
|
import { brandedDialog } from './styles';
|
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
type Props = BaseProps & {
|
2018-10-18 08:28:08 +00:00
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
/**
|
|
|
|
* The color-schemed stylesheet of the feature.
|
|
|
|
*/
|
|
|
|
_dialogStyles: StyleType,
|
|
|
|
|
2018-10-18 08:28:08 +00:00
|
|
|
/**
|
|
|
|
* Untranslated i18n key of the content to be displayed.
|
|
|
|
*
|
|
|
|
* NOTE: This dialog also adds support to Object type keys that will be
|
|
|
|
* translated using the provided params. See i18n function
|
|
|
|
* {@code translate(string, Object)} for more details.
|
|
|
|
*/
|
|
|
|
contentKey: string | { key: string, params: Object},
|
|
|
|
|
|
|
|
t: Function
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a confirm dialog component.
|
|
|
|
*/
|
|
|
|
class ConfirmDialog extends BaseSubmitDialog<Props, *> {
|
|
|
|
/**
|
|
|
|
* Returns the title key of the submit button.
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
_getSubmitButtonKey() {
|
2019-03-06 16:28:59 +00:00
|
|
|
return this.props.okKey || 'dialog.confirmYes';
|
2018-10-18 08:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_onCancel: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the 'No' button.
|
|
|
|
*
|
|
|
|
* NOTE: The {@code ConfirmDialog} is the only dialog right now that
|
|
|
|
* renders 2 buttons, mainly for clarity.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
_renderAdditionalButtons() {
|
2019-03-06 16:28:59 +00:00
|
|
|
const { _dialogStyles, cancelKey, t } = this.props;
|
2018-10-18 08:28:08 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
onPress = { this._onCancel }
|
|
|
|
style = { [
|
2019-03-05 18:16:23 +00:00
|
|
|
_dialogStyles.button,
|
2018-10-18 08:28:08 +00:00
|
|
|
brandedDialog.buttonFarLeft,
|
2019-01-22 10:35:28 +00:00
|
|
|
_dialogStyles.buttonSeparator
|
2018-10-18 08:28:08 +00:00
|
|
|
] }>
|
2019-03-05 18:16:23 +00:00
|
|
|
<Text style = { _dialogStyles.buttonLabel }>
|
2019-03-06 16:28:59 +00:00
|
|
|
{ t(cancelKey || 'dialog.confirmNo') }
|
2018-10-18 08:28:08 +00:00
|
|
|
</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements {@code BaseSubmitDialog._renderSubmittable}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
_renderSubmittable() {
|
2019-03-06 16:28:59 +00:00
|
|
|
if (this.props.children) {
|
|
|
|
return this.props.children;
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
const { _dialogStyles, contentKey, t } = this.props;
|
2018-10-18 08:28:08 +00:00
|
|
|
const content
|
|
|
|
= typeof contentKey === 'string'
|
|
|
|
? t(contentKey)
|
|
|
|
: this._renderHTML(t(contentKey.key, contentKey.params));
|
|
|
|
|
|
|
|
return (
|
2019-01-22 10:35:28 +00:00
|
|
|
<Text style = { _dialogStyles.text }>
|
2018-10-18 08:28:08 +00:00
|
|
|
{ content }
|
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderHTML: string => Object | string
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
export default translate(connect(_abstractMapStateToProps)(ConfirmDialog));
|