aboutsummaryrefslogtreecommitdiff
path: root/src/store/reducers/userReducer.ts
blob: 617c60bed7f4c8c5d62f5722289508e61c28b392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import {createSlice} from '@reduxjs/toolkit';
import {NO_USER_DATA} from '../initialStates';

/**
 * A reducer is a pure function with the sole responsibility of updating the state and nothing else.
 * No side effects are allowed.
 */

/**
 * Actions are a way to indicate what just happened / what is going to happen and update the state accordingly.
 */

/**
 * Create slice allows us
 * To initialise State , create Actions and Reducers in one go
 * Read more here https://redux.js.org/introduction/installation
 */

const userDataSlice = createSlice({
  name: 'userData',
  initialState: NO_USER_DATA,
  reducers: {
    userLoggedIn: (state, action) => {
      state.user = action.payload;
    },

    userDetailsFetched: (state, action) => {
      state.profile = action.payload.profile;
      state.avatar = action.payload.avatar;
      state.cover = action.payload.cover;
    },

    socialEdited: (state, action) => {
      const {social, value} = action.payload;
      switch (social) {
        case 'Snapchat':
          state.profile.snapchat = value;
          break;
        case 'TikTok':
          state.profile.tiktok = value;
          break;
      }
    },

    profileBadgesUpdated: (state, action) => {
      state.profile.badges = action.payload.badges;
    },

    profileBadgeRemoved: (state, action) => {
      state.profile.badges = state.profile.badges.filter(
        (badge) => badge.name !== action.payload.badge,
      );
    },

    profileCompletionStageUpdated: (state, action) => {
      state.profile.profile_completion_stage = action.payload.stage;
    },

    setSuggestedPeopleLinked: (state, action) => {
      state.profile.suggested_people_linked =
        action.payload.suggested_people_linked;
    },

    setIsOnboardedUser: (state, action) => {
      state.isOnboardedUser = action.payload.isOnboardedUser;
    },

    setNewNotificationReceived: (state, action) => {
      state.newNotificationReceived = action.payload.newNotificationReceived;
    },

    setReplyPosted: (state, action) => {
      state.replyPosted = action.payload.replyPosted;
    },

    setNewVersionAvailable: (state, action) => {
      state.newVersionAvailable = action.payload.newVersionAvailable;
    },

    setSuggestedPeopleImage: (state, action) => {
      state.suggestedPeopleImage = action.payload.suggestedPeopleImage;
    },

    clearHeaderAndProfileImages: (state) => {
      state.avatar = '';
      state.cover = '';
    },

    setMomentUploadProgressBar: (state, action) => {
      state.momentUploadProgressBar = action.payload.momentUploadProgressBar;
    },
  },
});

export const {
  userLoggedIn,
  userDetailsFetched,
  socialEdited,
  profileCompletionStageUpdated,
  setSuggestedPeopleLinked,
  setIsOnboardedUser,
  setNewVersionAvailable,
  setNewNotificationReceived,
  setReplyPosted,
  setSuggestedPeopleImage,
  clearHeaderAndProfileImages,
  profileBadgesUpdated,
  profileBadgeRemoved,
  setMomentUploadProgressBar,
} = userDataSlice.actions;
export const userDataReducer = userDataSlice.reducer;