2019-07-30 09:35:42 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { View } from 'react-native';
|
2017-09-10 18:56:27 +02:00
|
|
|
import PopupDialog, { DialogTitle, DialogButton } from 'react-native-popup-dialog';
|
2019-07-30 09:35:42 +02:00
|
|
|
import DatePicker from 'react-native-datepicker';
|
2017-09-10 18:56:27 +02:00
|
|
|
import moment from 'moment';
|
|
|
|
import { _ } from 'lib/locale.js';
|
2019-10-30 12:24:06 +02:00
|
|
|
const { time } = require('lib/time-utils.js');
|
2017-09-10 18:56:27 +02:00
|
|
|
|
2019-07-12 20:36:12 +02:00
|
|
|
class SelectDateTimeDialog extends React.PureComponent {
|
2017-09-10 18:56:27 +02:00
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.dialog_ = null;
|
|
|
|
this.shown_ = false;
|
|
|
|
this.state = { date: null };
|
2019-07-12 20:36:12 +02:00
|
|
|
|
|
|
|
this.onReject = this.onReject.bind(this);
|
2017-09-10 18:56:27 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 18:38:19 +02:00
|
|
|
UNSAFE_componentWillReceiveProps(newProps) {
|
2017-09-10 18:56:27 +02:00
|
|
|
if (newProps.date != this.state.date) {
|
|
|
|
this.setState({ date: newProps.date });
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('shown' in newProps) {
|
|
|
|
this.show(newProps.shown);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
show(doShow = true) {
|
|
|
|
if (doShow) {
|
|
|
|
this.dialog_.show();
|
|
|
|
} else {
|
|
|
|
this.dialog_.dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.shown_ = doShow;
|
|
|
|
}
|
|
|
|
|
|
|
|
dismiss() {
|
|
|
|
this.show(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
dateTimeFormat() {
|
2019-10-30 12:24:06 +02:00
|
|
|
return time.dateTimeFormat();
|
2017-09-10 18:56:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stringToDate(s) {
|
|
|
|
return moment(s, this.dateTimeFormat()).toDate();
|
|
|
|
}
|
|
|
|
|
|
|
|
onAccept() {
|
|
|
|
if (this.props.onAccept) this.props.onAccept(this.state.date);
|
|
|
|
}
|
|
|
|
|
|
|
|
onReject() {
|
|
|
|
if (this.props.onReject) this.props.onReject();
|
|
|
|
}
|
|
|
|
|
|
|
|
onClear() {
|
|
|
|
if (this.props.onAccept) this.props.onAccept(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-07-30 09:35:42 +02:00
|
|
|
const clearAlarmText = _('Clear alarm'); // For unknown reasons, this particular string doesn't get translated if it's directly in the text property below
|
2018-10-05 20:17:49 +02:00
|
|
|
|
2017-09-10 18:56:27 +02:00
|
|
|
const popupActions = [
|
2019-07-30 09:35:42 +02:00
|
|
|
<DialogButton text={_('Save alarm')} align="center" onPress={() => this.onAccept()} key="saveButton" />,
|
2018-10-05 20:17:49 +02:00
|
|
|
<DialogButton text={clearAlarmText} align="center" onPress={() => this.onClear()} key="clearButton" />,
|
2019-07-30 09:35:42 +02:00
|
|
|
<DialogButton text={_('Cancel')} align="center" onPress={() => this.onReject()} key="cancelButton" />,
|
2017-09-10 18:56:27 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<PopupDialog
|
|
|
|
ref={(dialog) => { this.dialog_ = dialog; }}
|
|
|
|
dialogTitle={<DialogTitle title={_('Set alarm')} />}
|
|
|
|
actions={popupActions}
|
2019-07-12 20:36:12 +02:00
|
|
|
dismissOnTouchOutside={false}
|
2017-09-10 18:56:27 +02:00
|
|
|
width={0.9}
|
|
|
|
height={350}
|
2019-07-30 09:35:42 +02:00
|
|
|
>
|
2020-02-05 00:09:34 +02:00
|
|
|
<View style={{ flex: 1, margin: 20, alignItems: 'center' }}>
|
2017-09-10 18:56:27 +02:00
|
|
|
<DatePicker
|
|
|
|
date={this.state.date}
|
|
|
|
mode="datetime"
|
|
|
|
placeholder={_('Select date')}
|
|
|
|
format={this.dateTimeFormat()}
|
|
|
|
confirmBtnText={_('Confirm')}
|
|
|
|
cancelBtnText={_('Cancel')}
|
|
|
|
onDateChange={(date) => { this.setState({ date: this.stringToDate(date) }); }}
|
2020-02-05 00:09:34 +02:00
|
|
|
style={{ width: 300 }}
|
2019-06-14 08:22:25 +02:00
|
|
|
customStyles={{
|
|
|
|
btnConfirm: {
|
|
|
|
paddingVertical: 0,
|
|
|
|
},
|
|
|
|
btnCancel: {
|
|
|
|
paddingVertical: 0,
|
|
|
|
},
|
|
|
|
}}
|
2017-09-10 18:56:27 +02:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
</PopupDialog>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
export { SelectDateTimeDialog };
|