2018-10-18 08:28:08 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { View, Text, TouchableOpacity } from 'react-native';
|
|
|
|
|
2019-01-22 10:35:28 +00:00
|
|
|
import { StyleType } from '../../../styles';
|
|
|
|
|
2018-10-18 08:28:08 +00:00
|
|
|
import BaseDialog, { type Props as BaseProps } from './BaseDialog';
|
|
|
|
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
|
|
|
t: Function
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract dialog to submit something. E.g. a confirmation or a form.
|
|
|
|
*/
|
|
|
|
class BaseSubmitDialog<P: Props, S: *> extends BaseDialog<P, S> {
|
|
|
|
/**
|
|
|
|
* Returns the title key of the submit button.
|
|
|
|
*
|
|
|
|
* NOTE: Please do not change this, this should be consistent accross the
|
|
|
|
* application. This method is here to be able to be overriden ONLY by the
|
|
|
|
* {@code ConfirmDialog}.
|
|
|
|
*
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
_getSubmitButtonKey() {
|
|
|
|
return 'dialog.Ok';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders additional buttons, if any - may be overwritten by children.
|
|
|
|
*
|
|
|
|
* @returns {?ReactElement}
|
|
|
|
*/
|
|
|
|
_renderAdditionalButtons() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements {@code BaseDialog._renderContent}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
_renderContent() {
|
2019-01-22 10:35:28 +00:00
|
|
|
const { _dialogStyles, t } = this.props;
|
2018-10-18 08:28:08 +00:00
|
|
|
const additionalButtons = this._renderAdditionalButtons();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<View style = { brandedDialog.mainWrapper }>
|
|
|
|
{ this._renderSubmittable() }
|
|
|
|
</View>
|
|
|
|
<View style = { brandedDialog.buttonWrapper }>
|
|
|
|
{ additionalButtons }
|
|
|
|
<TouchableOpacity
|
|
|
|
disabled = { this.props.okDisabled }
|
|
|
|
onPress = { this._onSubmit }
|
|
|
|
style = { [
|
2019-03-05 18:16:23 +00:00
|
|
|
_dialogStyles.button,
|
2018-10-18 08:28:08 +00:00
|
|
|
additionalButtons
|
|
|
|
? null : brandedDialog.buttonFarLeft,
|
|
|
|
brandedDialog.buttonFarRight
|
|
|
|
] }>
|
2019-03-05 18:16:23 +00:00
|
|
|
<Text style = { _dialogStyles.buttonLabel }>
|
2018-10-18 08:28:08 +00:00
|
|
|
{ t(this._getSubmitButtonKey()) }
|
|
|
|
</Text>
|
|
|
|
</TouchableOpacity>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_onCancel: () => void;
|
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
_onSubmit: () => boolean;
|
2018-10-18 08:28:08 +00:00
|
|
|
|
|
|
|
_renderHTML: string => Object | string
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the actual content of the dialog defining what is about to be
|
|
|
|
* submitted. E.g. a simple confirmation (text, properly wrapped) or a
|
|
|
|
* complex form.
|
|
|
|
*
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
_renderSubmittable: () => Object
|
|
|
|
}
|
|
|
|
|
|
|
|
export default BaseSubmitDialog;
|