From 13bc512e66a9c3c53af9c946915b330d78af0b20 Mon Sep 17 00:00:00 2001 From: romanskijdev Date: Sun, 12 Jul 2026 19:02:54 +0300 Subject: [PATCH] Added notifications page for admin --- package-lock.json | 687 +++++++++++++++++- package.json | 16 +- src/App.tsx | 3 +- src/api/notifications.ts | 27 + .../notifications/hooks/useNotifications.ts | 56 ++ .../notifications/utils/telegramHtml.ts | 31 + src/features/roles/hooks/useAllRoles.ts | 15 + src/pages/notifications/NotificationsPage.tsx | 45 ++ .../components/NotificationDetailsModal.tsx | 75 ++ .../components/NotificationsHistoryTable.tsx | 125 ++++ .../components/SendNotificationForm.tsx | 251 +++++++ src/types/api.ts | 38 + 12 files changed, 1329 insertions(+), 40 deletions(-) create mode 100644 src/api/notifications.ts create mode 100644 src/features/notifications/hooks/useNotifications.ts create mode 100644 src/features/notifications/utils/telegramHtml.ts create mode 100644 src/features/roles/hooks/useAllRoles.ts create mode 100644 src/pages/notifications/NotificationsPage.tsx create mode 100644 src/pages/notifications/components/NotificationDetailsModal.tsx create mode 100644 src/pages/notifications/components/NotificationsHistoryTable.tsx create mode 100644 src/pages/notifications/components/SendNotificationForm.tsx diff --git a/package-lock.json b/package-lock.json index 9907ca8..075320d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,14 +8,20 @@ "name": "ruspet_admin_frontend", "version": "0.0.0", "dependencies": { - "@mantine/core": "^9.3.1", - "@mantine/dates": "^9.3.1", + "@mantine/core": "^9.4.1", + "@mantine/dates": "^9.4.1", "@mantine/form": "^9.3.1", - "@mantine/hooks": "^9.3.1", - "@mantine/modals": "^9.3.1", - "@mantine/notifications": "^9.3.1", + "@mantine/hooks": "^9.4.1", + "@mantine/modals": "^9.4.1", + "@mantine/notifications": "^9.4.1", + "@mantine/tiptap": "^9.4.1", "@tabler/icons-react": "^3.44.0", "@tanstack/react-query": "^5.101.0", + "@tiptap/extension-link": "^3.27.3", + "@tiptap/extension-underline": "^3.27.3", + "@tiptap/pm": "^3.27.3", + "@tiptap/react": "^3.27.3", + "@tiptap/starter-kit": "^3.27.3", "axios": "^1.18.0", "crypto-js": "^4.2.0", "dayjs": "^1.11.21", @@ -624,34 +630,34 @@ } }, "node_modules/@mantine/core": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/@mantine/core/-/core-9.3.1.tgz", - "integrity": "sha512-4rBoHpggSohayE+Os7lKdbsHTw7m/uZRKYjk9DN6cKBhQIjdiULdcG+b4b5CMVZSqZDHPgT70uWGI7yqkn8Ufw==", + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/@mantine/core/-/core-9.4.1.tgz", + "integrity": "sha512-lZWEICrum4+vwKxzh/mk4RB1N6BqZ0Cshdl6lhm7OYLiQzmOaxKtOgyaWz+vr65G8mqTXjalZalB+wmMVBYK2Q==", "license": "MIT", "dependencies": { "@floating-ui/react": "^0.27.19", "clsx": "^2.1.1", "react-number-format": "^5.4.5", "react-remove-scroll": "^2.7.2", - "type-fest": "^5.6.0" + "type-fest": "^5.7.0" }, "peerDependencies": { - "@mantine/hooks": "9.3.1", + "@mantine/hooks": "9.4.1", "react": "^19.2.0", "react-dom": "^19.2.0" } }, "node_modules/@mantine/dates": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/@mantine/dates/-/dates-9.3.1.tgz", - "integrity": "sha512-Nh4XQyyV1AM0XRnUJugb1kNfCm++nkticsO8aroKmFPZ7cpGV7cjdL+4MJNPu1atS1EUePXl2VLLpKnrclpqOQ==", + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/@mantine/dates/-/dates-9.4.1.tgz", + "integrity": "sha512-DoQDvQMAlIw6ohwhUwYuTYQevG9y5AQmYWkhOHUuavABFEZmtBglkwziBoATvxT09I/6I56UMPhproXcS6XUfg==", "license": "MIT", "dependencies": { "clsx": "^2.1.1" }, "peerDependencies": { - "@mantine/core": "9.3.1", - "@mantine/hooks": "9.3.1", + "@mantine/core": "9.4.1", + "@mantine/hooks": "9.4.1", "dayjs": ">=1.0.0", "react": "^19.2.0", "react-dom": "^19.2.0" @@ -672,51 +678,65 @@ } }, "node_modules/@mantine/hooks": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/@mantine/hooks/-/hooks-9.3.1.tgz", - "integrity": "sha512-zAOlxV59j5CDgAnExN+ypaR6dVW1vwMKDvKUxIlUVd/e52qxYnPyYRD+shJmyOLaZRuQmVF0R/7mJAjt2jw9cA==", + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/@mantine/hooks/-/hooks-9.4.1.tgz", + "integrity": "sha512-eTI8wmzPx3r98zgKIEuvukmoGTHBhmtI6+9E6o2DbTmEU2eM1bCdjE2vFdf0op2AlRO0KEYEcZhNQi4T/SJk0A==", "license": "MIT", "peerDependencies": { "react": "^19.2.0" } }, "node_modules/@mantine/modals": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/@mantine/modals/-/modals-9.3.1.tgz", - "integrity": "sha512-JqP1o6hrfQJ5UCq97HJsI7uIPDy+WwvWwkkfctWqcYkFJA2DU8dVoPqvEhnhDQUIXNci3sx6XDoQZAq1Qg57mw==", + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/@mantine/modals/-/modals-9.4.1.tgz", + "integrity": "sha512-z5G3Biz7/5Ybz5Z8u5Xyvo9UBmFhAX/YXMf6U96ejvtAB11xVnCo8m37R5DJyzeFEqB4D1tvUgWiVVPBb+yadw==", "license": "MIT", "peerDependencies": { - "@mantine/core": "9.3.1", - "@mantine/hooks": "9.3.1", + "@mantine/core": "9.4.1", + "@mantine/hooks": "9.4.1", "react": "^19.2.0", "react-dom": "^19.2.0" } }, "node_modules/@mantine/notifications": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/@mantine/notifications/-/notifications-9.3.1.tgz", - "integrity": "sha512-irkD9uszgVftthbCLd+4lS7M1jkhL4sVrZASv8+43aIkncW+oQkCFpBuaOAf6uRcMjmQ7XnKs2O8bXYzl/DqgQ==", + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/@mantine/notifications/-/notifications-9.4.1.tgz", + "integrity": "sha512-Sm1g8E8RkFmesxpNz9zFvOjkTVxOa7dJJjMGoHNIXH+9/wO0s9kInny4mVnxTbLJJsD6nTqIQlk1v8tq2C4Ftw==", "license": "MIT", "dependencies": { - "@mantine/store": "9.3.1", + "@mantine/store": "9.4.1", "react-transition-group": "4.4.5" }, "peerDependencies": { - "@mantine/core": "9.3.1", - "@mantine/hooks": "9.3.1", + "@mantine/core": "9.4.1", + "@mantine/hooks": "9.4.1", "react": "^19.2.0", "react-dom": "^19.2.0" } }, "node_modules/@mantine/store": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/@mantine/store/-/store-9.3.1.tgz", - "integrity": "sha512-UZ8wGKfF/NFMHCDl1Rd0M8XtHdt4W1w3V4ohNpFSaP3nSjJ+Cu1FT+iIWtXwC0Ogha8XnuVQ7vm/dw2BUfpw+g==", + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/@mantine/store/-/store-9.4.1.tgz", + "integrity": "sha512-/DCZq0aqqIdm03J0RJ7pbzoau2cwY8ndSOjskHOKHhTeWMnOBdCKXA3oMO5aIDldDqJ9T7Io4Boh4Pt461zNQw==", "license": "MIT", "peerDependencies": { "react": "^19.2.0" } }, + "node_modules/@mantine/tiptap": { + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/@mantine/tiptap/-/tiptap-9.4.1.tgz", + "integrity": "sha512-0qN6SFh9BuwXNOHUf4ygx8LPvWcgU1zUULY7IJ9zKiVHfa1K6b0BRa8LpLVKtVv7K5NLyj2uHJwv+mXB+ypOJw==", + "license": "MIT", + "peerDependencies": { + "@mantine/core": "9.4.1", + "@mantine/hooks": "9.4.1", + "@tiptap/extension-link": ">=3.3.0", + "@tiptap/react": ">=3.3.0", + "react": "^19.2.0", + "react-dom": "^19.2.0" + } + }, "node_modules/@napi-rs/wasm-runtime": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.5.tgz", @@ -1111,6 +1131,435 @@ "react": "^18 || ^19" } }, + "node_modules/@tiptap/core": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/core/-/core-3.27.3.tgz", + "integrity": "sha512-TJj5929M96C1KlH796wS8MywfHDh49RhmakOyzyMMc9pFmRj9UXi1gj0TCXgsZtjEOG7B+m/DRvNOvnuvR9kmg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/pm": "3.27.3" + } + }, + "node_modules/@tiptap/extension-blockquote": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-blockquote/-/extension-blockquote-3.27.3.tgz", + "integrity": "sha512-VGoVMcqcGkkoduzEqQ70ZK5OOHBDn5iYeHJSgkvNoSHzYHl0CaKoWxoDKJjSWC5DAM4mBU+tXTlsiUp3evRMfA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3" + } + }, + "node_modules/@tiptap/extension-bold": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-bold/-/extension-bold-3.27.3.tgz", + "integrity": "sha512-pchbycFppBqBmvk+OxrQLIPZLNd3rNbcm7zOa+OTjluphpAcsJ6AmHBmiRhJUYWitV6/SA+0nujcaWxBp5hNcQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3" + } + }, + "node_modules/@tiptap/extension-bubble-menu": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-bubble-menu/-/extension-bubble-menu-3.27.3.tgz", + "integrity": "sha512-PKSM9g8BXzO0Lxm2gOin7FAFvxO6T0QvlXTXVke/GJn/sR1tEz7w5ybsvweytUPmSliUc601pfIUOHKEhIVC2Q==", + "license": "MIT", + "optional": true, + "dependencies": { + "@floating-ui/dom": "^1.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3", + "@tiptap/pm": "3.27.3" + } + }, + "node_modules/@tiptap/extension-bullet-list": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-bullet-list/-/extension-bullet-list-3.27.3.tgz", + "integrity": "sha512-owQW6mcgnYgQU1z5BqmslcjZFBUm1SGM/Ax++4R6XelIt/7ol6uSTjzjAzum+ASW7UlBbuJHuSgRjl8cA+RGkg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.27.3" + } + }, + "node_modules/@tiptap/extension-code": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-code/-/extension-code-3.27.3.tgz", + "integrity": "sha512-T7JF10Y3k7fyVujXXLVubdUh7fctgBUoiuxbvjotpltg1U/mPbOcT0UW/uif9j3H8TFvAwNApVw3x8bwwFUakA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3" + } + }, + "node_modules/@tiptap/extension-code-block": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-code-block/-/extension-code-block-3.27.3.tgz", + "integrity": "sha512-3CVnzkpGoqqI5KaXI9l9PMwLkx34SYY63tpeo0I0QjDk4LU+JTAQDTPJFSwB4zTsHZ7ZFMU0jjasFOZ1kZRVgw==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3", + "@tiptap/pm": "3.27.3" + } + }, + "node_modules/@tiptap/extension-document": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-document/-/extension-document-3.27.3.tgz", + "integrity": "sha512-PR25MRv56Nm4ETVLwA8nAh/0RrVdvD4D2nxnAC8kUkxz1WOYDaqTfPqqEeSWDoUUTUp1I1xzDkD4x0gEnAlmZA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3" + } + }, + "node_modules/@tiptap/extension-dropcursor": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-dropcursor/-/extension-dropcursor-3.27.3.tgz", + "integrity": "sha512-XsL0Ziual+ynXyx5JgLb0KIOShlMN3MW7+GQvf9PGRb1vOB7IOTRFDxMPrxDWcFIZ6WWMWSrbkCLOKHStt1BWg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extensions": "3.27.3" + } + }, + "node_modules/@tiptap/extension-floating-menu": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-floating-menu/-/extension-floating-menu-3.27.3.tgz", + "integrity": "sha512-qL+g1Z6MqZvYG4mHTPwub9II2fWZY+2I5VFfV8fzqy1HchBOyY6Df0mRKDNb0bmjBdFabIXnswz3iqLx3mDTbw==", + "license": "MIT", + "optional": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@floating-ui/dom": "^1.0.0", + "@tiptap/core": "3.27.3", + "@tiptap/pm": "3.27.3" + } + }, + "node_modules/@tiptap/extension-gapcursor": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-gapcursor/-/extension-gapcursor-3.27.3.tgz", + "integrity": "sha512-MVBqzwYrDOttkn2GOrvvKTDCymfSS2VGSKpahcKKhge5mweSDiqko2X1vBDnMF8aVW3WxIFfDMmO4VMmh8HDZA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extensions": "3.27.3" + } + }, + "node_modules/@tiptap/extension-hard-break": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-hard-break/-/extension-hard-break-3.27.3.tgz", + "integrity": "sha512-cySObJITR2CRrWII87mI2LJ12wEETTnxt2p1vvC6ZtUmKnB50fOu+ux8ZEt6KYNocIOtrEZthNFzTOx7R7UtrQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3" + } + }, + "node_modules/@tiptap/extension-heading": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-heading/-/extension-heading-3.27.3.tgz", + "integrity": "sha512-QHXnsNic6iId8pnsFZ8z4PkX5L+HCHa/D7rAi3nNWtPlSIAOxo4nKrALcB5/tHmY+XL8kEXKH3nsNLNEDLCYPg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3" + } + }, + "node_modules/@tiptap/extension-horizontal-rule": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-horizontal-rule/-/extension-horizontal-rule-3.27.3.tgz", + "integrity": "sha512-sNCuo0+Q001B5XTVWY+ULpWXQqtBNRmAqXxAexZl44bx3rDqHG8OzjwT4EM0LIj2+BYVbdqwaJ1vfQbZVEEbig==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3", + "@tiptap/pm": "3.27.3" + } + }, + "node_modules/@tiptap/extension-italic": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-italic/-/extension-italic-3.27.3.tgz", + "integrity": "sha512-7VpVi2vn8kGFAc/HLrt96J/E6+LXOGKn8xLhJS863t150yLIG3EPQLA1h+G5O6eo+/w+9YokvJAAJoeDihj1Jg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3" + } + }, + "node_modules/@tiptap/extension-link": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-link/-/extension-link-3.27.3.tgz", + "integrity": "sha512-iXmu1tJ/3vP60c9d+zfO3+X64vod2EyBrM1qeufecAtWA6t0bT9tYeka0Zq6qDRGsZK5zViO9F2lsY7eHXiYuA==", + "license": "MIT", + "dependencies": { + "linkifyjs": "^4.3.3" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3", + "@tiptap/pm": "3.27.3" + } + }, + "node_modules/@tiptap/extension-list": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-list/-/extension-list-3.27.3.tgz", + "integrity": "sha512-52rcaSzYjtVGUrNkdB8k1Bw/rId2lBirrWMvmnBLsieoeFd8zo8ow5zkwV057BYSgWXfnMAV7GOpDyq2IoSD9A==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3", + "@tiptap/pm": "3.27.3" + } + }, + "node_modules/@tiptap/extension-list-item": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-list-item/-/extension-list-item-3.27.3.tgz", + "integrity": "sha512-UddhVaQ7+V9IfQVVE8AJLNzSmyaaNpZPQsoPQxFNlJyOFxD6RwSTT8L4rb/TwbUctxSFWpyd1J7exzf33Ony/g==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.27.3" + } + }, + "node_modules/@tiptap/extension-list-keymap": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-list-keymap/-/extension-list-keymap-3.27.3.tgz", + "integrity": "sha512-GZPVg4QCFm41yTMPEPeTlH2odNeQwRuWHY/pt3pI5LsfipQ4kDBv6h9we928vJQUnU2Gg9Y3cL5iRbmXIWWTUA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.27.3" + } + }, + "node_modules/@tiptap/extension-ordered-list": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-ordered-list/-/extension-ordered-list-3.27.3.tgz", + "integrity": "sha512-oHYoE65WfRSM5tCcXi8MtQmzPxz83E2qw0pa2yHBKwr9xCCQUu8vJHJE+EJGduWdaNImv43+6/6kVMeYYbXRKg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.27.3" + } + }, + "node_modules/@tiptap/extension-paragraph": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-paragraph/-/extension-paragraph-3.27.3.tgz", + "integrity": "sha512-G5XPCN7lm0nULYPelJC2eUbKbt1q97j67e/HSWxwMYEXhceec5eNAtVfpDCRyXNO9osyBi2kXqLv/IQtxbch9A==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3" + } + }, + "node_modules/@tiptap/extension-strike": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-strike/-/extension-strike-3.27.3.tgz", + "integrity": "sha512-dp6Rs3I4zLVJPvAw2Q9yrNuYKcX5LTONH3/oyULvGsrqq5DKz7pqscfwhwnDSzrgm/3aCz6B9r1BVHlYI/DXlA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3" + } + }, + "node_modules/@tiptap/extension-text": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-text/-/extension-text-3.27.3.tgz", + "integrity": "sha512-wSatZ/bop0pleeC18nF90zvWWEoRe/ewZncvm8LjcMrXwq41kTEs3j7nZflMYAh7X8fZvu00UIMeEyCNJl+5Yg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3" + } + }, + "node_modules/@tiptap/extension-underline": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extension-underline/-/extension-underline-3.27.3.tgz", + "integrity": "sha512-YH7ka/Rp7ZwlzTuQCcs0OZ4CMSx/P/MzbseQKxKebEIZreWaKMZAaED97Fnu0dA66VlreD4/1C7xHJy84ovamg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3" + } + }, + "node_modules/@tiptap/extensions": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/extensions/-/extensions-3.27.3.tgz", + "integrity": "sha512-IA2QKUVJgzUPEhhkUfr6P5u5GFVfhiApiEaaHXBz07saL2c4HNoVs2RC18QlZDCtLNKrPR1mUScr72u7uYs+YQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3", + "@tiptap/pm": "3.27.3" + } + }, + "node_modules/@tiptap/pm": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/pm/-/pm-3.27.3.tgz", + "integrity": "sha512-ppiG57RxM3HSHHgcHT0hP6Ib4P56Sd5itxdV4w0hIGHKPGyLLKiAkYp+htIHa9T7IvjMdaqxIlsfyV3ZKsS1sw==", + "license": "MIT", + "dependencies": { + "prosemirror-changeset": "^2.4.1", + "prosemirror-commands": "^1.7.1", + "prosemirror-dropcursor": "^1.8.2", + "prosemirror-gapcursor": "^1.4.1", + "prosemirror-history": "^1.5.0", + "prosemirror-inputrules": "^1.5.1", + "prosemirror-keymap": "^1.2.3", + "prosemirror-model": "^1.25.9", + "prosemirror-schema-list": "^1.5.1", + "prosemirror-state": "^1.4.4", + "prosemirror-tables": "^1.8.5", + "prosemirror-transform": "^1.12.0", + "prosemirror-view": "^1.41.9" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + } + }, + "node_modules/@tiptap/react": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/react/-/react-3.27.3.tgz", + "integrity": "sha512-lanXxMScw/LevbRFuFw5MoQJ1grmHUDszwph2VIk4l2U5e/EDIw3rr4CeDME6Z4isVReD6zccMFVShkHqsv+jg==", + "license": "MIT", + "dependencies": { + "@types/use-sync-external-store": "^0.0.6", + "fast-equals": "^5.3.3", + "use-sync-external-store": "^1.4.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "optionalDependencies": { + "@tiptap/extension-bubble-menu": "^3.27.3", + "@tiptap/extension-floating-menu": "^3.27.3" + }, + "peerDependencies": { + "@tiptap/core": "3.27.3", + "@tiptap/pm": "3.27.3", + "@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0", + "@types/react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0", + "react": "^17.0.0 || ^18.0.0 || ^19.0.0", + "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, + "node_modules/@tiptap/starter-kit": { + "version": "3.27.3", + "resolved": "https://registry.npmjs.org/@tiptap/starter-kit/-/starter-kit-3.27.3.tgz", + "integrity": "sha512-xX3baFqiC30skntdhxUUvyJo755ON9c1pE83+2Wiq2g+Qnffg9knUuLCZStHoZZ318yB0aBsKAMvHWLtYDo8AA==", + "license": "MIT", + "dependencies": { + "@tiptap/core": "^3.27.3", + "@tiptap/extension-blockquote": "^3.27.3", + "@tiptap/extension-bold": "^3.27.3", + "@tiptap/extension-bullet-list": "^3.27.3", + "@tiptap/extension-code": "^3.27.3", + "@tiptap/extension-code-block": "^3.27.3", + "@tiptap/extension-document": "^3.27.3", + "@tiptap/extension-dropcursor": "^3.27.3", + "@tiptap/extension-gapcursor": "^3.27.3", + "@tiptap/extension-hard-break": "^3.27.3", + "@tiptap/extension-heading": "^3.27.3", + "@tiptap/extension-horizontal-rule": "^3.27.3", + "@tiptap/extension-italic": "^3.27.3", + "@tiptap/extension-link": "^3.27.3", + "@tiptap/extension-list": "^3.27.3", + "@tiptap/extension-list-item": "^3.27.3", + "@tiptap/extension-list-keymap": "^3.27.3", + "@tiptap/extension-ordered-list": "^3.27.3", + "@tiptap/extension-paragraph": "^3.27.3", + "@tiptap/extension-strike": "^3.27.3", + "@tiptap/extension-text": "^3.27.3", + "@tiptap/extension-underline": "^3.27.3", + "@tiptap/extensions": "^3.27.3", + "@tiptap/pm": "^3.27.3" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + } + }, "node_modules/@tybys/wasm-util": { "version": "0.10.2", "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.10.2.tgz", @@ -1244,7 +1693,6 @@ "version": "19.2.17", "resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.17.tgz", "integrity": "sha512-MXfmqaVPEVgkBT/aY0aGCkRWWtByiYQXo3xdQ8r5RzuFrPiRn8Gar2tQdXSUQ2GKV3bkXckek89V8wQBY2Q/Aw==", - "devOptional": true, "license": "MIT", "dependencies": { "csstype": "^3.2.2" @@ -1254,7 +1702,6 @@ "version": "19.2.3", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-19.2.3.tgz", "integrity": "sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==", - "dev": true, "license": "MIT", "peerDependencies": { "@types/react": "^19.2.0" @@ -2308,6 +2755,15 @@ "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", "license": "MIT" }, + "node_modules/fast-equals": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-5.4.1.tgz", + "integrity": "sha512-DjlFSM5Pk9cGcL0q5QXl66eGzx0N6szNgaswwc5ZphlBohjTVJSnGgI+rJVOgOi65qUoQnDZN4nDqi33udtydQ==", + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", @@ -3051,6 +3507,12 @@ "url": "https://opencollective.com/parcel" } }, + "node_modules/linkifyjs": { + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/linkifyjs/-/linkifyjs-4.3.3.tgz", + "integrity": "sha512-P8aEP5U/D1/IlTY2OeYsErdwh9bGuLE30NcXtKEjgdHcahveQoQwM2yZNsioQHsWFz0P7KKudisbrzCgR0sDHg==", + "license": "MIT" + }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -3210,6 +3672,12 @@ "node": ">= 0.8.0" } }, + "node_modules/orderedmap": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/orderedmap/-/orderedmap-2.1.1.tgz", + "integrity": "sha512-TvAWxi0nDe1j/rtMcWcIj94+Ffe6n7zhow33h40SKxmsmozs6dz/e+EajymfoFcHd7sxNn8yHM8839uixMOV6g==", + "license": "MIT" + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -3332,6 +3800,145 @@ "react-is": "^16.13.1" } }, + "node_modules/prosemirror-changeset": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/prosemirror-changeset/-/prosemirror-changeset-2.4.1.tgz", + "integrity": "sha512-96WBLhOaYhJ+kPhLg3uW359Tz6I/MfcrQfL4EGv4SrcqKEMC1gmoGrXHecPE8eOwTVCJ4IwgfzM8fFad25wNfw==", + "license": "MIT", + "dependencies": { + "prosemirror-transform": "^1.0.0" + } + }, + "node_modules/prosemirror-commands": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/prosemirror-commands/-/prosemirror-commands-1.7.1.tgz", + "integrity": "sha512-rT7qZnQtx5c0/y/KlYaGvtG411S97UaL6gdp6RIZ23DLHanMYLyfGBV5DtSnZdthQql7W+lEVbpSfwtO8T+L2w==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.0.0", + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.10.2" + } + }, + "node_modules/prosemirror-dropcursor": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/prosemirror-dropcursor/-/prosemirror-dropcursor-1.8.3.tgz", + "integrity": "sha512-FoYbsJR8gK+DGlqhNoE29Loa38eIZPzQRIb1VMaDNBoo4OLP6vVof/jR8qFY/6XvUd6Dhug8MDCHl2a/h8RTfQ==", + "license": "MIT", + "dependencies": { + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.1.0", + "prosemirror-view": "^1.1.0" + } + }, + "node_modules/prosemirror-gapcursor": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/prosemirror-gapcursor/-/prosemirror-gapcursor-1.4.1.tgz", + "integrity": "sha512-pMdYaEnjNMSwl11yjEGtgTmLkR08m/Vl+Jj443167p9eB3HVQKhYCc4gmHVDsLPODfZfjr/MmirsdyZziXbQKw==", + "license": "MIT", + "dependencies": { + "prosemirror-keymap": "^1.0.0", + "prosemirror-model": "^1.0.0", + "prosemirror-state": "^1.0.0", + "prosemirror-view": "^1.0.0" + } + }, + "node_modules/prosemirror-history": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/prosemirror-history/-/prosemirror-history-1.5.0.tgz", + "integrity": "sha512-zlzTiH01eKA55UAf1MEjtssJeHnGxO0j4K4Dpx+gnmX9n+SHNlDqI2oO1Kv1iPN5B1dm5fsljCfqKF9nFL6HRg==", + "license": "MIT", + "dependencies": { + "prosemirror-state": "^1.2.2", + "prosemirror-transform": "^1.0.0", + "prosemirror-view": "^1.31.0", + "rope-sequence": "^1.3.0" + } + }, + "node_modules/prosemirror-inputrules": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/prosemirror-inputrules/-/prosemirror-inputrules-1.5.1.tgz", + "integrity": "sha512-7wj4uMjKaXWAQ1CDgxNzNtR9AlsuwzHfdFH1ygEHA2KHF2DOEaXl1CJfNPAKCg9qNEh4rum975QLaCiQPyY6Fw==", + "license": "MIT", + "dependencies": { + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.0.0" + } + }, + "node_modules/prosemirror-keymap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/prosemirror-keymap/-/prosemirror-keymap-1.2.3.tgz", + "integrity": "sha512-4HucRlpiLd1IPQQXNqeo81BGtkY8Ai5smHhKW9jjPKRc2wQIxksg7Hl1tTI2IfT2B/LgX6bfYvXxEpJl7aKYKw==", + "license": "MIT", + "dependencies": { + "prosemirror-state": "^1.0.0", + "w3c-keyname": "^2.2.0" + } + }, + "node_modules/prosemirror-model": { + "version": "1.25.11", + "resolved": "https://registry.npmjs.org/prosemirror-model/-/prosemirror-model-1.25.11.tgz", + "integrity": "sha512-QWg9RhnpLlogAmp3p96uEFrE5txQpFynd4vhBAELkwgOCWQs/X0yCzB3/hrHqiPwf91RG5KyWq6553zs9JqIOQ==", + "license": "MIT", + "dependencies": { + "orderedmap": "^2.0.0" + } + }, + "node_modules/prosemirror-schema-list": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/prosemirror-schema-list/-/prosemirror-schema-list-1.5.1.tgz", + "integrity": "sha512-927lFx/uwyQaGwJxLWCZRkjXG0p48KpMj6ueoYiu4JX05GGuGcgzAy62dfiV8eFZftgyBUvLx76RsMe20fJl+Q==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.0.0", + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.7.3" + } + }, + "node_modules/prosemirror-state": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/prosemirror-state/-/prosemirror-state-1.4.4.tgz", + "integrity": "sha512-6jiYHH2CIGbCfnxdHbXZ12gySFY/fz/ulZE333G6bPqIZ4F+TXo9ifiR86nAHpWnfoNjOb3o5ESi7J8Uz1jXHw==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.0.0", + "prosemirror-transform": "^1.0.0", + "prosemirror-view": "^1.27.0" + } + }, + "node_modules/prosemirror-tables": { + "version": "1.8.5", + "resolved": "https://registry.npmjs.org/prosemirror-tables/-/prosemirror-tables-1.8.5.tgz", + "integrity": "sha512-V/0cDCsHKHe/tfWkeCmthNUcEp1IVO3p6vwN8XtwE9PZQLAZJigbw3QoraAdfJPir4NKJtNvOB8oYGKRl+t0Dw==", + "license": "MIT", + "dependencies": { + "prosemirror-keymap": "^1.2.3", + "prosemirror-model": "^1.25.4", + "prosemirror-state": "^1.4.4", + "prosemirror-transform": "^1.10.5", + "prosemirror-view": "^1.41.4" + } + }, + "node_modules/prosemirror-transform": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/prosemirror-transform/-/prosemirror-transform-1.12.0.tgz", + "integrity": "sha512-GxboyN4AMIsoHNtz5uf2r2Ru551i5hWeCMD6E2Ib4Eogqoub0NflniaBPVQ4MrGE5yZ8JV9tUHg9qcZTTrcN4w==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.21.0" + } + }, + "node_modules/prosemirror-view": { + "version": "1.42.1", + "resolved": "https://registry.npmjs.org/prosemirror-view/-/prosemirror-view-1.42.1.tgz", + "integrity": "sha512-rRqzZnRgkyh69XoOMrfFJHwauHscLBmHbq772kwbic1ymQAM8gXjzEbJse5j1ep2UO2HRIAQL0bY3kZ/RoqjVw==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.25.8", + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.1.0" + } + }, "node_modules/proxy-from-env": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz", @@ -3619,6 +4226,12 @@ "@rolldown/binding-win32-x64-msvc": "1.0.3" } }, + "node_modules/rope-sequence": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/rope-sequence/-/rope-sequence-1.3.4.tgz", + "integrity": "sha512-UT5EDe2cu2E/6O4igUr5PSFs23nvvukicWHx6GnOPlHAiiYbzNuCRQCuiUdHJQcqKalLKlrYJnjY0ySGsXNQXQ==", + "license": "MIT" + }, "node_modules/scheduler": { "version": "0.27.0", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz", @@ -4012,6 +4625,12 @@ } } }, + "node_modules/w3c-keyname": { + "version": "2.2.8", + "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz", + "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==", + "license": "MIT" + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index c4e3fd2..475a2dd 100644 --- a/package.json +++ b/package.json @@ -10,14 +10,20 @@ "preview": "vite preview" }, "dependencies": { - "@mantine/core": "^9.3.1", - "@mantine/dates": "^9.3.1", + "@mantine/core": "^9.4.1", + "@mantine/dates": "^9.4.1", "@mantine/form": "^9.3.1", - "@mantine/hooks": "^9.3.1", - "@mantine/modals": "^9.3.1", - "@mantine/notifications": "^9.3.1", + "@mantine/hooks": "^9.4.1", + "@mantine/modals": "^9.4.1", + "@mantine/notifications": "^9.4.1", + "@mantine/tiptap": "^9.4.1", "@tabler/icons-react": "^3.44.0", "@tanstack/react-query": "^5.101.0", + "@tiptap/extension-link": "^3.27.3", + "@tiptap/extension-underline": "^3.27.3", + "@tiptap/pm": "^3.27.3", + "@tiptap/react": "^3.27.3", + "@tiptap/starter-kit": "^3.27.3", "axios": "^1.18.0", "crypto-js": "^4.2.0", "dayjs": "^1.11.21", diff --git a/src/App.tsx b/src/App.tsx index b3e8d4e..d1d8326 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -19,6 +19,7 @@ import AdminsPage from './pages/admins/AdminsPage' import ApprovalTasksPage from './pages/approvalTasks/ApprovalTasksPage' import FlowTreePage from "@/pages/flowNodes/FlowTreePage.tsx"; import FlowTreeGuidePage from './pages/flowNodes/FlowTreeGuidePage' +import NotificationsPage from "@/pages/notifications/NotificationsPage.tsx"; const Placeholder = ({ title }: { title: string }) => (
@@ -52,7 +53,7 @@ function App() { }> } /> - } /> + } /> } /> } /> } /> diff --git a/src/api/notifications.ts b/src/api/notifications.ts new file mode 100644 index 0000000..b582148 --- /dev/null +++ b/src/api/notifications.ts @@ -0,0 +1,27 @@ +import apiClient from './client' +import type { Notification, ApiResponse, TargetFilters } from '@/types/api' + +export interface NotificationsListParams { + offset?: number + limit?: number + status?: string +} + +export interface CreateNotificationRequest { + title: string + message_html: string + photo_base64?: string + photo_file_name?: string + targets: TargetFilters +} + +export const notificationsApi = { + getList: (params: NotificationsListParams = {}) => + apiClient.get>('/notifications', { params }), + + getById: (id: number) => + apiClient.get(`/notifications/${id}`), + + create: (data: CreateNotificationRequest) => + apiClient.post('/notifications', data), +} \ No newline at end of file diff --git a/src/features/notifications/hooks/useNotifications.ts b/src/features/notifications/hooks/useNotifications.ts new file mode 100644 index 0000000..88a89a3 --- /dev/null +++ b/src/features/notifications/hooks/useNotifications.ts @@ -0,0 +1,56 @@ +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' +import { + notificationsApi, + type NotificationsListParams, + type CreateNotificationRequest, +} from '@/api/notifications' +import { notifications as mantineNotifications } from '@mantine/notifications' + +export const NOTIFICATIONS_QUERY_KEY = 'notifications' + +export function useNotifications(params: NotificationsListParams = {}) { + return useQuery({ + queryKey: [NOTIFICATIONS_QUERY_KEY, params], + queryFn: async () => { + const response = await notificationsApi.getList(params) + return response.data + }, + }) +} + +export function useNotification(id: number | null) { + return useQuery({ + queryKey: ['notification', id], + queryFn: async () => { + if (!id) return null + const response = await notificationsApi.getById(id) + return response.data + }, + enabled: !!id, + }) +} + +export function useCreateNotification() { + const queryClient = useQueryClient() + + return useMutation({ + mutationFn: (data: CreateNotificationRequest) => notificationsApi.create(data), + onSuccess: (response) => { + queryClient.invalidateQueries({ queryKey: [NOTIFICATIONS_QUERY_KEY] }) + const n = response.data + const hasFailed = (n.failed_count ?? 0) > 0 + mantineNotifications.show({ + title: hasFailed ? 'Отправлено с ошибками' : 'Отправлено', + message: `Доставлено: ${n.sent_count ?? 0} из ${n.total_count ?? 0}`, + color: hasFailed ? 'yellow' : 'green', + }) + }, + onError: (error: any) => { + mantineNotifications.show({ + title: 'Ошибка', + message: error.response?.data?.error_description || 'Не удалось отправить уведомление', + color: 'red', + }) + }, + }) +} \ No newline at end of file diff --git a/src/features/notifications/utils/telegramHtml.ts b/src/features/notifications/utils/telegramHtml.ts new file mode 100644 index 0000000..245ccdd --- /dev/null +++ b/src/features/notifications/utils/telegramHtml.ts @@ -0,0 +1,31 @@ +// Приводит HTML из Tiptap-редактора к набору тегов, которые понимает Telegram ParseMode=HTML. +// Разрешённые теги: b, i, u, s, a, code, pre, tg-spoiler +const ALLOWED_TAGS = new Set(['b', 'i', 'u', 's', 'a', 'code', 'pre', 'tg-spoiler']) + +export function convertHtmlToTelegram(html: string): string { + let result = html + + // Абзацы и переносы строк -> двойной/одинарный \n + result = result.replace(/<\/p>\s*

/gi, '\n\n') + result = result.replace(/<\/?p>/gi, '') + result = result.replace(//gi, '\n') + + // Синонимы тегов из Tiptap -> Telegram-теги + result = result + .replace(//gi, '').replace(/<\/strong>/gi, '') + .replace(//gi, '').replace(/<\/em>/gi, '') + .replace(//gi, '').replace(/<\/strike>/gi, '') + + // Ссылки: сохраняем только href, убираем target/rel/class и т.п. + result = result.replace(/]*href="([^"]*)"[^>]*>/gi, '') + + // Убираем все теги, не входящие в белый список Telegram + result = result.replace(/<(\/?)([a-zA-Z0-9-]+)([^>]*)>/g, (match, closing, rawTag) => { + const tag = rawTag.toLowerCase() + if (!ALLOWED_TAGS.has(tag)) return '' + if (tag === 'a' && !closing) return match // href уже нормализован выше + return closing ? `` : `<${tag}>` + }) + + return result.trim() +} \ No newline at end of file diff --git a/src/features/roles/hooks/useAllRoles.ts b/src/features/roles/hooks/useAllRoles.ts new file mode 100644 index 0000000..eaa712d --- /dev/null +++ b/src/features/roles/hooks/useAllRoles.ts @@ -0,0 +1,15 @@ +import { useQuery } from '@tanstack/react-query' +import { rolesApi } from '@/api/roles.ts' +import type { Role } from '@/types/api' + +export const ALL_ROLES_QUERY_KEY = 'roles-all' + +export function useAllRoles() { + return useQuery({ + queryKey: [ALL_ROLES_QUERY_KEY], + queryFn: async (): Promise => { + const response = await rolesApi.getList({ limit: 1000 }) + return response.data.data || [] + }, + }) +} \ No newline at end of file diff --git a/src/pages/notifications/NotificationsPage.tsx b/src/pages/notifications/NotificationsPage.tsx new file mode 100644 index 0000000..791f4a4 --- /dev/null +++ b/src/pages/notifications/NotificationsPage.tsx @@ -0,0 +1,45 @@ +import { Stack, Tabs, Text, Alert } from '@mantine/core' +import { IconSend, IconHistory, IconLock } from '@tabler/icons-react' +import { useAuth } from '@/hooks/useAuth' +import SendNotificationForm from './components/SendNotificationForm' +import NotificationsHistoryTable from './components/NotificationsHistoryTable' + +export default function NotificationsPage() { + const { user } = useAuth() + const isObserver = user?.is_observer === true + + return ( + + Уведомления + + + + {!isObserver && ( + }> + Отправить + + )} + }> + История + + + + {!isObserver && ( + + + + )} + + + + + + + {isObserver && ( + }> + В режиме наблюдателя доступен только просмотр истории уведомлений + + )} + + ) +} \ No newline at end of file diff --git a/src/pages/notifications/components/NotificationDetailsModal.tsx b/src/pages/notifications/components/NotificationDetailsModal.tsx new file mode 100644 index 0000000..544472f --- /dev/null +++ b/src/pages/notifications/components/NotificationDetailsModal.tsx @@ -0,0 +1,75 @@ +import { useNotification } from '@/features/notifications/hooks/useNotifications' +import { Modal, Stack, Text, Badge, ScrollArea, Table, Divider, Loader, Center } from '@mantine/core' + +interface Props { + notificationId: number | null + opened: boolean + onClose: () => void +} + +const RECIPIENT_STATUS_LABELS: Record = { + pending: { label: 'В очереди', color: 'gray' }, + sent: { label: 'Доставлено', color: 'green' }, + failed: { label: 'Ошибка', color: 'red' }, +} + +export default function NotificationDetailsModal({ notificationId, opened, onClose }: Props) { + const { data: notification, isLoading } = useNotification(notificationId) + + return ( + + {isLoading || !notification ? ( +

+ +
+ ) : ( + + + {notification.title} +
+ + + + + + + + + Пользователь + Статус + Ошибка + + + + {(notification.recipients || []).map((r) => { + const statusInfo = RECIPIENT_STATUS_LABELS[r.status || ''] || { + label: r.status || '—', + color: 'gray', + } + return ( + + {r.user?.full_name || `ID ${r.user_id}`} + + + {statusInfo.label} + + + + + {r.error_message || ''} + + + + ) + })} + +
+
+ + )} + + ) +} \ No newline at end of file diff --git a/src/pages/notifications/components/NotificationsHistoryTable.tsx b/src/pages/notifications/components/NotificationsHistoryTable.tsx new file mode 100644 index 0000000..fc0a9e2 --- /dev/null +++ b/src/pages/notifications/components/NotificationsHistoryTable.tsx @@ -0,0 +1,125 @@ +import { useState } from 'react' +import { + Paper, Table, Badge, Group, Text, Pagination, Loader, Center, Box, Stack, +} from '@mantine/core' +import NotificationDetailsModal from './NotificationDetailsModal' +import { useNotifications } from '@/features/notifications/hooks/useNotifications' + +const LIMIT = 20 + +const STATUS_LABELS: Record = { + pending: { label: 'В очереди', color: 'gray' }, + sending: { label: 'Отправляется', color: 'blue' }, + completed: { label: 'Завершено', color: 'green' }, + failed: { label: 'Ошибка', color: 'red' }, +} + +export default function NotificationsHistoryTable() { + const [page, setPage] = useState(1) + const [selectedId, setSelectedId] = useState(null) + + const { data, isLoading } = useNotifications({ + offset: (page - 1) * LIMIT, + limit: LIMIT, + }) + + const totalPages = data?.total_count ? Math.ceil(data.total_count / LIMIT) : 1 + + return ( + + + {isLoading ? ( +
+ +
+ ) : ( + <> + + + + ID + Заголовок + Статус + Доставлено + Дата отправки + + + + {data?.data?.length === 0 ? ( + + +
+ Уведомления не отправлялись +
+
+
+ ) : ( + (data?.data || []).map((n) => { + const statusInfo = STATUS_LABELS[n.status || ''] || { + label: n.status || '—', + color: 'gray', + } + return ( + setSelectedId(n.id!)} + > + {n.id} + + {n.title} + + + + {statusInfo.label} + + + + + + {n.sent_count ?? 0} + + {(n.failed_count ?? 0) > 0 && ( + + {n.failed_count} ошибок + + )} + + из {n.total_count ?? 0} + + + + + + {n.sent_at ? new Date(n.sent_at).toLocaleString('ru-RU') : '—'} + + + + ) + }) + )} +
+
+ + {totalPages > 1 && ( + + + + Страница {page} из {totalPages} + + + + + )} + + )} +
+ + setSelectedId(null)} + /> +
+ ) +} \ No newline at end of file diff --git a/src/pages/notifications/components/SendNotificationForm.tsx b/src/pages/notifications/components/SendNotificationForm.tsx new file mode 100644 index 0000000..52bad0f --- /dev/null +++ b/src/pages/notifications/components/SendNotificationForm.tsx @@ -0,0 +1,251 @@ +import { useState, useMemo } from 'react' +import { + Paper, Stack, TextInput, Button, Group, MultiSelect, Checkbox, + Text, FileButton, Image, ActionIcon, Divider, Alert, +} from '@mantine/core' +import { IconPhoto, IconX, IconSend, IconAlertCircle } from '@tabler/icons-react' +import { RichTextEditor, Link } from '@mantine/tiptap' +import { useEditor } from '@tiptap/react' +import StarterKit from '@tiptap/starter-kit' +import Underline from '@tiptap/extension-underline' +import { useDebouncedValue } from '@mantine/hooks' +import { useUsers } from '@/features/users/hooks/useUsers' +import { useDepartments } from '@/features/departments/hooks/useDepartments' +import { useAllRoles } from '@/features/roles/hooks/useAllRoles' +import {useCreateNotification} from "@/features/notifications/hooks/useNotifications.ts"; +import {convertHtmlToTelegram} from "@/features/notifications/utils/telegramHtml.ts"; + +const ROLE_TYPE_OPTIONS = [ + { value: 'director', label: 'Директора' }, + { value: 'approver', label: 'Согласующие' }, + { value: 'observer', label: 'Наблюдатели' }, + { value: 'executor', label: 'Исполнители' }, + { value: 'controller', label: 'Контролёры' }, +] + +export default function SendNotificationForm() { + const [title, setTitle] = useState('') + const [userSearch, setUserSearch] = useState('') + const [debouncedUserSearch] = useDebouncedValue(userSearch, 300) + + const [selectedUserIds, setSelectedUserIds] = useState([]) + const [selectedRoleIds, setSelectedRoleIds] = useState([]) + const [selectedRoleFlags, setSelectedRoleFlags] = useState([]) + const [selectedDepartmentIds, setSelectedDepartmentIds] = useState([]) + + const [photoBase64, setPhotoBase64] = useState(null) + const [photoFileName, setPhotoFileName] = useState(null) + const [photoPreviewUrl, setPhotoPreviewUrl] = useState(null) + + const { data: usersData } = useUsers({ + limit: 50, + ...(debouncedUserSearch && { full_name: debouncedUserSearch }), + }) + const { data: roles = [] } = useAllRoles() + const { data: departmentsResponse } = useDepartments({ limit: 1000 }) + const departments = departmentsResponse?.data || [] + + const createNotification = useCreateNotification() + + const editor = useEditor({ + extensions: [StarterKit, Underline, Link], + content: '', + }) + + const userOptions = useMemo( + () => (usersData?.data || []).map((u) => ({ + value: String(u.id), + label: u.full_name + (u.username ? ` (@${u.username})` : ''), + })), + [usersData], + ) + + const roleOptions = useMemo( + () => roles.map((r) => ({ value: String(r.id), label: r.name })), + [roles], + ) + + const departmentOptions = useMemo( + () => departments.map((d) => ({ value: String(d.id), label: d.name })), + [departments], + ) + + const handlePhotoChange = (file: File | null) => { + if (!file) { + setPhotoBase64(null) + setPhotoFileName(null) + setPhotoPreviewUrl(null) + return + } + const reader = new FileReader() + reader.onload = () => { + const result = reader.result as string + setPhotoBase64(result.split(',')[1] || '') + setPhotoFileName(file.name) + setPhotoPreviewUrl(result) + } + reader.readAsDataURL(file) + } + + const hasAnyTarget = + selectedUserIds.length > 0 || + selectedRoleIds.length > 0 || + selectedRoleFlags.length > 0 || + selectedDepartmentIds.length > 0 + + const messageHtml = editor?.getHTML() ?? '' + const isMessageEmpty = editor?.isEmpty ?? true + + const canSubmit = title.trim().length > 0 && !isMessageEmpty && hasAnyTarget + + const handleSubmit = () => { + if (!canSubmit) return + + createNotification.mutate( + { + title: title.trim(), + message_html: convertHtmlToTelegram(messageHtml), + photo_base64: photoBase64 || undefined, + photo_file_name: photoFileName || undefined, + targets: { + user_ids: selectedUserIds.map(Number), + role_ids: selectedRoleIds.map(Number), + role_type_flags: selectedRoleFlags, + department_ids: selectedDepartmentIds.map(Number), + }, + }, + { + onSuccess: () => { + setTitle('') + editor?.commands.clearContent() + setSelectedUserIds([]) + setSelectedRoleIds([]) + setSelectedRoleFlags([]) + setSelectedDepartmentIds([]) + handlePhotoChange(null) + }, + }, + ) + } + + return ( + + + setTitle(e.currentTarget.value)} + required + /> + + + Текст сообщения + + + + + + + + + + + + + + + + + Поддерживаются: жирный, курсив, подчёркнутый, зачёркнутый, код, ссылки — + остальное форматирование Telegram не отображает + + + + + Фото (опционально) + {photoPreviewUrl ? ( + + + handlePhotoChange(null)}> + + + + ) : ( + + {(props) => ( + + )} + + )} + + + + + + + + + + Тип роли + + + {ROLE_TYPE_OPTIONS.map((opt) => ( + + ))} + + + + + + + {!hasAnyTarget && ( + }> + Выберите хотя бы один способ определения получателей + + )} + + + + + + + ) +} \ No newline at end of file diff --git a/src/types/api.ts b/src/types/api.ts index bf8e6e3..d75933c 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -32,6 +32,7 @@ export interface Role { is_default?: boolean is_director?: boolean is_approver?: boolean + is_controller?: boolean is_observer?: boolean is_executor?: boolean description?: string @@ -291,4 +292,41 @@ export interface ApprovalFlowNode { created_at?: string updated_at?: string children?: ApprovalFlowNode[] +} + +export interface TargetFilters { + user_ids?: number[] + role_ids?: number[] + role_type_flags?: string[] // 'director' | 'approver' | 'observer' | 'executor' | 'controller' + department_ids?: number[] +} + +export interface NotificationRecipient { + id?: number + notification_id?: number + user_id?: number + status?: string // pending | sent | failed + error_message?: string + telegram_message_id?: number + sent_at?: string + created_at?: string + user?: User +} + +export interface Notification { + id?: number + title: string + message_html: string + photo_base64?: string + photo_file_name?: string + target_filters?: string // JSON-строка от бэкенда + status?: string // pending | sending | completed | failed + total_count?: number + sent_count?: number + failed_count?: number + created_by_id?: number + created_at?: string + updated_at?: string + sent_at?: string + recipients?: NotificationRecipient[] } \ No newline at end of file