@banch0u/core-project-test-repository 2.2.20 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,200 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ import React, { useMemo, useState } from "react";
5
+ import { Modal } from "antd";
6
+ import Button from "../Button";
7
+ import { useDispatch } from "react-redux";
8
+ import { requestActivation } from "../../store/slices/auth";
9
+ var LicenseWatermark = function LicenseWatermark(_ref) {
10
+ var companyInfo = _ref.companyInfo,
11
+ pathname = _ref.pathname;
12
+ var _useState = useState(false),
13
+ _useState2 = _slicedToArray(_useState, 2),
14
+ open = _useState2[0],
15
+ setOpen = _useState2[1];
16
+ var _useState3 = useState(""),
17
+ _useState4 = _slicedToArray(_useState3, 2),
18
+ note = _useState4[0],
19
+ setNote = _useState4[1];
20
+ var _useState5 = useState(false),
21
+ _useState6 = _slicedToArray(_useState5, 2),
22
+ loading = _useState6[0],
23
+ setLoading = _useState6[1];
24
+ var dispatch = useDispatch();
25
+
26
+ // ----------------------------
27
+ // URL → project mapping
28
+ // ----------------------------
29
+ var projectCodeFromUrl = useMemo(function () {
30
+ var path = (pathname || "").toLowerCase();
31
+ if (path.startsWith("/docflow")) return "docflow-api";
32
+ if (path.startsWith("/hr")) return "hr-api";
33
+ if (path.startsWith("/contracts")) return "contracts-api";
34
+ if (path.startsWith("/accounts")) return "accounts-api";
35
+ if (path.startsWith("/archive")) return "archive-api";
36
+ if (path.startsWith("/transport")) return "transport-api";
37
+ if (path.startsWith("/laboratory")) return "laboratory-api";
38
+ return null;
39
+ }, [pathname]);
40
+
41
+ // ----------------------------
42
+ // normalize company info
43
+ // ----------------------------
44
+ var rawProjects = useMemo(function () {
45
+ if (Array.isArray(companyInfo)) {
46
+ var _companyInfo$;
47
+ return companyInfo === null || companyInfo === void 0 || (_companyInfo$ = companyInfo[0]) === null || _companyInfo$ === void 0 ? void 0 : _companyInfo$.projects;
48
+ }
49
+ return companyInfo === null || companyInfo === void 0 ? void 0 : companyInfo.projects;
50
+ }, [companyInfo]);
51
+
52
+ // ----------------------------
53
+ // parse projects safely
54
+ // ----------------------------
55
+ var parseProjects = function parseProjects(raw) {
56
+ if (!raw || typeof raw !== "string") return [];
57
+ try {
58
+ var cleaned = raw.trim();
59
+ cleaned = cleaned.replace(/^.*?\[/, "[");
60
+ cleaned = cleaned.replace(/\}\}\\"?$/, "");
61
+ cleaned = cleaned.replace(/\}\}$/, "");
62
+ if (!cleaned.endsWith("]")) {
63
+ cleaned += "]";
64
+ }
65
+ return JSON.parse(cleaned);
66
+ } catch (err) {
67
+ console.error("Failed to parse projects:", err);
68
+ return [];
69
+ }
70
+ };
71
+ var projects = useMemo(function () {
72
+ return parseProjects(rawProjects);
73
+ }, [rawProjects]);
74
+
75
+ // ----------------------------
76
+ // find current project
77
+ // ----------------------------
78
+ var currentProject = useMemo(function () {
79
+ if (!Array.isArray(projects) || !projectCodeFromUrl) return null;
80
+ return projects.find(function (p) {
81
+ var _p$Code;
82
+ return (p === null || p === void 0 || (_p$Code = p.Code) === null || _p$Code === void 0 ? void 0 : _p$Code.toLowerCase().trim()) === projectCodeFromUrl.toLowerCase().trim();
83
+ });
84
+ }, [projects, projectCodeFromUrl]);
85
+
86
+ // ----------------------------
87
+ // license logic
88
+ // ----------------------------
89
+ var licenseStatus = useMemo(function () {
90
+ if (!(currentProject !== null && currentProject !== void 0 && currentProject.EndDate)) {
91
+ return {
92
+ status: "unknown"
93
+ };
94
+ }
95
+ var endDate = new Date(currentProject.EndDate);
96
+ var today = new Date();
97
+ var end = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
98
+ var now = new Date(today.getFullYear(), today.getMonth(), today.getDate());
99
+ var diffDays = Math.ceil((end - now) / (1000 * 60 * 60 * 24));
100
+ if (diffDays <= 0) {
101
+ return {
102
+ status: "expired",
103
+ text: "Lisenziya müddəti bitib",
104
+ color: "red"
105
+ };
106
+ }
107
+ if (diffDays <= 30) {
108
+ return {
109
+ status: "warning",
110
+ text: "Lisenziya m\xFCdd\u0259tinin bitm\u0259sin\u0259 ".concat(diffDays, " g\xFCn qal\u0131b"),
111
+ color: "yellow"
112
+ };
113
+ }
114
+ return {
115
+ status: "valid"
116
+ };
117
+ }, [currentProject]);
118
+
119
+ // ----------------------------
120
+ // activation handler
121
+ // ----------------------------
122
+ var handleActivate = /*#__PURE__*/function () {
123
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
124
+ var _t;
125
+ return _regeneratorRuntime.wrap(function (_context) {
126
+ while (1) switch (_context.prev = _context.next) {
127
+ case 0:
128
+ _context.prev = 0;
129
+ setLoading(true);
130
+ _context.next = 1;
131
+ return dispatch(requestActivation());
132
+ case 1:
133
+ setOpen(false);
134
+ setNote("");
135
+ _context.next = 3;
136
+ break;
137
+ case 2:
138
+ _context.prev = 2;
139
+ _t = _context["catch"](0);
140
+ console.error(_t);
141
+ case 3:
142
+ _context.prev = 3;
143
+ setLoading(false);
144
+ window.location.reload();
145
+ return _context.finish(3);
146
+ case 4:
147
+ case "end":
148
+ return _context.stop();
149
+ }
150
+ }, _callee, null, [[0, 2, 3, 4]]);
151
+ }));
152
+ return function handleActivate() {
153
+ return _ref2.apply(this, arguments);
154
+ };
155
+ }();
156
+
157
+ // ----------------------------
158
+ // render
159
+ // ----------------------------
160
+ if (licenseStatus.status === "valid") return null;
161
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
162
+ onClick: function onClick() {
163
+ return setOpen(true);
164
+ },
165
+ style: {
166
+ position: "absolute",
167
+ top: 0,
168
+ left: 0,
169
+ background: licenseStatus.color,
170
+ fontSize: 18,
171
+ color: "#000",
172
+ width: "100%",
173
+ zIndex: 9999,
174
+ display: "flex",
175
+ justifyContent: "center",
176
+ alignItems: "center",
177
+ cursor: "pointer"
178
+ }
179
+ }, licenseStatus.status === "expired" ? "Lisenziya müddəti bitib" : licenseStatus.text), /*#__PURE__*/React.createElement(Modal, {
180
+ title: "Lisenziyan\u0131n aktivl\u0259\u015Fdirilm\u0259si",
181
+ open: open,
182
+ onCancel: function onCancel() {
183
+ return setOpen(false);
184
+ },
185
+ footer: null
186
+ }, /*#__PURE__*/React.createElement("div", {
187
+ style: {
188
+ marginTop: 16,
189
+ textAlign: "right",
190
+ gap: 8,
191
+ display: "flex",
192
+ justifyContent: "flex-end"
193
+ }
194
+ }, /*#__PURE__*/React.createElement(Button, {
195
+ color: "green",
196
+ loading: loading,
197
+ onClick: handleActivate
198
+ }, "Aktivasiya t\u0259l\u0259b et"))));
199
+ };
200
+ export default LicenseWatermark;
@@ -3,10 +3,10 @@ import React, { useEffect, useState } from "react";
3
3
  import style from "./index.module.scss";
4
4
  import ProfileOptions from "../../components/ProfileOptions";
5
5
  import AppSelect from "./AppSelect";
6
- import { useDispatch } from "react-redux";
6
+ import { useDispatch, useSelector } from "react-redux";
7
7
  import { getLoginType } from "../../store/slices/auth";
8
8
  import { getCompanyInfo } from "../../store/slices/companyInfo";
9
- import { useSelector } from "react-redux";
9
+ import LicenseWatermark from "../../components/LicenseWatermark/LicenseWatermark";
10
10
  var Header = function Header() {
11
11
  var _companyInfo$;
12
12
  var _useState = useState(localStorage.getItem("theme") || "light"),
@@ -17,14 +17,14 @@ var Header = function Header() {
17
17
  var companyInfo = useSelector(function (state) {
18
18
  return state.companyInfo.companyInfo;
19
19
  });
20
- var updateTheme = function updateTheme() {
21
- var newTheme = localStorage.getItem("theme") || "light";
22
- setTheme(newTheme);
23
- };
20
+ var pathname = window.location.pathname;
24
21
  useEffect(function () {
25
- window.addEventListener("themeChange", updateTheme);
22
+ var handler = function handler() {
23
+ return setTheme(localStorage.getItem("theme") || "light");
24
+ };
25
+ window.addEventListener("themeChange", handler);
26
26
  return function () {
27
- return window.removeEventListener("themeChange", updateTheme);
27
+ return window.removeEventListener("themeChange", handler);
28
28
  };
29
29
  }, []);
30
30
  useEffect(function () {
@@ -34,7 +34,10 @@ var Header = function Header() {
34
34
  return /*#__PURE__*/React.createElement("header", {
35
35
  className: style.header,
36
36
  "data-no-invert": true
37
- }, /*#__PURE__*/React.createElement(AppSelect, {
37
+ }, /*#__PURE__*/React.createElement(LicenseWatermark, {
38
+ companyInfo: companyInfo,
39
+ pathname: pathname
40
+ }), /*#__PURE__*/React.createElement(AppSelect, {
38
41
  mainPage: companyInfo === null || companyInfo === void 0 || (_companyInfo$ = companyInfo[0]) === null || _companyInfo$ === void 0 ? void 0 : _companyInfo$.mainPage
39
42
  }), /*#__PURE__*/React.createElement(ProfileOptions, null));
40
43
  };
@@ -168,6 +168,36 @@ export var changePassword = createAsyncThunk("/changePassword", /*#__PURE__*/fun
168
168
  return _ref0.apply(this, arguments);
169
169
  };
170
170
  }());
171
+ export var requestActivation = createAsyncThunk("/requestActivation", /*#__PURE__*/function () {
172
+ var _ref10 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_, _ref1) {
173
+ var dispatch, response, _t6;
174
+ return _regeneratorRuntime.wrap(function (_context6) {
175
+ while (1) switch (_context6.prev = _context6.next) {
176
+ case 0:
177
+ dispatch = _ref1.dispatch;
178
+ _context6.prev = 1;
179
+ dispatch(setLoading(true));
180
+ _context6.next = 2;
181
+ return AuthServices.requestActivation();
182
+ case 2:
183
+ response = _context6.sent;
184
+ dispatch(setLoading(false));
185
+ return _context6.abrupt("return", response);
186
+ case 3:
187
+ _context6.prev = 3;
188
+ _t6 = _context6["catch"](1);
189
+ errorMessage(_t6.response.data.message);
190
+ dispatch(setLoading(false));
191
+ case 4:
192
+ case "end":
193
+ return _context6.stop();
194
+ }
195
+ }, _callee6, null, [[1, 3]]);
196
+ }));
197
+ return function (_x1, _x10) {
198
+ return _ref10.apply(this, arguments);
199
+ };
200
+ }());
171
201
  export var auth = createSlice({
172
202
  name: "auth",
173
203
  initialState: initialState,
@@ -192,16 +222,16 @@ export var auth = createSlice({
192
222
  }
193
223
  },
194
224
  extraReducers: function extraReducers(builder) {
195
- builder.addCase(login.fulfilled, function (state, _ref1) {
196
- var payload = _ref1.payload;
225
+ builder.addCase(login.fulfilled, function (state, _ref11) {
226
+ var payload = _ref11.payload;
197
227
  state.user = payload;
198
228
  });
199
- builder.addCase(getProfileInfo.fulfilled, function (state, _ref10) {
200
- var payload = _ref10.payload;
229
+ builder.addCase(getProfileInfo.fulfilled, function (state, _ref12) {
230
+ var payload = _ref12.payload;
201
231
  state.profileInfo = payload;
202
232
  });
203
- builder.addCase(getLoginType.fulfilled, function (state, _ref11) {
204
- var payload = _ref11.payload;
233
+ builder.addCase(getLoginType.fulfilled, function (state, _ref13) {
234
+ var payload = _ref13.payload;
205
235
  state.loginType = payload;
206
236
  });
207
237
  }
@@ -102,4 +102,22 @@ _defineProperty(AuthServices, "changePassword", /*#__PURE__*/function () {
102
102
  return _ref5.apply(this, arguments);
103
103
  };
104
104
  }());
105
+ _defineProperty(AuthServices, "requestActivation", /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
106
+ var response;
107
+ return _regeneratorRuntime.wrap(function (_context6) {
108
+ while (1) switch (_context6.prev = _context6.next) {
109
+ case 0:
110
+ _context6.next = 1;
111
+ return api.put("/licences", {
112
+ prompt: "Request Activation"
113
+ });
114
+ case 1:
115
+ response = _context6.sent;
116
+ return _context6.abrupt("return", response);
117
+ case 2:
118
+ case "end":
119
+ return _context6.stop();
120
+ }
121
+ }, _callee6);
122
+ })));
105
123
  export default AuthServices;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banch0u/core-project-test-repository",
3
- "version": "2.2.20",
3
+ "version": "2.3.1",
4
4
  "description": "Shared core features for all projects",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -15,18 +15,18 @@
15
15
  "license": "MIT",
16
16
  "scripts": {
17
17
  "clean": "rimraf dist",
18
- "build": "npm run precheck && npm run clean && babel src --out-dir dist --copy-files",
19
- "watch": "chokidar \"src\" -i 'dist' -c \"npm run build && yalc push --force\"",
18
+ "build": "babel src --out-dir dist --copy-files",
19
+ "watch": "babel src --out-dir dist --copy-files --watch",
20
+ "watch:push": "chokidar \"dist/**/*\" -c \"yalc push --changed --verbose\"",
20
21
  "pull": "git pull",
21
- "dev": "npm run pull && npm run precheck && npm run watch",
22
- "precheck": "node compiler-checks.js",
23
- "publish:patch": "npm run build && npm version patch && npm publish",
24
- "publish:minor": "npm run build && npm version minor && npm publish",
25
- "publish:major": "npm run build && npm version major && npm publish"
22
+ "dev": "npm run pull && concurrently \"npm run watch\" \"npm run watch:push\"",
23
+ "push": "yalc push --changed --verbose",
24
+ "publish:patch": "npm run clean && npm run build && npm version patch && npm publish",
25
+ "publish:minor": "npm run clean && npm run build && npm version minor && npm publish",
26
+ "publish:major": "npm run clean && npm run build && npm version major && npm publish"
26
27
  },
27
28
  "dependencies": {
28
29
  "@ant-design/icons": "^6.0.0",
29
- "@banch0u/core-project-test-repository": "file:.yalc/@banch0u/core-project-test-repository",
30
30
  "@microsoft/signalr": "^8.0.7",
31
31
  "@pdftron/webviewer": "^11.2.0",
32
32
  "@reduxjs/toolkit": "^2.6.1",
@@ -56,6 +56,7 @@
56
56
  "@babel/preset-react": "^7.26.3",
57
57
  "babel-loader": "^9.2.1",
58
58
  "chokidar-cli": "^3.0.0",
59
+ "concurrently": "^9.2.1",
59
60
  "eslint": "^8.57.1",
60
61
  "eslint-import-resolver-node": "^0.3.9",
61
62
  "eslint-plugin-import": "^2.31.0",