// Define the initial state const initialState = { api: api, baseURL: baseURL, redirect: ``, editor: null, editorIsLoading: true, profile: {}, isLoggedIn: false, loginLoading: false, landingPageUrl: config.landingPageUrl, referral: "", toolsKeyword: "", error: "", copyToClipboardText: "", feedback: "", }; // Define the actions const setProfile = (profile) => ({ type: 'SET_PROFILE', payload: profile, }); const setIsLoggedIn = (isLoggedIn) => ({ type: 'SET_IS_LOGGED_IN', payload: isLoggedIn, }); const setReferral = (referral) => ({ type: 'SET_REFERRAL', payload: referral, }); const setToolsKeyword = (keyword) => ({ type: 'SET_TOOLS_KEYWORD', payload: keyword, }); const setEditor = (editor) => ({ type: 'SET_EDITOR', payload: editor, }); const setEditorIsLoading = (isLoading) => ({ type: 'SET_EDITOR_IS_LOADING', payload: isLoading, }); const setError = (error) => ({ type: 'SET_ERROR', payload: error, }); const setCopyToClipboardText = (text) => ({ type: 'SET_COPY_TO_CLIPBOARD_TEXT', payload: text, }); const setFeedback = (feedback) => ({ type: 'SET_FEEDBACK', payload: feedback, }); // Define the reducer function reducer(state = initialState, action) { switch (action.type) { case 'SET_PROFILE': return { ...state, profile: action.payload }; case 'SET_IS_LOGGED_IN': return { ...state, isLoggedIn: action.payload }; case 'SET_REFERRAL': return { ...state, referral: action.payload }; case 'SET_TOOLS_KEYWORD': return { ...state, toolsKeyword: action.payload }; case 'SET_EDITOR': return { ...state, editor: action.payload }; case 'SET_EDITOR_IS_LOADING': return { ...state, editorIsLoading: action.payload }; case 'SET_ERROR': return { ...state, error: action.payload }; case 'SET_COPY_TO_CLIPBOARD_TEXT': return { ...state, copyToClipboardText: action.payload }; case 'SET_FEEDBACK': return { ...state, feedback: action.payload }; default: return state; } } // Create the Redux store const store = createStore(reducer); // Dispatch actions to update the state store.dispatch(setProfile(profile)); store.dispatch(setIsLoggedIn(true)); store.dispatch(setReferral(referral)); store.dispatch(setToolsKeyword(keyword)); store.dispatch(setEditor(editor)); store.dispatch(setEditorIsLoading(true)); store.dispatch(setError(error)); store.dispatch(setCopyToClipboardText(text)); store.dispatch(setFeedback(feedback));