2019-05-07 16:47:33 +02:00
|
|
|
import React from 'react';
|
2023-04-12 16:58:42 +03:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2022-02-08 13:25:32 +02:00
|
|
|
import Dialog from 'react-native-dialog';
|
2023-03-21 09:47:52 +02:00
|
|
|
import { connect } from 'react-redux';
|
2019-05-07 16:47:33 +02:00
|
|
|
|
2023-04-03 13:49:19 +03:00
|
|
|
import { translate } from '../../../i18n/functions';
|
2019-05-07 16:47:33 +02:00
|
|
|
import { _abstractMapStateToProps } from '../../functions';
|
2022-02-03 17:45:02 +02:00
|
|
|
import { renderHTML } from '../functions.native';
|
2019-05-07 16:47:33 +02:00
|
|
|
|
2023-04-12 16:58:42 +03:00
|
|
|
import AbstractDialog, { IProps as AbstractProps } from './AbstractDialog';
|
2023-03-23 13:24:57 +02:00
|
|
|
|
2023-04-12 16:58:42 +03:00
|
|
|
interface IProps extends AbstractProps, WithTranslation {
|
2019-05-07 16:47:33 +02: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.
|
|
|
|
|
*/
|
2023-04-12 16:58:42 +03:00
|
|
|
contentKey: string | { key: string; params: Object; };
|
|
|
|
|
}
|
2019-05-07 16:47:33 +02:00
|
|
|
|
|
|
|
|
/**
|
2022-02-08 13:25:32 +02:00
|
|
|
* Implements an alert dialog, to simply show an error or a message,
|
|
|
|
|
* then disappear on dismiss.
|
2019-05-07 16:47:33 +02:00
|
|
|
*/
|
2023-04-12 16:58:42 +03:00
|
|
|
class AlertDialog extends AbstractDialog<IProps> {
|
2019-05-07 16:47:33 +02:00
|
|
|
/**
|
2022-02-08 13:25:32 +02:00
|
|
|
* Implements React's {@link Component#render}.
|
2019-05-07 16:47:33 +02:00
|
|
|
*
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2025-03-12 10:19:11 -05:00
|
|
|
override render() {
|
2022-02-08 13:25:32 +02:00
|
|
|
const { contentKey, t } = this.props;
|
2019-05-07 16:47:33 +02:00
|
|
|
const content
|
|
|
|
|
= typeof contentKey === 'string'
|
|
|
|
|
? t(contentKey)
|
2022-02-03 17:45:02 +02:00
|
|
|
: renderHTML(t(contentKey.key, contentKey.params));
|
2019-05-07 16:47:33 +02:00
|
|
|
|
|
|
|
|
return (
|
2022-06-20 11:50:40 +02:00
|
|
|
<Dialog.Container
|
2023-09-04 15:42:41 +03:00
|
|
|
coverScreen = { false }
|
2022-06-20 11:50:40 +02:00
|
|
|
visible = { true }>
|
|
|
|
|
<Dialog.Description>
|
|
|
|
|
{ content }
|
|
|
|
|
</Dialog.Description>
|
|
|
|
|
<Dialog.Button
|
|
|
|
|
label = { t('dialog.Ok') }
|
|
|
|
|
onPress = { this._onSubmit } />
|
|
|
|
|
</Dialog.Container>
|
2019-05-07 16:47:33 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default translate(connect(_abstractMapStateToProps)(AlertDialog));
|