UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

162 lines (142 loc) 9.46 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunkLWUL5WRWjs = require('./chunk-LWUL5WRW.js'); var _chunkBJMKBBN3js = require('./chunk-BJMKBBN3.js'); var _chunkWWXDXIV7js = require('./chunk-WWXDXIV7.js'); var _chunkTCLRDUMFjs = require('./chunk-TCLRDUMF.js'); var _chunk34ST3MKOjs = require('./chunk-34ST3MKO.js'); var _chunkANT66KVKjs = require('./chunk-ANT66KVK.js'); // src/components/AlertManagerView/AlertsManagerView.tsx var _CaretLeft = require('@phosphor-icons/react/dist/csr/CaretLeft'); var _CaretRight = require('@phosphor-icons/react/dist/csr/CaretRight'); var _User = require('@phosphor-icons/react/dist/csr/User'); var _jsxruntime = require('react/jsx-runtime'); var AlertsManagerView = ({ alertData, isOpen = false, onClose, imageLink, defaultImage, currentPage = 1, totalPages: externalTotalPages, onPageChange, itemsPerPage = 10 }) => { const totalPages = _nullishCoalesce(externalTotalPages, () => ( Math.ceil(alertData.recipients.length / itemsPerPage))); const effectiveCurrentPage = Math.min(totalPages, Math.max(1, currentPage)); const startIndex = (effectiveCurrentPage - 1) * itemsPerPage; const endIndex = startIndex + itemsPerPage; const paginatedRecipients = alertData.recipients.slice(startIndex, endIndex); const handleClose = () => { _optionalChain([onClose, 'optionalCall', _ => _()]); }; const formatDate = (dateInput) => { const date = dateInput instanceof Date ? dateInput : new Date(dateInput); if (Number.isNaN(date.getTime())) return String(dateInput); return date.toLocaleDateString("pt-BR", { day: "2-digit", month: "2-digit", year: "numeric" }); }; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkTCLRDUMFjs.Modal_default, { isOpen, onClose: handleClose, title: alertData.title, size: "md", contentClassName: "p-0", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex flex-col h-[calc(100vh-8rem)] max-h-[700px]", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex-1 overflow-y-auto px-6 py-4", children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "bg-background-50 px-5 py-6 flex flex-col items-center gap-4 rounded-xl mb-4", children: [ (imageLink || alertData.image || defaultImage) && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "img", { src: imageLink || alertData.image || defaultImage || void 0, alt: alertData.title || "Imagem do alerta" } ), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col items-center text-center gap-3", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "lg", weight: "semibold", children: alertData.title || "Sem T\xEDtulo" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "sm", weight: "normal", className: "text-text-500", children: alertData.message || "Sem mensagem" }) ] }) ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkWWXDXIV7js.Divider_default, { className: "my-4" }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex justify-between items-center mb-4 px-2", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "sm", weight: "bold", className: "text-text-700", children: "Enviado em" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "sm", weight: "medium", className: "text-text-900", children: formatDate(alertData.sentAt) }) ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkWWXDXIV7js.Divider_default, { className: "my-4" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "mb-4", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkLWUL5WRWjs.Table_default, { variant: "borderless", className: "table-fixed", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkLWUL5WRWjs.TableHeader, { children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkLWUL5WRWjs.TableRow, { variant: "borderless", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkLWUL5WRWjs.TableHead, { className: "py-2 px-3.5 text-start", children: "Destinat\xE1rio" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkLWUL5WRWjs.TableHead, { className: "py-2 px-3.5 w-[120px] text-start", children: "Status" }) ] }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkLWUL5WRWjs.TableBody, { variant: "borderless", children: paginatedRecipients.map((recipient) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkLWUL5WRWjs.TableRow, { children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkLWUL5WRWjs.TableCell, { className: "py-2 px-3.5 flex flex-row gap-2 text-start truncate", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "rounded-full size-6 bg-primary-100 flex items-center justify-center", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _User.UserIcon, { className: "text-primary-950", size: 18 }) }), recipient.name ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkLWUL5WRWjs.TableCell, { className: "py-2 px-3.5 text-center", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex justify-center items-center gap-1", children: recipient.status === "viewed" ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkBJMKBBN3js.Badge_default, { variant: "solid", action: "success", children: "Visualizado" }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkBJMKBBN3js.Badge_default, { variant: "solid", action: "error", children: "Pendente" }) }) }) ] }, recipient.id)) }) ] }) }), totalPages > 1 && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex justify-end items-center gap-2 bg-background-50 border border-border-200 py-3.5 px-2 rounded-b-2xl", children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkANT66KVKjs.Text_default, { size: "sm", className: "text-text-600", children: [ "P\xE1gina ", effectiveCurrentPage, " de ", totalPages ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex gap-2", children: onPageChange ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "link", size: "extra-small", onClick: () => onPageChange(Math.max(1, effectiveCurrentPage - 1)), disabled: effectiveCurrentPage === 1, iconLeft: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _CaretLeft.CaretLeftIcon, {}), children: "Anterior" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "link", size: "extra-small", onClick: () => onPageChange( Math.min(totalPages, effectiveCurrentPage + 1) ), disabled: effectiveCurrentPage === totalPages, iconRight: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _CaretRight.CaretRightIcon, {}), children: "Pr\xF3ximo" } ) ] }) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "link", size: "extra-small", disabled: effectiveCurrentPage === 1, iconLeft: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _CaretLeft.CaretLeftIcon, {}), children: "Anterior" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "link", size: "extra-small", disabled: effectiveCurrentPage === totalPages, iconRight: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _CaretRight.CaretRightIcon, {}), children: "Pr\xF3ximo" } ) ] }) }) ] }) ] }) }) } ); }; exports.AlertsManagerView = AlertsManagerView; //# sourceMappingURL=chunk-SNI6CL3H.js.map