Browse Source

CONFIG | One signal

merge-requests/255/merge
Vitalik 2 years ago
parent
commit
c7b32c1e66
  1. 2
      .env
  2. 3
      package.json
  3. 1
      public/index.html
  4. 13
      scripts/push.sh
  5. 9
      src/config/index.ts
  6. 51
      src/services/system/notifications.service.ts

2
.env

@ -1 +1 @@ @@ -1 +1 @@
REACT_APP_MOD=local
REACT_APP_MOD=production

3
package.json

@ -176,7 +176,8 @@ @@ -176,7 +176,8 @@
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"test": "node scripts/test.js"
"test": "node scripts/test.js",
"push:prod": "sh ./scripts/push.sh"
},
"devDependencies": {
"@babel/helper-call-delegate": "^7.12.13",

1
public/index.html

@ -27,6 +27,7 @@ @@ -27,6 +27,7 @@
href="https://use.fontawesome.com/releases/v5.7.0/css/all.css"
rel="stylesheet"
/>
<title>Task me ;)</title>
</head>

13
scripts/push.sh

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
# npm run build
ssh -p 32452 programmer@195.201.197.217 "
cd /home/programmer/web-app &&
rm -R build
"
scp -P 32452 -r ./build programmer@195.201.197.217:/home/programmer/web-app/build
ssh -p 32452 programmer@195.201.197.217 "nginx -s reload"

9
src/config/index.ts

@ -9,13 +9,18 @@ export const config = { @@ -9,13 +9,18 @@ export const config = {
apiUrl: "https://taskme-api.work-jetup.site/",
socketUrl: "https://taskme-api.work-jetup.site",
pdfViewer: "https://taskme-pdf-viewer.work-jetup.site",
oneSignalId: "8b9066f5-8c3f-49f7-bef4-c5ab621f9d27",,
oneSignalSafaryId: "",
};
const mod = _.defaultTo(process.env.REACT_APP_MOD, "local");
if (mod === "production") {
config.apiUrl = "http://v2-taskme-api.work-jetup.site/";
config.socketUrl = "http://v2-taskme-api.work-jetup.site";
config.apiUrl = "https://tasks-api.rwsbank.com.ua/";
config.socketUrl = "https://tasks-api.rwsbank.com.ua";
config.oneSignalId = "5e1a5e18-33e5-4ed3-8423-45b1abc354c6";
config.oneSignalSafaryId =
"web.onesignal.auto.66c89079-ab76-4c24-84be-2fca07f56f6c";
}
export default config;

51
src/services/system/notifications.service.ts

@ -1,4 +1,5 @@ @@ -1,4 +1,5 @@
import { notificApi } from "@/api/notifications/request";
import config from "@/config";
import { RouteEnum } from "@/containers/App/router";
import { IPushNotification, NotificationKeys } from "@/shared";
import { SelectChatId } from "@/store/chats";
@ -7,7 +8,7 @@ import OneSignal from "react-onesignal"; @@ -7,7 +8,7 @@ import OneSignal from "react-onesignal";
export const needRedirect = {
to: null,
payload: null
payload: null,
};
const saveNeedRedirect = ({ to, payload }) => {
@ -26,9 +27,9 @@ export const notificationActions = ( @@ -26,9 +27,9 @@ export const notificationActions = (
);
saveNeedRedirect({
to: `/chats?id=${notification.data.chatId}`,
payload: null
payload: null,
});
}
},
},
[NotificationKeys.NEW_CHAT_MEMBER]: {
redirect: () => {
@ -37,17 +38,17 @@ export const notificationActions = ( @@ -37,17 +38,17 @@ export const notificationActions = (
);
saveNeedRedirect({
to: `/chats?id=${notification.data.chatId}`,
payload: null
payload: null,
});
}
},
},
[NotificationKeys.NEW_TASK]: {
redirect: () => {
saveNeedRedirect({
to: RouteEnum.Tasks,
payload: null
payload: null,
});
}
},
},
[NotificationKeys.NEW_TASK_COMMENT]: {
redirect: () => {
@ -55,10 +56,10 @@ export const notificationActions = ( @@ -55,10 +56,10 @@ export const notificationActions = (
to: RouteEnum.Tasks,
payload: {
type: NotificationKeys.NEW_TASK_COMMENT,
taskId: notification.data.taskId
}
taskId: notification.data.taskId,
},
});
}
},
},
[NotificationKeys.NEW_TASK_FILE]: {
redirect: () => {
@ -66,22 +67,22 @@ export const notificationActions = ( @@ -66,22 +67,22 @@ export const notificationActions = (
to: RouteEnum.Tasks,
payload: {
type: NotificationKeys.NEW_TASK_FILE,
taskId: notification.data.taskId
}
taskId: notification.data.taskId,
},
});
}
},
},
[NotificationKeys.TODAY_BIRTHDAY]: {
redirect: () => {
saveNeedRedirect({
to: RouteEnum.Contacts,
payload: { soonBirthday: true }
payload: { soonBirthday: true },
});
}
}
},
},
});
const onOpened = openResult => {
const onOpened = (openResult) => {
try {
const notif: IPushNotification = {
id: 0,
@ -90,7 +91,7 @@ const onOpened = openResult => { @@ -90,7 +91,7 @@ const onOpened = openResult => {
createDate: null,
isRead: false,
userId: null,
data: openResult.data as any
data: openResult.data as any,
};
const action = notificationActions(notif)[
@ -106,13 +107,15 @@ const onOpened = openResult => { @@ -106,13 +107,15 @@ const onOpened = openResult => {
const runOneSignal = async () => {
try {
await OneSignal.init({
appId: "8b9066f5-8c3f-49f7-bef4-c5ab621f9d27",
allowLocalhostAsSecureOrigin: false
appId: config.oneSignalId,
allowLocalhostAsSecureOrigin: false,
});
console.log("one signal is inited");
const isPermitted = await OneSignal.getNotificationPermission();
console.log("is notifications permitted", isPermitted);
if (isPermitted !== "granted") await OneSignal.showNativePrompt();
if (isPermitted !== "granted") await OneSignal.showSlidedownPrompt();
if (isPermitted) await OneSignal.setSubscription(true);
@ -121,14 +124,14 @@ const runOneSignal = async () => { @@ -121,14 +124,14 @@ const runOneSignal = async () => {
if (userId)
await notificApi.saveUserDevice({
notificationUserId: userId,
deviceUuid: userId
deviceUuid: userId,
});
} catch (e) {
console.log("ONE SIGNAL RUNNING ERROR", e);
}
};
OneSignal.on("subscriptionChange", async isSubscribed => {
OneSignal.on("subscriptionChange", async (isSubscribed) => {
console.log("SUBSCRIPTION IS CHANGED", isSubscribed);
await OneSignal.setSubscription(isSubscribed);
});
@ -136,5 +139,5 @@ OneSignal.on("subscriptionChange", async isSubscribed => { @@ -136,5 +139,5 @@ OneSignal.on("subscriptionChange", async isSubscribed => {
OneSignal.addListenerForNotificationOpened(onOpened);
export const notificationsService = {
runOneSignal
runOneSignal,
};

Loading…
Cancel
Save