@aglyn/plugins-inbox 1.0.0-beta.234 → 1.0.0-beta.235

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aglyn/plugins-inbox",
3
- "version": "1.0.0-beta.234",
3
+ "version": "1.0.0-beta.235",
4
4
  "license": "Apache-2.0",
5
5
  "homepage": "https://aglyn.com",
6
6
  "repository": {
@@ -25,16 +25,16 @@
25
25
  "./package.json": "./package.json"
26
26
  },
27
27
  "dependencies": {
28
- "@aglyn/aglyn": "1.0.0-beta.234",
29
- "@aglyn/shared-data-mdi": "1.0.0-beta.234",
30
- "@aglyn/shared-ui-jsx": "1.0.0-beta.234",
31
- "@aglyn/shared-ui-next": "1.0.0-beta.234",
32
- "@aglyn/shared-ui-snackstack": "1.0.0-beta.234",
33
- "@aglyn/shared-util-email": "1.0.0-beta.234",
34
- "@aglyn/shared-util-http": "1.0.0-beta.234",
35
- "@aglyn/shared-util-tools": "1.0.0-beta.234",
36
- "@aglyn/tenant-data-admin": "1.0.0-beta.234",
37
- "@aglyn/tenant-feature-instance": "1.0.0-beta.234",
28
+ "@aglyn/aglyn": "1.0.0-beta.235",
29
+ "@aglyn/shared-data-mdi": "1.0.0-beta.235",
30
+ "@aglyn/shared-ui-jsx": "1.0.0-beta.235",
31
+ "@aglyn/shared-ui-next": "1.0.0-beta.235",
32
+ "@aglyn/shared-ui-snackstack": "1.0.0-beta.235",
33
+ "@aglyn/shared-util-email": "1.0.0-beta.235",
34
+ "@aglyn/shared-util-http": "1.0.0-beta.235",
35
+ "@aglyn/shared-util-tools": "1.0.0-beta.235",
36
+ "@aglyn/tenant-data-admin": "1.0.0-beta.235",
37
+ "@aglyn/tenant-feature-instance": "1.0.0-beta.235",
38
38
  "@swc/helpers": "0.5.23"
39
39
  },
40
40
  "peerDependencies": {
@@ -124,8 +124,7 @@ import { scopeTokensForHost } from "@aglyn/aglyn/app-utils/scope-tokens";
124
124
  return /*#__PURE__*/ _jsx(CardDisplay, {
125
125
  header: 'Inbox',
126
126
  help: pluginDocsHelp('forms', {
127
- anchor: '#the-inbox',
128
- excerpt: 'The newest form submissions on this site — the Inbox has the ' + 'full list, the reader, and the routing each one took.'
127
+ anchor: '#inbox-card'
129
128
  }),
130
129
  contentGutterX: true,
131
130
  contentGutterY: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/inbox/src/lib/components/inbox-glance-card.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n buildRoute,\n CRM_LEAD_CLOSED_STATUSES,\n openLeadsFromCounts,\n pluginDocsHelp,\n Route,\n} from '@aglyn/aglyn'\n// The CRM's route builder by its leaf path, not the plugin barrel: the\n// barrel is the CRM's site entry point, and a dashboard card named there\n// would ship to every published page.\nimport { pluginRecordListHref } from '@aglyn/aglyn/plugin-manager/plugin-record-routes'\nimport { pluginRecordListQuery } from '@aglyn/aglyn/plugin-manager/plugin-record-lists'\nimport { AppLink, CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { Avatar, Box, Button, Stack, Typography } from '@mui/material'\nimport {\n collection,\n getCountFromServer,\n query,\n where,\n} from 'firebase/firestore'\nimport { useParams } from 'next/navigation'\nimport { useEffect, useState } from 'react'\nimport { useOrgDataScope, useFirestore, useFirestoreCollection } from '@aglyn/tenant-feature-instance'\nimport { useRecordRouteContext } from './use-record-route-context'\nimport {\n relativeTime,\n senderHue,\n submissionSender,\n} from '../model/submission-presenter'\nimport { scopeTokensForHost } from '@aglyn/aglyn/app-utils/scope-tokens'\n\n/**\n * Rows on the card, plus one so it can say the inbox holds more.\n *\n * The extra document is never rendered — it is what turns \"there may be\n * more\" into a fact, the same probe the console's paged lists use.\n */\nconst PREVIEW_ROWS = 3\n\n/**\n * The inbox at a glance: who wrote in, how long ago, and how many are\n * unread.\n *\n * A dashboard is where a site owner looks first, and a form submission is\n * the one thing on it that is waiting for a REPLY — until now it was two\n * clicks away with nothing on the dashboard saying it had arrived.\n *\n * Renders nothing until the site has a submission, the same rule the other\n * capability glances follow: an empty card about forms on a site with no\n * form is an advertisement, not a summary.\n *\n * `orderBy('createdAt', 'desc')` is checked against the writer rather than\n * assumed — an `orderBy` drops documents missing the field, which on a\n * newest-first list is invisible. `libs/plugins/forms/src/lib/server/form-submit.ts`\n * is the only path that creates one and stamps `createdAt: serverTimestamp()`\n * on every add, the v1 API only reads and deletes, and `formSubmissions` is\n * absent from `IMPORTABLE_FIELDS`, so no restore can mint one without it.\n */\nexport function InboxGlanceCard(props: { hostId: string }) {\n const { hostId } = props\n const firestore = useFirestore()\n const { orgSlug, host } = useParams<{ orgSlug: string; host: string }>()\n const { data: submissionDocs } = useFirestoreCollection<any>(\n () =>\n // The newest of the site's, one past the preview, through the list\n // source the forms plugin publishes for its records (AGL-3080).\n pluginRecordListQuery('formSubmission', firestore, {\n hostId,\n limit: PREVIEW_ROWS + 1,\n }),\n [firestore, hostId],\n { idField: '$id' },\n )\n\n /*\n * How many leads are waiting to be worked (AGL-2622), so the dashboard\n * says where the Inbox's captures went and the CRM's Leads list is one\n * click from here. Two server-side counts rather than a window: a lead\n * nobody has touched carries no status field at all — it is `new` by\n * absence, the rule `crmLeadStatus` reads — and Firestore can neither\n * count an absent field nor exclude the closed statuses without dropping\n * the unstamped rows too. So the open count is every lead less the ones\n * closed by a stamped status — `openLeadsFromCounts`, the subtraction the\n * CRM's own glance card makes — and both counts are aggregations that cost\n * one read per thousand index entries, not one per lead. `null` until\n * they land, and left null on a refused read so the line is withheld\n * rather than drawn as zero.\n */\n const routeContext = useRecordRouteContext()\n const leadsHref = routeContext\n ? pluginRecordListHref('lead', routeContext)\n : null\n /*\n * The lead silo is the org's (AGL-3275), narrowed to this site by\n * `visibleTo`. Reading `hosts/{hostId}/leads` showed a site its\n * pre-migration rows and nothing captured since.\n *\n * `orgId` settles AFTER the first render — it is a `hostIndex` lookup —\n * so it is a dependency of the counts below: an effect keyed on the site\n * alone ran once with no org, returned, and never asked again.\n */\n const { orgId } = useOrgDataScope({ hostId })\n const [openLeads, setOpenLeads] = useState<number | null>(null)\n useEffect(() => {\n let active = true\n if (!orgId) return undefined\n const leads = collection(firestore, 'orgs', orgId, 'leads')\n const scoped = where('visibleTo', 'array-contains-any', scopeTokensForHost(hostId))\n void Promise.all([\n getCountFromServer(query(leads, scoped)),\n getCountFromServer(\n query(leads, scoped, where('status', 'in', CRM_LEAD_CLOSED_STATUSES)),\n ),\n ])\n .then(([all, closed]) => {\n if (!active) return\n setOpenLeads(openLeadsFromCounts(all.data().count, closed.data().count))\n })\n .catch(() => undefined)\n return () => {\n active = false\n }\n }, [firestore, hostId, orgId])\n\n const submissions = submissionDocs ?? []\n if (!submissions.length && !openLeads) return null\n const rows = submissions.slice(0, PREVIEW_ROWS)\n const unread = rows.filter((submission: any) => !submission.read).length\n\n return (\n <CardDisplay\n header={'Inbox'}\n help={pluginDocsHelp('forms', {\n anchor: '#the-inbox',\n excerpt:\n 'The newest form submissions on this site — the Inbox has the ' +\n 'full list, the reader, and the routing each one took.',\n })}\n contentGutterX\n contentGutterY\n HeaderProps={{\n action: (\n <Button\n component={AppLink as any}\n {...({ componentVariant: 'naked', nativeButton: false } as any)}\n href={buildRoute(Route.HOST_INBOX, { orgSlug, host })}\n size=\"small\"\n color=\"primary\"\n >\n {'Open inbox'}\n </Button>\n ),\n }}\n >\n <Stack spacing={1}>\n {rows.map((submission: any) => {\n const sender = submissionSender(submission.fields)\n const hue = senderHue(sender.label)\n return (\n <Stack\n key={submission.$id}\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center' }}\n >\n {/*\n The unread DOT, as the Inbox itself draws it — same fact, same\n shape, so a reader recognizes the row when they open it.\n */}\n <Box\n aria-label={submission.read ? undefined : 'Unread'}\n sx={{\n width: 8,\n height: 8,\n borderRadius: '50%',\n bgcolor: submission.read ? 'transparent' : 'primary.main',\n flexShrink: 0,\n }}\n />\n <Avatar\n sx={{\n width: 28,\n height: 28,\n typography: 'caption',\n bgcolor: `hsl(${hue} 55% 45%)`,\n }}\n >\n {sender.initials}\n </Avatar>\n <Stack sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {sender.label}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {submission.formName ?? 'Form'}\n </Typography>\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {relativeTime(submission.createdAt?.toDate?.().getTime())}\n </Typography>\n </Stack>\n )\n })}\n {/*\n What the card is NOT showing. `submissions` holds the probe row, so\n a fourth document is a fact rather than an inference from a full\n page — and the unread count is stated over the rows on screen, not\n over the collection, because counting the collection is a read this\n card has no reason to pay for.\n */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {[\n unread ? `${unread} unread here` : null,\n submissions.length > PREVIEW_ROWS ? 'more in the Inbox' : null,\n ]\n .filter(Boolean)\n .join(' · ') || 'All caught up'}\n </Typography>\n {/*\n Where the captures went (AGL-2622): the leads still to be worked,\n and the Leads list where they are, which the plugin that keeps\n them publishes. Text alone until the route params settle or where\n no plugin publishes one, so the line never links to nowhere.\n */}\n {openLeads ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${openLeads.toLocaleString()} open lead${openLeads === 1 ? '' : 's'} · `}\n {leadsHref ? (\n <AppLink href={leadsHref}>\n {'Work them in the CRM'}\n </AppLink>\n ) : (\n 'in the CRM'\n )}\n </Typography>\n ) : null}\n </Stack>\n </CardDisplay>\n )\n}\nInboxGlanceCard.displayName = 'InboxGlanceCard'\n\nexport default InboxGlanceCard\n"],"names":["buildRoute","CRM_LEAD_CLOSED_STATUSES","openLeadsFromCounts","pluginDocsHelp","Route","pluginRecordListHref","pluginRecordListQuery","AppLink","CardDisplay","Avatar","Box","Button","Stack","Typography","collection","getCountFromServer","query","where","useParams","useEffect","useState","useOrgDataScope","useFirestore","useFirestoreCollection","useRecordRouteContext","relativeTime","senderHue","submissionSender","scopeTokensForHost","PREVIEW_ROWS","InboxGlanceCard","props","hostId","firestore","orgSlug","host","data","submissionDocs","limit","idField","routeContext","leadsHref","orgId","openLeads","setOpenLeads","active","undefined","leads","scoped","Promise","all","then","closed","count","catch","submissions","length","rows","slice","unread","filter","submission","read","header","help","anchor","excerpt","contentGutterX","contentGutterY","HeaderProps","action","component","componentVariant","nativeButton","href","HOST_INBOX","size","color","spacing","map","sender","fields","hue","label","direction","sx","alignItems","aria-label","width","height","borderRadius","bgcolor","flexShrink","typography","initials","flex","minWidth","variant","noWrap","formName","createdAt","toDate","getTime","$id","Boolean","join","toLocaleString","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SACEA,UAAU,EACVC,wBAAwB,EACxBC,mBAAmB,EACnBC,cAAc,EACdC,KAAK,QACA,eAAc;AACrB,uEAAuE;AACvE,yEAAyE;AACzE,sCAAsC;AACtC,SAASC,oBAAoB,QAAQ,mDAAkD;AACvF,SAASC,qBAAqB,QAAQ,kDAAiD;AACvF,SAASC,OAAO,EAAEC,WAAW,QAAQ,uBAAsB;AAC3D,SAASC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AACtE,SACEC,UAAU,EACVC,kBAAkB,EAClBC,KAAK,EACLC,KAAK,QACA,qBAAoB;AAC3B,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAC3C,SAASC,eAAe,EAAEC,YAAY,EAA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S,CAAC,IAAI,EAAET,IAAI,SAAS,CAAC;gCAChC;0CAECF,OAAOc,QAAQ;;0CAElB,MAAClF;gCAAMyE,IAAI;oCAAEU,MAAM;oCAAGC,UAAU;gCAAE;;kDAChC,KAACnF;wCAAWoF,SAAQ;wCAAQC,MAAM;kDAC/BlB,OAAOG,KAAK;;kDAEf,KAACtE;wCAAWoF,SAAQ;wCAAUpB,OAAM;wCAAiBqB,MAAM;mDACxDrC,uBAAAA,WAAWsC,QAAQ,YAAnBtC,uBAAuB;;;;0CAG5B,KAAChD;gCAAWoF,SAAQ;gCAAUpB,OAAM;gCAAiBqB,MAAM;0CACxDzE,cAAaoC,wBAAAA,WAAWuC,SAAS,sBAApBvC,+BAAAA,sBAAsBwC,MAAM,qBAA5BxC,kCAAAA,uBAAiCyC,OAAO;;;uBAtCnDzC,WAAW0C,GAAG;gBA0CzB;8BAQA,KAAC1F;oBAAWoF,SAAQ;oBAAUpB,OAAM;8BACjC;wBACClB,SAAS,GAAGA,OAAO,YAAY,CAAC,GAAG;wBACnCJ,YAAYC,MAAM,GAAG3B,eAAe,sBAAsB;qBAC3D,CACE+B,MAAM,CAAC4C,SACPC,IAAI,CAAC,UAAU;;gBAQnB9D,0BACC,MAAC9B;oBAAWoF,SAAQ;oBAAUpB,OAAM;;wBACjC,GAAGlC,UAAU+D,cAAc,GAAG,UAAU,EAAE/D,cAAc,IAAI,KAAK,IAAI,GAAG,CAAC;wBACzEF,0BACC,KAAClC;4BAAQmE,MAAMjC;sCACZ;6BAGH;;qBAGF;;;;AAIZ;AACAX,gBAAgB6E,WAAW,GAAG;AAE9B,eAAe7E,gBAAe"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/inbox/src/lib/components/inbox-glance-card.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n buildRoute,\n CRM_LEAD_CLOSED_STATUSES,\n openLeadsFromCounts,\n pluginDocsHelp,\n Route,\n} from '@aglyn/aglyn'\n// The CRM's route builder by its leaf path, not the plugin barrel: the\n// barrel is the CRM's site entry point, and a dashboard card named there\n// would ship to every published page.\nimport { pluginRecordListHref } from '@aglyn/aglyn/plugin-manager/plugin-record-routes'\nimport { pluginRecordListQuery } from '@aglyn/aglyn/plugin-manager/plugin-record-lists'\nimport { AppLink, CardDisplay } from '@aglyn/shared-ui-jsx'\nimport { Avatar, Box, Button, Stack, Typography } from '@mui/material'\nimport {\n collection,\n getCountFromServer,\n query,\n where,\n} from 'firebase/firestore'\nimport { useParams } from 'next/navigation'\nimport { useEffect, useState } from 'react'\nimport { useOrgDataScope, useFirestore, useFirestoreCollection } from '@aglyn/tenant-feature-instance'\nimport { useRecordRouteContext } from './use-record-route-context'\nimport {\n relativeTime,\n senderHue,\n submissionSender,\n} from '../model/submission-presenter'\nimport { scopeTokensForHost } from '@aglyn/aglyn/app-utils/scope-tokens'\n\n/**\n * Rows on the card, plus one so it can say the inbox holds more.\n *\n * The extra document is never rendered — it is what turns \"there may be\n * more\" into a fact, the same probe the console's paged lists use.\n */\nconst PREVIEW_ROWS = 3\n\n/**\n * The inbox at a glance: who wrote in, how long ago, and how many are\n * unread.\n *\n * A dashboard is where a site owner looks first, and a form submission is\n * the one thing on it that is waiting for a REPLY — until now it was two\n * clicks away with nothing on the dashboard saying it had arrived.\n *\n * Renders nothing until the site has a submission, the same rule the other\n * capability glances follow: an empty card about forms on a site with no\n * form is an advertisement, not a summary.\n *\n * `orderBy('createdAt', 'desc')` is checked against the writer rather than\n * assumed — an `orderBy` drops documents missing the field, which on a\n * newest-first list is invisible. `libs/plugins/forms/src/lib/server/form-submit.ts`\n * is the only path that creates one and stamps `createdAt: serverTimestamp()`\n * on every add, the v1 API only reads and deletes, and `formSubmissions` is\n * absent from `IMPORTABLE_FIELDS`, so no restore can mint one without it.\n */\nexport function InboxGlanceCard(props: { hostId: string }) {\n const { hostId } = props\n const firestore = useFirestore()\n const { orgSlug, host } = useParams<{ orgSlug: string; host: string }>()\n const { data: submissionDocs } = useFirestoreCollection<any>(\n () =>\n // The newest of the site's, one past the preview, through the list\n // source the forms plugin publishes for its records (AGL-3080).\n pluginRecordListQuery('formSubmission', firestore, {\n hostId,\n limit: PREVIEW_ROWS + 1,\n }),\n [firestore, hostId],\n { idField: '$id' },\n )\n\n /*\n * How many leads are waiting to be worked (AGL-2622), so the dashboard\n * says where the Inbox's captures went and the CRM's Leads list is one\n * click from here. Two server-side counts rather than a window: a lead\n * nobody has touched carries no status field at all — it is `new` by\n * absence, the rule `crmLeadStatus` reads — and Firestore can neither\n * count an absent field nor exclude the closed statuses without dropping\n * the unstamped rows too. So the open count is every lead less the ones\n * closed by a stamped status — `openLeadsFromCounts`, the subtraction the\n * CRM's own glance card makes — and both counts are aggregations that cost\n * one read per thousand index entries, not one per lead. `null` until\n * they land, and left null on a refused read so the line is withheld\n * rather than drawn as zero.\n */\n const routeContext = useRecordRouteContext()\n const leadsHref = routeContext\n ? pluginRecordListHref('lead', routeContext)\n : null\n /*\n * The lead silo is the org's (AGL-3275), narrowed to this site by\n * `visibleTo`. Reading `hosts/{hostId}/leads` showed a site its\n * pre-migration rows and nothing captured since.\n *\n * `orgId` settles AFTER the first render — it is a `hostIndex` lookup —\n * so it is a dependency of the counts below: an effect keyed on the site\n * alone ran once with no org, returned, and never asked again.\n */\n const { orgId } = useOrgDataScope({ hostId })\n const [openLeads, setOpenLeads] = useState<number | null>(null)\n useEffect(() => {\n let active = true\n if (!orgId) return undefined\n const leads = collection(firestore, 'orgs', orgId, 'leads')\n const scoped = where('visibleTo', 'array-contains-any', scopeTokensForHost(hostId))\n void Promise.all([\n getCountFromServer(query(leads, scoped)),\n getCountFromServer(\n query(leads, scoped, where('status', 'in', CRM_LEAD_CLOSED_STATUSES)),\n ),\n ])\n .then(([all, closed]) => {\n if (!active) return\n setOpenLeads(openLeadsFromCounts(all.data().count, closed.data().count))\n })\n .catch(() => undefined)\n return () => {\n active = false\n }\n }, [firestore, hostId, orgId])\n\n const submissions = submissionDocs ?? []\n if (!submissions.length && !openLeads) return null\n const rows = submissions.slice(0, PREVIEW_ROWS)\n const unread = rows.filter((submission: any) => !submission.read).length\n\n return (\n <CardDisplay\n header={'Inbox'}\n help={pluginDocsHelp('forms', { anchor: '#inbox-card' })}\n contentGutterX\n contentGutterY\n HeaderProps={{\n action: (\n <Button\n component={AppLink as any}\n {...({ componentVariant: 'naked', nativeButton: false } as any)}\n href={buildRoute(Route.HOST_INBOX, { orgSlug, host })}\n size=\"small\"\n color=\"primary\"\n >\n {'Open inbox'}\n </Button>\n ),\n }}\n >\n <Stack spacing={1}>\n {rows.map((submission: any) => {\n const sender = submissionSender(submission.fields)\n const hue = senderHue(sender.label)\n return (\n <Stack\n key={submission.$id}\n direction=\"row\"\n spacing={1}\n sx={{ alignItems: 'center' }}\n >\n {/*\n The unread DOT, as the Inbox itself draws it — same fact, same\n shape, so a reader recognizes the row when they open it.\n */}\n <Box\n aria-label={submission.read ? undefined : 'Unread'}\n sx={{\n width: 8,\n height: 8,\n borderRadius: '50%',\n bgcolor: submission.read ? 'transparent' : 'primary.main',\n flexShrink: 0,\n }}\n />\n <Avatar\n sx={{\n width: 28,\n height: 28,\n typography: 'caption',\n bgcolor: `hsl(${hue} 55% 45%)`,\n }}\n >\n {sender.initials}\n </Avatar>\n <Stack sx={{ flex: 1, minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {sender.label}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {submission.formName ?? 'Form'}\n </Typography>\n </Stack>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {relativeTime(submission.createdAt?.toDate?.().getTime())}\n </Typography>\n </Stack>\n )\n })}\n {/*\n What the card is NOT showing. `submissions` holds the probe row, so\n a fourth document is a fact rather than an inference from a full\n page — and the unread count is stated over the rows on screen, not\n over the collection, because counting the collection is a read this\n card has no reason to pay for.\n */}\n <Typography variant=\"caption\" color=\"text.secondary\">\n {[\n unread ? `${unread} unread here` : null,\n submissions.length > PREVIEW_ROWS ? 'more in the Inbox' : null,\n ]\n .filter(Boolean)\n .join(' · ') || 'All caught up'}\n </Typography>\n {/*\n Where the captures went (AGL-2622): the leads still to be worked,\n and the Leads list where they are, which the plugin that keeps\n them publishes. Text alone until the route params settle or where\n no plugin publishes one, so the line never links to nowhere.\n */}\n {openLeads ? (\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`${openLeads.toLocaleString()} open lead${openLeads === 1 ? '' : 's'} · `}\n {leadsHref ? (\n <AppLink href={leadsHref}>\n {'Work them in the CRM'}\n </AppLink>\n ) : (\n 'in the CRM'\n )}\n </Typography>\n ) : null}\n </Stack>\n </CardDisplay>\n )\n}\nInboxGlanceCard.displayName = 'InboxGlanceCard'\n\nexport default InboxGlanceCard\n"],"names":["buildRoute","CRM_LEAD_CLOSED_STATUSES","openLeadsFromCounts","pluginDocsHelp","Route","pluginRecordListHref","pluginRecordListQuery","AppLink","CardDisplay","Avatar","Box","Button","Stack","Typography","collection","getCountFromServer","query","where","useParams","useEffect","useState","useOrgDataScope","useFirestore","useFirestoreCollection","useRecordRouteContext","relativeTime","senderHue","submissionSender","scopeTokensForHost","PREVIEW_ROWS","InboxGlanceCard","props","hostId","firestore","orgSlug","host","data","submissionDocs","limit","idField","routeContext","leadsHref","orgId","openLeads","setOpenLeads","active","undefined","leads","scoped","Promise","all","then","closed","count","catch","submissions","length","rows","slice","unread","filter","submission","read","header","help","anchor","contentGutterX","contentGutterY","HeaderProps","action","component","componentVariant","nativeButton","href","HOST_INBOX","size","color","spacing","map","sender","fields","hue","label","direction","sx","alignItems","aria-label","width","height","borderRadius","bgcolor","flexShrink","typography","initials","flex","minWidth","variant","noWrap","formName","createdAt","toDate","getTime","$id","Boolean","join","toLocaleString","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SACEA,UAAU,EACVC,wBAAwB,EACxBC,mBAAmB,EACnBC,cAAc,EACdC,KAAK,QACA,eAAc;AACrB,uEAAuE;AACvE,yEAAyE;AACzE,sCAAsC;AACtC,SAASC,oBAAoB,QAAQ,mDAAkD;AACvF,SAASC,qBAAqB,QAAQ,kDAAiD;AACvF,SAASC,OAAO,EAAEC,WAAW,QAAQ,uBAAsB;AAC3D,SAASC,MAAM,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK,EAAEC,UAAU,QAAQ,gBAAe;AACtE,SACEC,UAAU,EACVC,kBAAkB,EAClBC,KAAK,EACLC,KAAK,QACA,qBAAoB;AAC3B,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAC3C,SAASC,eAAe,EAAEC,YAAY,EAAEC,sBAAsB,QAAQ,iCAAgC;AACtG,SAASC,qBAAqB,QAAQ,gCAA4B;AAClE,SACEC,YAAY,EACZC,SAAS,EACTC,gBAAgB,QACX,mCAA+B;AACtC,SAASC,kBAAkB,QAAQ,sCAAqC;AAExE;;;;;CAKC,GACD,MAAMC,eAAe;AAErB;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,SAASC,gBAAgBC,KAAyB;IACvD,MAAM,EAAEC,MAAM,EAAE,GAAGD;IACnB,MAAME,YAAYX;IAClB,MAAM,EAAEY,OAAO,EAAEC,IAAI,EAAE,GAAGjB;IAC1B,MAAM,EAAEkB,MAAMC,cAAc,EAAE,GAAGd,uBAC/B,IACE,mEAAmE;QACnE,gEAAgE;QAChEjB,sBAAsB,kBAAkB2B,WAAW;YACjDD;YACAM,OAAOT,eAAe;QACxB,IACF;QAACI;QAAWD;KAAO,EACnB;QAA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oBAAUpB,OAAM;8BACjC;wBACCjB,SAAS,GAAGA,OAAO,YAAY,CAAC,GAAG;wBACnCJ,YAAYC,MAAM,GAAG3B,eAAe,sBAAsB;qBAC3D,CACE+B,MAAM,CAAC2C,SACPC,IAAI,CAAC,UAAU;;gBAQnB7D,0BACC,MAAC9B;oBAAWmF,SAAQ;oBAAUpB,OAAM;;wBACjC,GAAGjC,UAAU8D,cAAc,GAAG,UAAU,EAAE9D,cAAc,IAAI,KAAK,IAAI,GAAG,CAAC;wBACzEF,0BACC,KAAClC;4BAAQkE,MAAMhC;sCACZ;6BAGH;;qBAGF;;;;AAIZ;AACAX,gBAAgB4E,WAAW,GAAG;AAE9B,eAAe5E,gBAAe"}
@@ -593,7 +593,11 @@ export function SubmissionsCard({ hostId, formId, orgMount }) {
593
593
  children: [
594
594
  /*#__PURE__*/ _jsxs(CardDisplay, {
595
595
  header: scoped ? 'Submissions to this form' : 'Form Submissions',
596
- help: pluginDocsHelp('forms', hostId == null ? {
596
+ help: pluginDocsHelp('forms', // Scoped to one form, this is the form page's own "Submissions to
597
+ // this form" card, opened in place — the same card, the same link.
598
+ scoped ? {
599
+ anchor: '#form-submissions'
600
+ } : hostId == null ? {
597
601
  anchor: '#every-sites-inbox-at-once',
598
602
  excerpt: 'Every site’s form messages in one list, newest first, ' + 'each under the site it was sent to.'
599
603
  } : {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../libs/plugins/inbox/src/lib/components/submissions-card.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n FORMS_MAX_PER_HOST,\n pluginDocsHelp,\n type ConsolePluginOrgMount,\n} from '@aglyn/aglyn'\nimport { INBOX_SUBMISSION_PARAM } from '../model/inbox-record-routes'\nimport { hostPublicOrigin } from '@aglyn/aglyn/app-utils/host-naming'\nimport { submissionFiledUnder, submissionLinks } from '../model/submission-links'\n\n/** The forms plugin's record kind this card reads (AGL-3080). */\nconst FORM_SUBMISSION_KIND = 'formSubmission'\n// A deep import, NOT the plugin barrel (AGL-1151): the barrel is the entry\n// point the tenant's loader dynamically imports to activate the marketing\n// plugin's SITE half, so a console card named there ships to every published\n// page. The component path reaches the same module without crossing it.\nimport { InboxRecordAttributionZone } from './inbox-attribution-zone'\n// The CRM's route builder by its leaf path, for the reason above: the barrel\n// is the plugin's site entry point.\nimport {\n pluginRecordByEmailHref,\n pluginRecordHref,\n pluginRecordListHref,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-routes'\nimport {\n mdiAccountArrowRight,\n mdiDeleteOutline,\n mdiEmailOpenOutline,\n mdiEmailOutline,\n} from '@aglyn/shared-data-mdi'\nimport { AppLink, CardDisplay, MdiIcon, useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport ListFilterChips from '@aglyn/shared-ui-jsx/components/list-filter-chips.component'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport ListQueryNotices, {\n listQueryRefusals,\n} from '@aglyn/shared-ui-jsx/components/list-query-notices.component'\nimport {\n ListRowActions,\n ListTable,\n listActionsColumn,\n} from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport type { RowActionsMenuItem } from '@aglyn/shared-ui-jsx/components/row-actions-menu.component'\nimport {\n type ListFilterOption,\n listFilterGridColumns,\n} from '@aglyn/shared-ui-jsx/const/list-grid-filter'\nimport type { ListQueryDeclaration } from '@aglyn/shared-ui-jsx/const/list-query-plan'\nimport { TABLE_ROW_HEIGHT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport { useListGridFilter } from '@aglyn/shared-ui-jsx/hooks/use-list-grid-filter'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n useFirestore,\n useFirestoreCollection,\n usePluginApiPost,\n} from '@aglyn/tenant-feature-instance'\nimport { useListQuery } from '@aglyn/tenant-feature-instance/hooks/use-list-query'\nimport { useListColumnSort } from '@aglyn/shared-ui-jsx/hooks/use-list-column-sort'\nimport type { ListQuerySort } from '@aglyn/shared-ui-jsx/const/list-query-plan'\nimport {\n Avatar,\n Box,\n Button,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Divider,\n Stack,\n Tooltip,\n Typography,\n} from '@mui/material'\nimport type { GridColDef } from '@mui/x-data-grid'\nimport {\n collection,\n deleteDoc,\n getDoc,\n limit,\n orderBy,\n query,\n updateDoc,\n} from 'firebase/firestore'\n// The submissions are the forms plugin's records, walked and opened through\n// the list source it publishes (AGL-3080).\nimport {\n pluginRecordListDoc,\n pluginRecordListWalk,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-lists'\nimport { useSearchParams } from 'next/navigation'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport {\n relativeTime,\n routingChips,\n senderHue,\n submissionSender,\n} from '../model/submission-presenter'\nimport {\n FORM_SCOPED_SUBMISSION_LIST_QUERY,\n ORG_SUBMISSION_LIST_QUERY,\n SUBMISSION_FILTER_HEADERS,\n SUBMISSION_LIST_QUERY,\n SUBMISSION_READ_OPTIONS,\n formSubmissionBase,\n orgSubmissionBase,\n} from '../constants/list-queries'\nimport { orgSiteName } from './inbox-org-sites'\nimport SubmissionListAssignment from './submission-list-assignment.component'\nimport SubmissionReply from './submission-reply.component'\nimport { useRecordRouteContext } from './use-record-route-context'\n\n\n/**\n * The forms plugin's recount route (AGL-3330), by address: this plugin\n * shows the submissions a form counts and may not import the plugin that\n * keeps the counts.\n */\nconst FORM_STATS_API_PATH = '/api/forms/stats'\n/** Read, Form and Site are picked, so the panel shows selects. */\nconst SUBMISSION_SELECT_FIELDS = ['read', 'formId', 'hostId']\nconst SUBMISSION_HIDDEN_COLUMNS = { read: false, formId: false }\n\n/** Every field of a message, as one line — what the Message column draws. */\n/** The page-sorted headers, for their notice (AGL-3680). */\nconst SUBMISSION_PAGE_SORT_HEADERS = { from: 'From', hostId: 'Site', message: 'Message' }\n\nconst messageTextOf = (submission: any): string =>\n Object.entries(submission?.fields ?? {})\n .map(([key, value]) => `${key}: ${value}`)\n .join(' · ')\n\n/**\n * The Submissions section of the Inbox (AGL-77/104/109 → AGL-395): the form\n * messages a site collected, newest first, and the reader that opens one.\n *\n * Its own component since AGL-2501, when the Inbox's tabs became routes. The\n * split is what makes \"mount only the section being read\" structural: hooks\n * cannot be conditional, so a page holding every section's reads pays for all\n * of them whichever one the URL names.\n */\nexport interface SubmissionsCardProps {\n /**\n * The site whose submissions are listed, or `null` on the organization's\n * Inbox, where the card lists every site's at once (AGL-3303) and each row\n * is acted on as the site it was sent to.\n */\n hostId: string | null\n /** The organization and its sites — present exactly when `hostId` is `null`. */\n orgMount?: ConsolePluginOrgMount\n /**\n * Narrow this card to ONE form, permanently.\n *\n * What the forms plugin's detail surface renders instead of a second\n * submissions table. The reader has already chosen the subject by being on\n * that page, so scoping here does three things a copy would have had to\n * re-derive: the form picker is not rendered (there is nothing to pick),\n * the site's `forms` collection is not read at all (the picker was its only\n * consumer), and the empty state names the form rather than the site.\n *\n * Everything else — the paged walk, the reader dialog, read/unread,\n * delete, reply, list assignment, attribution — is the same code answering\n * a narrower query. That is the reason this is a prop rather than a second\n * component: a per-form table written separately would be a second reader\n * to keep in step, and it would have been the one to reintroduce the\n * unordered `limit()` this card's own comment exists to warn about.\n */\n formId?: string\n}\n\nexport function SubmissionsCard({\n hostId,\n formId,\n orgMount,\n}: SubmissionsCardProps) {\n const firestore = useFirestore()\n const { enqueueSnackbar } = useSnackbar()\n const postPluginApi = usePluginApiPost()\n const { confirm } = useConfirmationContext()\n /** Scoped to one form: the subject is fixed and nothing may widen it. */\n const scoped = Boolean(formId)\n /** Every site of this organization at once, when no site is named. */\n const orgId = hostId == null ? (orgMount?.orgId ?? null) : null\n /*\n * The site a row lives on, which is where every act on it is addressed:\n * this card's own site, or — across every site — the `hostId` the submit\n * route stamps on the row. That stamp is frozen against a client update and\n * written from the row's own path, so it names the document's real parent;\n * the rules check the host role on that site either way.\n */\n const siteOf = useCallback(\n (submission: any): string | null =>\n hostId ??\n (typeof submission?.hostId === 'string' && submission.hostId\n ? submission.hostId\n : null),\n [hostId],\n )\n /*\n * Where the sender's CONTACT is (AGL-2612). A submission that carried an\n * address updated a contact in the CRM at stage Lead; the row links to\n * it by that address, and the Contacts list — which holds the id nothing\n * here does — opens the record. The same hub path the Members & leads\n * rows use to open a lead.\n */\n const routeContext = useRecordRouteContext()\n\n /*\n * The site's forms, for the Submissions filter.\n *\n * `FORMS_MAX_PER_HOST` is a read WINDOW, not a cap on the collection — how\n * many forms a site may hold is `formsPerHost`, enforced at the create in\n * `/api/hosts/resources`, and a staff-set per-org override can raise it\n * past this window. So the window can be smaller than the catalog, and one\n * more document than fits is read on purpose: a filter that quietly listed\n * the first N would report \"this form does not exist\" and \"this form is\n * past the window\" as the same empty answer.\n *\n * Ordered by `__name__`. `displayName` would be the nicer order and is the\n * wrong instrument: `orderBy` on a data field DROPS every document missing\n * it, invisibly, so a form saved without a name would vanish from its own\n * filter. The list is sorted for display below, where a missing name is\n * merely ugly.\n */\n const { data: formDocs } = useFirestoreCollection<any>(\n () =>\n // Forms are one site's catalog. Across every site there is no single\n // catalog to filter by, and picking a site is how a reader gets one.\n scoped || !hostId\n ? null\n : query(\n collection(firestore, 'hosts', hostId, 'forms'),\n orderBy('__name__'),\n limit(FORMS_MAX_PER_HOST + 1),\n ),\n [firestore, hostId, scoped],\n { idField: '$id' },\n )\n /** More forms exist than the window shows; the filter has to say so. */\n const formsTruncated = (formDocs?.length ?? 0) > FORMS_MAX_PER_HOST\n const forms = useMemo(\n () =>\n [...(formDocs ?? [])]\n .slice(0, FORMS_MAX_PER_HOST)\n .sort((left: any, right: any) =>\n String(left.displayName ?? left.$id).localeCompare(\n String(right.displayName ?? right.$id),\n ),\n ),\n [formDocs],\n )\n /** Form is offered where the site's catalog is read. */\n const offersForm = !scoped && Boolean(hostId) && forms.length > 0\n /*\n * WHAT THIS CARD'S LIST CAN BE ASKED (AGL-3321) — every clause and the\n * search on the query, see `SUBMISSION_LIST_QUERY`:\n *\n * - a site's Inbox: From, Read and — where the site has forms — Form;\n * - a card scoped to one form: that form is the list's own scope, and\n * Form has nothing left to pick, so it is not offered. The scope wins\n * over any clause: it is the base, and no clause can reach it;\n * - every site's, on the organization's Inbox: From, Read and Site,\n * under the `orgId` clause the rules require of the group read.\n */\n const declaration = useMemo<ListQueryDeclaration>(() => {\n if (scoped) return FORM_SCOPED_SUBMISSION_LIST_QUERY\n if (hostId == null) return ORG_SUBMISSION_LIST_QUERY\n return offersForm\n ? SUBMISSION_LIST_QUERY\n : {\n ...SUBMISSION_LIST_QUERY,\n fields: SUBMISSION_LIST_QUERY.fields.filter((field) => field.column !== 'formId'),\n }\n }, [scoped, hostId, offersForm])\n const base = useMemo(\n () =>\n formId ? formSubmissionBase(formId) : hostId == null && orgId ? orgSubmissionBase(orgId) : [],\n [formId, hostId, orgId],\n )\n const gridFilter = useListGridFilter({ selectFields: SUBMISSION_SELECT_FIELDS })\n /*\n * EVERY HEADER SORTS (AGL-3680). Received and Read order the QUERY (see\n * `SUBMISSION_LIST_QUERY`); From, Site and Message are drawn from the\n * message, so they sort the page on screen and say so. Null is newest\n * first, the inbox's own order.\n */\n const [askedSort, setAskedSort] = useState<ListQuerySort | null>(null)\n\n /*\n * The inbox WALKS its submissions instead of sampling them (AGL-2501,\n * AGL-2292), and every filter and search word is a predicate on the walk\n * (AGL-3321), so a page is a page of the matches.\n *\n * `limit(200)` carried no `orderBy`, so Firestore answered it in\n * DOCUMENT-ID order over ids `add()` generates — an arbitrary two hundred\n * of the site's messages, which the client sort then arranged newest-first\n * so the result looked like a feed. A site past two hundred submissions\n * could not reach the rest, and the messages missing left no gap: the row\n * dates on screen simply skipped, which reads as a quiet week rather than\n * as an unreachable inbox.\n *\n * `createdAt` is safe to order on, checked against the writer rather than\n * assumed: `libs/plugins/forms/src/lib/server/form-submit.ts` is the only path\n * that creates one and stamps `createdAt: serverTimestamp()` on every add,\n * the v1 API only ever reads and deletes, and `formSubmissions` is absent\n * from `IMPORTABLE_FIELDS`, so no restore path can make one without it.\n *\n * EVERY SITE'S SUBMISSIONS IN ONE QUERY on the organization's Inbox\n * (AGL-3303), not a listener per site: the collection group, newest first.\n * The `orgId` clause is not a filter this card could drop. The rules admit\n * a group read only when it is narrowed to an org the reader spans, so an\n * unfiltered group query is refused outright. Every submission carries\n * `orgId`: the submit route stamps it, and the rows written before it did\n * were stamped once (AGL-3303). A row without one would be in no\n * organization's list, though its own site's Inbox lists it either way.\n */\n const {\n rows: submissions,\n hasMore: hasMoreSubmissions,\n page: submissionPage,\n setPage: setSubmissionPage,\n pageSize: submissionPageSize,\n setPageSize: setSubmissionPageSize,\n plan,\n } = useListQuery<any>({\n collection: pluginRecordListWalk(FORM_SUBMISSION_KIND, firestore, { hostId, orgId }),\n declaration,\n request: {\n clauses: gridFilter.clauses,\n search: gridFilter.searchWords,\n sort: askedSort,\n base,\n },\n deps: [firestore, hostId, orgId],\n idField: '$id',\n })\n const submissionOptions = useMemo<Readonly<Record<string, readonly ListFilterOption[]>>>(\n () => ({\n read: SUBMISSION_READ_OPTIONS,\n ...(offersForm\n ? {\n formId: forms.map((form: any) => ({\n value: String(form.$id),\n label: String(form.displayName || form.$id),\n })),\n }\n : {}),\n ...(hostId == null\n ? {\n hostId: (orgMount?.hosts ?? []).map((host) => ({\n value: host.id,\n label: host.name || host.id,\n })),\n }\n : {}),\n }),\n [offersForm, forms, hostId, orgMount],\n )\n const refusals = useMemo(\n () =>\n listQueryRefusals(plan.refused, {\n fields: declaration.fields,\n headers: SUBMISSION_FILTER_HEADERS,\n options: submissionOptions,\n }),\n [plan.refused, declaration, submissionOptions],\n )\n const submissionPageSorts = useMemo(\n () => ({\n from: (submission: any) => submissionSender(submission.fields).label,\n hostId: (submission: any) => orgSiteName(orgMount, submission.hostId),\n message: (submission: any) => messageTextOf(submission),\n }),\n [orgMount],\n )\n const columnSort = useListColumnSort<any>({\n sorts: declaration.sorts,\n defaultSort: declaration.sorts[0],\n sort: askedSort,\n onSortChange: setAskedSort,\n orderBy: plan.orderBy,\n rows: submissions,\n pageSorts: submissionPageSorts,\n headers: SUBMISSION_PAGE_SORT_HEADERS,\n })\n const searching = gridFilter.searchWords.some((word) => word.trim())\n const filtering = gridFilter.clauses.length > 0 || searching\n /** Narrowed by nothing but a Form clause. */\n const onlyForm =\n !searching &&\n gridFilter.clauses.length > 0 &&\n gridFilter.clauses.every((clause) => clause.field === 'formId')\n\n // Mail reader (AGL-104): opening a submission shows the full message and\n // marks it read.\n const [reader, setReader] = useState<any | null>(null)\n const handleOpenReader = useCallback(\n (submission: any) => () => {\n setReader(submission)\n const site = siteOf(submission)\n const submissionDoc = site\n ? pluginRecordListDoc(FORM_SUBMISSION_KIND, firestore, { hostId: site, id: submission.$id })\n : null\n if (!submission.read && submissionDoc) {\n void updateDoc(submissionDoc, { read: true })\n }\n },\n [firestore, siteOf],\n )\n\n const handleToggleRead = useCallback(\n (submission: any) => () => {\n const site = siteOf(submission)\n const submissionDoc = site\n ? pluginRecordListDoc(FORM_SUBMISSION_KIND, firestore, { hostId: site, id: submission.$id })\n : null\n if (!submissionDoc) return\n void updateDoc(submissionDoc, { read: !submission.read })\n },\n [firestore, siteOf],\n )\n\n /*\n * A submission named in the URL opens in the reader on arrival (AGL-2622).\n *\n * A contact's timeline names the submission that captured the person, and\n * the address it links to is this tab with `?submission={id}`. The\n * document is read once, by id, rather than looked for in the paged\n * window: the window is the newest page of a walk that may not reach a\n * submission from months back, and one document read is what the URL\n * asked for. Opening it marks it read, as a click on the row would. A\n * submission that is gone says so, because a reader that silently stays\n * shut reads as the link having done nothing.\n *\n * Once per id: the ref keeps a re-render — and the same URL re-settling —\n * from reopening a reader the person has since closed. The landing read\n * is judged against that ref rather than an effect cleanup: a listener\n * settling while the read is in flight re-renders this card, and a\n * cleanup keyed on any dep would cancel the answer to the question the\n * URL just asked.\n */\n const searchParams = useSearchParams()\n const seededSubmissionId = searchParams?.get(INBOX_SUBMISSION_PARAM) ?? null\n const seededOpened = useRef<string | null>(null)\n useEffect(() => {\n // A submission link names one site's Inbox; the org's has no site to read\n // the id under.\n if (!hostId) return\n if (!seededSubmissionId || seededOpened.current === seededSubmissionId) return\n seededOpened.current = seededSubmissionId\n const seededDoc = pluginRecordListDoc(FORM_SUBMISSION_KIND, firestore, {\n hostId,\n id: seededSubmissionId,\n })\n if (!seededDoc) return\n void getDoc(seededDoc)\n .then((snapshot) => {\n if (seededOpened.current !== snapshot.id) return\n if (!snapshot.exists()) {\n enqueueSnackbar('That submission is no longer in the Inbox.', {\n variant: 'warning',\n persist: false,\n })\n return\n }\n handleOpenReader({ ...snapshot.data(), $id: snapshot.id })()\n })\n .catch(() => undefined)\n }, [seededSubmissionId, firestore, hostId, handleOpenReader, enqueueSnackbar])\n\n const handleDelete = useCallback(\n (submission: any) => async () => {\n const site = siteOf(submission)\n const submissionDoc = site\n ? pluginRecordListDoc(FORM_SUBMISSION_KIND, firestore, { hostId: site, id: submission.$id })\n : null\n if (!site || !submissionDoc) return\n const confirmed = await confirm({\n title: 'Delete this submission?',\n description: 'The submission is removed permanently.',\n confirmationText: 'Delete',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n await deleteDoc(submissionDoc)\n enqueueSnackbar('Submission deleted', {\n variant: 'success',\n persist: false,\n })\n /*\n * The form counted this submission when it arrived (AGL-3330), and an\n * increment cannot see a delete: the forms plugin recounts the form\n * from the rows that are left. Best effort — the delete has happened\n * either way, and the recount script catches a follow-up that failed.\n */\n if (typeof submission.formId === 'string' && submission.formId) {\n void postPluginApi(FORM_STATS_API_PATH, { hostId: site, formIds: [submission.formId] })\n }\n },\n [confirm, firestore, siteOf, enqueueSnackbar, postPluginApi],\n )\n\n /*\n * One row per submission, newest first: who sent it, what it said and how\n * long ago. The row opens the reader, which also marks it read.\n */\n const submissionActions = (submission: any): RowActionsMenuItem[] => {\n const senderEmail = submissionSender(submission.fields).email\n // Where the sender's contact is read, asked of whichever plugin keeps\n // people; with none loaded there is no such page, and no menu item.\n const contactsHref = routeContext\n ? pluginRecordListHref('contact', routeContext)\n : null\n return [\n ...(routeContext && contactsHref\n ? [\n {\n key: 'crm',\n label: 'Open contact in CRM',\n icon: <MdiIcon path={mdiAccountArrowRight.path} size={0.8} />,\n ...(senderEmail\n ? {\n href:\n pluginRecordByEmailHref(\n 'contact',\n routeContext,\n senderEmail,\n ) ?? contactsHref,\n }\n : {\n disabled: true,\n disabledReason:\n 'This submission carried no email address, so no contact was updated.',\n }),\n },\n ]\n : []),\n {\n key: 'read',\n label: submission.read ? 'Mark unread' : 'Mark read',\n icon: (\n <MdiIcon\n path={submission.read ? mdiEmailOutline.path : mdiEmailOpenOutline.path}\n size={0.8}\n />\n ),\n onClick: handleToggleRead(submission),\n },\n {\n key: 'delete',\n label: 'Delete',\n icon: <MdiIcon path={mdiDeleteOutline.path} size={0.8} />,\n destructive: true,\n onClick: handleDelete(submission),\n },\n ]\n }\n const submissionColumns: GridColDef[] = [\n {\n /*\n The mockup's list is people, not forms (AGL-2168): an initials avatar,\n the sender, and the form name beneath it. The unread DOT replaces the\n `New` chip — the row is already bold, and a chip that says \"New\" beside\n bold text is the same fact twice.\n */\n field: 'from',\n headerName: 'From',\n flex: 1,\n minWidth: 220,\n valueGetter: (_value, submission) => submissionSender(submission.fields).label,\n renderCell: ({ row: submission }) => {\n const sender = submissionSender(submission.fields)\n const hue = senderHue(sender.label)\n return (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', minWidth: 0 }}>\n {!submission.read ? (\n <Box\n aria-label=\"Unread\"\n sx={{\n width: 8,\n height: 8,\n borderRadius: '50%',\n bgcolor: 'primary.main',\n flexShrink: 0,\n }}\n />\n ) : (\n <Box sx={{ width: 8, flexShrink: 0 }} />\n )}\n <Avatar\n sx={{\n width: 28,\n height: 28,\n fontSize: 13,\n bgcolor: `hsl(${hue} 55% 45%)`,\n }}\n >\n {sender.initials}\n </Avatar>\n <Stack sx={{ minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {sender.label}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {submission.formName ?? 'Form'}\n </Typography>\n </Stack>\n </Stack>\n )\n },\n },\n /*\n Which site it was sent to, on the organization's Inbox only — under a\n site every row is that site's, and a column saying so would be noise.\n */\n ...(hostId == null\n ? [\n {\n field: 'hostId',\n headerName: 'Site',\n flex: 1,\n minWidth: 140,\n // Sorted and drawn by name; the filter matches the id.\n valueGetter: (_value: unknown, submission: any) =>\n orgSiteName(orgMount, submission.hostId),\n renderCell: ({ row: submission }: { row: any }) =>\n orgSiteName(orgMount, submission.hostId),\n } satisfies GridColDef,\n ]\n : []),\n {\n field: 'message',\n headerName: 'Message',\n flex: 2,\n minWidth: 260,\n valueGetter: (_value, submission) => messageTextOf(submission),\n renderCell: ({ value }) => (\n <Typography variant=\"body2\" noWrap>\n {value}\n </Typography>\n ),\n },\n {\n /*\n Relative, as the mockup shows it — an inbox is scanned for recency and a\n locale timestamp makes the reader do the subtraction. The absolute time\n stays on the detail dialog, where it is the fact you actually want.\n */\n field: 'createdAt',\n headerName: 'Received',\n width: 130,\n valueGetter: (_value, submission) =>\n submission.createdAt?.toDate?.()?.getTime?.() ?? 0,\n renderCell: ({ row: submission }) => (\n <Tooltip title={submission.createdAt?.toDate?.().toLocaleString() ?? ''}>\n <span>{relativeTime(submission.createdAt?.toDate?.().getTime())}</span>\n </Tooltip>\n ),\n },\n /*\n READ, as the panel picks it — never drawn: the unread dot and the bold\n row already say it. A boolean field has no hidden column of its own (the\n grid's boolean operators are not the select's), so it is declared here,\n kept hidden and out of Manage columns.\n */\n {\n field: 'read',\n headerName: 'Read',\n hideable: false,\n valueGetter: (_value, submission) => String(Boolean(submission.read)),\n },\n /*\n One overflow menu, as the Members & leads rows have: two inline buttons\n had no room for a third, and the contact link is the one a reader\n reaches for after reading. Present but disabled for a submission with no\n address, with the reason — a row that simply lacked the item would read\n as the contact not existing.\n */\n listActionsColumn(\n (submission) => (\n <ListRowActions\n label={String(submissionSender(submission.fields).email ?? submission.$id)}\n items={submissionActions(submission)}\n />\n ),\n { width: 72 },\n ),\n ]\n\n /** The site the open submission was sent to, which its reader acts as. */\n const readerSite = reader ? siteOf(reader) : null\n\n return (\n <>\n <CardDisplay\n header={scoped ? 'Submissions to this form' : 'Form Submissions'}\n help={pluginDocsHelp(\n 'forms',\n hostId == null\n ? {\n anchor: '#every-sites-inbox-at-once',\n excerpt:\n 'Every site’s form messages in one list, newest first, ' +\n 'each under the site it was sent to.',\n }\n : {\n anchor: '#the-inbox',\n excerpt:\n 'Messages your forms collected, newest first, showing who ' +\n 'sent each one and where it was routed.',\n },\n )}\n contentGutterX\n contentGutterY\n contentBordered=\"all\"\n >\n {/*\n * The Inbox stays the site-wide answer to \"who is waiting for a\n * reply\" — that question does not decompose by form. The panel's\n * Form filter narrows it on request; it does not turn the page into\n * a per-form view. It is offered only when the site HAS forms, and\n * never on a card already scoped to one.\n */}\n {offersForm && formsTruncated ? (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\" sx={{ mb: 1 }}>\n {`The Form filter offers the first ${FORMS_MAX_PER_HOST.toLocaleString()} ` +\n 'forms. Narrow by form is incomplete; with no Form filter the ' +\n 'list still covers every submission.'}\n </Typography>\n ) : null}\n {hostId == null ? (\n <Typography\n variant=\"body2\"\n color=\"text.secondary\"\n sx={{ mb: submissions.length ? 2 : 1 }}\n >\n {'Every site’s submissions, newest first. Choose a site to ' +\n 'narrow them by form.'}\n </Typography>\n ) : null}\n {submissions.length === 0 && !hasMoreSubmissions && !filtering ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {scoped\n ? 'No submissions carry this form’s id yet. Messages this ' +\n 'form’s design collected before it became a form entity are ' +\n 'in the Inbox, filed under the name they were sent with.'\n : hostId == null\n ? 'No form submissions on any site yet.'\n : 'No form submissions yet. Add a Contact Form element to a ' +\n 'page — visitor messages arrive here.'}\n </Typography>\n ) : (\n <>\n <ListFilterChips\n fields={declaration.fields}\n headers={SUBMISSION_FILTER_HEADERS}\n clauses={gridFilter.clauses}\n onChange={gridFilter.setClauses}\n options={submissionOptions}\n />\n <ListQueryNotices\n refused={refusals}\n notices={[...plan.notices, ...columnSort.notices]}\n />\n <ListTable\n aria-label={scoped ? 'Submissions to this form' : 'Form submissions'}\n rows={columnSort.rows}\n columnSort={columnSort}\n columns={listFilterGridColumns(\n submissionColumns,\n declaration.fields,\n submissionOptions,\n SUBMISSION_FILTER_HEADERS,\n )}\n initialState={{ columns: { columnVisibilityModel: SUBMISSION_HIDDEN_COLUMNS } }}\n noRowsLabel={\n onlyForm\n ? 'No submissions for this form yet. Submissions sent before ' +\n 'the form was created are listed with no Form filter.'\n : 'No submissions match these filters'\n }\n rowHeight={TABLE_ROW_HEIGHT}\n onOpen={(_id, submission) => handleOpenReader(submission)()}\n // An unread submission reads bold across its row, which is why\n // the list needs no `New` chip.\n getRowClassName={({ row }) => (row.read ? '' : 'submission-unread')}\n sx={{\n '& .submission-unread .MuiDataGrid-cell, & .submission-unread .MuiTypography-root':\n { fontWeight: 'fontWeightBold' },\n }}\n // Paged by the footer below, so the grid must not also slice.\n hideFooter\n // The panel, the search and the headers go to the query (From,\n // Site and Message sort the page, and say so).\n filterMode=\"server\"\n filterModel={gridFilter.filterModel}\n onFilterModelChange={gridFilter.onFilterModelChange}\n quickFilter\n />\n <ListPagination\n page={submissionPage}\n pageSize={submissionPageSize}\n rowCount={submissions.length}\n hasMore={hasMoreSubmissions}\n onPageChange={setSubmissionPage}\n onPageSizeChange={setSubmissionPageSize}\n />\n </>\n )}\n </CardDisplay>\n <Dialog\n open={Boolean(reader)}\n onClose={() => setReader(null)}\n maxWidth=\"sm\"\n fullWidth\n >\n <DialogTitle>{reader?.formName ?? 'Form submission'}</DialogTitle>\n <DialogContent>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Received ${reader?.createdAt?.toDate?.().toLocaleString() ?? ''}` +\n // The site it was sent to, where the list spans every site.\n (hostId == null && readerSite\n ? ` · ${orgSiteName(orgMount, readerSite)}`\n : '')}\n </Typography>\n {/*\n WHERE IT CAME IN, AND WHAT IT MADE (AGL-3461) — the form, the page\n it was on, and the lead or contact it filed, each a link to its\n own page. The page is also the field the marketing console's\n landing-page grouping joins on, so a reader can check one row\n against that grouping. Each link is asked of the plugin that owns\n the record, and is text where no plugin answers.\n */}\n {reader ? (\n <Stack spacing={0.5} sx={{ mt: 1 }}>\n {submissionLinks({\n submission: reader,\n hrefOf: (kind, id) =>\n routeContext ? pluginRecordHref(kind, routeContext, id) : null,\n siteOrigin:\n hostPublicOrigin({\n subdomain:\n (hostId != null ? routeContext?.host : null) ??\n orgMount?.hosts.find((site) => site.id === readerSite)?.subdomain ??\n null,\n }) ?? null,\n }).map((link) => (\n <Stack key={link.key} direction=\"row\" spacing={1} sx={{ alignItems: 'baseline' }}>\n <Typography variant=\"caption\" color=\"text.secondary\" sx={{ minWidth: 72 }}>\n {link.label}\n </Typography>\n {link.href ? (\n <AppLink\n href={link.href}\n {...(link.external ? { target: '_blank', rel: 'noopener' } : {})}\n >\n {link.text}\n </AppLink>\n ) : (\n <Typography variant=\"body2\">{link.text}</Typography>\n )}\n </Stack>\n ))}\n </Stack>\n ) : null}\n <Divider sx={{ my: 1.5 }} />\n <Stack spacing={1.5}>\n {Object.entries(reader?.fields ?? {}).map(([key, value]) => (\n <Stack key={key} spacing={0.25}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {key}\n </Typography>\n <Typography\n variant=\"body2\"\n sx={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}\n >\n {String(value)}\n </Typography>\n </Stack>\n ))}\n </Stack>\n {/*\n What happened to this submission (AGL-2168). The mockup puts\n these under the fields: `Saved to Inbox` and `Added to \"Leads\"\n dataset`. The second is stamped by the submit route only when a\n record was really appended — a form bound to a deleted dataset,\n or one whose record quota is full, shows no chip rather than a\n chip for a row that does not exist. Both are failures the route\n already swallows silently, and a chip that lied about them\n would be worse than the silence.\n */}\n <Stack\n useFlexGap\n direction=\"row\"\n spacing={1}\n sx={{ mt: 2, flexWrap: 'wrap', rowGap: 1 }}\n >\n {routingChips(reader?.routing).map((chip) => (\n <Chip\n key={chip.label}\n size=\"small\"\n label={chip.label}\n color={chip.color}\n variant=\"outlined\"\n />\n ))}\n </Stack>\n {/*\n WHERE THIS SUBMISSION CAME FROM.\n\n One keyed document read — the attribution's id is `form:{id}` and\n the submission's id is that `{id}` — paid when a merchant opens a\n submission rather than once per row of the list. A submission that\n was credited to nobody renders the sentence saying so; it never\n renders a campaign with a zero beside it.\n */}\n {reader?.$id && readerSite ? (\n <Box sx={{ mt: 2 }}>\n <InboxRecordAttributionZone\n hostId={readerSite}\n recordKind=\"form\"\n recordId={String(reader.$id)}\n filedUnder={submissionFiledUnder(reader)}\n />\n </Box>\n ) : null}\n {/*\n Answering the person is the act the Inbox exists for, and it is\n inside the reader rather than on the row because a reply written\n without the message in front of you is the reply that answers the\n wrong question. Mounted with the dialog, so its reads — the site\n name and the replies already sent — are paid when a merchant opens\n a submission and not once per visit to this page.\n */}\n {reader && readerSite ? (\n <SubmissionReply hostId={readerSite} submission={reader} />\n ) : null}\n {/*\n Enrolling the sender in a marketing list — a SEPARATE act from\n answering them, and a separate card, because the person asked to\n be answered and did not ask to be marketed to. Its reads are paid\n only when a merchant presses its own button, so opening a\n submission to read it costs nothing extra.\n */}\n {reader && readerSite ? (\n <SubmissionListAssignment hostId={readerSite} submission={reader} />\n ) : null}\n </DialogContent>\n <DialogActions>\n <Button\n color=\"error\"\n onClick={async () => {\n const target = reader\n setReader(null)\n if (target) await handleDelete(target)()\n }}\n >\n {'Delete'}\n </Button>\n <Button\n onClick={() => {\n if (reader) void handleToggleRead({ ...reader, read: true })()\n setReader(null)\n }}\n >\n {'Mark unread'}\n </Button>\n <Button variant=\"contained\" onClick={() => setReader(null)}>\n {'Close'}\n </Button>\n </DialogActions>\n </Dialog>\n </>\n )\n}\nSubmissionsCard.displayName = 'SubmissionsCard'\n\nexport default SubmissionsCard\n"],"names":["FORMS_MAX_PER_HOST","pluginDocsHelp","INBOX_SUBMISSION_PARAM","hostPublicOrigin","submissionFiledUnder","submissionLinks","FORM_SUBMISSION_KIND","InboxRecordAttributionZone","pluginRecordByEmailHref","pluginRecordHref","pluginRecordListHref","mdiAccountArrowRight","mdiDeleteOutline","mdiEmailOpenOutline","mdiEmailOutline","AppLink","CardDisplay","MdiIcon","useConfirmationContext","ListFilterChips","ListPagination","ListQueryNotices","listQueryRefusals","ListRowActions","ListTable","listActionsColumn","listFilterGridColumns","TABLE_ROW_HEIGHT","useListGridFilter","useSnackbar","useFirestore","useFirestoreCollection","usePluginApiPost","useListQuery","useListColumnSort","Avatar","Box","Button","Chip","Dialog","DialogActions","DialogContent","DialogTitle","Divider","Stack","Tooltip","Typography","collection","deleteDoc","getDoc","limit","orderBy","query","updateDoc","pluginRecordListDoc","pluginRecordListWalk","useSearchParams","useCallback","useEffect","useMemo","useRef","useState","relativeTime","routingChips","senderHue","submissionSender","FORM_SCOPED_SUBMISSION_LIST_QUERY","ORG_SUBMISSION_LIST_QUERY","SUBMISSION_FILTER_HEADERS","SUBMISSION_LIST_QUERY","SUBMISSION_READ_OPTIONS","formSubmissionBase","orgSubmissionBase","orgSiteName","SubmissionListAssignment","SubmissionReply","useRecordRouteContext","FORM_STATS_API_PATH","SUBMISSION_SELECT_FIELDS","SUBMISSION_HIDDEN_COLUMNS","read","formId","SUBMISSION_PAGE_SORT_HEADERS","from","hostId","message","messageTextOf","submission","Object","entries","fields","map","key","value","join","SubmissionsCard","orgMount","reader","firestore","enqueueSnackbar","postPluginApi","confirm","scoped","Boolean","orgId","siteOf","routeContext","data","formDocs","idField","formsTruncated","length","forms","slice","sort","left","right","String","displayName","$id","localeCompare","offersForm","declaration","filter","field","column","base","gridFilter","selectFields","askedSort","setAskedSort","rows","submissions","hasMore","hasMoreSubmissions","page","submissionPage","setPage","setSubmissionPage","pageSize","submissionPageSize","setPageSize","setSubmissionPageSize","plan","request","clauses","search","searchWords","deps","submissionOptions","form","label","hosts","host","id","name","refusals","refused","headers","options","submissionPageSorts","columnSort","sorts","defaultSort","onSortChange","pageSorts","searching","some","word","trim","filtering","onlyForm","every","clause","setReader","handleOpenReader","site","submissionDoc","handleToggleRead","searchParams","seededSubmissionId","get","seededOpened","current","seededDoc","then","snapshot","exists","variant","persist","catch","undefined","handleDelete","confirmed","title","description","confirmationText","confirmationButtonProps","color","formIds","submissionActions","senderEmail","email","contactsHref","icon","path","size","href","disabled","disabledReason","onClick","destructive","submissionColumns","headerName","flex","minWidth","valueGetter","_value","renderCell","row","sender","hue","direction","spacing","sx","alignItems","aria-label","width","height","borderRadius","bgcolor","flexShrink","fontSize","initials","noWrap","formName","createdAt","toDate","getTime","toLocaleString","span","hideable","items","readerSite","header","help","anchor","excerpt","contentGutterX","contentGutterY","contentBordered","component","mb","onChange","setClauses","notices","columns","initialState","columnVisibilityModel","noRowsLabel","rowHeight","onOpen","_id","getRowClassName","fontWeight","hideFooter","filterMode","filterModel","onFilterModelChange","quickFilter","rowCount","onPageChange","onPageSizeChange","open","onClose","maxWidth","fullWidth","mt","hrefOf","kind","siteOrigin","subdomain","find","link","external","target","rel","text","my","whiteSpace","wordBreak","useFlexGap","flexWrap","rowGap","routing","chip","recordKind","recordId","filedUnder"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SACEA,kBAAkB,EAClBC,cAAc,QAET,eAAc;AACrB,SAASC,sBAAsB,QAAQ,kCAA8B;AACrE,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,oBAAoB,EAAEC,eAAe,QAAQ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D;;;kCAEN,MAACzD;;0CACC,KAACH;gCACCiK,OAAM;gCACNY,SAAS;oCACP,MAAM2E,SAAS5L;oCACf6E,UAAU;oCACV,IAAI+G,QAAQ,MAAM7F,aAAa6F;gCACjC;0CAEC;;0CAEH,KAACxP;gCACC6K,SAAS;oCACP,IAAIjH,QAAQ,KAAKiF,iBAAiB,aAAKjF;wCAAQjB,MAAM;;oCACrD8F,UAAU;gCACZ;0CAEC;;0CAEH,KAACzI;gCAAOuJ,SAAQ;gCAAYsB,SAAS,IAAMpC,UAAU;0CAClD;;;;;;;;AAMb;AACA/E,gBAAgBuB,WAAW,GAAG;AAE9B,eAAevB,gBAAe"}
1
+ {"version":3,"sources":["../../../../../../../libs/plugins/inbox/src/lib/components/submissions-card.component.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport {\n FORMS_MAX_PER_HOST,\n pluginDocsHelp,\n type ConsolePluginOrgMount,\n} from '@aglyn/aglyn'\nimport { INBOX_SUBMISSION_PARAM } from '../model/inbox-record-routes'\nimport { hostPublicOrigin } from '@aglyn/aglyn/app-utils/host-naming'\nimport { submissionFiledUnder, submissionLinks } from '../model/submission-links'\n\n/** The forms plugin's record kind this card reads (AGL-3080). */\nconst FORM_SUBMISSION_KIND = 'formSubmission'\n// A deep import, NOT the plugin barrel (AGL-1151): the barrel is the entry\n// point the tenant's loader dynamically imports to activate the marketing\n// plugin's SITE half, so a console card named there ships to every published\n// page. The component path reaches the same module without crossing it.\nimport { InboxRecordAttributionZone } from './inbox-attribution-zone'\n// The CRM's route builder by its leaf path, for the reason above: the barrel\n// is the plugin's site entry point.\nimport {\n pluginRecordByEmailHref,\n pluginRecordHref,\n pluginRecordListHref,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-routes'\nimport {\n mdiAccountArrowRight,\n mdiDeleteOutline,\n mdiEmailOpenOutline,\n mdiEmailOutline,\n} from '@aglyn/shared-data-mdi'\nimport { AppLink, CardDisplay, MdiIcon, useConfirmationContext } from '@aglyn/shared-ui-jsx'\nimport ListFilterChips from '@aglyn/shared-ui-jsx/components/list-filter-chips.component'\nimport { ListPagination } from '@aglyn/shared-ui-jsx/components/list-pagination.component'\nimport ListQueryNotices, {\n listQueryRefusals,\n} from '@aglyn/shared-ui-jsx/components/list-query-notices.component'\nimport {\n ListRowActions,\n ListTable,\n listActionsColumn,\n} from '@aglyn/shared-ui-jsx/components/list-table.component'\nimport type { RowActionsMenuItem } from '@aglyn/shared-ui-jsx/components/row-actions-menu.component'\nimport {\n type ListFilterOption,\n listFilterGridColumns,\n} from '@aglyn/shared-ui-jsx/const/list-grid-filter'\nimport type { ListQueryDeclaration } from '@aglyn/shared-ui-jsx/const/list-query-plan'\nimport { TABLE_ROW_HEIGHT } from '@aglyn/shared-ui-jsx/const/table-pagination'\nimport { useListGridFilter } from '@aglyn/shared-ui-jsx/hooks/use-list-grid-filter'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n useFirestore,\n useFirestoreCollection,\n usePluginApiPost,\n} from '@aglyn/tenant-feature-instance'\nimport { useListQuery } from '@aglyn/tenant-feature-instance/hooks/use-list-query'\nimport { useListColumnSort } from '@aglyn/shared-ui-jsx/hooks/use-list-column-sort'\nimport type { ListQuerySort } from '@aglyn/shared-ui-jsx/const/list-query-plan'\nimport {\n Avatar,\n Box,\n Button,\n Chip,\n Dialog,\n DialogActions,\n DialogContent,\n DialogTitle,\n Divider,\n Stack,\n Tooltip,\n Typography,\n} from '@mui/material'\nimport type { GridColDef } from '@mui/x-data-grid'\nimport {\n collection,\n deleteDoc,\n getDoc,\n limit,\n orderBy,\n query,\n updateDoc,\n} from 'firebase/firestore'\n// The submissions are the forms plugin's records, walked and opened through\n// the list source it publishes (AGL-3080).\nimport {\n pluginRecordListDoc,\n pluginRecordListWalk,\n} from '@aglyn/aglyn/plugin-manager/plugin-record-lists'\nimport { useSearchParams } from 'next/navigation'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport {\n relativeTime,\n routingChips,\n senderHue,\n submissionSender,\n} from '../model/submission-presenter'\nimport {\n FORM_SCOPED_SUBMISSION_LIST_QUERY,\n ORG_SUBMISSION_LIST_QUERY,\n SUBMISSION_FILTER_HEADERS,\n SUBMISSION_LIST_QUERY,\n SUBMISSION_READ_OPTIONS,\n formSubmissionBase,\n orgSubmissionBase,\n} from '../constants/list-queries'\nimport { orgSiteName } from './inbox-org-sites'\nimport SubmissionListAssignment from './submission-list-assignment.component'\nimport SubmissionReply from './submission-reply.component'\nimport { useRecordRouteContext } from './use-record-route-context'\n\n\n/**\n * The forms plugin's recount route (AGL-3330), by address: this plugin\n * shows the submissions a form counts and may not import the plugin that\n * keeps the counts.\n */\nconst FORM_STATS_API_PATH = '/api/forms/stats'\n/** Read, Form and Site are picked, so the panel shows selects. */\nconst SUBMISSION_SELECT_FIELDS = ['read', 'formId', 'hostId']\nconst SUBMISSION_HIDDEN_COLUMNS = { read: false, formId: false }\n\n/** Every field of a message, as one line — what the Message column draws. */\n/** The page-sorted headers, for their notice (AGL-3680). */\nconst SUBMISSION_PAGE_SORT_HEADERS = { from: 'From', hostId: 'Site', message: 'Message' }\n\nconst messageTextOf = (submission: any): string =>\n Object.entries(submission?.fields ?? {})\n .map(([key, value]) => `${key}: ${value}`)\n .join(' · ')\n\n/**\n * The Submissions section of the Inbox (AGL-77/104/109 → AGL-395): the form\n * messages a site collected, newest first, and the reader that opens one.\n *\n * Its own component since AGL-2501, when the Inbox's tabs became routes. The\n * split is what makes \"mount only the section being read\" structural: hooks\n * cannot be conditional, so a page holding every section's reads pays for all\n * of them whichever one the URL names.\n */\nexport interface SubmissionsCardProps {\n /**\n * The site whose submissions are listed, or `null` on the organization's\n * Inbox, where the card lists every site's at once (AGL-3303) and each row\n * is acted on as the site it was sent to.\n */\n hostId: string | null\n /** The organization and its sites — present exactly when `hostId` is `null`. */\n orgMount?: ConsolePluginOrgMount\n /**\n * Narrow this card to ONE form, permanently.\n *\n * What the forms plugin's detail surface renders instead of a second\n * submissions table. The reader has already chosen the subject by being on\n * that page, so scoping here does three things a copy would have had to\n * re-derive: the form picker is not rendered (there is nothing to pick),\n * the site's `forms` collection is not read at all (the picker was its only\n * consumer), and the empty state names the form rather than the site.\n *\n * Everything else — the paged walk, the reader dialog, read/unread,\n * delete, reply, list assignment, attribution — is the same code answering\n * a narrower query. That is the reason this is a prop rather than a second\n * component: a per-form table written separately would be a second reader\n * to keep in step, and it would have been the one to reintroduce the\n * unordered `limit()` this card's own comment exists to warn about.\n */\n formId?: string\n}\n\nexport function SubmissionsCard({\n hostId,\n formId,\n orgMount,\n}: SubmissionsCardProps) {\n const firestore = useFirestore()\n const { enqueueSnackbar } = useSnackbar()\n const postPluginApi = usePluginApiPost()\n const { confirm } = useConfirmationContext()\n /** Scoped to one form: the subject is fixed and nothing may widen it. */\n const scoped = Boolean(formId)\n /** Every site of this organization at once, when no site is named. */\n const orgId = hostId == null ? (orgMount?.orgId ?? null) : null\n /*\n * The site a row lives on, which is where every act on it is addressed:\n * this card's own site, or — across every site — the `hostId` the submit\n * route stamps on the row. That stamp is frozen against a client update and\n * written from the row's own path, so it names the document's real parent;\n * the rules check the host role on that site either way.\n */\n const siteOf = useCallback(\n (submission: any): string | null =>\n hostId ??\n (typeof submission?.hostId === 'string' && submission.hostId\n ? submission.hostId\n : null),\n [hostId],\n )\n /*\n * Where the sender's CONTACT is (AGL-2612). A submission that carried an\n * address updated a contact in the CRM at stage Lead; the row links to\n * it by that address, and the Contacts list — which holds the id nothing\n * here does — opens the record. The same hub path the Members & leads\n * rows use to open a lead.\n */\n const routeContext = useRecordRouteContext()\n\n /*\n * The site's forms, for the Submissions filter.\n *\n * `FORMS_MAX_PER_HOST` is a read WINDOW, not a cap on the collection — how\n * many forms a site may hold is `formsPerHost`, enforced at the create in\n * `/api/hosts/resources`, and a staff-set per-org override can raise it\n * past this window. So the window can be smaller than the catalog, and one\n * more document than fits is read on purpose: a filter that quietly listed\n * the first N would report \"this form does not exist\" and \"this form is\n * past the window\" as the same empty answer.\n *\n * Ordered by `__name__`. `displayName` would be the nicer order and is the\n * wrong instrument: `orderBy` on a data field DROPS every document missing\n * it, invisibly, so a form saved without a name would vanish from its own\n * filter. The list is sorted for display below, where a missing name is\n * merely ugly.\n */\n const { data: formDocs } = useFirestoreCollection<any>(\n () =>\n // Forms are one site's catalog. Across every site there is no single\n // catalog to filter by, and picking a site is how a reader gets one.\n scoped || !hostId\n ? null\n : query(\n collection(firestore, 'hosts', hostId, 'forms'),\n orderBy('__name__'),\n limit(FORMS_MAX_PER_HOST + 1),\n ),\n [firestore, hostId, scoped],\n { idField: '$id' },\n )\n /** More forms exist than the window shows; the filter has to say so. */\n const formsTruncated = (formDocs?.length ?? 0) > FORMS_MAX_PER_HOST\n const forms = useMemo(\n () =>\n [...(formDocs ?? [])]\n .slice(0, FORMS_MAX_PER_HOST)\n .sort((left: any, right: any) =>\n String(left.displayName ?? left.$id).localeCompare(\n String(right.displayName ?? right.$id),\n ),\n ),\n [formDocs],\n )\n /** Form is offered where the site's catalog is read. */\n const offersForm = !scoped && Boolean(hostId) && forms.length > 0\n /*\n * WHAT THIS CARD'S LIST CAN BE ASKED (AGL-3321) — every clause and the\n * search on the query, see `SUBMISSION_LIST_QUERY`:\n *\n * - a site's Inbox: From, Read and — where the site has forms — Form;\n * - a card scoped to one form: that form is the list's own scope, and\n * Form has nothing left to pick, so it is not offered. The scope wins\n * over any clause: it is the base, and no clause can reach it;\n * - every site's, on the organization's Inbox: From, Read and Site,\n * under the `orgId` clause the rules require of the group read.\n */\n const declaration = useMemo<ListQueryDeclaration>(() => {\n if (scoped) return FORM_SCOPED_SUBMISSION_LIST_QUERY\n if (hostId == null) return ORG_SUBMISSION_LIST_QUERY\n return offersForm\n ? SUBMISSION_LIST_QUERY\n : {\n ...SUBMISSION_LIST_QUERY,\n fields: SUBMISSION_LIST_QUERY.fields.filter((field) => field.column !== 'formId'),\n }\n }, [scoped, hostId, offersForm])\n const base = useMemo(\n () =>\n formId ? formSubmissionBase(formId) : hostId == null && orgId ? orgSubmissionBase(orgId) : [],\n [formId, hostId, orgId],\n )\n const gridFilter = useListGridFilter({ selectFields: SUBMISSION_SELECT_FIELDS })\n /*\n * EVERY HEADER SORTS (AGL-3680). Received and Read order the QUERY (see\n * `SUBMISSION_LIST_QUERY`); From, Site and Message are drawn from the\n * message, so they sort the page on screen and say so. Null is newest\n * first, the inbox's own order.\n */\n const [askedSort, setAskedSort] = useState<ListQuerySort | null>(null)\n\n /*\n * The inbox WALKS its submissions instead of sampling them (AGL-2501,\n * AGL-2292), and every filter and search word is a predicate on the walk\n * (AGL-3321), so a page is a page of the matches.\n *\n * `limit(200)` carried no `orderBy`, so Firestore answered it in\n * DOCUMENT-ID order over ids `add()` generates — an arbitrary two hundred\n * of the site's messages, which the client sort then arranged newest-first\n * so the result looked like a feed. A site past two hundred submissions\n * could not reach the rest, and the messages missing left no gap: the row\n * dates on screen simply skipped, which reads as a quiet week rather than\n * as an unreachable inbox.\n *\n * `createdAt` is safe to order on, checked against the writer rather than\n * assumed: `libs/plugins/forms/src/lib/server/form-submit.ts` is the only path\n * that creates one and stamps `createdAt: serverTimestamp()` on every add,\n * the v1 API only ever reads and deletes, and `formSubmissions` is absent\n * from `IMPORTABLE_FIELDS`, so no restore path can make one without it.\n *\n * EVERY SITE'S SUBMISSIONS IN ONE QUERY on the organization's Inbox\n * (AGL-3303), not a listener per site: the collection group, newest first.\n * The `orgId` clause is not a filter this card could drop. The rules admit\n * a group read only when it is narrowed to an org the reader spans, so an\n * unfiltered group query is refused outright. Every submission carries\n * `orgId`: the submit route stamps it, and the rows written before it did\n * were stamped once (AGL-3303). A row without one would be in no\n * organization's list, though its own site's Inbox lists it either way.\n */\n const {\n rows: submissions,\n hasMore: hasMoreSubmissions,\n page: submissionPage,\n setPage: setSubmissionPage,\n pageSize: submissionPageSize,\n setPageSize: setSubmissionPageSize,\n plan,\n } = useListQuery<any>({\n collection: pluginRecordListWalk(FORM_SUBMISSION_KIND, firestore, { hostId, orgId }),\n declaration,\n request: {\n clauses: gridFilter.clauses,\n search: gridFilter.searchWords,\n sort: askedSort,\n base,\n },\n deps: [firestore, hostId, orgId],\n idField: '$id',\n })\n const submissionOptions = useMemo<Readonly<Record<string, readonly ListFilterOption[]>>>(\n () => ({\n read: SUBMISSION_READ_OPTIONS,\n ...(offersForm\n ? {\n formId: forms.map((form: any) => ({\n value: String(form.$id),\n label: String(form.displayName || form.$id),\n })),\n }\n : {}),\n ...(hostId == null\n ? {\n hostId: (orgMount?.hosts ?? []).map((host) => ({\n value: host.id,\n label: host.name || host.id,\n })),\n }\n : {}),\n }),\n [offersForm, forms, hostId, orgMount],\n )\n const refusals = useMemo(\n () =>\n listQueryRefusals(plan.refused, {\n fields: declaration.fields,\n headers: SUBMISSION_FILTER_HEADERS,\n options: submissionOptions,\n }),\n [plan.refused, declaration, submissionOptions],\n )\n const submissionPageSorts = useMemo(\n () => ({\n from: (submission: any) => submissionSender(submission.fields).label,\n hostId: (submission: any) => orgSiteName(orgMount, submission.hostId),\n message: (submission: any) => messageTextOf(submission),\n }),\n [orgMount],\n )\n const columnSort = useListColumnSort<any>({\n sorts: declaration.sorts,\n defaultSort: declaration.sorts[0],\n sort: askedSort,\n onSortChange: setAskedSort,\n orderBy: plan.orderBy,\n rows: submissions,\n pageSorts: submissionPageSorts,\n headers: SUBMISSION_PAGE_SORT_HEADERS,\n })\n const searching = gridFilter.searchWords.some((word) => word.trim())\n const filtering = gridFilter.clauses.length > 0 || searching\n /** Narrowed by nothing but a Form clause. */\n const onlyForm =\n !searching &&\n gridFilter.clauses.length > 0 &&\n gridFilter.clauses.every((clause) => clause.field === 'formId')\n\n // Mail reader (AGL-104): opening a submission shows the full message and\n // marks it read.\n const [reader, setReader] = useState<any | null>(null)\n const handleOpenReader = useCallback(\n (submission: any) => () => {\n setReader(submission)\n const site = siteOf(submission)\n const submissionDoc = site\n ? pluginRecordListDoc(FORM_SUBMISSION_KIND, firestore, { hostId: site, id: submission.$id })\n : null\n if (!submission.read && submissionDoc) {\n void updateDoc(submissionDoc, { read: true })\n }\n },\n [firestore, siteOf],\n )\n\n const handleToggleRead = useCallback(\n (submission: any) => () => {\n const site = siteOf(submission)\n const submissionDoc = site\n ? pluginRecordListDoc(FORM_SUBMISSION_KIND, firestore, { hostId: site, id: submission.$id })\n : null\n if (!submissionDoc) return\n void updateDoc(submissionDoc, { read: !submission.read })\n },\n [firestore, siteOf],\n )\n\n /*\n * A submission named in the URL opens in the reader on arrival (AGL-2622).\n *\n * A contact's timeline names the submission that captured the person, and\n * the address it links to is this tab with `?submission={id}`. The\n * document is read once, by id, rather than looked for in the paged\n * window: the window is the newest page of a walk that may not reach a\n * submission from months back, and one document read is what the URL\n * asked for. Opening it marks it read, as a click on the row would. A\n * submission that is gone says so, because a reader that silently stays\n * shut reads as the link having done nothing.\n *\n * Once per id: the ref keeps a re-render — and the same URL re-settling —\n * from reopening a reader the person has since closed. The landing read\n * is judged against that ref rather than an effect cleanup: a listener\n * settling while the read is in flight re-renders this card, and a\n * cleanup keyed on any dep would cancel the answer to the question the\n * URL just asked.\n */\n const searchParams = useSearchParams()\n const seededSubmissionId = searchParams?.get(INBOX_SUBMISSION_PARAM) ?? null\n const seededOpened = useRef<string | null>(null)\n useEffect(() => {\n // A submission link names one site's Inbox; the org's has no site to read\n // the id under.\n if (!hostId) return\n if (!seededSubmissionId || seededOpened.current === seededSubmissionId) return\n seededOpened.current = seededSubmissionId\n const seededDoc = pluginRecordListDoc(FORM_SUBMISSION_KIND, firestore, {\n hostId,\n id: seededSubmissionId,\n })\n if (!seededDoc) return\n void getDoc(seededDoc)\n .then((snapshot) => {\n if (seededOpened.current !== snapshot.id) return\n if (!snapshot.exists()) {\n enqueueSnackbar('That submission is no longer in the Inbox.', {\n variant: 'warning',\n persist: false,\n })\n return\n }\n handleOpenReader({ ...snapshot.data(), $id: snapshot.id })()\n })\n .catch(() => undefined)\n }, [seededSubmissionId, firestore, hostId, handleOpenReader, enqueueSnackbar])\n\n const handleDelete = useCallback(\n (submission: any) => async () => {\n const site = siteOf(submission)\n const submissionDoc = site\n ? pluginRecordListDoc(FORM_SUBMISSION_KIND, firestore, { hostId: site, id: submission.$id })\n : null\n if (!site || !submissionDoc) return\n const confirmed = await confirm({\n title: 'Delete this submission?',\n description: 'The submission is removed permanently.',\n confirmationText: 'Delete',\n confirmationButtonProps: { color: 'error' },\n })\n .then(() => true)\n .catch(() => false)\n if (!confirmed) return\n await deleteDoc(submissionDoc)\n enqueueSnackbar('Submission deleted', {\n variant: 'success',\n persist: false,\n })\n /*\n * The form counted this submission when it arrived (AGL-3330), and an\n * increment cannot see a delete: the forms plugin recounts the form\n * from the rows that are left. Best effort — the delete has happened\n * either way, and the recount script catches a follow-up that failed.\n */\n if (typeof submission.formId === 'string' && submission.formId) {\n void postPluginApi(FORM_STATS_API_PATH, { hostId: site, formIds: [submission.formId] })\n }\n },\n [confirm, firestore, siteOf, enqueueSnackbar, postPluginApi],\n )\n\n /*\n * One row per submission, newest first: who sent it, what it said and how\n * long ago. The row opens the reader, which also marks it read.\n */\n const submissionActions = (submission: any): RowActionsMenuItem[] => {\n const senderEmail = submissionSender(submission.fields).email\n // Where the sender's contact is read, asked of whichever plugin keeps\n // people; with none loaded there is no such page, and no menu item.\n const contactsHref = routeContext\n ? pluginRecordListHref('contact', routeContext)\n : null\n return [\n ...(routeContext && contactsHref\n ? [\n {\n key: 'crm',\n label: 'Open contact in CRM',\n icon: <MdiIcon path={mdiAccountArrowRight.path} size={0.8} />,\n ...(senderEmail\n ? {\n href:\n pluginRecordByEmailHref(\n 'contact',\n routeContext,\n senderEmail,\n ) ?? contactsHref,\n }\n : {\n disabled: true,\n disabledReason:\n 'This submission carried no email address, so no contact was updated.',\n }),\n },\n ]\n : []),\n {\n key: 'read',\n label: submission.read ? 'Mark unread' : 'Mark read',\n icon: (\n <MdiIcon\n path={submission.read ? mdiEmailOutline.path : mdiEmailOpenOutline.path}\n size={0.8}\n />\n ),\n onClick: handleToggleRead(submission),\n },\n {\n key: 'delete',\n label: 'Delete',\n icon: <MdiIcon path={mdiDeleteOutline.path} size={0.8} />,\n destructive: true,\n onClick: handleDelete(submission),\n },\n ]\n }\n const submissionColumns: GridColDef[] = [\n {\n /*\n The mockup's list is people, not forms (AGL-2168): an initials avatar,\n the sender, and the form name beneath it. The unread DOT replaces the\n `New` chip — the row is already bold, and a chip that says \"New\" beside\n bold text is the same fact twice.\n */\n field: 'from',\n headerName: 'From',\n flex: 1,\n minWidth: 220,\n valueGetter: (_value, submission) => submissionSender(submission.fields).label,\n renderCell: ({ row: submission }) => {\n const sender = submissionSender(submission.fields)\n const hue = senderHue(sender.label)\n return (\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center', minWidth: 0 }}>\n {!submission.read ? (\n <Box\n aria-label=\"Unread\"\n sx={{\n width: 8,\n height: 8,\n borderRadius: '50%',\n bgcolor: 'primary.main',\n flexShrink: 0,\n }}\n />\n ) : (\n <Box sx={{ width: 8, flexShrink: 0 }} />\n )}\n <Avatar\n sx={{\n width: 28,\n height: 28,\n fontSize: 13,\n bgcolor: `hsl(${hue} 55% 45%)`,\n }}\n >\n {sender.initials}\n </Avatar>\n <Stack sx={{ minWidth: 0 }}>\n <Typography variant=\"body2\" noWrap>\n {sender.label}\n </Typography>\n <Typography variant=\"caption\" color=\"text.secondary\" noWrap>\n {submission.formName ?? 'Form'}\n </Typography>\n </Stack>\n </Stack>\n )\n },\n },\n /*\n Which site it was sent to, on the organization's Inbox only — under a\n site every row is that site's, and a column saying so would be noise.\n */\n ...(hostId == null\n ? [\n {\n field: 'hostId',\n headerName: 'Site',\n flex: 1,\n minWidth: 140,\n // Sorted and drawn by name; the filter matches the id.\n valueGetter: (_value: unknown, submission: any) =>\n orgSiteName(orgMount, submission.hostId),\n renderCell: ({ row: submission }: { row: any }) =>\n orgSiteName(orgMount, submission.hostId),\n } satisfies GridColDef,\n ]\n : []),\n {\n field: 'message',\n headerName: 'Message',\n flex: 2,\n minWidth: 260,\n valueGetter: (_value, submission) => messageTextOf(submission),\n renderCell: ({ value }) => (\n <Typography variant=\"body2\" noWrap>\n {value}\n </Typography>\n ),\n },\n {\n /*\n Relative, as the mockup shows it — an inbox is scanned for recency and a\n locale timestamp makes the reader do the subtraction. The absolute time\n stays on the detail dialog, where it is the fact you actually want.\n */\n field: 'createdAt',\n headerName: 'Received',\n width: 130,\n valueGetter: (_value, submission) =>\n submission.createdAt?.toDate?.()?.getTime?.() ?? 0,\n renderCell: ({ row: submission }) => (\n <Tooltip title={submission.createdAt?.toDate?.().toLocaleString() ?? ''}>\n <span>{relativeTime(submission.createdAt?.toDate?.().getTime())}</span>\n </Tooltip>\n ),\n },\n /*\n READ, as the panel picks it — never drawn: the unread dot and the bold\n row already say it. A boolean field has no hidden column of its own (the\n grid's boolean operators are not the select's), so it is declared here,\n kept hidden and out of Manage columns.\n */\n {\n field: 'read',\n headerName: 'Read',\n hideable: false,\n valueGetter: (_value, submission) => String(Boolean(submission.read)),\n },\n /*\n One overflow menu, as the Members & leads rows have: two inline buttons\n had no room for a third, and the contact link is the one a reader\n reaches for after reading. Present but disabled for a submission with no\n address, with the reason — a row that simply lacked the item would read\n as the contact not existing.\n */\n listActionsColumn(\n (submission) => (\n <ListRowActions\n label={String(submissionSender(submission.fields).email ?? submission.$id)}\n items={submissionActions(submission)}\n />\n ),\n { width: 72 },\n ),\n ]\n\n /** The site the open submission was sent to, which its reader acts as. */\n const readerSite = reader ? siteOf(reader) : null\n\n return (\n <>\n <CardDisplay\n header={scoped ? 'Submissions to this form' : 'Form Submissions'}\n help={pluginDocsHelp(\n 'forms',\n // Scoped to one form, this is the form page's own \"Submissions to\n // this form\" card, opened in place — the same card, the same link.\n scoped\n ? { anchor: '#form-submissions' }\n : hostId == null\n ? {\n anchor: '#every-sites-inbox-at-once',\n excerpt:\n 'Every site’s form messages in one list, newest first, ' +\n 'each under the site it was sent to.',\n }\n : {\n anchor: '#the-inbox',\n excerpt:\n 'Messages your forms collected, newest first, showing who ' +\n 'sent each one and where it was routed.',\n },\n )}\n contentGutterX\n contentGutterY\n contentBordered=\"all\"\n >\n {/*\n * The Inbox stays the site-wide answer to \"who is waiting for a\n * reply\" — that question does not decompose by form. The panel's\n * Form filter narrows it on request; it does not turn the page into\n * a per-form view. It is offered only when the site HAS forms, and\n * never on a card already scoped to one.\n */}\n {offersForm && formsTruncated ? (\n <Typography variant=\"caption\" color=\"text.secondary\" component=\"p\" sx={{ mb: 1 }}>\n {`The Form filter offers the first ${FORMS_MAX_PER_HOST.toLocaleString()} ` +\n 'forms. Narrow by form is incomplete; with no Form filter the ' +\n 'list still covers every submission.'}\n </Typography>\n ) : null}\n {hostId == null ? (\n <Typography\n variant=\"body2\"\n color=\"text.secondary\"\n sx={{ mb: submissions.length ? 2 : 1 }}\n >\n {'Every site’s submissions, newest first. Choose a site to ' +\n 'narrow them by form.'}\n </Typography>\n ) : null}\n {submissions.length === 0 && !hasMoreSubmissions && !filtering ? (\n <Typography variant=\"body2\" color=\"text.secondary\">\n {scoped\n ? 'No submissions carry this form’s id yet. Messages this ' +\n 'form’s design collected before it became a form entity are ' +\n 'in the Inbox, filed under the name they were sent with.'\n : hostId == null\n ? 'No form submissions on any site yet.'\n : 'No form submissions yet. Add a Contact Form element to a ' +\n 'page — visitor messages arrive here.'}\n </Typography>\n ) : (\n <>\n <ListFilterChips\n fields={declaration.fields}\n headers={SUBMISSION_FILTER_HEADERS}\n clauses={gridFilter.clauses}\n onChange={gridFilter.setClauses}\n options={submissionOptions}\n />\n <ListQueryNotices\n refused={refusals}\n notices={[...plan.notices, ...columnSort.notices]}\n />\n <ListTable\n aria-label={scoped ? 'Submissions to this form' : 'Form submissions'}\n rows={columnSort.rows}\n columnSort={columnSort}\n columns={listFilterGridColumns(\n submissionColumns,\n declaration.fields,\n submissionOptions,\n SUBMISSION_FILTER_HEADERS,\n )}\n initialState={{ columns: { columnVisibilityModel: SUBMISSION_HIDDEN_COLUMNS } }}\n noRowsLabel={\n onlyForm\n ? 'No submissions for this form yet. Submissions sent before ' +\n 'the form was created are listed with no Form filter.'\n : 'No submissions match these filters'\n }\n rowHeight={TABLE_ROW_HEIGHT}\n onOpen={(_id, submission) => handleOpenReader(submission)()}\n // An unread submission reads bold across its row, which is why\n // the list needs no `New` chip.\n getRowClassName={({ row }) => (row.read ? '' : 'submission-unread')}\n sx={{\n '& .submission-unread .MuiDataGrid-cell, & .submission-unread .MuiTypography-root':\n { fontWeight: 'fontWeightBold' },\n }}\n // Paged by the footer below, so the grid must not also slice.\n hideFooter\n // The panel, the search and the headers go to the query (From,\n // Site and Message sort the page, and say so).\n filterMode=\"server\"\n filterModel={gridFilter.filterModel}\n onFilterModelChange={gridFilter.onFilterModelChange}\n quickFilter\n />\n <ListPagination\n page={submissionPage}\n pageSize={submissionPageSize}\n rowCount={submissions.length}\n hasMore={hasMoreSubmissions}\n onPageChange={setSubmissionPage}\n onPageSizeChange={setSubmissionPageSize}\n />\n </>\n )}\n </CardDisplay>\n <Dialog\n open={Boolean(reader)}\n onClose={() => setReader(null)}\n maxWidth=\"sm\"\n fullWidth\n >\n <DialogTitle>{reader?.formName ?? 'Form submission'}</DialogTitle>\n <DialogContent>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {`Received ${reader?.createdAt?.toDate?.().toLocaleString() ?? ''}` +\n // The site it was sent to, where the list spans every site.\n (hostId == null && readerSite\n ? ` · ${orgSiteName(orgMount, readerSite)}`\n : '')}\n </Typography>\n {/*\n WHERE IT CAME IN, AND WHAT IT MADE (AGL-3461) — the form, the page\n it was on, and the lead or contact it filed, each a link to its\n own page. The page is also the field the marketing console's\n landing-page grouping joins on, so a reader can check one row\n against that grouping. Each link is asked of the plugin that owns\n the record, and is text where no plugin answers.\n */}\n {reader ? (\n <Stack spacing={0.5} sx={{ mt: 1 }}>\n {submissionLinks({\n submission: reader,\n hrefOf: (kind, id) =>\n routeContext ? pluginRecordHref(kind, routeContext, id) : null,\n siteOrigin:\n hostPublicOrigin({\n subdomain:\n (hostId != null ? routeContext?.host : null) ??\n orgMount?.hosts.find((site) => site.id === readerSite)?.subdomain ??\n null,\n }) ?? null,\n }).map((link) => (\n <Stack key={link.key} direction=\"row\" spacing={1} sx={{ alignItems: 'baseline' }}>\n <Typography variant=\"caption\" color=\"text.secondary\" sx={{ minWidth: 72 }}>\n {link.label}\n </Typography>\n {link.href ? (\n <AppLink\n href={link.href}\n {...(link.external ? { target: '_blank', rel: 'noopener' } : {})}\n >\n {link.text}\n </AppLink>\n ) : (\n <Typography variant=\"body2\">{link.text}</Typography>\n )}\n </Stack>\n ))}\n </Stack>\n ) : null}\n <Divider sx={{ my: 1.5 }} />\n <Stack spacing={1.5}>\n {Object.entries(reader?.fields ?? {}).map(([key, value]) => (\n <Stack key={key} spacing={0.25}>\n <Typography variant=\"caption\" color=\"text.secondary\">\n {key}\n </Typography>\n <Typography\n variant=\"body2\"\n sx={{ whiteSpace: 'pre-wrap', wordBreak: 'break-word' }}\n >\n {String(value)}\n </Typography>\n </Stack>\n ))}\n </Stack>\n {/*\n What happened to this submission (AGL-2168). The mockup puts\n these under the fields: `Saved to Inbox` and `Added to \"Leads\"\n dataset`. The second is stamped by the submit route only when a\n record was really appended — a form bound to a deleted dataset,\n or one whose record quota is full, shows no chip rather than a\n chip for a row that does not exist. Both are failures the route\n already swallows silently, and a chip that lied about them\n would be worse than the silence.\n */}\n <Stack\n useFlexGap\n direction=\"row\"\n spacing={1}\n sx={{ mt: 2, flexWrap: 'wrap', rowGap: 1 }}\n >\n {routingChips(reader?.routing).map((chip) => (\n <Chip\n key={chip.label}\n size=\"small\"\n label={chip.label}\n color={chip.color}\n variant=\"outlined\"\n />\n ))}\n </Stack>\n {/*\n WHERE THIS SUBMISSION CAME FROM.\n\n One keyed document read — the attribution's id is `form:{id}` and\n the submission's id is that `{id}` — paid when a merchant opens a\n submission rather than once per row of the list. A submission that\n was credited to nobody renders the sentence saying so; it never\n renders a campaign with a zero beside it.\n */}\n {reader?.$id && readerSite ? (\n <Box sx={{ mt: 2 }}>\n <InboxRecordAttributionZone\n hostId={readerSite}\n recordKind=\"form\"\n recordId={String(reader.$id)}\n filedUnder={submissionFiledUnder(reader)}\n />\n </Box>\n ) : null}\n {/*\n Answering the person is the act the Inbox exists for, and it is\n inside the reader rather than on the row because a reply written\n without the message in front of you is the reply that answers the\n wrong question. Mounted with the dialog, so its reads — the site\n name and the replies already sent — are paid when a merchant opens\n a submission and not once per visit to this page.\n */}\n {reader && readerSite ? (\n <SubmissionReply hostId={readerSite} submission={reader} />\n ) : null}\n {/*\n Enrolling the sender in a marketing list — a SEPARATE act from\n answering them, and a separate card, because the person asked to\n be answered and did not ask to be marketed to. Its reads are paid\n only when a merchant presses its own button, so opening a\n submission to read it costs nothing extra.\n */}\n {reader && readerSite ? (\n <SubmissionListAssignment hostId={readerSite} submission={reader} />\n ) : null}\n </DialogContent>\n <DialogActions>\n <Button\n color=\"error\"\n onClick={async () => {\n const target = reader\n setReader(null)\n if (target) await handleDelete(target)()\n }}\n >\n {'Delete'}\n </Button>\n <Button\n onClick={() => {\n if (reader) void handleToggleRead({ ...reader, read: true })()\n setReader(null)\n }}\n >\n {'Mark unread'}\n </Button>\n <Button variant=\"contained\" onClick={() => setReader(null)}>\n {'Close'}\n </Button>\n </DialogActions>\n </Dialog>\n </>\n )\n}\nSubmissionsCard.displayName = 'SubmissionsCard'\n\nexport default SubmissionsCard\n"],"names":["FORMS_MAX_PER_HOST","pluginDocsHelp","INBOX_SUBMISSION_PARAM","hostPublicOrigin","submissionFiledUnder","submissionLinks","FORM_SUBMISSION_KIND","InboxRecordAttributionZone","pluginRecordByEmailHref","pluginRecordHref","pluginRecordListHref","mdiAccountArrowRight","mdiDeleteOutline","mdiEmailOpenOutline","mdiEmailOutline","AppLink","CardDisplay","MdiIcon","useConfirmationContext","ListFilterChips","ListPagination","ListQueryNotices","listQueryRefusals","ListRowActions","ListTable","listActionsColumn","listFilterGridColumns","TABLE_ROW_HEIGHT","useListGridFilter","useSnackbar","useFirestore","useFirestoreCollection","usePluginApiPost","useListQuery","useListColumnSort","Avatar","Box","Button","Chip","Dialog","DialogActions","DialogContent","DialogTitle","Divider","Stack","Tooltip","Typography","collection","deleteDoc","getDoc","limit","orderBy","query","updateDoc","pluginRecordListDoc","pluginRecordListWalk","useSearchParams","useCallback","useEffect","useMemo","useRef","useState","relativeTime","routingChips","senderHue","submissionSender","FORM_SCOPED_SUBMISSION_LIST_QUERY","ORG_SUBMISSION_LIST_QUERY","SUBMISSION_FILTER_HEADERS","SUBMISSION_LIST_QUERY","SUBMISSION_READ_OPTIONS","formSubmissionBase","orgSubmissionBase","orgSiteName","SubmissionListAssignment","SubmissionReply","useRecordRouteContext","FORM_STATS_API_PATH","SUBMISSION_SELECT_FIELDS","SUBMISSION_HIDDEN_COLUMNS","read","formId","SUBMISSION_PAGE_SORT_HEADERS","from","hostId","message","messageTextOf","submission","Object","entries","fields","map","key","value","join","SubmissionsCard","orgMount","reader","firestore","enqueueSnackbar","postPluginApi","confirm","scoped","Boolean","orgId","siteOf","routeContext","data","formDocs","idField","formsTruncated","length","forms","slice","sort","left","right","String","displayName","$id","localeCompare","offersForm","declaration","filter","field","column","base","gridFilter","selectFields","askedSort","setAskedSort","rows","submissions","hasMore","hasMoreSubmissions","page","submissionPage","setPage","setSubmissionPage","pageSize","submissionPageSize","setPageSize","setSubmissionPageSize","plan","request","clauses","search","searchWords","deps","submissionOptions","form","label","hosts","host","id","name","refusals","refused","headers","options","submissionPageSorts","columnSort","sorts","defaultSort","onSortChange","pageSorts","searching","some","word","trim","filtering","onlyForm","every","clause","setReader","handleOpenReader","site","submissionDoc","handleToggleRead","searchParams","seededSubmissionId","get","seededOpened","current","seededDoc","then","snapshot","exists","variant","persist","catch","undefined","handleDelete","confirmed","title","description","confirmationText","confirmationButtonProps","color","formIds","submissionActions","senderEmail","email","contactsHref","icon","path","size","href","disabled","disabledReason","onClick","destructive","submissionColumns","headerName","flex","minWidth","valueGetter","_value","renderCell","row","sender","hue","direction","spacing","sx","alignItems","aria-label","width","height","borderRadius","bgcolor","flexShrink","fontSize","initials","noWrap","formName","createdAt","toDate","getTime","toLocaleString","span","hideable","items","readerSite","header","help","anchor","excerpt","contentGutterX","contentGutterY","contentBordered","component","mb","onChange","setClauses","notices","columns","initialState","columnVisibilityModel","noRowsLabel","rowHeight","onOpen","_id","getRowClassName","fontWeight","hideFooter","filterMode","filterModel","onFilterModelChange","quickFilter","rowCount","onPageChange","onPageSizeChange","open","onClose","maxWidth","fullWidth","mt","hrefOf","kind","siteOrigin","subdomain","find","link","external","target","rel","text","my","whiteSpace","wordBreak","useFlexGap","flexWrap","rowGap","routing","chip","recordKind","recordId","filedUnder"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SACEA,kBAAkB,EAClBC,cAAc,QAET,eAAc;AACrB,SAASC,sBAAsB,QAAQ,kCAA8B;AACrE,SAASC,gBAAgB,QAAQ,qCAAoC;AACrE,SAASC,oBAAoB,EAAEC,eAAe,QAAQ,+BAA2B;AAEjF,+DAA+D,GAC/D,MAAMC,uBAAuB;AAC7B,2EAA2E;AAC3E,0EAA0E;AAC1E,6EAA6E;AAC7E,wEAAwE;AACxE,SAASC,0BAA0B,QAAQ,8BAA0B;AACrE,6EAA6E;AAC7E,oCAAoC;AACpC,SACEC,uBAAuB,EACvBC,gBAAgB,EAChBC,oBAAoB,QACf,mDAAkD;AACzD,SACEC,oBAAoB,EACpBC,gBAAgB,EAChBC,mBAAmB,EACnBC,eAAe,QACV,yBAAwB;AAC/B,SAASC,OAAO,EAAEC,WAAW,EA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