Skip to content

Commit 6ed41ac

Browse files
authored
Merge branch 'dev' into CW-fix-confliсе
2 parents f572fee + 05f3419 commit 6ed41ac

File tree

112 files changed

+2094
-605
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+2094
-605
lines changed

public/firebase-messaging-sw.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* eslint-disable */
2+
// firebase-messaging-sw.js
3+
importScripts(
4+
"https://www.gstatic.com/firebasejs/10.7.1/firebase-app-compat.js",
5+
);
6+
importScripts(
7+
"https://www.gstatic.com/firebasejs/10.7.1/firebase-messaging-compat.js",
8+
);
9+
10+
const ENV = {
11+
LOCAL: "http://localhost:3000",
12+
DEV: "https://web-dev.common.io",
13+
STAGE: "https://web-staging.common.io",
14+
PRODUCTION: "https://common.io",
15+
};
16+
17+
const FIREBASE_CONFIG_ENV = {
18+
DEV: {
19+
apiKey: "AIzaSyDbTFuksgOkIVWDiFe_HG7-BE8X6Dwsg-0",
20+
authDomain: "common-dev-34b09.firebaseapp.com",
21+
databaseURL: "https://common-dev-34b09.firebaseio.com",
22+
projectId: "common-dev-34b09",
23+
storageBucket: "common-dev-34b09.appspot.com",
24+
messagingSenderId: "870639147922",
25+
appId: "1:870639147922:web:9ee954bb1dd52e25cb7f4b",
26+
},
27+
STAGE: {
28+
apiKey: "AIzaSyBASCWJMV64mZJObeFEitLmdUC1HqmtjJk",
29+
authDomain: "common-staging-1d426.firebaseapp.com",
30+
databaseURL: "https://common-staging-1d426.firebaseio.com",
31+
projectId: "common-staging-1d426",
32+
storageBucket: "common-staging-1d426.appspot.com",
33+
messagingSenderId: "701579202562",
34+
appId: "1:701579202562:web:5729d8a875f98f6709571b",
35+
},
36+
PRODUCTION: {
37+
apiKey: "AIzaSyAlYrKLd6KNKVkhmNEMKfb0cWHSWicCBOY",
38+
authDomain: "common-production-67641.firebaseapp.com",
39+
databaseURL: "https://common-production-67641.firebaseio.com",
40+
projectId: "common-production-67641",
41+
storageBucket: "common-production-67641.appspot.com",
42+
messagingSenderId: "461029494046",
43+
appId: "1:461029494046:web:4e2e4afbbeb7b487b48d0f",
44+
},
45+
};
46+
47+
let firebaseConfig = {};
48+
49+
switch (location.origin) {
50+
case ENV.LOCAL:
51+
case ENV.DEV: {
52+
firebaseConfig = FIREBASE_CONFIG_ENV.DEV;
53+
break;
54+
}
55+
case ENV.STAGE: {
56+
firebaseConfig = FIREBASE_CONFIG_ENV.STAGE;
57+
break;
58+
}
59+
case ENV.PRODUCTION: {
60+
firebaseConfig = FIREBASE_CONFIG_ENV.PRODUCTION;
61+
break;
62+
}
63+
default: {
64+
firebaseConfig = FIREBASE_CONFIG_ENV.DEV;
65+
break;
66+
}
67+
}
68+
69+
firebase.initializeApp(firebaseConfig);
70+
71+
const messaging = firebase.messaging();
72+
73+
messaging.onBackgroundMessage((payload) => {
74+
const notificationTitle = payload.notification.title;
75+
const notificationOptions = {
76+
body: payload.notification.body,
77+
data: payload.data,
78+
icon: "/logo.png",
79+
};
80+
81+
self.registration.showNotification(notificationTitle, notificationOptions);
82+
});

public/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@
4646
}
4747

4848
.loader-wrapper {
49-
position: relative;
49+
position: absolute;
5050
left: 50%;
51-
transform: translateX(-50%);
51+
top: 50%;
52+
transform: translate(-50%, -50%);
5253
height: 75px;
5354
width: 75px;
5455
background-image: url(/icons/loader-pink.svg);

public/logo.png

20.8 KB
Loading

src/config.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export const local: Configuration = {
2727
deadSeaCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
2828
parentsForClimateCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
2929
saadiaCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
30+
vapidKey:
31+
"BHVFyNetSC6oA2uFejnUFuDcSUYcas2R5lwW80z6gZc6zODp7rRdh2t8bht3LygJWjyI1toV165EYgdZqxCS_Y4",
3032
};
3133

3234
const dev: Configuration = {
@@ -44,6 +46,8 @@ const dev: Configuration = {
4446
deadSeaCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
4547
parentsForClimateCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
4648
saadiaCommonId: "958dca85-7bc1-4714-95bd-1fc6343f0654",
49+
vapidKey:
50+
"BHVFyNetSC6oA2uFejnUFuDcSUYcas2R5lwW80z6gZc6zODp7rRdh2t8bht3LygJWjyI1toV165EYgdZqxCS_Y4",
4751
};
4852

4953
const stage: Configuration = {
@@ -62,6 +66,8 @@ const stage: Configuration = {
6266
deadSeaCommonId: "a55a1e9b-104a-4866-9f4f-3e017bbae281",
6367
parentsForClimateCommonId: "a55a1e9b-104a-4866-9f4f-3e017bbae281",
6468
saadiaCommonId: "a55a1e9b-104a-4866-9f4f-3e017bbae281",
69+
vapidKey:
70+
"BBvr8z8QaPSJJfIRxmjBrq5Vs49BY95uZK_6QFyR7gKWgwrs5toDy-hvwWEtk-rbkVHBgOu9l2orK45u1n--9M0",
6571
};
6672

6773
const production: Configuration = {
@@ -80,6 +86,8 @@ const production: Configuration = {
8086
deadSeaCommonId: "6cfbfae6-2e5c-4b3b-ba70-e8fd871f48e2",
8187
parentsForClimateCommonId: "04ac2ec2-5cb2-4ab9-ae3f-5f223f482768",
8288
saadiaCommonId: "7c8c8996-b678-44df-9a57-e291431eb00f",
89+
vapidKey:
90+
"BKJ324iR-B5SoDG42bMrC_Q_poAv7BO-Z3AuMh5Grrg6TxO1QnN6mgzt2KyFFax0JSuuUhUKP-OrcTUPfboVqns",
8391
};
8492

8593
const config: ConfigurationObject = {

src/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import "./projectSetupImports";
22
import React from "react";
33
import ReactDOM from "react-dom";
4+
import { enableMapSet } from "immer";
45
import { App, AppWrapper } from "@/pages/App";
56

7+
enableMapSet();
8+
69
ReactDOM.render(
710
<AppWrapper>
811
<App />

src/pages/App/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ThemeHandler,
1414
UserNotificationsAmountHandler,
1515
WebViewLoginHandler,
16+
NotificationsHandler,
1617
} from "./handlers";
1718
import { Router } from "./router";
1819

@@ -34,6 +35,7 @@ const App = () => {
3435
<ThemeHandler />
3536
<UserNotificationsAmountHandler />
3637
<WebViewLoginHandler />
38+
<NotificationsHandler />
3739
<LoginContainer />
3840
<Router />
3941
</ReactRouter>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { FC, useEffect, useState } from "react";
2+
import { useSelector } from "react-redux";
3+
import { selectUser } from "@/pages/Auth/store/selectors";
4+
import { NotificationService } from "@/services";
5+
6+
const NotificationsHandler: FC = () => {
7+
const user = useSelector(selectUser());
8+
const userId = user?.uid;
9+
const [isRegistered, setIsRegistered] = useState(false);
10+
11+
function initServiceWorker() {
12+
navigator.serviceWorker
13+
.register("/firebase-messaging-sw.js")
14+
.then((registration) => {
15+
setIsRegistered(true);
16+
return registration;
17+
})
18+
.catch((err) => {
19+
console.log("ServiceWorker registration failed: ", err);
20+
});
21+
}
22+
23+
// Check if the service worker is already registered or register a new one
24+
useEffect(() => {
25+
if ("serviceWorker" in navigator) {
26+
navigator.serviceWorker
27+
.getRegistration("/firebase-messaging-sw.js")
28+
.then((existingRegistration) => {
29+
if (existingRegistration) {
30+
setIsRegistered(true);
31+
} else {
32+
initServiceWorker();
33+
}
34+
35+
return;
36+
})
37+
.catch((err) => {
38+
console.log("Error checking service worker registration: ", err);
39+
});
40+
}
41+
}, []);
42+
43+
// Handle notification permissions and foreground message listener
44+
useEffect(() => {
45+
if (!userId || !isRegistered) {
46+
return;
47+
}
48+
49+
let unsubscribeOnMessage;
50+
(async () => {
51+
const hasPermissions = await NotificationService.requestPermissions();
52+
if (!hasPermissions) {
53+
console.log("Notification permissions denied");
54+
return;
55+
}
56+
57+
await NotificationService.saveFCMToken();
58+
unsubscribeOnMessage = NotificationService.onForegroundMessage();
59+
})();
60+
61+
return () => {
62+
if (unsubscribeOnMessage) {
63+
unsubscribeOnMessage();
64+
}
65+
};
66+
}, [userId, isRegistered]);
67+
68+
return null;
69+
};
70+
71+
export default NotificationsHandler;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as NotificationsHandler } from "./NotificationsHandler";

src/pages/App/handlers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from "./TextDirectionHandler";
33
export * from "./UserNotificationsAmountHandler";
44
export * from "./WebViewLoginHandler";
55
export * from "./ThemeHandler";
6+
export * from "./NotificationsHandler";

src/pages/App/router/Router.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ROUTES } from "./configuration";
66
const Router: FC = () => (
77
<Switch>
88
{ROUTES.map((layoutConfiguration, index) => (
9-
<Layout key={index} {...layoutConfiguration} />
9+
<Layout key={index} {...layoutConfiguration} />
1010
))}
1111
<Redirect />
1212
</Switch>

src/pages/App/router/components/Layout/Layout.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
import React, { FC } from "react";
1+
import React, { FC, Suspense } from "react";
22
import { Route, Switch } from "react-router-dom";
33
import { LayoutConfigurationWithRouteProps } from "../../types";
44
import { LayoutRoute } from "../LayoutRoute";
5+
import { SuspenseLoader } from "@/shared/ui-kit";
56

67
const Layout: FC<LayoutConfigurationWithRouteProps> = (props) => {
78
const { component: LayoutComponent, routes, ...restProps } = props;
89

910
return (
1011
<LayoutRoute routeConfigurations={routes} {...restProps}>
1112
<LayoutComponent>
13+
<Suspense fallback={SuspenseLoader}>
1214
<Switch>
13-
{routes.map((route) => (
14-
<Route key={route.path} {...route} />
15-
))}
15+
{routes.map((route) => <Route key={route.path} {...route} />)}
1616
</Switch>
17+
</Suspense>
1718
</LayoutComponent>
1819
</LayoutRoute>
1920
);

src/pages/App/router/components/LayoutRoute/LayoutRoute.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FC, useMemo } from "react";
1+
import React, { FC, Suspense, useMemo } from "react";
22
import { useSelector } from "react-redux";
33
import { Route, RouteProps } from "react-router-dom";
44
import { Route as RouteConfiguration } from "@/pages/App/router/types";
@@ -9,6 +9,7 @@ import {
99
import { matchRoute } from "@/shared/utils";
1010
import { LayoutRouteContext, LayoutRouteContextValue } from "./context";
1111
import { renderRouteContent } from "./helpers";
12+
import { SuspenseLoader } from "@/shared/ui-kit";
1213

1314
interface PrivateRouteProps extends RouteProps {
1415
routeConfigurations: RouteConfiguration[];
@@ -36,19 +37,21 @@ const LayoutRoute: FC<PrivateRouteProps> = (props) => {
3637

3738
return (
3839
<LayoutRouteContext.Provider value={contextValue}>
39-
<Route
40-
{...restProps}
41-
render={(routeProps) =>
42-
renderRouteContent({
43-
...routeProps,
44-
component,
45-
children,
46-
configuration: routeConfiguration,
47-
userRoles: userRoles || [],
48-
authenticated,
49-
})
50-
}
51-
/>
40+
<Suspense fallback={SuspenseLoader}>
41+
<Route
42+
{...restProps}
43+
render={(routeProps) =>
44+
renderRouteContent({
45+
...routeProps,
46+
component,
47+
children,
48+
configuration: routeConfiguration,
49+
userRoles: userRoles || [],
50+
authenticated,
51+
})
52+
}
53+
/>
54+
</Suspense>
5255
</LayoutRouteContext.Provider>
5356
);
5457
};

0 commit comments

Comments
 (0)