@banch0u/core-project-test-repository 1.4.0 → 1.4.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.
@@ -1,12 +1,10 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
- import React, { useCallback, useRef, useState } from "react";
3
+ import React, { useRef, useState } from "react";
5
4
  import { useDispatch, useSelector } from "react-redux";
6
5
  import { readNotification, readNotificationAll } from "../../store/slices/notification";
7
- import { Button, Form, List, Typography } from "antd";
6
+ import { Button, List, Tooltip, Typography } from "antd";
8
7
  import { CheckOutlined, EyeOutlined, SettingOutlined } from "@ant-design/icons";
9
- import { Modal } from "antd";
10
8
  import style from "./index.module.scss";
11
9
  import NotificationSettingsContent from "../NotificationSettingsContent";
12
10
  import FormModal from "../FormModal";
@@ -17,14 +15,12 @@ var NotificationDropdown = function NotificationDropdown(_ref) {
17
15
  setSize = _ref.setSize,
18
16
  setPage = _ref.setPage;
19
17
  var dispatch = useDispatch();
20
- var ref = useRef();
18
+ var modalRef = useRef(); // ⬅️ Modal ref
19
+ var contentRef = useRef(); // ⬅️ NotificationSettingsContent ref
20
+
21
21
  var notifications = useSelector(function (state) {
22
22
  return state.notification.notifications;
23
23
  });
24
- var _useState = useState(false),
25
- _useState2 = _slicedToArray(_useState, 2),
26
- isSettingsOpen = _useState2[0],
27
- setIsSettingsOpen = _useState2[1];
28
24
  var notReadenCount = notifications === null || notifications === void 0 ? void 0 : notifications.notReadenCount;
29
25
  var totalCount = notifications === null || notifications === void 0 ? void 0 : notifications.totalCount;
30
26
  var items = (notifications === null || notifications === void 0 || (_notifications$notifi = notifications.notifications) === null || _notifications$notifi === void 0 ? void 0 : _notifications$notifi.items) || [];
@@ -40,17 +36,13 @@ var NotificationDropdown = function NotificationDropdown(_ref) {
40
36
  };
41
37
  }
42
38
  };
43
- var onOpenModal = function onOpenModal() {
44
- var _ref$current;
45
- ref === null || ref === void 0 || (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.open();
46
- };
47
39
  var handleRead = function handleRead(id) {
48
40
  return dispatch(readNotification({
49
41
  id: id
50
42
  }));
51
43
  };
52
44
  var handleReadAll = function handleReadAll() {
53
- dispatch(readNotificationAll());
45
+ return dispatch(readNotificationAll());
54
46
  };
55
47
  var handleNotificationClick = /*#__PURE__*/function () {
56
48
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(value, id) {
@@ -85,7 +77,16 @@ var NotificationDropdown = function NotificationDropdown(_ref) {
85
77
  var handleLoadMore = function handleLoadMore() {
86
78
  var newSize = size + 20;
87
79
  setSize(newSize);
88
- setPage(1); // always use page 1 when growing size
80
+ setPage(1);
81
+ };
82
+ var onOpenModal = function onOpenModal() {
83
+ var _contentRef$current, _contentRef$current$r, _modalRef$current, _modalRef$current$ope;
84
+ contentRef === null || contentRef === void 0 || (_contentRef$current = contentRef.current) === null || _contentRef$current === void 0 || (_contentRef$current$r = _contentRef$current.refresh) === null || _contentRef$current$r === void 0 || _contentRef$current$r.call(_contentRef$current); // ⬅️ Trigger getNotificationSettings()
85
+ modalRef === null || modalRef === void 0 || (_modalRef$current = modalRef.current) === null || _modalRef$current === void 0 || (_modalRef$current$ope = _modalRef$current.open) === null || _modalRef$current$ope === void 0 || _modalRef$current$ope.call(_modalRef$current); // ⬅️ Open modal
86
+ };
87
+ var onCloseModal = function onCloseModal() {
88
+ var _modalRef$current2, _modalRef$current2$cl;
89
+ modalRef === null || modalRef === void 0 || (_modalRef$current2 = modalRef.current) === null || _modalRef$current2 === void 0 || (_modalRef$current2$cl = _modalRef$current2.close) === null || _modalRef$current2$cl === void 0 || _modalRef$current2$cl.call(_modalRef$current2); // ⬅️ Open modal
89
90
  };
90
91
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
91
92
  className: style.dropdownWrapper
@@ -104,9 +105,7 @@ var NotificationDropdown = function NotificationDropdown(_ref) {
104
105
  size: "small",
105
106
  icon: /*#__PURE__*/React.createElement(SettingOutlined, null),
106
107
  type: "text",
107
- onClick: function onClick() {
108
- return onOpenModal();
109
- }
108
+ onClick: onOpenModal
110
109
  }))), /*#__PURE__*/React.createElement(List, {
111
110
  dataSource: items,
112
111
  locale: {
@@ -115,17 +114,19 @@ var NotificationDropdown = function NotificationDropdown(_ref) {
115
114
  renderItem: function renderItem(item) {
116
115
  var parsed = parseNotification(item.text);
117
116
  return /*#__PURE__*/React.createElement(List.Item, {
118
- className: "".concat(style.notificationItem, " ").concat(!item.read ? style.unread : ""),
119
- actions: [!item.read && /*#__PURE__*/React.createElement(Button, {
117
+ className: "".concat(style.notificationItem, " ").concat(item.isReaden ? style.read : style.unread),
118
+ actions: [!item.isReaden && /*#__PURE__*/React.createElement(Tooltip, {
119
+ title: "Oxu"
120
+ }, /*#__PURE__*/React.createElement(Button, {
120
121
  size: "small",
121
122
  type: "link",
122
123
  icon: /*#__PURE__*/React.createElement(EyeOutlined, null),
123
124
  onClick: function onClick() {
124
125
  return handleRead(item.id);
125
126
  }
126
- })]
127
+ }))]
127
128
  }, /*#__PURE__*/React.createElement(List.Item.Meta, {
128
- title: /*#__PURE__*/React.createElement("span", {
129
+ title: /*#__PURE__*/React.createElement("div", {
129
130
  onClick: function onClick() {
130
131
  return handleNotificationClick(item.text, item.id);
131
132
  },
@@ -151,11 +152,12 @@ var NotificationDropdown = function NotificationDropdown(_ref) {
151
152
  type: "text",
152
153
  onClick: handleLoadMore
153
154
  }, "Daha \xE7ox g\xF6st\u0259r"))), /*#__PURE__*/React.createElement(FormModal, {
154
- ref: ref,
155
+ ref: modalRef,
155
156
  width: 695,
156
157
  showButtons: false
157
158
  }, /*#__PURE__*/React.createElement(NotificationSettingsContent, {
158
- ref: ref
159
+ ref: contentRef,
160
+ onClose: onCloseModal
159
161
  })));
160
162
  };
161
163
  export default NotificationDropdown;
@@ -50,10 +50,13 @@
50
50
  background-color: #deeaf5;
51
51
  }
52
52
  }
53
-
53
+ .read {
54
+ background-color: white;
55
+ font-weight: 500;
56
+ }
54
57
  .unread {
55
58
  background-color: #f6f6f6;
56
- font-weight: 600;
59
+ font-weight: 700;
57
60
  }
58
61
 
59
62
  .loadMore {
@@ -1,11 +1,12 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
- import React, { useCallback, useEffect, useState } from "react";
2
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
3
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
+ import React, { useCallback, useEffect, useState, useImperativeHandle } from "react";
6
6
  import { Form, Switch, Typography, Row, Col, Select } from "antd";
7
7
  import { useDispatch, useSelector } from "react-redux";
8
8
  import { editNotificationSettings, getNotificationSettings } from "../../store/slices/notification";
9
+ import { useLocation } from "react-router-dom";
9
10
  import style from "./index.module.scss";
10
11
  import Button from "../Button";
11
12
  var Title = Typography.Title,
@@ -35,10 +36,17 @@ var NotificationSettingsContent = /*#__PURE__*/React.forwardRef(function (props,
35
36
  _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
36
37
  form = _Form$useForm2[0];
37
38
  var dispatch = useDispatch();
39
+ var location = useLocation();
38
40
  var initialValues = useSelector(function (state) {
39
41
  return state.notification.notificationSettings;
40
42
  });
41
- var _useState = useState("docFlowSettings"),
43
+ var getDefaultProjectFromPath = function getDefaultProjectFromPath(path) {
44
+ if (path.includes("/contract")) return "contractSettings";
45
+ return "docFlowSettings";
46
+ };
47
+ var _useState = useState(function () {
48
+ return getDefaultProjectFromPath(location.pathname);
49
+ }),
42
50
  _useState2 = _slicedToArray(_useState, 2),
43
51
  selectedProject = _useState2[0],
44
52
  setSelectedProject = _useState2[1];
@@ -46,6 +54,15 @@ var NotificationSettingsContent = /*#__PURE__*/React.forwardRef(function (props,
46
54
  _useState4 = _slicedToArray(_useState3, 2),
47
55
  allValues = _useState4[0],
48
56
  setAllValues = _useState4[1];
57
+ useImperativeHandle(ref, function () {
58
+ return {
59
+ refresh: function refresh() {
60
+ var projectFromPath = getDefaultProjectFromPath(location.pathname);
61
+ setSelectedProject(projectFromPath);
62
+ dispatch(getNotificationSettings());
63
+ }
64
+ };
65
+ });
49
66
  useEffect(function () {
50
67
  dispatch(getNotificationSettings());
51
68
  }, [dispatch]);
@@ -56,16 +73,64 @@ var NotificationSettingsContent = /*#__PURE__*/React.forwardRef(function (props,
56
73
  }
57
74
  }, [initialValues, form]);
58
75
  var handleSwitchChange = function handleSwitchChange(namePath, checked) {
59
- var updated = _objectSpread({}, allValues);
76
+ var updated = structuredClone(allValues);
60
77
  var target = updated;
61
78
  namePath.forEach(function (key, i) {
62
79
  if (i === namePath.length - 1) {
63
80
  target[key] = checked;
64
81
  } else {
65
- target[key] = _objectSpread({}, target[key]);
66
82
  target = target[key];
67
83
  }
68
84
  });
85
+
86
+ // Toggle all child switches if general toggle is used
87
+ if (namePath[0] === "generalSettings" && (namePath[1] === "internalIsActive" || namePath[1] === "emailIsActive")) {
88
+ var typeToChange = namePath[1] === "internalIsActive" ? "internalSettings" : "emailSettings";
89
+ Object.keys(projectOptions).forEach(function (projectKey) {
90
+ if (!updated[projectKey]) updated[projectKey] = {};
91
+ if (!updated[projectKey][typeToChange]) updated[projectKey][typeToChange] = {};
92
+ projectOptions[projectKey].keys.forEach(function (key) {
93
+ updated[projectKey][typeToChange][key] = checked;
94
+ });
95
+ });
96
+ }
97
+
98
+ // If any child switch is turned ON → set general ON
99
+ if (namePath.length === 3 && (namePath[1] === "internalSettings" || namePath[1] === "emailSettings") && checked === true) {
100
+ var generalKey = namePath[1] === "internalSettings" ? "internalIsActive" : "emailIsActive";
101
+ if (!updated.generalSettings) updated.generalSettings = {};
102
+ updated.generalSettings[generalKey] = true;
103
+ }
104
+
105
+ // If child turned OFF → check if all children are OFF → turn OFF general
106
+ if (namePath.length === 3 && (namePath[1] === "internalSettings" || namePath[1] === "emailSettings")) {
107
+ var type = namePath[1];
108
+ var _generalKey = type === "internalSettings" ? "internalIsActive" : "emailIsActive";
109
+ var anyOn = false;
110
+ Object.keys(projectOptions).forEach(function (projectKey) {
111
+ var _updated$projectKey;
112
+ var settings = ((_updated$projectKey = updated[projectKey]) === null || _updated$projectKey === void 0 ? void 0 : _updated$projectKey[type]) || {};
113
+ var _iterator = _createForOfIteratorHelper(projectOptions[projectKey].keys),
114
+ _step;
115
+ try {
116
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
117
+ var key = _step.value;
118
+ if (settings[key]) {
119
+ anyOn = true;
120
+ break;
121
+ }
122
+ }
123
+ } catch (err) {
124
+ _iterator.e(err);
125
+ } finally {
126
+ _iterator.f();
127
+ }
128
+ });
129
+ if (!anyOn) {
130
+ if (!updated.generalSettings) updated.generalSettings = {};
131
+ updated.generalSettings[_generalKey] = false;
132
+ }
133
+ }
69
134
  setAllValues(updated);
70
135
  form.setFieldsValue(updated);
71
136
  };
@@ -73,7 +138,7 @@ var NotificationSettingsContent = /*#__PURE__*/React.forwardRef(function (props,
73
138
  return projectOptions[selectedProject].keys.map(function (key) {
74
139
  var _allValues$selectedPr, _allValues$selectedPr2;
75
140
  return /*#__PURE__*/React.createElement(Col, {
76
- span: 12,
141
+ span: 6,
77
142
  key: "".concat(selectedProject, "-").concat(type, "-").concat(key)
78
143
  }, /*#__PURE__*/React.createElement(Form.Item, {
79
144
  className: style.inlineSwitch,
@@ -89,8 +154,9 @@ var NotificationSettingsContent = /*#__PURE__*/React.forwardRef(function (props,
89
154
  });
90
155
  };
91
156
  var onSubmit = useCallback(function (data) {
92
- console.log(data, "ew");
157
+ var _props$onClose;
93
158
  dispatch(editNotificationSettings(data));
159
+ props === null || props === void 0 || (_props$onClose = props.onClose) === null || _props$onClose === void 0 || _props$onClose.call(props);
94
160
  }, [dispatch]);
95
161
  return /*#__PURE__*/React.createElement("div", {
96
162
  className: style.settingsWrapper
@@ -142,17 +208,17 @@ var NotificationSettingsContent = /*#__PURE__*/React.forwardRef(function (props,
142
208
  }))), /*#__PURE__*/React.createElement(Text, {
143
209
  className: style.settingGroupTitle
144
210
  }, "Daxili"), /*#__PURE__*/React.createElement(Row, {
145
- gutter: [40, 0]
211
+ gutter: [24, 24]
146
212
  }, renderSwitches("internalSettings")), /*#__PURE__*/React.createElement(Text, {
147
213
  className: style.settingGroupTitle
148
214
  }, "Email"), /*#__PURE__*/React.createElement(Row, {
149
- gutter: [40, 0]
215
+ gutter: [24, 24]
150
216
  }, renderSwitches("emailSettings")), /*#__PURE__*/React.createElement("div", {
151
217
  className: style.next_buttons_
152
218
  }, /*#__PURE__*/React.createElement(Button, {
153
219
  onClick: function onClick(e) {
154
- var _ref$current, _ref$current$close;
155
- ref === null || ref === void 0 || (_ref$current = ref.current) === null || _ref$current === void 0 || (_ref$current$close = _ref$current.close) === null || _ref$current$close === void 0 || _ref$current$close.call(_ref$current);
220
+ var _props$onClose2;
221
+ props === null || props === void 0 || (_props$onClose2 = props.onClose) === null || _props$onClose2 === void 0 || _props$onClose2.call(props);
156
222
  e.preventDefault();
157
223
  },
158
224
  color: "white"
@@ -35,7 +35,7 @@ var ProfileOptions = function ProfileOptions() {
35
35
  var notifications = useSelector(function (state) {
36
36
  return state.notification.notifications;
37
37
  });
38
- console.log(notifications);
38
+ console.log(notificationsRender);
39
39
  var _useState5 = useState(localStorage.getItem("theme") || "light"),
40
40
  _useState6 = _slicedToArray(_useState5, 2),
41
41
  theme = _useState6[0],
@@ -73,6 +73,9 @@ var ProfileOptions = function ProfileOptions() {
73
73
  page: page
74
74
  }));
75
75
  }, [dispatch, size, page, notificationsRender]);
76
+ useEffect(function () {
77
+ console.log("notificationsRender:", notificationsRender);
78
+ }, [notificationsRender]);
76
79
  var rootUrl = window.location.origin;
77
80
  var menu1 = /*#__PURE__*/React.createElement(Menu, null, /*#__PURE__*/React.createElement("div", {
78
81
  className: style.links
@@ -1,17 +1,10 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- // hooks/useNotification.js
3
- import { useEffect, useState } from "react";
1
+ import { useEffect } from "react";
4
2
  import * as signalR from "@microsoft/signalr";
5
3
  import { infoMessageBottomRight } from "../utils/message";
4
+ import { setNotificationsRender } from "../store/slices/global";
5
+ import store from "../store/store"; // ⬅️ Import your Redux store explicitly
6
+
6
7
  var useNotification = function useNotification() {
7
- var _useState = useState(function () {
8
- // localStorage'dan bildirimi başlat
9
- var savedNotifications = localStorage.getItem("notifications");
10
- return savedNotifications ? JSON.parse(savedNotifications) : [];
11
- }),
12
- _useState2 = _slicedToArray(_useState, 2),
13
- notifications = _useState2[0],
14
- setNotifications = _useState2[1];
15
8
  useEffect(function () {
16
9
  var token = localStorage.getItem("token");
17
10
  var baseUrl;
@@ -33,6 +26,7 @@ var useNotification = function useNotification() {
33
26
  console.log("SignalR bağlantısı quruldu.");
34
27
  connection.on("receive", function (message) {
35
28
  console.log("Yeni bildiriş:", message);
29
+ store.dispatch(setNotificationsRender());
36
30
  infoMessageBottomRight(message);
37
31
  });
38
32
  })["catch"](function (err) {
@@ -43,6 +37,5 @@ var useNotification = function useNotification() {
43
37
  console.log("SignalR bağlantısı bağlandı.");
44
38
  };
45
39
  }, []);
46
- return notifications;
47
40
  };
48
41
  export default useNotification;
@@ -11,9 +11,8 @@ export var global = createSlice({
11
11
  var payload = _ref.payload;
12
12
  state.loading = payload;
13
13
  },
14
- setNotificationsRender: function setNotificationsRender(state, _ref2) {
15
- var payload = _ref2.payload;
16
- state.notificationsRender = payload;
14
+ setNotificationsRender: function setNotificationsRender(state) {
15
+ state.notificationsRender = !state.notificationsRender;
17
16
  }
18
17
  }
19
18
  });
@@ -35,7 +35,7 @@ _defineProperty(Services, "readNotification", /*#__PURE__*/function () {
35
35
  while (1) switch (_context2.prev = _context2.next) {
36
36
  case 0:
37
37
  _context2.next = 2;
38
- return api.post("/NotificationDetails", data);
38
+ return api.put("/NotificationDetails", data);
39
39
  case 2:
40
40
  response = _context2.sent;
41
41
  return _context2.abrupt("return", response === null || response === void 0 ? void 0 : response.data);
@@ -55,7 +55,9 @@ _defineProperty(Services, "readNotificationAll", /*#__PURE__*/_asyncToGenerator(
55
55
  while (1) switch (_context3.prev = _context3.next) {
56
56
  case 0:
57
57
  _context3.next = 2;
58
- return api.post("/NotificationDetails/ReadAll");
58
+ return api.put("/NotificationDetails/ReadAll", {
59
+ id: ""
60
+ });
59
61
  case 2:
60
62
  response = _context3.sent;
61
63
  return _context3.abrupt("return", response === null || response === void 0 ? void 0 : response.data);
@@ -104,7 +106,7 @@ _defineProperty(Services, "editNotificationSettings", /*#__PURE__*/function () {
104
106
  while (1) switch (_context6.prev = _context6.next) {
105
107
  case 0:
106
108
  _context6.next = 2;
107
- return api.post("/notificationusersettings", data);
109
+ return api.put("/notificationusersettings", data);
108
110
  case 2:
109
111
  response = _context6.sent;
110
112
  return _context6.abrupt("return", response === null || response === void 0 ? void 0 : response.data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banch0u/core-project-test-repository",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "Shared core features for all projects",
5
5
  "main": "dist/index.js",
6
6
  "files": [