w-aura/src/store/payment.ts
Денис Катаев 1ccc5aa835 Preview/discount pages
2024-02-10 02:30:02 +00:00

49 lines
1.5 KiB
TypeScript

import { ISubscriptionPlan } from "@/api/resources/SubscriptionPlans";
import { SubscriptionReceipt } from "@/api/resources/UserSubscriptionReceipts";
import { createSlice, createSelector } from "@reduxjs/toolkit";
import type { PayloadAction } from "@reduxjs/toolkit";
interface IPayment {
selectedPrice: number | null;
isDiscount: boolean;
activeSubPlan: ISubscriptionPlan | null;
subscriptionReceipt: SubscriptionReceipt | null;
}
const initialState: IPayment = {
selectedPrice: null,
isDiscount: false,
activeSubPlan: null,
subscriptionReceipt: 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 const selectSubscriptionReceipt = createSelector(
(state: { payment: IPayment }) => state.payment.subscriptionReceipt,
(payment) => payment
);
export default paymentSlice.reducer;