Migrated settings module to TS

This commit is contained in:
Alejandro Celaya
2020-08-24 17:32:20 +02:00
parent 0b4a348969
commit fefa4e7848
7 changed files with 40 additions and 40 deletions

View File

@@ -1,15 +1,14 @@
import React from 'react';
import { Card, CardBody, CardHeader } from 'reactstrap';
import PropTypes from 'prop-types';
import ToggleSwitch from '../utils/ToggleSwitch';
import { SettingsType } from './reducers/settings';
import { Settings } from './reducers/settings';
const propTypes = {
settings: SettingsType,
setRealTimeUpdates: PropTypes.func,
};
interface RealTimeUpdatesProps {
settings: Settings;
setRealTimeUpdates: (enabled: boolean) => void;
}
const RealTimeUpdates = ({ settings: { realTimeUpdates }, setRealTimeUpdates }) => (
const RealTimeUpdates = ({ settings: { realTimeUpdates }, setRealTimeUpdates }: RealTimeUpdatesProps) => (
<Card>
<CardHeader>Real-time updates</CardHeader>
<CardBody>
@@ -20,6 +19,4 @@ const RealTimeUpdates = ({ settings: { realTimeUpdates }, setRealTimeUpdates })
</Card>
);
RealTimeUpdates.propTypes = propTypes;
export default RealTimeUpdates;

View File

@@ -1,7 +1,7 @@
import React from 'react';
import React, { FC } from 'react';
import NoMenuLayout from '../common/NoMenuLayout';
const Settings = (RealTimeUpdates) => () => (
const Settings = (RealTimeUpdates: FC) => () => (
<NoMenuLayout>
<RealTimeUpdates />
</NoMenuLayout>

View File

@@ -1,25 +0,0 @@
import { handleActions } from 'redux-actions';
import PropTypes from 'prop-types';
export const SET_REAL_TIME_UPDATES = 'shlink/realTimeUpdates/SET_REAL_TIME_UPDATES';
export const SettingsType = PropTypes.shape({
realTimeUpdates: PropTypes.shape({
enabled: PropTypes.bool.isRequired,
}),
});
const initialState = {
realTimeUpdates: {
enabled: true,
},
};
export default handleActions({
[SET_REAL_TIME_UPDATES]: (state, { realTimeUpdates }) => ({ ...state, realTimeUpdates }),
}, initialState);
export const setRealTimeUpdates = (enabled) => ({
type: SET_REAL_TIME_UPDATES,
realTimeUpdates: { enabled },
});

View File

@@ -0,0 +1,27 @@
import { handleActions } from 'redux-actions';
import { Action } from 'redux';
export const SET_REAL_TIME_UPDATES = 'shlink/realTimeUpdates/SET_REAL_TIME_UPDATES';
interface RealTimeUpdates {
enabled: boolean;
}
export interface Settings {
realTimeUpdates: RealTimeUpdates;
}
const initialState: Settings = {
realTimeUpdates: {
enabled: true,
},
};
export default handleActions<Settings, any>({
[SET_REAL_TIME_UPDATES]: (state, { realTimeUpdates }: any) => ({ ...state, realTimeUpdates }),
}, initialState);
export const setRealTimeUpdates = (enabled: boolean): Action & Settings => ({
type: SET_REAL_TIME_UPDATES,
realTimeUpdates: { enabled },
});