- Replaced references to "Solicitar Acesso" with "Abrir Chamado" across the application for consistency in terminology. - Updated routing logic to reflect the new ticket management flow, ensuring that the dashboard and sidebar components point to the correct paths. - Removed the obsolete "Solicitar Acesso" page, streamlining the user experience and reducing unnecessary navigation options. - Enhanced backend schema to support new ticket functionalities, including ticket creation and management.
54 lines
1.2 KiB
TypeScript
54 lines
1.2 KiB
TypeScript
import { writable } from "svelte/store";
|
|
import type { Doc, Id } from "@sgse-app/backend/convex/_generated/dataModel";
|
|
|
|
export type TicketDetalhe = {
|
|
ticket: Doc<"tickets">;
|
|
interactions: Doc<"ticketInteractions">[];
|
|
};
|
|
|
|
function createChamadosStore() {
|
|
const tickets = writable<Array<Doc<"tickets">>>([]);
|
|
const detalhes = writable<Record<string, TicketDetalhe>>({});
|
|
const carregando = writable(false);
|
|
|
|
function setTickets(lista: Array<Doc<"tickets">>) {
|
|
tickets.set(lista);
|
|
}
|
|
|
|
function upsertTicket(ticket: Doc<"tickets">) {
|
|
tickets.update((current) => {
|
|
const existente = current.findIndex((t) => t._id === ticket._id);
|
|
if (existente >= 0) {
|
|
const copia = [...current];
|
|
copia[existente] = ticket;
|
|
return copia;
|
|
}
|
|
return [ticket, ...current];
|
|
});
|
|
}
|
|
|
|
function setDetalhe(ticketId: Id<"tickets">, detalhe: TicketDetalhe) {
|
|
detalhes.update((mapa) => ({
|
|
...mapa,
|
|
[ticketId]: detalhe,
|
|
}));
|
|
}
|
|
|
|
function setCarregando(flag: boolean) {
|
|
carregando.set(flag);
|
|
}
|
|
|
|
return {
|
|
tickets,
|
|
detalhes,
|
|
carregando,
|
|
setTickets,
|
|
upsertTicket,
|
|
setDetalhe,
|
|
setCarregando,
|
|
};
|
|
}
|
|
|
|
export const chamadosStore = createChamadosStore();
|
|
|