mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 20:30:33 +00:00
36 lines
958 B
TypeScript
36 lines
958 B
TypeScript
import { MapStateToProps, connect } from 'react-redux';
|
|
import {
|
|
getPlansPeriodSelector,
|
|
getPlansSelector,
|
|
} from '@/store/plans/plans.selectors';
|
|
import { ApplicationState } from '@/store/reducers';
|
|
|
|
export interface WithPlansProps {
|
|
plans: ReturnType<ReturnType<typeof getPlansSelector>>;
|
|
plansPeriod: ReturnType<ReturnType<typeof getPlansPeriodSelector>>;
|
|
}
|
|
|
|
type MapState<Props> = (
|
|
mapped: WithPlansProps,
|
|
state: ApplicationState,
|
|
props: Props,
|
|
) => any;
|
|
|
|
export function withPlans<Props>(mapState?: MapState<Props>) {
|
|
const mapStateToProps: MapStateToProps<
|
|
WithPlansProps,
|
|
Props,
|
|
ApplicationState
|
|
> = (state, props) => {
|
|
const getPlans = getPlansSelector();
|
|
const getPlansPeriod = getPlansPeriodSelector();
|
|
|
|
const mapped = {
|
|
plans: getPlans(state),
|
|
plansPeriod: getPlansPeriod(state),
|
|
};
|
|
return mapState ? mapState(mapped, state, props) : mapped;
|
|
};
|
|
return connect(mapStateToProps);
|
|
}
|