diff --git a/README.MD b/README.MD index a3e429b14..6a6325ba6 100644 --- a/README.MD +++ b/README.MD @@ -20,4 +20,6 @@ NGROK TEsting: Finding deadfiles - run from client directory -npx deadfile ./src/index.js --exclude build templates +npx deadfile ./src/index.js --exclude build templates + +cd client && yarn build && cd build && scp -r ** imex@prod-tor1.imex.online:~/bodyshop/client/build && cd .. &&cd .. \ No newline at end of file diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index d627443d4..53e83750f 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -7498,6 +7498,48 @@ + + newversionmessage + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + newversiontitle + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + rbacunauth false diff --git a/client/src/App/App.container.jsx b/client/src/App/App.container.jsx index e15528449..cb880a7fa 100644 --- a/client/src/App/App.container.jsx +++ b/client/src/App/App.container.jsx @@ -1,4 +1,6 @@ import { ApolloProvider } from "@apollo/react-common"; +import { ConfigProvider } from "antd"; +import enLocale from "antd/es/locale/en_US"; import { ApolloLink } from "apollo-boost"; import { InMemoryCache } from "apollo-cache-inmemory"; import ApolloClient from "apollo-client"; @@ -9,16 +11,15 @@ import apolloLogger from "apollo-link-logger"; import { RetryLink } from "apollo-link-retry"; import { WebSocketLink } from "apollo-link-ws"; import { getMainDefinition } from "apollo-utilities"; +import axios from "axios"; import LogRocket from "logrocket"; +import moment from "moment"; import React from "react"; import GlobalLoadingBar from "../components/global-loading-bar/global-loading-bar.component"; import { auth } from "../firebase/firebase.utils"; import errorLink from "../graphql/apollo-error-handling"; import App from "./App"; -import { ConfigProvider } from "antd"; -import enLocale from "antd/es/locale/en_US"; -import moment from "moment"; -import axios from "axios"; +import RegisterServiceWorker from "./registerServiceWorker.component"; moment.locale("en-US"); @@ -151,6 +152,7 @@ export default function AppContainer() { locale={enLocale} > + diff --git a/client/src/App/registerServiceWorker.component.jsx b/client/src/App/registerServiceWorker.component.jsx new file mode 100644 index 000000000..0dbeafcf5 --- /dev/null +++ b/client/src/App/registerServiceWorker.component.jsx @@ -0,0 +1,48 @@ +import { AlertOutlined } from "@ant-design/icons"; +import { Button, notification } from "antd"; +import i18n from "i18next"; +import React, { useEffect } from "react"; +import * as serviceWorker from "../serviceWorker"; + +export default function RegisterServiceWorker() { + useEffect(() => { + console.log("SWR Use Effect Fired."); + const onServiceWorkerUpdate = (registration) => { + console.log("onServiceWorkerUpdate", registration); + + const key = `open${Date.now()}`; + const btn = ( + + ); + notification.open({ + icon: , + message: i18n.t("general.messages.newversiontitle"), + description: i18n.t("general.messages.newversionmessage"), + duration: 0, + btn, + key, + }); + }; + + if (process.env.NODE_ENV === "production") { + console.log("SWR Registering SW..."); + serviceWorker.register({ onUpdate: onServiceWorkerUpdate }); + } + }, []); + + return
Service Worker Registration.
; +} diff --git a/client/src/index.js b/client/src/index.js index 8cb47c9a0..b06a3e704 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -2,7 +2,7 @@ import React from "react"; import ReactDOM from "react-dom"; import { BrowserRouter } from "react-router-dom"; import "./translations/i18n"; -import * as serviceWorker from "./serviceWorker"; +//import * as serviceWorker from "./serviceWorker"; import { Provider } from "react-redux"; import { PersistGate } from "redux-persist/integration/react"; import { store, persistor } from "./redux/store"; @@ -26,4 +26,4 @@ ReactDOM.render( document.getElementById("root") ); -serviceWorker.register(); +//serviceWorker.register(); diff --git a/client/src/serviceWorker.js b/client/src/serviceWorker.js index 372b6674d..4562ae5e0 100644 --- a/client/src/serviceWorker.js +++ b/client/src/serviceWorker.js @@ -58,6 +58,16 @@ function registerValidSW(swUrl, config) { navigator.serviceWorker .register(swUrl) .then((registration) => { + // Start addition--- + // https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#manual_updates + // Added code, as our application will be open for a long time and we are a SPA, we need + // to trigger checks for updates frequently + setInterval(() => { + console.log("Checking if service worker was updated in server"); + registration.update(); + }, 15 * 60 * 1000); // Every 15 mins check + // End addition--- + registration.onupdatefound = () => { const installingWorker = registration.installing; if (installingWorker == null) { diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index bbdf75adb..57413dcc8 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -483,6 +483,8 @@ }, "messages": { "exception": "$t(titles.app) has encountered an error. Please try again. If the problem persists, please submit a support ticket or contact us.", + "newversionmessage": "Click refresh below to update to the latest available version of ImEX Online.", + "newversiontitle": "New version of ImEX Online Available", "rbacunauth": "You are not authorized to view this content. Please reach out to your shop manager to change your access level.", "unsavedchanges": "You have unsaved changes.", "unsavedchangespopup": "You have unsaved changes. Are you sure you want to leave?" diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 4246ca0cc..06f68b8d2 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -483,6 +483,8 @@ }, "messages": { "exception": "", + "newversionmessage": "", + "newversiontitle": "", "rbacunauth": "", "unsavedchanges": "Usted tiene cambios no guardados.", "unsavedchangespopup": "" diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 16d64ab9a..74d30c69d 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -483,6 +483,8 @@ }, "messages": { "exception": "", + "newversionmessage": "", + "newversiontitle": "", "rbacunauth": "", "unsavedchanges": "Vous avez des changements non enregistrés.", "unsavedchangespopup": ""