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>) { 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;