mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-21 05:56:20 +00:00
Migrated settings module to TS
This commit is contained in:
@@ -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;
|
||||
@@ -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>
|
||||
@@ -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 },
|
||||
});
|
||||
27
src/settings/reducers/settings.ts
Normal file
27
src/settings/reducers/settings.ts
Normal 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 },
|
||||
});
|
||||
Reference in New Issue
Block a user