UNPKG

analytica-frontend-lib

Version:

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

437 lines (412 loc) 20.6 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 _chunk7JXDCLY6js = require('./chunk-7JXDCLY6.js'); var _chunkSZD7L65Qjs = require('./chunk-SZD7L65Q.js'); var _chunkNEDUOGWUjs = require('./chunk-NEDUOGWU.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/Support/components/TicketModal.tsx var _react = require('react'); var _dayjs = require('dayjs'); var _dayjs2 = _interopRequireDefault(_dayjs); require('dayjs/locale/pt-br'); // src/components/Support/utils/supportUtils.tsx var _react3 = require('@phosphor-icons/react'); var _jsxruntime = require('react/jsx-runtime'); var getCategoryIcon = (category, size = 16) => { if (!category) return null; switch (category) { case "acesso" /* ACESSO */: return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react3.KeyIcon, { size }); case "tecnico" /* TECNICO */: return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react3.BugIcon, { size }); case "outros" /* OUTROS */: return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react3.InfoIcon, { size }); default: return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react3.InfoIcon, { size }); } }; // src/components/Support/components/TicketModal.tsx _dayjs2.default.locale("pt-br"); var AnswerSkeleton = () => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "bg-background p-4 space-y-6 rounded-xl", children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center space-x-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkNEDUOGWUjs.SkeletonText, { width: "80px", height: 16 }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkNEDUOGWUjs.SkeletonText, { width: "200px", height: 16 }) ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkWWXDXIV7js.Divider_default, {}), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-start space-x-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkNEDUOGWUjs.SkeletonText, { width: "80px", height: 16 }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex-1 space-y-2", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkNEDUOGWUjs.SkeletonText, { width: "100%", height: 16 }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkNEDUOGWUjs.SkeletonText, { width: "80%", height: 16 }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkNEDUOGWUjs.SkeletonText, { width: "60%", height: 16 }) ] }) ] }) ] }); var TicketModal = ({ ticket, isOpen, onClose, onTicketClose, apiClient, userId }) => { const [showCloseConfirmation, setShowCloseConfirmation] = _react.useState.call(void 0, false); const [responseText, setResponseText] = _react.useState.call(void 0, ""); const [answers, setAnswers] = _react.useState.call(void 0, []); const [isSubmittingAnswer, setIsSubmittingAnswer] = _react.useState.call(void 0, false); const [isLoadingAnswers, setIsLoadingAnswers] = _react.useState.call(void 0, false); const handleCloseTicket = () => { _optionalChain([onTicketClose, 'optionalCall', _ => _(ticket.id)]); setShowCloseConfirmation(false); onClose(); }; const fetchAnswers = _react.useCallback.call(void 0, async () => { if (!ticket.id || ticket.status !== "respondido" /* RESPONDIDO */) return; setIsLoadingAnswers(true); try { const response = await apiClient.get( `/support/answer/${ticket.id}` ); setAnswers(response.data.data || []); } catch (error) { console.error("Erro ao buscar respostas:", error); setAnswers([]); } finally { setIsLoadingAnswers(false); } }, [ticket.id, ticket.status, apiClient]); const handleSubmitAnswer = async () => { if (!responseText.trim() || !userId || !ticket.id) { return; } setIsSubmittingAnswer(true); try { const requestData = { userId, supportId: ticket.id, answer: responseText.trim() }; await apiClient.post( "/support/answer", requestData ); setResponseText(""); await fetchAnswers(); } catch (error) { console.error("Erro ao enviar resposta:", error); } finally { setIsSubmittingAnswer(false); } }; const canCloseTicket = ticket.status !== "encerrado" /* ENCERRADO */; _react.useEffect.call(void 0, () => { if (isOpen) { setResponseText(""); (async () => { await fetchAnswers(); })().catch((error) => { console.error("Erro ao carregar respostas:", error); }); } else { setAnswers([]); } }, [isOpen, fetchAnswers]); return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkTCLRDUMFjs.Modal_default, { isOpen, onClose, title: `Pedido: ${ticket.title}`, size: "lg", hideCloseButton: false, closeOnEscape: true, "data-testid": "ticket-modal", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex flex-col h-full max-h-[80vh]", children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex justify-between items-center mb-3", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "bold", className: "text-text-950", children: "Detalhes" }), canCloseTicket && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "outline", size: "small", action: "negative", onClick: () => setShowCloseConfirmation(true), children: "Encerrar Pedido" } ) ] }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex-1 overflow-y-auto pr-2 space-y-6", children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "bg-background p-4 space-y-6 rounded-xl", children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center space-x-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "semibold", className: "text-text-700 w-20", children: "ID" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "normal", className: "text-text-600", children: ticket.id }) ] }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center space-x-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "semibold", className: "text-text-700 w-20", children: "Aberto em" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "normal", className: "text-text-600", children: _dayjs2.default.call(void 0, ticket.createdAt).format("DD MMMM YYYY, [\xE0s] HH[h]") }) ] }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center space-x-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "semibold", className: "text-text-700 w-20", children: "Status" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkBJMKBBN3js.Badge_default, { variant: "solid", size: "small", action: _chunk7JXDCLY6js.getStatusBadgeAction.call(void 0, ticket.status), className: "w-fit", children: _chunk7JXDCLY6js.getStatusText.call(void 0, ticket.status) } ) ] }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center space-x-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "semibold", className: "text-text-700 w-20", children: "Tipo" } ), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkBJMKBBN3js.Badge_default, { variant: "solid", size: "small", action: "muted", className: "w-fit", children: [ getCategoryIcon(ticket.category), _chunk7JXDCLY6js.getCategoryText.call(void 0, ticket.category) ] } ) ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkWWXDXIV7js.Divider_default, {}), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-start space-x-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "semibold", className: "text-text-700 w-20", children: "Descri\xE7\xE3o" } ), ticket.description && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "normal", className: "text-text-600", children: ticket.description }) ] }) ] }), ticket.status === "respondido" /* RESPONDIDO */ && isLoadingAnswers && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "bold", className: "text-text-950 my-6", children: "Resposta de Suporte T\xE9cnico" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, AnswerSkeleton, {}) ] }), !isLoadingAnswers && answers.some((answer) => answer.userId !== userId) && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "bold", className: "text-text-950 my-6", children: "Resposta de Suporte T\xE9cnico" }), answers.filter((answer) => answer.userId !== userId).sort( (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime() ).slice(0, 1).map((answer) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "bg-background p-4 space-y-6 rounded-xl", children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center space-x-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "semibold", className: "text-text-700 w-20", children: "Recebido" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "normal", className: "text-text-600", children: _dayjs2.default.call(void 0, answer.createdAt).format( "DD MMMM YYYY, [\xE0s] HH[h]" ) } ) ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkWWXDXIV7js.Divider_default, {}), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-start space-x-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "semibold", className: "text-text-700 w-20", children: "Resposta" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "normal", className: "text-text-600", children: answer.answer } ) ] }) ] }, answer.id )) ] }), !isLoadingAnswers && answers.some((answer) => answer.userId === userId) && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "bold", className: "text-text-950 my-6", children: "Resposta enviada" }), answers.filter((answer) => answer.userId === userId).sort( (a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime() ).slice(0, 1).map((answer) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "bg-background p-4 space-y-6 rounded-xl", children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-center space-x-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "semibold", className: "text-text-700 w-20", children: "Enviada" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "normal", className: "text-text-600", children: _dayjs2.default.call(void 0, answer.createdAt).format( "DD MMMM YYYY, [\xE0s] HH[h]" ) } ) ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkWWXDXIV7js.Divider_default, {}), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex items-start space-x-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "semibold", className: "text-text-700 w-20", children: "Resposta" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "md", weight: "normal", className: "text-text-600", children: answer.answer } ) ] }) ] }, answer.id )) ] }), !isLoadingAnswers && answers.some((answer) => answer.userId !== userId) && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "lg", weight: "bold", className: "text-text-950 my-6", children: "Responder" }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "space-y-4", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkSZD7L65Qjs.TextArea_default, { placeholder: "Detalhe o problema aqui.", rows: 4, className: "w-full", value: responseText, onChange: (e) => setResponseText(e.target.value) } ), responseText.trim().length > 0 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: "flex justify-end", children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "solid", size: "medium", onClick: handleSubmitAnswer, disabled: isSubmittingAnswer, children: isSubmittingAnswer ? "Enviando..." : "Enviar" } ) }) ] }) ] }) ] }) ] }) } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkTCLRDUMFjs.Modal_default, { isOpen: showCloseConfirmation, onClose: () => setShowCloseConfirmation(false), title: "Encerrar pedido?", size: "md", hideCloseButton: false, closeOnEscape: true, "data-testid": "close-ticket-modal", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "space-y-6", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkANT66KVKjs.Text_default, { size: "sm", weight: "normal", className: "text-text-700", children: "Ao encerrar este pedido, ele ser\xE1 fechado e n\xE3o poder\xE1 mais ser atualizado." }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex gap-3 justify-end", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "outline", size: "medium", onClick: () => setShowCloseConfirmation(false), children: "Cancelar" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk34ST3MKOjs.Button_default, { variant: "solid", size: "medium", action: "negative", onClick: handleCloseTicket, children: "Encerrar" } ) ] }) ] }) } ) ] }); }; exports.getCategoryIcon = getCategoryIcon; exports.TicketModal = TicketModal; //# sourceMappingURL=chunk-FRDMGH3F.js.map