2019-02-27 01:40:01 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2020-05-26 04:00:13 +08:00
|
|
|
import { defineMessages } from 'react-intl';
|
2019-02-27 01:40:01 +08:00
|
|
|
|
|
|
|
import Button from '/imports/ui/components/button/component';
|
|
|
|
import Modal from '/imports/ui/components/modal/simple/component';
|
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
|
|
|
|
|
|
|
import { styles } from './styles';
|
2020-12-01 00:09:35 +08:00
|
|
|
import {Meteor} from "meteor/meteor";
|
2019-02-27 01:40:01 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
2020-05-26 04:00:13 +08:00
|
|
|
intl: PropTypes.object.isRequired,
|
2019-02-27 01:40:01 +08:00
|
|
|
responseDelay: PropTypes.number.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
activityCheckTitle: {
|
|
|
|
id: 'app.user.activityCheck',
|
|
|
|
description: 'Title for activity check modal',
|
|
|
|
},
|
|
|
|
activityCheckLabel: {
|
|
|
|
id: 'app.user.activityCheck.label',
|
|
|
|
description: 'Label for activity check modal',
|
|
|
|
},
|
|
|
|
activityCheckButton: {
|
|
|
|
id: 'app.user.activityCheck.check',
|
|
|
|
description: 'Check button for activity modal',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const handleInactivityDismiss = () => makeCall('userActivitySign');
|
|
|
|
|
|
|
|
class ActivityCheck extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
const { responseDelay } = this.props;
|
|
|
|
|
|
|
|
this.state = ({
|
|
|
|
responseDelay,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.stopRemainingTime = this.stopRemainingTime.bind(this);
|
|
|
|
this.updateRemainingTime = this.updateRemainingTime.bind(this);
|
2019-03-12 20:28:11 +08:00
|
|
|
this.playAudioAlert = this.playAudioAlert.bind(this);
|
2019-02-27 01:40:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2019-03-12 20:28:11 +08:00
|
|
|
this.playAudioAlert();
|
2019-02-27 01:40:01 +08:00
|
|
|
this.interval = this.updateRemainingTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
this.stopRemainingTime();
|
|
|
|
this.interval = this.updateRemainingTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.stopRemainingTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateRemainingTime() {
|
|
|
|
const { responseDelay } = this.state;
|
|
|
|
|
|
|
|
return setInterval(() => {
|
|
|
|
const remainingTime = responseDelay - 1;
|
2020-08-03 20:44:21 +08:00
|
|
|
|
2019-02-27 01:40:01 +08:00
|
|
|
this.setState({
|
|
|
|
responseDelay: remainingTime,
|
|
|
|
});
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
stopRemainingTime() {
|
|
|
|
clearInterval(this.interval);
|
|
|
|
}
|
|
|
|
|
2019-03-12 20:28:11 +08:00
|
|
|
playAudioAlert() {
|
2020-12-01 00:09:35 +08:00
|
|
|
this.alert = new Audio(`${Meteor.settings.public.app.cdn + Meteor.settings.public.app.basename + Meteor.settings.public.app.instanceId}/resources/sounds/notify.mp3`);
|
2019-03-12 20:28:11 +08:00
|
|
|
this.alert.play();
|
|
|
|
}
|
|
|
|
|
2019-02-27 01:40:01 +08:00
|
|
|
render() {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
const { responseDelay } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
hideBorder
|
2019-03-13 02:02:52 +08:00
|
|
|
onRequestClose={handleInactivityDismiss}
|
2019-02-27 01:40:01 +08:00
|
|
|
shouldCloseOnOverlayClick={false}
|
|
|
|
shouldShowCloseButton={false}
|
|
|
|
>
|
|
|
|
<div className={styles.activityModalContent}>
|
|
|
|
<h1>{intl.formatMessage(intlMessages.activityCheckTitle)}</h1>
|
|
|
|
<p>{intl.formatMessage(intlMessages.activityCheckLabel, { 0: responseDelay })}</p>
|
|
|
|
<Button
|
|
|
|
color="primary"
|
2020-08-03 20:44:21 +08:00
|
|
|
disabled={responseDelay <= 0}
|
2019-02-27 01:40:01 +08:00
|
|
|
label={intl.formatMessage(intlMessages.activityCheckButton)}
|
|
|
|
onClick={handleInactivityDismiss}
|
|
|
|
role="button"
|
|
|
|
size="lg"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ActivityCheck.propTypes = propTypes;
|
|
|
|
|
|
|
|
export default ActivityCheck;
|