diff --git a/public/banner.png b/public/banner.png old mode 100755 new mode 100644 index a8cb9be..9f1e570 Binary files a/public/banner.png and b/public/banner.png differ diff --git a/public/features.png b/public/features.png index db2359f..eb4f8ef 100644 Binary files a/public/features.png and b/public/features.png differ diff --git a/src/assets/react.svg b/src/assets/react.svg deleted file mode 100644 index 6c87de9..0000000 --- a/src/assets/react.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/components/AppHeader/index.jsx b/src/components/AppHeader/index.jsx index 99d0ab3..825d3ef 100644 --- a/src/components/AppHeader/index.jsx +++ b/src/components/AppHeader/index.jsx @@ -13,7 +13,7 @@ import SettingsIcon from "@mui/icons-material/Settings"; import SearchIcon from "@mui/icons-material/Search"; import RefreshIcon from "@mui/icons-material/Refresh"; import { - setFilterType, + searchEmails, toggleSidebarCollapsed, } from "@app/store/mailAppReducer/actions"; import { uploadPicture, userLogout } from "@app/store/authReducer/actions"; @@ -82,7 +82,7 @@ const AppHeader = ({ viewMode, handleViewModeChange }) => { const handleSearchText = (e) => { setSearchTextState(e.target.value); dispatch( - setFilterType({ + searchEmails({ selectedFolder: !searchTextState && "inbox", selectedFilter: "", selectedLabel: "", diff --git a/src/store/mailAppReducer/actions/index.js b/src/store/mailAppReducer/actions/index.js index 7bb7952..41a5012 100644 --- a/src/store/mailAppReducer/actions/index.js +++ b/src/store/mailAppReducer/actions/index.js @@ -17,6 +17,31 @@ export const setFilterType = createAsyncThunk( } ); +export const searchEmails = createAsyncThunk( + "mailbox/searchEmails", + async (filterType, { rejectWithValue }) => { + try { + if (filterType.searchText.length > 0) { + const config = { + headers: { + "Content-Type": "application/json", + Authorization: JSON.parse(localStorage.getItem("token")), + email: JSON.parse(localStorage.getItem("user")).email, + }, + params: { search: filterType.searchText }, + }; + const response = await axios.get( + `${baseURL}/nylas/search-emails`, + config + ); + return response.data; + } + } catch (error) { + return rejectWithValue(error.response?.data || "Something went wrong"); + } + } +); + export const getLabelsList = createAsyncThunk( "mailbox/getLabelsList", async (_, { rejectWithValue }) => { diff --git a/src/store/mailAppReducer/index.js b/src/store/mailAppReducer/index.js index 6f7e769..0aacddd 100644 --- a/src/store/mailAppReducer/index.js +++ b/src/store/mailAppReducer/index.js @@ -19,6 +19,7 @@ import { getSelectedMail, updateSelectedMail, replyToMail, + searchEmails, nullifySelectedMail as nullifySelectedMailThunk, } from "./actions"; @@ -38,6 +39,7 @@ const initialState = { selectedMail: null, totalMailCount: null, loading: { + searchEmails: false, isSideBarCollapsed: false, setFilterType: false, getLabelsList: false, @@ -61,6 +63,7 @@ const initialState = { }, error: { isSideBarCollapsed: null, + searchEmails: null, setFilterType: null, getLabelsList: null, addNewLabel: null, @@ -597,6 +600,23 @@ const mailAppReducer = createSlice({ state.loading.replyToMail = false; state.error.replyToMail = action.payload; }); + + // Async Thunk: replyToMail + builder + .addCase(searchEmails.pending, (state) => { + state.loading.searchEmails = true; + state.error.searchEmails = null; + }) + .addCase(searchEmails.fulfilled, (state, action) => { + state.loading.searchEmails = false; + if (action.payload?.length > 0) { + state.mailsList = action.payload; + } + }) + .addCase(searchEmails.rejected, (state, action) => { + state.loading.searchEmails = false; + state.error.searchEmails = "Something went wrong!"; + }); }, });