diff --git a/src/settings/RealTimeUpdates.js b/src/settings/RealTimeUpdates.js
index 80d65fbe..d2de544a 100644
--- a/src/settings/RealTimeUpdates.js
+++ b/src/settings/RealTimeUpdates.js
@@ -1,7 +1,7 @@
import React from 'react';
import { Card, CardBody, CardHeader } from 'reactstrap';
import PropTypes from 'prop-types';
-import Checkbox from '../utils/Checkbox';
+import ToggleSwitch from '../utils/ToggleSwitch';
import { SettingsType } from './reducers/settings';
const propTypes = {
@@ -13,9 +13,9 @@ const RealTimeUpdates = ({ settings: { realTimeUpdates }, setRealTimeUpdates })
Real-time updates
-
+
Enable or disable real-time updates, when using Shlink v2.2.0 or newer.
-
+
);
diff --git a/src/utils/BooleanControl.js b/src/utils/BooleanControl.js
new file mode 100644
index 00000000..3daa7d9f
--- /dev/null
+++ b/src/utils/BooleanControl.js
@@ -0,0 +1,36 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import classNames from 'classnames';
+import { v4 as uuid } from 'uuid';
+
+export const basePropTypes = {
+ checked: PropTypes.bool.isRequired,
+ onChange: PropTypes.func.isRequired,
+ children: PropTypes.oneOfType([ PropTypes.string, PropTypes.node ]),
+ className: PropTypes.string,
+};
+
+const propTypes = {
+ ...basePropTypes,
+ type: PropTypes.oneOf([ 'switch', 'checkbox' ]).isRequired,
+};
+
+const BooleanControl = ({ checked, onChange, className, children, type }) => {
+ const id = uuid();
+ const onChecked = (e) => onChange(e.target.checked, e);
+ const typeClasses = {
+ 'custom-switch': type === 'switch',
+ 'custom-checkbox': type === 'checkbox',
+ };
+
+ return (
+
+
+
+
+ );
+};
+
+BooleanControl.propTypes = propTypes;
+
+export default BooleanControl;
diff --git a/src/utils/Checkbox.js b/src/utils/Checkbox.js
index 0c39e5e4..b253bdfc 100644
--- a/src/utils/Checkbox.js
+++ b/src/utils/Checkbox.js
@@ -1,27 +1,8 @@
import React from 'react';
-import PropTypes from 'prop-types';
-import classNames from 'classnames';
-import { v4 as uuid } from 'uuid';
+import BooleanControl, { basePropTypes } from './BooleanControl';
-const propTypes = {
- checked: PropTypes.bool.isRequired,
- onChange: PropTypes.func.isRequired,
- children: PropTypes.oneOfType([ PropTypes.string, PropTypes.node ]),
- className: PropTypes.string,
-};
+const Checkbox = (props) => ;
-const Checkbox = ({ checked, onChange, className, children }) => {
- const id = uuid();
- const onChecked = (e) => onChange(e.target.checked, e);
-
- return (
-
-
-
-
- );
-};
-
-Checkbox.propTypes = propTypes;
+Checkbox.propTypes = basePropTypes;
export default Checkbox;
diff --git a/src/utils/ToggleSwitch.js b/src/utils/ToggleSwitch.js
new file mode 100644
index 00000000..8f45e96f
--- /dev/null
+++ b/src/utils/ToggleSwitch.js
@@ -0,0 +1,8 @@
+import React from 'react';
+import BooleanControl, { basePropTypes } from './BooleanControl';
+
+const ToggleSwitch = (props) => ;
+
+ToggleSwitch.propTypes = basePropTypes;
+
+export default ToggleSwitch;
diff --git a/src/visits/helpers/LineChartCard.js b/src/visits/helpers/LineChartCard.js
index d3f3593e..bd4a1808 100644
--- a/src/visits/helpers/LineChartCard.js
+++ b/src/visits/helpers/LineChartCard.js
@@ -17,7 +17,7 @@ import { fillTheGaps } from '../../utils/helpers/visits';
import './LineChartCard.scss';
import { useToggle } from '../../utils/helpers/hooks';
import { rangeOf } from '../../utils/utils';
-import Checkbox from '../../utils/Checkbox';
+import ToggleSwitch from '../../utils/ToggleSwitch';
const propTypes = {
title: PropTypes.string,
@@ -167,9 +167,9 @@ const LineChartCard = ({ title, visits, highlightedVisits, highlightedLabel = 'S
-
+
Skip dates with no visits
-
+
diff --git a/test/visits/helpers/LineChartCard.test.js b/test/visits/helpers/LineChartCard.test.js
index 5d692f5b..348ba365 100644
--- a/test/visits/helpers/LineChartCard.test.js
+++ b/test/visits/helpers/LineChartCard.test.js
@@ -4,7 +4,7 @@ import { CardHeader, DropdownItem } from 'reactstrap';
import { Line } from 'react-chartjs-2';
import moment from 'moment';
import LineChartCard from '../../../src/visits/helpers/LineChartCard';
-import Checkbox from '../../../src/utils/Checkbox';
+import ToggleSwitch from '../../../src/utils/ToggleSwitch';
describe('', () => {
let wrapper;
@@ -90,7 +90,7 @@ describe('', () => {
]);
expect(wrapper.find(Line).prop('data').labels).toHaveLength(2);
- wrapper.find(Checkbox).simulate('change');
+ wrapper.find(ToggleSwitch).simulate('change');
expect(wrapper.find(Line).prop('data').labels).toHaveLength(4);
});
});