@burdenoff/microfe-support 2026.903.2 → 2026.1001.1
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.
|
@@ -6,7 +6,7 @@ import { buildTicketFilter as o, matchesTicketClientFilters as s, matchesTicketS
|
|
|
6
6
|
import { useEffect as u, useMemo as d, useState as f } from "react";
|
|
7
7
|
//#region src/support/hooks/useTicketListOperations.ts
|
|
8
8
|
function p(p = !1) {
|
|
9
|
-
let { currentUser: m, productId: h, showAllProductTickets: g } = e(), _ = n((e) => e.ticketFilter), v = n((e) => e.updateTicketFilter), [y, b] = f(() => _.search.trim()), x = !p, S = !t(m?.role) && !g, C = !S || !!h, w = S ? h : void 0, T = x ?
|
|
9
|
+
let { currentUser: m, productId: h, showAllProductTickets: g } = e(), _ = n((e) => e.ticketFilter), v = n((e) => e.updateTicketFilter), [y, b] = f(() => _.search.trim()), x = !p, S = !t(m?.role) && !g, C = !S || !!h, w = S ? h : void 0, T = x ? 25 : S ? 50 : 10;
|
|
10
10
|
u(() => {
|
|
11
11
|
let e = setTimeout(() => {
|
|
12
12
|
b(_.search.trim());
|
|
@@ -30,18 +30,21 @@ function p(p = !1) {
|
|
|
30
30
|
}, k = r({
|
|
31
31
|
variables: O,
|
|
32
32
|
skip: !x || !C,
|
|
33
|
-
|
|
33
|
+
fetchPolicy: "cache-first",
|
|
34
|
+
notifyOnNetworkStatusChange: !1
|
|
34
35
|
}), A = i({
|
|
35
36
|
variables: O,
|
|
36
37
|
skip: x || !C,
|
|
37
|
-
|
|
38
|
+
fetchPolicy: "cache-first",
|
|
39
|
+
notifyOnNetworkStatusChange: !1
|
|
38
40
|
}), { data: j, loading: M, error: N, fetchMore: P, refetch: F } = x ? k : A, { data: I, loading: L } = a({
|
|
39
41
|
variables: {
|
|
40
42
|
query: y,
|
|
41
43
|
limit: 20
|
|
42
44
|
},
|
|
43
45
|
skip: x || y.length === 0 || D || !C,
|
|
44
|
-
|
|
46
|
+
fetchPolicy: "cache-first",
|
|
47
|
+
notifyOnNetworkStatusChange: !1
|
|
45
48
|
}), R = () => {
|
|
46
49
|
let e = j?.supportTickets?.nodes?.length || 0;
|
|
47
50
|
j?.supportTickets?.hasMore && P({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTicketListOperations.js","names":[],"sources":["../../../src/support/hooks/useTicketListOperations.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react';\nimport { useSupportStore } from '../store/supportStore';\nimport {\n useGetTicketsQuery,\n useGetMyTicketsQuery,\n useSearchTicketsQuery,\n} from '../../generated/global-operations';\nimport { type SupportTicket } from '../../generated/global-types';\nimport { useSupport } from '../providers/SupportProvider';\nimport { isAdminRole } from '../utils';\nimport {\n buildTicketFilter,\n matchesTicketSearch,\n matchesTicketClientFilters,\n scopeTicketFilterToProduct,\n} from '../utils/ticketFilters';\n\n/**\n * Drives the ticket list query for both the consumer (\"my tickets\") surface and\n * the admin triage surface.\n *\n * `adminView` is the authoritative switch:\n * - `false` (default — consumer routes): query `mySupportTickets`, which the\n * backend pins to the calling actor (`payload.sub`). This is the privacy\n * boundary — a user only ever sees tickets they created, even when the user\n * is a @burdenoff.com platform admin (the `supportTickets` query widens for\n * those accounts and would otherwise leak every user's tickets here).\n * - `true` (admin routes): query `supportTickets`, the cross-user/admin read.\n *\n * In consumer mode, search runs locally over the loaded self-scoped tickets\n * rather than calling the server `searchTickets` resolver, which applies the\n * same platform-admin widening and would re-introduce the leak.\n */\nexport function useTicketListOperations(adminView = false) {\n const { currentUser, productId, showAllProductTickets } = useSupport();\n const ticketFilter = useSupportStore((state) => state.ticketFilter);\n const updateTicketFilter = useSupportStore((state) => state.updateTicketFilter);\n const [debouncedSearch, setDebouncedSearch] = useState(() => ticketFilter.search.trim());\n const selfScoped = !adminView;\n const shouldScopeToProduct = !isAdminRole(currentUser?.role) && !showAllProductTickets;\n const hasRequiredProductScope = !shouldScopeToProduct || Boolean(productId);\n const scopedProductId = shouldScopeToProduct ? productId : undefined;\n //
|
|
1
|
+
{"version":3,"file":"useTicketListOperations.js","names":[],"sources":["../../../src/support/hooks/useTicketListOperations.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react';\nimport { useSupportStore } from '../store/supportStore';\nimport {\n useGetTicketsQuery,\n useGetMyTicketsQuery,\n useSearchTicketsQuery,\n} from '../../generated/global-operations';\nimport { type SupportTicket } from '../../generated/global-types';\nimport { useSupport } from '../providers/SupportProvider';\nimport { isAdminRole } from '../utils';\nimport {\n buildTicketFilter,\n matchesTicketSearch,\n matchesTicketClientFilters,\n scopeTicketFilterToProduct,\n} from '../utils/ticketFilters';\n\n/**\n * Drives the ticket list query for both the consumer (\"my tickets\") surface and\n * the admin triage surface.\n *\n * `adminView` is the authoritative switch:\n * - `false` (default — consumer routes): query `mySupportTickets`, which the\n * backend pins to the calling actor (`payload.sub`). This is the privacy\n * boundary — a user only ever sees tickets they created, even when the user\n * is a @burdenoff.com platform admin (the `supportTickets` query widens for\n * those accounts and would otherwise leak every user's tickets here).\n * - `true` (admin routes): query `supportTickets`, the cross-user/admin read.\n *\n * In consumer mode, search runs locally over the loaded self-scoped tickets\n * rather than calling the server `searchTickets` resolver, which applies the\n * same platform-admin widening and would re-introduce the leak.\n */\nexport function useTicketListOperations(adminView = false) {\n const { currentUser, productId, showAllProductTickets } = useSupport();\n const ticketFilter = useSupportStore((state) => state.ticketFilter);\n const updateTicketFilter = useSupportStore((state) => state.updateTicketFilter);\n const [debouncedSearch, setDebouncedSearch] = useState(() => ticketFilter.search.trim());\n const selfScoped = !adminView;\n const shouldScopeToProduct = !isAdminRole(currentUser?.role) && !showAllProductTickets;\n const hasRequiredProductScope = !shouldScopeToProduct || Boolean(productId);\n const scopedProductId = shouldScopeToProduct ? productId : undefined;\n // Keep the initial self-scoped payload small; Load More extends local search.\n const ticketListLimit = selfScoped ? 25 : shouldScopeToProduct ? 50 : 10;\n\n useEffect(() => {\n const timer = setTimeout(() => {\n setDebouncedSearch(ticketFilter.search.trim());\n }, 300);\n\n return () => clearTimeout(timer);\n }, [ticketFilter.search]);\n\n const filter = useMemo(\n () => scopeTicketFilterToProduct(buildTicketFilter(ticketFilter), scopedProductId),\n [scopedProductId, ticketFilter]\n );\n // Consumer mode always searches locally (no server searchTickets call); admin\n // mode searches locally only when scoped to a single product.\n const useScopedLocalSearch = selfScoped\n ? Boolean(debouncedSearch)\n : Boolean(scopedProductId && debouncedSearch);\n\n useEffect(() => {\n if (!hasRequiredProductScope) {\n console.warn(\n 'Support ticket list requires a productId for product-scoped views, but none was resolved.'\n );\n }\n }, [hasRequiredProductScope]);\n\n useEffect(() => {\n if (scopedProductId && ticketFilter.productId && ticketFilter.productId !== scopedProductId) {\n console.warn(\n 'Product-scoped ticket filter conflicts with active product scope; using scoped product.'\n );\n updateTicketFilter({ productId: null });\n }\n }, [scopedProductId, ticketFilter.productId, updateTicketFilter]);\n\n const queryVariables = {\n filter,\n limit: ticketListLimit,\n offset: 0,\n };\n\n // Both hooks return the same `{ supportTickets: { nodes, totalCount, hasMore } }`\n // shape — GetMyTickets aliases `mySupportTickets` to `supportTickets` — so only\n // one runs at a time (the other is skipped) and downstream code is shared.\n const myTicketsResult = useGetMyTicketsQuery({\n variables: queryVariables,\n skip: !selfScoped || !hasRequiredProductScope,\n fetchPolicy: 'cache-first',\n notifyOnNetworkStatusChange: false,\n });\n const allTicketsResult = useGetTicketsQuery({\n variables: queryVariables,\n skip: selfScoped || !hasRequiredProductScope,\n fetchPolicy: 'cache-first',\n notifyOnNetworkStatusChange: false,\n });\n\n const {\n data: ticketsData,\n loading: ticketsLoading,\n error: ticketsError,\n fetchMore: fetchMoreTickets,\n refetch: refetchTickets,\n } = selfScoped ? myTicketsResult : allTicketsResult;\n\n const { data: searchedTicketsData, loading: searchLoading } = useSearchTicketsQuery({\n variables: {\n query: debouncedSearch,\n limit: 20,\n },\n // Self mode never hits the server search resolver — see hook docs.\n skip:\n selfScoped ||\n debouncedSearch.length === 0 ||\n useScopedLocalSearch ||\n !hasRequiredProductScope,\n fetchPolicy: 'cache-first',\n notifyOnNetworkStatusChange: false,\n });\n\n const loadMoreTickets = () => {\n const currentCount = ticketsData?.supportTickets?.nodes?.length || 0;\n if (ticketsData?.supportTickets?.hasMore) {\n fetchMoreTickets({\n variables: {\n offset: currentCount,\n },\n updateQuery: (prev, { fetchMoreResult }) => {\n if (!fetchMoreResult) return prev;\n return {\n supportTickets: {\n ...fetchMoreResult.supportTickets,\n nodes: [\n ...(prev.supportTickets?.nodes || []),\n ...(fetchMoreResult.supportTickets?.nodes || []),\n ],\n },\n };\n },\n });\n }\n };\n\n const listTickets = ticketsData?.supportTickets?.nodes || [];\n let tickets: SupportTicket[] = listTickets;\n\n if (!hasRequiredProductScope) {\n tickets = [];\n } else if (useScopedLocalSearch) {\n // The search endpoint has no product filter, so scoped search is local to loaded tickets.\n tickets = listTickets.filter(\n (ticket: SupportTicket) =>\n matchesTicketSearch(ticket, debouncedSearch) &&\n matchesTicketClientFilters(ticket, ticketFilter)\n );\n } else if (debouncedSearch) {\n tickets = (searchedTicketsData?.searchTickets || []).filter((ticket: SupportTicket) =>\n matchesTicketClientFilters(ticket, ticketFilter)\n );\n }\n const shouldUseListLoading = useScopedLocalSearch || !debouncedSearch;\n // The \"results limited to loaded tickets\" hint is only truthful when more\n // tickets exist server-side than are loaded. In self mode the full set is\n // usually loaded (limit 25), so suppress the hint unless there really is more.\n const hasMore = Boolean(ticketsData?.supportTickets?.hasMore);\n const showScopedSearchHint = selfScoped ? useScopedLocalSearch && hasMore : useScopedLocalSearch;\n\n return {\n tickets,\n ticketsLoading: shouldUseListLoading ? ticketsLoading : searchLoading,\n ticketsError,\n totalTickets: useScopedLocalSearch\n ? tickets.length\n : ticketsData?.supportTickets?.totalCount || 0,\n hasMoreTickets: hasMore,\n isScopedLocalSearch: showScopedSearchHint,\n isMissingProductScope: !hasRequiredProductScope,\n loadMoreTickets,\n refetchTickets,\n };\n}\n"],"mappings":";;;;;;;AAiCA,SAA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