remove network servcie
This commit is contained in:
1 parent
b817a16459
commit
34762ef475
7 files changed
+19
-1276
No files matched your search
@@ -7,7 +7,6 @@ import lightTheme from "./Utils/Theme/lightTheme";
|
||||
import darkTheme from "./Utils/Theme/darkTheme";
|
||||
import { CssBaseline, GlobalStyles } from "@mui/material";
|
||||
import { logger } from "./Utils/Logger"; // Import the logger
|
||||
import { networkService } from "./main";
|
||||
import { Routes } from "./Routes";
|
||||
import AppLayout from "@/Components/v1/Layouts/AppLayout";
|
||||
|
||||
@@ -18,7 +17,6 @@ function App() {
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
logger.cleanup();
|
||||
networkService.cleanup();
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import { useState } from "react";
|
||||
import { networkService } from "../main.jsx";
|
||||
import { useSelector } from "react-redux";
|
||||
import { createToast } from "../Utils/toastUtils.jsx";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const useSendTestEmail = () => {
|
||||
const [isSending, setIsSending] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
const user = useSelector((state) => state.auth.user);
|
||||
const { t } = useTranslation();
|
||||
|
||||
/**
|
||||
* Send a test email with optional email configuration
|
||||
* @param {Object} emailConfig - Optional email configuration parameters
|
||||
*/
|
||||
const sendTestEmail = async (emailConfig = null) => {
|
||||
try {
|
||||
setIsSending(true);
|
||||
setError(null);
|
||||
|
||||
// Send the test email with or without configuration
|
||||
const response = await networkService.sendTestEmail({
|
||||
to: user.email,
|
||||
emailConfig,
|
||||
});
|
||||
|
||||
if (typeof response?.data?.data?.messageId !== "undefined") {
|
||||
createToast({
|
||||
body: t("settingsTestEmailSuccess", "Test email sent successfully"),
|
||||
});
|
||||
} else {
|
||||
throw new Error(
|
||||
response?.data?.error ||
|
||||
t("settingsTestEmailFailed", "Failed to send test email")
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
createToast({
|
||||
body: t("failedToSendEmail"),
|
||||
});
|
||||
setError(error);
|
||||
createToast({
|
||||
body: t(
|
||||
"settingsTestEmailFailedWithReason",
|
||||
"Failed to send test email: {{reason}}",
|
||||
{
|
||||
reason: error.message || t("settingsTestEmailUnknownError", "Unknown error"),
|
||||
}
|
||||
),
|
||||
variant: "error",
|
||||
});
|
||||
} finally {
|
||||
setIsSending(false);
|
||||
}
|
||||
};
|
||||
return [isSending, error, sendTestEmail];
|
||||
};
|
||||
|
||||
export { useSendTestEmail };
|
||||
@@ -2,7 +2,7 @@ import React, { useState } from "react";
|
||||
import { Box, Typography, Button, Stack } from "@mui/material";
|
||||
import { useTheme } from "@emotion/react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { networkService } from "@/Utils/NetworkService.js";
|
||||
import { get } from "@/Utils/ApiClient";
|
||||
import Alert from "@/Components/v1/Alert/index.jsx";
|
||||
import { createToast } from "@/Utils/toastUtils.jsx";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -24,7 +24,7 @@ const ServerUnreachable = () => {
|
||||
try {
|
||||
// Try to connect to the backend with a simple API call
|
||||
// We'll use any lightweight endpoint that doesn't require authentication
|
||||
await networkService.axiosInstance.get("/health", { timeout: 5000 });
|
||||
await get("/health", { timeout: 5000 });
|
||||
|
||||
// If successful, show toast and navigate to login page
|
||||
createToast({
|
||||
|
||||
@@ -12,7 +12,8 @@ import { PropTypes } from "prop-types";
|
||||
import { useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PasswordEndAdornment } from "@/Components/v1/Inputs/TextInput/Adornments/index.jsx";
|
||||
import { useSendTestEmail } from "@/Hooks/useSendTestEmail.js";
|
||||
import { usePost } from "@/Hooks/UseApi";
|
||||
import { useSelector } from "react-redux";
|
||||
import { createToast } from "@/Utils/toastUtils.jsx";
|
||||
|
||||
const SettingsEmail = ({
|
||||
@@ -48,7 +49,8 @@ const SettingsEmail = ({
|
||||
const [password, setPassword] = useState("");
|
||||
|
||||
// Network
|
||||
const [isSending, , sendTestEmail] = useSendTestEmail(); // Using empty placeholder for unused error variable
|
||||
const { post: sendTestEmailFn, loading: isSending } = usePost();
|
||||
const user = useSelector((state) => state.auth.user);
|
||||
|
||||
// Handlers
|
||||
const handlePasswordChange = (e) => {
|
||||
@@ -94,7 +96,10 @@ const SettingsEmail = ({
|
||||
}
|
||||
|
||||
// Send test email with current form values
|
||||
sendTestEmail(emailConfig);
|
||||
sendTestEmailFn("/settings/test-email", {
|
||||
to: user.email,
|
||||
...emailConfig,
|
||||
});
|
||||
};
|
||||
|
||||
if (!isAdmin) {
|
||||
@@ -297,6 +302,14 @@ const SettingsEmail = ({
|
||||
</Box>
|
||||
</Box>
|
||||
|
||||
<pre>
|
||||
{JSON.stringify({
|
||||
systemEmailHost,
|
||||
systemEmailAddress,
|
||||
systemEmailPassword,
|
||||
})}
|
||||
</pre>
|
||||
|
||||
<Box>
|
||||
{systemEmailHost &&
|
||||
systemEmailPort &&
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,16 +0,0 @@
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { setNetworkService } from "./NetworkService";
|
||||
import NetworkService, { networkService } from "./NetworkService";
|
||||
import { store } from "../store";
|
||||
|
||||
const NetworkServiceProvider = ({ children }) => {
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
if (!networkService) {
|
||||
setNetworkService(new NetworkService(store, dispatch, navigate));
|
||||
}
|
||||
return children;
|
||||
};
|
||||
|
||||
export default NetworkServiceProvider;
|
||||
+1
-6
@@ -5,9 +5,6 @@ import { BrowserRouter as Router } from "react-router-dom";
|
||||
import { Provider } from "react-redux";
|
||||
import { persistor, store } from "./store";
|
||||
import { PersistGate } from "redux-persist/integration/react";
|
||||
import NetworkServiceProvider from "./Utils/NetworkServiceProvider.jsx";
|
||||
import { networkService } from "./Utils/NetworkService";
|
||||
export { networkService };
|
||||
import I18nLoader from "./Components/v1/I18nLoader";
|
||||
import { initApiClient } from "./Utils/ApiClient";
|
||||
|
||||
@@ -21,9 +18,7 @@ ReactDOM.createRoot(document.getElementById("root")).render(
|
||||
>
|
||||
<I18nLoader />
|
||||
<Router>
|
||||
<NetworkServiceProvider>
|
||||
<App />
|
||||
</NetworkServiceProvider>
|
||||
<App />
|
||||
</Router>
|
||||
</PersistGate>
|
||||
</Provider>
|
||||
|
||||
Reference in new issue
Block a user