2020-12-08 21:10:29 +03:00
|
|
|
import { FormGroup, Input } from 'reactstrap';
|
2020-09-09 20:16:04 +03:00
|
|
|
import classNames from 'classnames';
|
2020-07-14 17:05:00 +03:00
|
|
|
import ToggleSwitch from '../utils/ToggleSwitch';
|
2020-12-08 21:10:29 +03:00
|
|
|
import { SimpleCard } from '../utils/SimpleCard';
|
2022-03-05 16:43:43 +03:00
|
|
|
import { FormText } from '../utils/forms/FormText';
|
2022-03-05 21:57:48 +03:00
|
|
|
import { LabeledFormGroup } from '../utils/forms/LabeledFormGroup';
|
2022-03-06 12:58:30 +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}`;
|
|
|
|
|
2021-12-25 12:49:12 +03:00
|
|
|
const RealTimeUpdatesSettings = (
|
2020-09-09 20:16:04 +03:00
|
|
|
{ settings: { realTimeUpdates }, toggleRealTimeUpdates, setRealTimeUpdatesInterval }: RealTimeUpdatesProps,
|
|
|
|
) => (
|
2021-03-06 19:30:21 +03:00
|
|
|
<SimpleCard title="Real-time updates" className="h-100">
|
2020-12-08 21:10:29 +03:00
|
|
|
<FormGroup>
|
|
|
|
<ToggleSwitch checked={realTimeUpdates.enabled} onChange={toggleRealTimeUpdates}>
|
2021-11-06 12:55:01 +03:00
|
|
|
Enable or disable real-time updates.
|
2022-03-05 16:04:01 +03:00
|
|
|
<FormText>
|
2021-02-16 21:25:23 +03:00
|
|
|
Real-time updates are currently being <b>{realTimeUpdates.enabled ? 'processed' : 'ignored'}</b>.
|
2022-03-05 16:04:01 +03:00
|
|
|
</FormText>
|
2020-12-08 21:10:29 +03:00
|
|
|
</ToggleSwitch>
|
|
|
|
</FormGroup>
|
2022-03-05 21:57:48 +03:00
|
|
|
<LabeledFormGroup
|
|
|
|
noMargin
|
|
|
|
label="Real-time updates frequency (in minutes):"
|
|
|
|
labelClassName={classNames('form-label', { 'text-muted': !realTimeUpdates.enabled })}
|
|
|
|
>
|
2020-12-08 21:10:29 +03:00
|
|
|
<Input
|
|
|
|
type="number"
|
|
|
|
min={0}
|
|
|
|
placeholder="Immediate"
|
|
|
|
disabled={!realTimeUpdates.enabled}
|
|
|
|
value={intervalValue(realTimeUpdates.interval)}
|
2021-09-20 22:23:39 +03:00
|
|
|
onChange={({ target }) => setRealTimeUpdatesInterval(Number(target.value))}
|
2020-12-08 21:10:29 +03:00
|
|
|
/>
|
|
|
|
{realTimeUpdates.enabled && (
|
2022-03-05 16:04:01 +03:00
|
|
|
<FormText>
|
2020-12-08 21:10:29 +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>
|
|
|
|
)}
|
|
|
|
{!realTimeUpdates.interval && 'Updates will be reflected in the UI as soon as they happen.'}
|
2022-03-05 16:04:01 +03:00
|
|
|
</FormText>
|
2020-12-08 21:10:29 +03:00
|
|
|
)}
|
2022-03-05 21:57:48 +03:00
|
|
|
</LabeledFormGroup>
|
2020-12-08 21:10:29 +03:00
|
|
|
</SimpleCard>
|
2020-04-25 10:49:54 +03:00
|
|
|
);
|
|
|
|
|
2021-12-25 12:49:12 +03:00
|
|
|
export default RealTimeUpdatesSettings;
|