popupSlice.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { createSlice, PayloadAction } from "@reduxjs/toolkit";
  2. import loadingSlice from "../loading/loadingSlice";
  3. const popupSlice = createSlice({
  4. name: "popup",
  5. initialState: {
  6. notification: {
  7. isOpen: false,
  8. isSuccess: true,
  9. title: "Notification",
  10. message: "",
  11. buttonText: "Close",
  12. hasRightButton: false,
  13. rightButtonText: "Confirm",
  14. rightButtonAction: "",
  15. },
  16. compatibilityModal: {
  17. isOpen: false,
  18. },
  19. qrModal: {
  20. isOpen: false,
  21. qrData: "",
  22. },
  23. },
  24. reducers: {
  25. openPopup: (state, action: PayloadAction<any>) => {
  26. return {
  27. ...state,
  28. notification: {
  29. isOpen: true,
  30. isSuccess: action.payload?.isSuccess ?? true,
  31. title: action.payload?.title ?? "Notification",
  32. message: action.payload?.message,
  33. buttonText: action.payload?.buttonText ?? "Close",
  34. hasRightButton: action.payload?.hasRightButton ?? false,
  35. rightButtonText: action.payload?.rightButtonText ?? "Confirm",
  36. rightButtonAction: action.payload?.rightButtonAction ?? "",
  37. },
  38. };
  39. },
  40. closePopup: (state) => {
  41. state.notification.isOpen = false;
  42. },
  43. openCompatibilityModal: (state) => {
  44. state.compatibilityModal.isOpen = true;
  45. },
  46. closeCompatibilityModal: (state) => {
  47. state.compatibilityModal.isOpen = false;
  48. },
  49. openQRModal: (state, action: PayloadAction<string>) => {
  50. state.qrModal.isOpen = true;
  51. state.qrModal.qrData = action.payload;
  52. },
  53. closeQRModal: (state) => {
  54. state.qrModal.isOpen = false;
  55. },
  56. },
  57. });
  58. export const {
  59. openPopup,
  60. closePopup,
  61. openCompatibilityModal,
  62. closeCompatibilityModal,
  63. openQRModal,
  64. closeQRModal,
  65. } = popupSlice.actions;
  66. export default popupSlice.reducer;