feat: upgrade the subscription plans

This commit is contained in:
Ahmed Bouhuolia
2024-07-13 18:19:18 +02:00
parent 81b26c6f13
commit eb3f23554f
14 changed files with 397 additions and 156 deletions

View File

@@ -1,17 +1,35 @@
// @ts-nocheck
import { connect } from 'react-redux';
import { MapStateToProps, connect } from 'react-redux';
import {
getPlansPeriodSelector,
getPlansSelector,
} from '@/store/plans/plans.selectors';
import { ApplicationState } from '@/store/reducers';
export default (mapState) => {
const mapStateToProps = (state, props) => {
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, props),
plans: getPlans(state),
plansPeriod: getPlansPeriod(state),
};
return mapState ? mapState(mapped, state, props) : mapped;
};
return connect(mapStateToProps);
};
}

View File

@@ -1,9 +1,22 @@
// @ts-nocheck
import { connect } from 'react-redux';
import { initSubscriptionPlans } from '@/store/plans/plans.actions';
import { MapDispatchToProps, connect } from 'react-redux';
import {
SubscriptionPlansPeriod,
changePlansPeriod,
initSubscriptionPlans,
} from '@/store/plans/plans.reducer';
export const mapDispatchToProps = (dispatch) => ({
export interface WithSubscriptionPlansActionsProps {
initSubscriptionPlans: () => void;
changeSubscriptionPlansPeriod: (period: SubscriptionPlansPeriod) => void;
}
export const mapDispatchToProps: MapDispatchToProps<
WithSubscriptionPlansActionsProps,
{}
> = (dispatch: any) => ({
initSubscriptionPlans: () => dispatch(initSubscriptionPlans()),
changeSubscriptionPlansPeriod: (period: SubscriptionPlansPeriod) =>
dispatch(changePlansPeriod({ period })),
});
export default connect(null, mapDispatchToProps);
export default connect(null, mapDispatchToProps);