2020-04-25 10:49:54 +03:00
|
|
|
import React from 'react';
|
2020-09-09 20:16:04 +03:00
|
|
|
import { Card, CardBody, CardHeader, FormGroup, Input } from 'reactstrap';
|
|
|
|
import classNames from 'classnames';
|
2020-07-14 17:05:00 +03:00
|
|
|
import ToggleSwitch from '../utils/ToggleSwitch';
|
2020-08-24 18:32:20 +03:00
|
|
|
import { Settings } from './reducers/settings';
|
2020-04-25 10:49:54 +03:00
|
|
|
|
2020-08-24 18:32:20 +03:00
|
|
|
interface RealTimeUpdatesProps {
|
|
|
|
settings: Settings;
|
2020-09-09 20:16:04 +03:00
|
|
|
toggleRealTimeUpdates: (enabled: boolean) => void;
|
|
|
|
setRealTimeUpdatesInterval: (interval: number) => void;
|
2020-08-24 18:32:20 +03:00
|
|
|
}
|
2020-04-25 10:49:54 +03:00
|
|
|
|
2020-09-09 20:16:04 +03:00
|
|
|
const intervalValue = (interval?: number) => !interval ? '' : `${interval}`;
|
|
|
|
|
|
|
|
const RealTimeUpdates = (
|
|
|
|
{ settings: { realTimeUpdates }, toggleRealTimeUpdates, setRealTimeUpdatesInterval }: RealTimeUpdatesProps,
|
|
|
|
) => (
|
2020-04-25 10:49:54 +03:00
|
|
|
<Card>
|
|
|
|
<CardHeader>Real-time updates</CardHeader>
|
|
|
|
<CardBody>
|
2020-09-09 20:16:04 +03:00
|
|
|
<FormGroup>
|
|
|
|
<ToggleSwitch checked={realTimeUpdates.enabled} onChange={toggleRealTimeUpdates}>
|
|
|
|
Enable or disable real-time updates, when using Shlink v2.2.0 or newer.
|
|
|
|
</ToggleSwitch>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup className="mb-0">
|
|
|
|
<label className={classNames({ 'text-muted': !realTimeUpdates.enabled })}>
|
|
|
|
Real-time updates frequency (in minutes):
|
|
|
|
</label>
|
|
|
|
<Input
|
|
|
|
type="number"
|
|
|
|
min={0}
|
2020-09-12 09:52:03 +03:00
|
|
|
placeholder="Immediate"
|
2020-09-09 20:16:04 +03:00
|
|
|
disabled={!realTimeUpdates.enabled}
|
|
|
|
value={intervalValue(realTimeUpdates.interval)}
|
|
|
|
onChange={(e) => setRealTimeUpdatesInterval(Number(e.target.value))}
|
|
|
|
/>
|
|
|
|
{realTimeUpdates.enabled && (
|
|
|
|
<small className="form-text text-muted">
|
2020-09-12 12:55:49 +03:00
|
|
|
{realTimeUpdates.interval !== undefined && realTimeUpdates.interval > 0 && (
|
|
|
|
<span>
|
|
|
|
Updates will be reflected in the UI every <b>{realTimeUpdates.interval}</b> minute{realTimeUpdates.interval > 1 && 's'}.
|
|
|
|
</span>
|
|
|
|
)}
|
2020-09-09 20:16:04 +03:00
|
|
|
{!realTimeUpdates.interval && 'Updates will be reflected in the UI as soon as they happen.'}
|
|
|
|
</small>
|
|
|
|
)}
|
|
|
|
</FormGroup>
|
2020-04-25 10:49:54 +03:00
|
|
|
</CardBody>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
|
|
|
|
export default RealTimeUpdates;
|