Skip to content

Commit 2d4be50

Browse files
committed
update apis and store
1 parent af59912 commit 2d4be50

File tree

30 files changed

+1143
-769
lines changed

30 files changed

+1143
-769
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@nylas/nylas-react": "^0.1.0",
1818
"@reduxjs/toolkit": "^1.9.5",
1919
"axios": "^1.5.0",
20+
"dompurify": "^3.0.5",
2021
"emoji-picker-react": "^4.5.2",
2122
"moment": "^2.29.4",
2223
"prop-types": "^15.8.1",

pnpm-lock.yaml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/nylas-logo.svg

Lines changed: 19 additions & 0 deletions
Loading

src/App.jsx

Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { lazy, Suspense, useEffect, useState } from "react";
22
import { Route, Routes, Navigate } from "react-router-dom";
33
import { useDispatch, useSelector } from "react-redux";
4-
import { userLogin } from "@app/store/authReducer/actions";
54
import { red } from "@mui/material/colors";
65
import { ThemeProvider, createTheme } from "@mui/material/styles";
76
import { indigo, pink } from "@mui/material/colors";
7+
import { useNylas } from "@nylas/nylas-react";
8+
import { userGetToken } from "@app/store/authReducer/actions";
89

910
const theme = createTheme({
1011
breakpoints: {
@@ -222,31 +223,91 @@ const darkTheme = createTheme({
222223
});
223224

224225
const App = () => {
225-
const { loading, userInfo, error } = useSelector((state) => state.auth);
226+
const { loading, currentUser, error } = useSelector((state) => state.auth);
227+
const [currentAuthUser, setCurrentAuthUser] = useState(currentUser);
226228
const [currentTheme, setCurrentTheme] = useState("light");
227229

228230
const dispatch = useDispatch();
229-
230-
const submitForm = (data) => {
231-
dispatch(userLogin({ email: "test", password: "test" }));
232-
};
233-
234231
const Landing = lazy(() => import("@app/pages/Landing"));
232+
const Login = lazy(() => import("@app/pages/Login"));
233+
const MailApp = lazy(() => import("@app/pages/MailApp"));
234+
235+
const nylas = useNylas();
235236

236237
useEffect(() => {
237238
setCurrentTheme(localStorage.getItem("theme"));
238-
}, [dispatch, localStorage.getItem("user"), localStorage.getItem("theme")]);
239+
}, [dispatch, localStorage.getItem("theme")]);
240+
241+
useEffect(() => {
242+
setCurrentAuthUser(JSON.parse(localStorage.getItem("user")));
243+
}, []);
244+
245+
useEffect(() => {
246+
if (!nylas) {
247+
return;
248+
}
249+
const params = new URLSearchParams(window.location.search);
250+
if (params.has("code")) {
251+
dispatch(userGetToken({ nylas: nylas }));
252+
}
253+
}, [nylas]);
239254

240255
return (
241256
<ThemeProvider theme={currentTheme === "light" ? theme : darkTheme}>
242257
<Suspense>
243258
<Routes>
244-
<Route exact path="/" element={<Landing />} />
259+
<Route
260+
exact
261+
path="/"
262+
element={
263+
<>
264+
{currentAuthUser ? (
265+
<Navigate to={"/mail"} replace />
266+
) : (
267+
<Landing />
268+
)}
269+
</>
270+
}
271+
/>
272+
<Route
273+
exact
274+
path="/mail"
275+
element={<>{currentAuthUser ? <MailApp /> : <Login />}</>}
276+
/>
277+
<Route
278+
exact
279+
path="/login"
280+
element={
281+
<>
282+
{currentAuthUser ? (
283+
<Navigate to={"/mail"} replace />
284+
) : (
285+
<Login />
286+
)}
287+
</>
288+
}
289+
/>
245290
<Route exact path="/home" element={<Navigate to={"/"} replace />} />
291+
<Route path="/:url*" element={<RedirectToNylas />} />
246292
</Routes>
247293
</Suspense>
248294
</ThemeProvider>
249295
);
250296
};
251297

298+
function RedirectToNylas() {
299+
// A hack to redirect to nylas api
300+
// Get the current URL from window.location.href
301+
const currentUrl = window.location.href;
302+
// Extract the URL part between quotation marks
303+
const parts = currentUrl.split("%22");
304+
305+
if (parts.length >= 2) {
306+
const extractedContent = parts[1];
307+
// Redirect to the extracted URL
308+
window.location.href = extractedContent;
309+
}
310+
311+
return null;
312+
}
252313
export default App;

src/components/AppHeader.jsx

Lines changed: 0 additions & 186 deletions
This file was deleted.

0 commit comments

Comments
 (0)