awing-library 2.1.3 → 2.1.4

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.
Files changed (66) hide show
  1. package/lib/ACM-AXN/Campaign/index.js +2 -1
  2. package/lib/ACM-AXN/DomainPreview/PreviewButton.js +50 -27
  3. package/lib/ACM-AXN/Notifications/Constant.d.ts +144 -0
  4. package/lib/ACM-AXN/Notifications/Constant.js +134 -0
  5. package/lib/ACM-AXN/Notifications/Context.d.ts +8 -0
  6. package/lib/ACM-AXN/Notifications/Context.js +10 -0
  7. package/lib/ACM-AXN/Notifications/Hooks.d.ts +7 -0
  8. package/lib/ACM-AXN/Notifications/Hooks.js +17 -0
  9. package/lib/ACM-AXN/Notifications/NotificationDetail/HeaderInfo/ButtonTabs.js +26 -20
  10. package/lib/ACM-AXN/Notifications/NotificationDetail/HeaderInfo/MenuNotification.d.ts +1 -1
  11. package/lib/ACM-AXN/Notifications/NotificationDetail/HeaderInfo/MenuNotification.js +30 -39
  12. package/lib/ACM-AXN/Notifications/NotificationDetail/HeaderInfo/index.d.ts +2 -5
  13. package/lib/ACM-AXN/Notifications/NotificationDetail/HeaderInfo/index.js +18 -15
  14. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationEmpty.d.ts +1 -1
  15. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationEmpty.js +15 -15
  16. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationEmpty.test.d.ts +0 -6
  17. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationEmpty.test.js +29 -28
  18. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/Message.d.ts +10 -0
  19. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/Message.js +380 -0
  20. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/NotificationAvatar.d.ts +1 -1
  21. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/NotificationAvatar.js +3 -3
  22. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/NotificationAvatar.test.d.ts +0 -6
  23. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/NotificationAvatar.test.js +38 -48
  24. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/NotificationContent.d.ts +2 -2
  25. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/NotificationContent.js +32 -32
  26. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/NotificationContent.test.d.ts +0 -6
  27. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/NotificationContent.test.js +65 -73
  28. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/index.d.ts +4 -11
  29. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/index.js +46 -36
  30. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/index.test.d.ts +0 -6
  31. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationItem/index.test.js +56 -50
  32. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/NotificationLoading.js +30 -30
  33. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/index.d.ts +3 -15
  34. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/index.js +35 -4
  35. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/index.test.d.ts +0 -6
  36. package/lib/ACM-AXN/Notifications/NotificationDetail/NotificationList/index.test.js +88 -83
  37. package/lib/ACM-AXN/Notifications/NotificationDetail/index.d.ts +1 -1
  38. package/lib/ACM-AXN/Notifications/NotificationDetail/index.js +101 -100
  39. package/lib/ACM-AXN/Notifications/{NotificationPopover.d.ts → NotificationPopover/Container.d.ts} +2 -2
  40. package/lib/ACM-AXN/Notifications/NotificationPopover/Container.js +149 -0
  41. package/lib/ACM-AXN/Notifications/{NotificationPopover.test.d.ts → NotificationPopover/Container.test.d.ts} +1 -1
  42. package/lib/ACM-AXN/Notifications/{NotificationPopover.test.js → NotificationPopover/Container.test.js} +5 -5
  43. package/lib/ACM-AXN/Notifications/NotificationPopover/index.d.ts +8 -0
  44. package/lib/ACM-AXN/Notifications/NotificationPopover/index.js +13 -0
  45. package/lib/ACM-AXN/Notifications/NotificationScreen.d.ts +1 -1
  46. package/lib/ACM-AXN/Notifications/NotificationScreen.js +4 -4
  47. package/lib/ACM-AXN/Notifications/Types.d.ts +241 -0
  48. package/lib/ACM-AXN/Notifications/Types.js +290 -0
  49. package/lib/ACM-AXN/Notifications/index.d.ts +2 -2
  50. package/lib/ACM-AXN/Notifications/index.js +5 -5
  51. package/lib/ACM-AXN/Page/Container.js +2 -2
  52. package/lib/ACM-AXN/Page/index.js +2 -1
  53. package/lib/ACM-AXN/PlaceGroup/Context.d.ts +1 -1
  54. package/lib/ACM-AXN/ViewTemplate/TemplateField/Fields/BasicField/index.js +1 -1
  55. package/lib/AWING/Directory/CreateDirectory.d.ts +3 -0
  56. package/lib/AWING/Directory/CreateDirectory.js +27 -10
  57. package/lib/Commons/Components/ClassicBaseDrawer.d.ts +1 -0
  58. package/lib/Commons/Components/ClassicBaseDrawer.js +7 -3
  59. package/lib/translate/en/translation.json +53 -0
  60. package/lib/translate/vi/translation.json +53 -0
  61. package/package.json +2 -1
  62. package/lib/ACM-AXN/Notifications/NotificationDetail/Common.d.ts +0 -39
  63. package/lib/ACM-AXN/Notifications/NotificationDetail/Common.js +0 -304
  64. package/lib/ACM-AXN/Notifications/NotificationPopover.js +0 -69
  65. package/lib/ACM-AXN/Page/ViewDomain/index.d.ts +0 -9
  66. package/lib/ACM-AXN/Page/ViewDomain/index.js +0 -148
@@ -13,44 +13,44 @@ var react_1 = __importDefault(require("react"));
13
13
  var material_1 = require("@mui/material");
14
14
  var NotificationLoading = function () {
15
15
  return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { component: "div", sx: {
16
- display: "flex",
17
- flexDirection: "row",
18
- padding: "8px",
19
- borderRadius: "8px",
16
+ display: 'flex',
17
+ flexDirection: 'row',
18
+ padding: '8px',
19
+ borderRadius: '8px',
20
20
  }, children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "circular", children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { sx: {
21
- width: "56px",
22
- height: "56px",
21
+ width: '56px',
22
+ height: '56px',
23
23
  } }) }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "div", ml: 1, sx: {
24
24
  flex: 1,
25
- display: "flex",
26
- flexDirection: "column",
27
- justifyContent: "space-around",
28
- }, children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "100%", height: "20px", sx: { borderRadius: "8px" }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "40%", height: "10px", sx: { borderRadius: "8px" }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) })] })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "div", sx: {
29
- display: "flex",
30
- flexDirection: "row",
31
- padding: "8px",
32
- borderRadius: "8px",
25
+ display: 'flex',
26
+ flexDirection: 'column',
27
+ justifyContent: 'space-around',
28
+ }, children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "100%", height: "20px", sx: { borderRadius: '8px' }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "40%", height: "10px", sx: { borderRadius: '8px' }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) })] })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "div", sx: {
29
+ display: 'flex',
30
+ flexDirection: 'row',
31
+ padding: '8px',
32
+ borderRadius: '8px',
33
33
  }, children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "circular", children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { sx: {
34
- width: "56px",
35
- height: "56px",
34
+ width: '56px',
35
+ height: '56px',
36
36
  } }) }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "div", ml: 1, sx: {
37
37
  flex: 1,
38
- display: "flex",
39
- flexDirection: "column",
40
- justifyContent: "space-around",
41
- }, children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "60%", height: "20px", sx: { borderRadius: "8px" }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "30%", height: "10px", sx: { borderRadius: "8px" }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) })] })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "div", sx: {
42
- display: "flex",
43
- flexDirection: "row",
44
- padding: "8px",
45
- borderRadius: "8px",
38
+ display: 'flex',
39
+ flexDirection: 'column',
40
+ justifyContent: 'space-around',
41
+ }, children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "60%", height: "20px", sx: { borderRadius: '8px' }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "30%", height: "10px", sx: { borderRadius: '8px' }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) })] })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "div", sx: {
42
+ display: 'flex',
43
+ flexDirection: 'row',
44
+ padding: '8px',
45
+ borderRadius: '8px',
46
46
  }, children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "circular", children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { sx: {
47
- width: "56px",
48
- height: "56px",
47
+ width: '56px',
48
+ height: '56px',
49
49
  } }) }), (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "div", ml: 1, sx: {
50
50
  flex: 1,
51
- display: "flex",
52
- flexDirection: "column",
53
- justifyContent: "space-around",
54
- }, children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "80%", height: "20px", sx: { borderRadius: "8px" }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "30%", height: "10px", sx: { borderRadius: "8px" }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) })] })] })] }));
51
+ display: 'flex',
52
+ flexDirection: 'column',
53
+ justifyContent: 'space-around',
54
+ }, children: [(0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "80%", height: "20px", sx: { borderRadius: '8px' }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) }), (0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", width: "30%", height: "10px", sx: { borderRadius: '8px' }, children: (0, jsx_runtime_1.jsx)(material_1.Typography, { children: "." }) })] })] })] }));
55
55
  };
56
56
  exports.default = NotificationLoading;
@@ -4,27 +4,15 @@
4
4
  *
5
5
  **/
6
6
  /// <reference types="react" />
7
- interface NotificationItemData {
8
- id: string | number;
9
- content: string;
10
- url: string;
11
- status: boolean;
12
- userName: string;
13
- avatarUrl: string;
14
- time: number | string;
15
- }
16
- interface ValueItem {
17
- id: string | number;
18
- status: boolean;
19
- }
7
+ import { IValueItem, NotificationMessage } from '../../Types';
20
8
  interface PropsNotificationList {
21
9
  valueFilter: {
22
10
  textSearch: string;
23
11
  tabs: string;
24
12
  };
25
13
  isLoading: boolean;
26
- notifications: NotificationItemData[];
27
- onUpdateStatus: (dataSent: ValueItem | string) => void;
14
+ notificationMessage: NotificationMessage[];
15
+ onUpdateStatus: (dataSent: IValueItem | string) => void;
28
16
  }
29
17
  declare const NotificationList: (props: PropsNotificationList) => JSX.Element;
30
18
  export default NotificationList;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
@@ -9,16 +32,24 @@ var jsx_runtime_1 = require("react/jsx-runtime");
9
32
  * @author dauquan1108@gmail.com on 11/27/2023.
10
33
  *
11
34
  **/
12
- var react_1 = __importDefault(require("react"));
35
+ var react_1 = __importStar(require("react"));
36
+ var Constant_1 = require("../../Constant");
13
37
  var NotificationItem_1 = __importDefault(require("./NotificationItem"));
14
38
  var NotificationEmpty_1 = __importDefault(require("./NotificationEmpty"));
15
39
  var NotificationLoading_1 = __importDefault(require("./NotificationLoading"));
40
+ var Types_1 = require("../../Types");
16
41
  var NotificationList = function (props) {
17
42
  var _a;
18
- var valueFilter = props.valueFilter, notifications = props.notifications, onUpdateStatus = props.onUpdateStatus, _b = props.isLoading, isLoading = _b === void 0 ? false : _b;
43
+ var valueFilter = props.valueFilter, onUpdateStatus = props.onUpdateStatus, _b = props.isLoading, isLoading = _b === void 0 ? false : _b, notificationMessage = props.notificationMessage;
44
+ var _c = (0, react_1.useState)(notificationMessage), notifications = _c[0], setNotifications = _c[1];
45
+ (0, react_1.useLayoutEffect)(function () {
46
+ setNotifications(valueFilter.tabs === Constant_1.Constants.UNREAD
47
+ ? notificationMessage.filter(function (item) { return item.status === Types_1.NotificationMessageStatus.Read; })
48
+ : notificationMessage);
49
+ }, [notificationMessage, valueFilter.tabs]);
19
50
  if (!notifications.length && !isLoading) {
20
- return (0, jsx_runtime_1.jsx)(NotificationEmpty_1.default, { isSearch: ((_a = valueFilter === null || valueFilter === void 0 ? void 0 : valueFilter.textSearch) === null || _a === void 0 ? void 0 : _a.length) > 0 });
51
+ return ((0, jsx_runtime_1.jsx)(NotificationEmpty_1.default, { isSearch: ((_a = valueFilter === null || valueFilter === void 0 ? void 0 : valueFilter.textSearch) === null || _a === void 0 ? void 0 : _a.length) > 0 }));
21
52
  }
22
- return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [notifications.map(function (item) { return ((0, jsx_runtime_1.jsx)(NotificationItem_1.default, { data: item, onUpdateStatus: onUpdateStatus }, item.id)); }), isLoading && (0, jsx_runtime_1.jsx)(NotificationLoading_1.default, {})] }));
53
+ return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [notifications.map(function (item) { return ((0, jsx_runtime_1.jsx)(NotificationItem_1.default, { notificationMessage: item, onUpdateStatus: onUpdateStatus }, item.id)); }), isLoading && (0, jsx_runtime_1.jsx)(NotificationLoading_1.default, {})] }));
23
54
  };
24
55
  exports.default = NotificationList;
@@ -1,6 +0,0 @@
1
- /**
2
- *
3
- * @author dauquan1108@gmail.com on 12/7/2023.
4
- *
5
- **/
6
- import "@testing-library/jest-dom";
@@ -1,84 +1,89 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- var jsx_runtime_1 = require("react/jsx-runtime");
18
- var react_1 = require("@testing-library/react");
19
- require("@testing-library/jest-dom");
20
- // Component
21
- var _1 = __importDefault(require("."));
22
- jest.mock('./NotificationItem', function () { return function (props) {
23
- var data = props.data, onUpdateStatus = props.onUpdateStatus;
24
- return ((0, jsx_runtime_1.jsx)("div", { "data-testid": "notification-item", onClick: function () { return onUpdateStatus(data.id); }, children: (0, jsx_runtime_1.jsx)("span", { children: data.content }) }));
25
- }; });
26
- jest.mock("./NotificationLoading", function () { return function () {
27
- return (0, jsx_runtime_1.jsx)("div", { children: "icon Loading" });
28
- }; });
29
- describe("NotificationList component", function () {
30
- it("Hiển thị thông báo đối với trường hợp 'notifications' chưa có dữ liệu", function () {
31
- var props = {
32
- isLoading: false,
33
- notifications: [],
34
- onUpdateStatus: function () { return null; },
35
- valueFilter: { textSearch: "", tabs: "" },
36
- };
37
- var getByText = (0, react_1.render)((0, jsx_runtime_1.jsx)(_1.default, __assign({}, props))).getByText;
38
- var noNotificationsText = getByText("Notifications.TitleNoNotifications");
39
- expect(noNotificationsText).toBeInTheDocument();
40
- });
41
- it("Hiện thị danh sách thông báo khi notifications có dữ liệu", function () {
42
- var props = {
43
- isLoading: false,
44
- notifications: [
45
- {
46
- id: "1",
47
- content: '<p>Chiến dịch <a href="https://github.com/dauquan1108" target="_blank" style="text-decoration: none; color: blue;" title="Đậu Xuân Quân">Đậu Xuân Quân</a> đã được cập nhật.</p>',
48
- url: "https://awing.vn/",
49
- status: true,
50
- userName: "Đậu Xuân Quân",
51
- avatarUrl: "https://i.pinimg.com/564x/7d/be/68/7dbe686677277a06de561b16c1e2740b.jpg",
52
- time: "2023-12-06 10:30",
53
- },
54
- ],
55
- onUpdateStatus: function () { return null; },
56
- valueFilter: { textSearch: "", tabs: "" },
57
- };
58
- var notifications = [
59
- {
60
- id: "1",
61
- content: '<p>Chiến dịch <a href="https://github.com/dauquan1108" target="_blank" style="text-decoration: none; color: blue;" title="Đậu Xuân Quân">Đậu Xuân Quân</a> đã được cập nhật.</p>',
62
- url: "https://awing.vn/",
63
- status: true,
64
- userName: "Đậu Xuân Quân",
65
- avatarUrl: "https://i.pinimg.com/564x/7d/be/68/7dbe686677277a06de561b16c1e2740b.jpg",
66
- time: "2023-12-06 10:30",
67
- },
68
- ];
69
- var getAllByTestId = (0, react_1.render)((0, jsx_runtime_1.jsx)(_1.default, { valueFilter: { textSearch: "", tabs: "" }, onUpdateStatus: function () { return null; }, isLoading: false, notifications: notifications })).getAllByTestId;
70
- var notificationItems = getAllByTestId('notification-item');
71
- expect(notificationItems).toHaveLength(notifications.length);
72
- });
73
- it("Hiển thị trạng thái Loading khi 'isLoading=true'.", function () {
74
- var props = {
75
- isLoading: true,
76
- notifications: [],
77
- onUpdateStatus: function () { return null; },
78
- valueFilter: { textSearch: "", tabs: "" },
79
- };
80
- var getByText = (0, react_1.render)((0, jsx_runtime_1.jsx)(_1.default, __assign({}, props))).getByText;
81
- var iconLoading = getByText("icon Loading");
82
- expect(iconLoading).toBeInTheDocument();
83
- });
84
- });
2
+ // /**
3
+ // *
4
+ // * @author dauquan1108@gmail.com on 12/7/2023.
5
+ // *
6
+ // **/
7
+ // import React from "react";
8
+ // import { render } from "@testing-library/react";
9
+ // import "@testing-library/jest-dom";
10
+ // // Component
11
+ // import NotificationList from ".";
12
+ // jest.mock('./NotificationItem', () => (props:any) => {
13
+ // const { data, onUpdateStatus } = props;
14
+ // return (
15
+ // <div data-testid="notification-item" onClick={() => onUpdateStatus(data.id)}>
16
+ // <span>{data.content}</span>
17
+ // </div>
18
+ // );
19
+ // });
20
+ // jest.mock("./NotificationLoading", () => () => {
21
+ // return <div>icon Loading</div>;
22
+ // });
23
+ // describe("NotificationList component", () => {
24
+ // it("Hiển thị thông báo đối với trường hợp 'notifications' chưa dữ liệu", () => {
25
+ // const props = {
26
+ // isLoading: false,
27
+ // notifications: [],
28
+ // onUpdateStatus: () => null,
29
+ // valueFilter: { textSearch: "", tabs: "" },
30
+ // };
31
+ // const { getByText } = render(<NotificationList {...props} />);
32
+ // const noNotificationsText = getByText("Notifications.TitleNoNotifications");
33
+ // expect(noNotificationsText).toBeInTheDocument();
34
+ // });
35
+ // it("Hiện thị danh sách thông báo khi notifications có dữ liệu", () => {
36
+ // const props = {
37
+ // isLoading: false,
38
+ // notifications: [
39
+ // {
40
+ // id: "1",
41
+ // content:
42
+ // '<p>Chiến dịch <a href="https://github.com/dauquan1108" target="_blank" style="text-decoration: none; color: blue;" title="Đậu Xuân Quân">Đậu Xuân Quân</a> đã được cập nhật.</p>',
43
+ // url: "https://awing.vn/",
44
+ // status: true,
45
+ // userName: "Đậu Xuân Quân",
46
+ // avatarUrl:
47
+ // "https://i.pinimg.com/564x/7d/be/68/7dbe686677277a06de561b16c1e2740b.jpg",
48
+ // time: "2023-12-06 10:30",
49
+ // },
50
+ // ],
51
+ // onUpdateStatus: () => null,
52
+ // valueFilter: { textSearch: "", tabs: "" },
53
+ // };
54
+ // const notifications = [
55
+ // {
56
+ // id: "1",
57
+ // content:
58
+ // '<p>Chiến dịch <a href="https://github.com/dauquan1108" target="_blank" style="text-decoration: none; color: blue;" title="Đậu Xuân Quân">Đậu Xuân Quân</a> đã được cập nhật.</p>',
59
+ // url: "https://awing.vn/",
60
+ // status: true,
61
+ // userName: "Đậu Xuân Quân",
62
+ // avatarUrl:
63
+ // "https://i.pinimg.com/564x/7d/be/68/7dbe686677277a06de561b16c1e2740b.jpg",
64
+ // time: "2023-12-06 10:30",
65
+ // },
66
+ // ];
67
+ // const { getAllByTestId } = render(
68
+ // <NotificationList
69
+ // valueFilter={{ textSearch: "", tabs: "" }}
70
+ // onUpdateStatus={() => null}
71
+ // isLoading={false}
72
+ // notifications={notifications}
73
+ // />
74
+ // );
75
+ // const notificationItems = getAllByTestId('notification-item');
76
+ // expect(notificationItems).toHaveLength(notifications.length);
77
+ // });
78
+ // it("Hiển thị trạng thái Loading khi 'isLoading=true'.", () => {
79
+ // const props = {
80
+ // isLoading: true,
81
+ // notifications: [],
82
+ // onUpdateStatus: () => null,
83
+ // valueFilter: { textSearch: "", tabs: "" },
84
+ // };
85
+ // const { getByText } = render(<NotificationList {...props} />);
86
+ // const iconLoading = getByText("icon Loading");
87
+ // expect(iconLoading).toBeInTheDocument();
88
+ // });
89
+ // });
@@ -3,6 +3,6 @@
3
3
  * @author dauquan1108@gmail.com on 11/27/2023.
4
4
  *
5
5
  **/
6
- import React from "react";
6
+ import React from 'react';
7
7
  declare const NotificationDetail: React.FC;
8
8
  export default NotificationDetail;
@@ -10,41 +10,37 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
21
35
  };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
37
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
38
+ if (ar || !(i in from)) {
39
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
40
+ ar[i] = from[i];
41
+ }
47
42
  }
43
+ return to.concat(ar || Array.prototype.slice.call(from));
48
44
  };
49
45
  var __importDefault = (this && this.__importDefault) || function (mod) {
50
46
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -56,63 +52,27 @@ var jsx_runtime_1 = require("react/jsx-runtime");
56
52
  * @author dauquan1108@gmail.com on 11/27/2023.
57
53
  *
58
54
  **/
59
- var react_1 = __importDefault(require("react"));
55
+ var react_1 = __importStar(require("react"));
60
56
  var Box_1 = __importDefault(require("@mui/material/Box"));
57
+ var react_i18next_1 = require("react-i18next");
58
+ var i18n_1 = __importDefault(require("../../../i18n"));
61
59
  var HeaderInfo_1 = __importDefault(require("./HeaderInfo"));
60
+ var Constant_1 = require("../Constant");
61
+ var Hooks_1 = __importDefault(require("../Hooks"));
62
62
  var NotificationList_1 = __importDefault(require("./NotificationList"));
63
- var Common_1 = require("../NotificationDetail/Common");
63
+ var Types_1 = require("../Types");
64
64
  var NotificationDetail = function () {
65
- var _a = react_1.default.useState([]), notifications = _a[0], setNotifications = _a[1];
66
- var _b = react_1.default.useState({
67
- textSearch: "",
68
- tabs: Common_1.types.ALL,
69
- }), valueFilter = _b[0], setValueFilter = _b[1];
70
- var _c = react_1.default.useState(false), isLoading = _c[0], setIsLoading = _c[1];
71
- var handleCallApi = function (apiUrl) { return __awaiter(void 0, void 0, void 0, function () {
72
- var response, data, error_1;
73
- return __generator(this, function (_a) {
74
- switch (_a.label) {
75
- case 0:
76
- if (isLoading) {
77
- return [2 /*return*/];
78
- }
79
- // Thực hiện Call API ở đoạn này và thêm 1 số ĐK nữa để xử lý trong đoạn code sau ("Chưa hoàn thành").
80
- // 1: Nếu gặp lỗi, data trả về rộng tắt trạng thái loading.
81
- setIsLoading(true);
82
- _a.label = 1;
83
- case 1:
84
- _a.trys.push([1, 4, 5, 6]);
85
- return [4 /*yield*/, fetch(apiUrl)];
86
- case 2:
87
- response = _a.sent();
88
- if (!response.ok) {
89
- throw new Error("HTTP error! Status: ".concat(response.status));
90
- }
91
- return [4 /*yield*/, response.json()];
92
- case 3:
93
- data = (_a.sent()) || [];
94
- setNotifications(data);
95
- return [3 /*break*/, 6];
96
- case 4:
97
- error_1 = _a.sent();
98
- console.error('Error fetching data:', error_1);
99
- return [3 /*break*/, 6];
100
- case 5:
101
- setIsLoading(false);
102
- return [7 /*endfinally*/];
103
- case 6: return [2 /*return*/];
104
- }
105
- });
106
- }); };
107
- var handleIntersection = react_1.default.useCallback(function (entries) {
108
- var firsEntry = entries[0];
109
- if (firsEntry.isIntersecting) {
110
- handleCallApi('https://run.mocky.io/v3/68ae1ad5-8e13-4d00-a8ef-134215e61978');
111
- }
112
- }, []);
113
- react_1.default.useEffect(function () {
65
+ var service = (0, Hooks_1.default)().service;
66
+ var _a = (0, react_1.useState)({
67
+ textSearch: '',
68
+ tabs: Constant_1.Constants.ALL,
69
+ }), valueFilter = _a[0], setValueFilter = _a[1];
70
+ var _b = react_1.default.useState(false), isLoading = _b[0], setIsLoading = _b[1];
71
+ var _c = react_1.default.useState(-1), count = _c[0], setCount = _c[1];
72
+ var _d = (0, react_1.useState)([]), notificationMessage = _d[0], setNotificationMessage = _d[1];
73
+ (0, react_1.useEffect)(function () {
114
74
  var observer = new IntersectionObserver(handleIntersection);
115
- var lastItem = document.getElementById("last-Item");
75
+ var lastItem = document.getElementById('last-Item');
116
76
  if (observer && lastItem) {
117
77
  setIsLoading(true);
118
78
  observer.observe(lastItem);
@@ -123,28 +83,69 @@ var NotificationDetail = function () {
123
83
  }
124
84
  };
125
85
  }, []);
126
- var handleValueFilter = react_1.default.useCallback(function (textSearch, tabs) {
127
- // Cập nhật từ khóa tìm kiếm và tabs
128
- setValueFilter({ textSearch: textSearch, tabs: tabs });
86
+ (0, react_1.useEffect)(function () {
87
+ if (count >= 0) {
88
+ setIsLoading(true);
89
+ service
90
+ .notificationsPaging(count, Constant_1.Constants.PAGE_SIZE_DEFAULT, valueFilter.textSearch, [])
91
+ .then(function (res) {
92
+ setNotificationMessage(function (prevMessages) {
93
+ var newItems = res.items.filter(function (newItem) {
94
+ return !prevMessages.some(function (prevItem) { return prevItem.id === newItem.id; });
95
+ });
96
+ return __spreadArray(__spreadArray([], prevMessages, true), newItems, true);
97
+ });
98
+ })
99
+ .finally(function () {
100
+ setIsLoading(false);
101
+ });
102
+ }
103
+ // eslint-disable-next-line react-hooks/exhaustive-deps
104
+ }, [count, valueFilter.textSearch]);
105
+ var handleIntersection = (0, react_1.useCallback)(function (entries) {
106
+ var firsEntry = entries[0];
107
+ if (firsEntry.isIntersecting) {
108
+ setCount(function (old) { return old + 1; });
109
+ }
129
110
  }, []);
130
- var handleUpdateStatus = react_1.default.useCallback(function (dataSent) {
131
- // Cập nhật trạng thái item trong notifications
132
- if (typeof dataSent === "string") {
133
- var isCheckStatus = notifications.some(function (item) { return item.status; });
111
+ var handleValueFilter = function (textSearch, tabs) {
112
+ tabs === Constant_1.Constants.ALL && setCount(0);
113
+ setNotificationMessage([]);
114
+ setValueFilter({ textSearch: textSearch, tabs: tabs });
115
+ };
116
+ var handleUpdateStatus = (0, react_1.useCallback)(function (dataSent) {
117
+ if (typeof dataSent === 'string') {
118
+ var isCheckStatus = notificationMessage.some(function (item) {
119
+ return item.status === Types_1.NotificationMessageStatus.Read;
120
+ });
134
121
  if (isCheckStatus) {
135
- setNotifications(function (prevNotifications) {
136
- return prevNotifications.map(function (item) { return (__assign(__assign({}, item), { status: false })); });
122
+ service.notificationsReadAll().then(function () {
123
+ setNotificationMessage(function (prevNotifications) {
124
+ return prevNotifications.map(function (item) { return (__assign(__assign({}, item), { status: Types_1.NotificationMessageStatus.Unread })); });
125
+ });
137
126
  });
138
127
  }
139
128
  }
140
129
  else {
141
- setNotifications(function (prevNotifications) {
142
- return prevNotifications.map(function (item) {
143
- return item.id === dataSent.id ? __assign(__assign({}, item), { status: !item.status }) : item;
130
+ var handleUpdateStatusItem_1 = function () {
131
+ setNotificationMessage(function (prevNotifications) {
132
+ return prevNotifications.map(function (item) { return (__assign(__assign({}, item), { status: item.id === dataSent.id
133
+ ? item.status ===
134
+ Types_1.NotificationMessageStatus.Read
135
+ ? Types_1.NotificationMessageStatus.Unread
136
+ : Types_1.NotificationMessageStatus.Read
137
+ : item.status })); });
138
+ });
139
+ };
140
+ dataSent.status === Types_1.NotificationMessageStatus.Unread
141
+ ? service.notificationsRead([dataSent.id]).then(function () {
142
+ handleUpdateStatusItem_1();
143
+ })
144
+ : service.notificationsUnread([dataSent.id]).then(function () {
145
+ handleUpdateStatusItem_1();
144
146
  });
145
- });
146
147
  }
147
- }, [notifications]);
148
- return ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsx)(Box_1.default, { pt: 2, pl: 2, pr: 2, pb: 1, component: "div", children: (0, jsx_runtime_1.jsx)(HeaderInfo_1.default, { valueFilter: valueFilter, onValueFilter: handleValueFilter, onUpdateStatus: handleUpdateStatus }) }), (0, jsx_runtime_1.jsx)(Box_1.default, { pl: 1, pr: 1, pb: 1, component: "div", children: (0, jsx_runtime_1.jsx)(NotificationList_1.default, { isLoading: isLoading, valueFilter: valueFilter, notifications: notifications, onUpdateStatus: handleUpdateStatus }) }), (0, jsx_runtime_1.jsx)(Box_1.default, { id: "last-Item", component: "div" })] }));
148
+ }, [notificationMessage, service]);
149
+ return ((0, jsx_runtime_1.jsxs)(react_i18next_1.I18nextProvider, { i18n: i18n_1.default, children: [(0, jsx_runtime_1.jsx)(Box_1.default, { pt: 2, pl: 2, pr: 2, pb: 1, component: "div", children: (0, jsx_runtime_1.jsx)(HeaderInfo_1.default, { valueFilter: valueFilter, onValueFilter: handleValueFilter, onUpdateStatus: handleUpdateStatus }) }), (0, jsx_runtime_1.jsx)(Box_1.default, { pl: 1, pr: 1, pb: 1, component: "div", children: (0, jsx_runtime_1.jsx)(NotificationList_1.default, { isLoading: isLoading, valueFilter: valueFilter, notificationMessage: notificationMessage, onUpdateStatus: handleUpdateStatus }) }), (0, jsx_runtime_1.jsx)(Box_1.default, { id: "last-Item", component: "div", sx: { height: '20px' } })] }));
149
150
  };
150
151
  exports.default = NotificationDetail;
@@ -4,5 +4,5 @@
4
4
  *
5
5
  **/
6
6
  import React from 'react';
7
- declare const NotificationPopover: React.FC;
8
- export default NotificationPopover;
7
+ declare const Container: React.FC;
8
+ export default Container;