w-aura/src/store/payment.ts

42 lines
1.2 KiB
TypeScript

import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans";
import { createSlice, createSelector } from "@reduxjs/toolkit";
import type { PayloadAction } from "@reduxjs/toolkit";
interface IPayment {
selectedPrice: number | null;
isDiscount: boolean;
activeSubPlan: ISubscriptionPlan | null;
}
const initialState: IPayment = {
selectedPrice: null,
isDiscount: false,
activeSubPlan: null
};
const paymentSlice = createSlice({
name: "payment",
initialState,
reducers: {
update(state, action: PayloadAction<Partial<IPayment>>) {
return { ...state, ...action.payload };
},
},
extraReducers: (builder) => builder.addCase("reset", () => initialState),
});
export const { actions } = paymentSlice;
export const selectSelectedPrice = createSelector(
(state: { payment: IPayment }) => state.payment.selectedPrice,
(payment) => payment
);
export const selectActiveSubPlan = createSelector(
(state: { payment: IPayment }) => state.payment.activeSubPlan,
(payment) => payment
);
export const selectIsDiscount = createSelector(
(state: { payment: IPayment }) => state.payment.isDiscount,
(payment) => payment
);
export default paymentSlice.reducer;