@aglyn/plugins-marketing 1.20.3 → 1.22.0
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 +17 -17
- package/src/lib/components/announcement-bar-card.component.js +35 -14
- package/src/lib/components/announcement-bar-card.component.js.map +1 -1
- package/src/lib/components/host-experiments-card.component.js +33 -3
- package/src/lib/components/host-experiments-card.component.js.map +1 -1
- package/src/lib/components/host-overlays-card.component.js +35 -5
- package/src/lib/components/host-overlays-card.component.js.map +1 -1
- package/src/lib/components/popup-card.component.js +35 -13
- package/src/lib/components/popup-card.component.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-marketing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,22 +25,22 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.
|
|
29
|
-
"@aglyn/shared-data-enums": "1.
|
|
30
|
-
"@aglyn/shared-data-mdi": "1.
|
|
31
|
-
"@aglyn/shared-ui-email-campaigns": "1.
|
|
32
|
-
"@aglyn/shared-ui-jsx": "1.
|
|
33
|
-
"@aglyn/shared-ui-jsx-forms": "1.
|
|
34
|
-
"@aglyn/shared-ui-next": "1.
|
|
35
|
-
"@aglyn/shared-ui-snackstack": "1.
|
|
36
|
-
"@aglyn/shared-util-email": "1.
|
|
37
|
-
"@aglyn/shared-util-http": "1.
|
|
38
|
-
"@aglyn/shared-util-timestamp": "1.
|
|
39
|
-
"@aglyn/shared-util-tools": "1.
|
|
40
|
-
"@aglyn/tenant-data-admin": "1.
|
|
41
|
-
"@aglyn/tenant-feature-instance": "1.
|
|
42
|
-
"@aglyn/tenant-runtime": "1.
|
|
43
|
-
"@swc/helpers": "0.5.
|
|
28
|
+
"@aglyn/aglyn": "1.22.0",
|
|
29
|
+
"@aglyn/shared-data-enums": "1.22.0",
|
|
30
|
+
"@aglyn/shared-data-mdi": "1.22.0",
|
|
31
|
+
"@aglyn/shared-ui-email-campaigns": "1.22.0",
|
|
32
|
+
"@aglyn/shared-ui-jsx": "1.22.0",
|
|
33
|
+
"@aglyn/shared-ui-jsx-forms": "1.22.0",
|
|
34
|
+
"@aglyn/shared-ui-next": "1.22.0",
|
|
35
|
+
"@aglyn/shared-ui-snackstack": "1.22.0",
|
|
36
|
+
"@aglyn/shared-util-email": "1.22.0",
|
|
37
|
+
"@aglyn/shared-util-http": "1.22.0",
|
|
38
|
+
"@aglyn/shared-util-timestamp": "1.22.0",
|
|
39
|
+
"@aglyn/shared-util-tools": "1.22.0",
|
|
40
|
+
"@aglyn/tenant-data-admin": "1.22.0",
|
|
41
|
+
"@aglyn/tenant-feature-instance": "1.22.0",
|
|
42
|
+
"@aglyn/tenant-runtime": "1.22.0",
|
|
43
|
+
"@swc/helpers": "0.5.24"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@mui/material": "^9.3.1",
|
|
@@ -21,9 +21,9 @@ import { CardDisplay, useLoading } from "@aglyn/shared-ui-jsx";
|
|
|
21
21
|
import { useSnackbar } from "@aglyn/shared-ui-snackstack";
|
|
22
22
|
import { Alert, Box, Button, Stack, Switch, TextField, Typography } from "@mui/material";
|
|
23
23
|
import { doc } from "firebase/firestore";
|
|
24
|
-
import { useEffect, useState } from "react";
|
|
25
24
|
import { useFirestore, useFirestoreDoc, useHostActivityLogger, useUser, writeGuardedBySeed } from "@aglyn/tenant-feature-instance";
|
|
26
25
|
import { writeSiteWideChange } from "@aglyn/tenant-feature-instance/hooks/helpers/site-wide-change";
|
|
26
|
+
import { heldSaveLabel, isSeedChecking, seedCheckingText, useHeldSave, useSeedEdits } from "@aglyn/tenant-feature-instance/hooks/use-seed-edits";
|
|
27
27
|
import OverlayStatsRow from "./overlay-stats-row.component.js";
|
|
28
28
|
import { OVERLAY_COPY_HELPER_TEXT, shownAsTypedHelperText, useOverlayCopyEditor } from "./use-overlay-copy-editor.js";
|
|
29
29
|
/**
|
|
@@ -60,15 +60,19 @@ import { OVERLAY_COPY_HELPER_TEXT, shownAsTypedHelperText, useOverlayCopyEditor
|
|
|
60
60
|
});
|
|
61
61
|
const entitled = checkEntitlement(org, 'marketingOverlays');
|
|
62
62
|
const saved = (_ref = host == null ? void 0 : host.announcementBar) != null ? _ref : {};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
/*
|
|
64
|
+
* What was typed, kept as EDITS over the stored bar (AGL-4047). Another
|
|
65
|
+
* session's edit, or the server's copy arriving after a page drawn from
|
|
66
|
+
* the cache, moves every field nobody touched; it used to reset the whole
|
|
67
|
+
* form, typed fields included. Save is held until the server has answered
|
|
68
|
+
* (`checking`).
|
|
69
|
+
*/ const savedKey = JSON.stringify(saved);
|
|
70
|
+
const form = useSeedEdits(saved);
|
|
71
|
+
const draft = form.values;
|
|
72
|
+
const checking = isSeedChecking({
|
|
73
|
+
fromCache: hostFromCache,
|
|
74
|
+
unreadable: hostStatus === 'error'
|
|
75
|
+
});
|
|
72
76
|
// `draft.text` is held in its stored form; the field shows it as typed.
|
|
73
77
|
const copy = useOverlayCopyEditor({
|
|
74
78
|
hostId,
|
|
@@ -83,9 +87,10 @@ import { OVERLAY_COPY_HELPER_TEXT, shownAsTypedHelperText, useOverlayCopyEditor
|
|
|
83
87
|
const dirty = JSON.stringify(_extends({}, draft, {
|
|
84
88
|
text: copy.stored(draft.text)
|
|
85
89
|
})) !== savedKey;
|
|
86
|
-
const patch = (partial)=>
|
|
90
|
+
const patch = (partial)=>form.edit(partial);
|
|
87
91
|
const textShownAsTyped = copy.shownAsTyped(draft.text);
|
|
88
92
|
const handleSave = async ()=>{
|
|
93
|
+
const written = form.edits;
|
|
89
94
|
const dequeue = queueLoading();
|
|
90
95
|
try {
|
|
91
96
|
/**
|
|
@@ -141,6 +146,7 @@ import { OVERLAY_COPY_HELPER_TEXT, shownAsTypedHelperText, useOverlayCopyEditor
|
|
|
141
146
|
persist: false
|
|
142
147
|
});
|
|
143
148
|
}
|
|
149
|
+
form.settle(written);
|
|
144
150
|
enqueueSnackbar('Announcement bar saved', {
|
|
145
151
|
variant: 'success',
|
|
146
152
|
persist: false
|
|
@@ -155,6 +161,15 @@ import { OVERLAY_COPY_HELPER_TEXT, shownAsTypedHelperText, useOverlayCopyEditor
|
|
|
155
161
|
dequeue();
|
|
156
162
|
}
|
|
157
163
|
};
|
|
164
|
+
// A press while Save is held is kept, and saves once confirmed (AGL-4047).
|
|
165
|
+
const held = useHeldSave(handleSave, {
|
|
166
|
+
checking,
|
|
167
|
+
subject: 'announcement bar',
|
|
168
|
+
onRefused: (message)=>enqueueSnackbar(message, {
|
|
169
|
+
variant: 'warning',
|
|
170
|
+
persist: false
|
|
171
|
+
})
|
|
172
|
+
});
|
|
158
173
|
return /*#__PURE__*/ _jsx(CardDisplay, {
|
|
159
174
|
header: "Announcement bar",
|
|
160
175
|
help: pluginDocsHelp('marketingOverlays', {
|
|
@@ -281,13 +296,19 @@ import { OVERLAY_COPY_HELPER_TEXT, shownAsTypedHelperText, useOverlayCopyEditor
|
|
|
281
296
|
/*#__PURE__*/ _jsx(Button, {
|
|
282
297
|
variant: "contained",
|
|
283
298
|
color: "primary",
|
|
284
|
-
disabled: !dirty || Boolean(draft.enabled) && !((_draft_text = draft.text) == null ? void 0 : _draft_text.trim()) || copy.pending(draft.text),
|
|
285
|
-
onClick:
|
|
299
|
+
disabled: !dirty || Boolean(draft.enabled) && !((_draft_text = draft.text) == null ? void 0 : _draft_text.trim()) || copy.pending(draft.text) || held.saving,
|
|
300
|
+
onClick: held.press,
|
|
286
301
|
sx: {
|
|
287
302
|
alignSelf: 'flex-start'
|
|
288
303
|
},
|
|
289
|
-
children: 'Save'
|
|
304
|
+
children: heldSaveLabel(held, 'Save')
|
|
290
305
|
}),
|
|
306
|
+
dirty && checking ? /*#__PURE__*/ _jsx(Typography, {
|
|
307
|
+
variant: "body2",
|
|
308
|
+
color: "text.secondary",
|
|
309
|
+
role: "status",
|
|
310
|
+
children: seedCheckingText('announcement bar')
|
|
311
|
+
}) : null,
|
|
291
312
|
/*#__PURE__*/ _jsx(OverlayStatsRow, {
|
|
292
313
|
hostId: hostId,
|
|
293
314
|
actionKey: "barClick",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/components/announcement-bar-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 type AglynOrgBilling,\n checkEntitlement,\n type HostAnnouncementBar,\n pluginDocsHelp,\n} from '@aglyn/aglyn'\nimport { CardDisplay, useLoading } from '@aglyn/shared-ui-jsx'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Alert,\n Box,\n Button,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { doc } from 'firebase/firestore'\nimport { useEffect, useState } from 'react'\nimport {\n useFirestore,\n useFirestoreDoc,\n useHostActivityLogger,\n useUser,\n writeGuardedBySeed,\n} from '@aglyn/tenant-feature-instance'\nimport { writeSiteWideChange } from '@aglyn/tenant-feature-instance/hooks/helpers/site-wide-change'\nimport OverlayStatsRow from './overlay-stats-row.component'\nimport {\n OVERLAY_COPY_HELPER_TEXT,\n shownAsTypedHelperText,\n useOverlayCopyEditor,\n} from './use-overlay-copy-editor'\n\nexport interface AnnouncementBarCardProps {\n hostId: string\n /** Resolved entitlement source (AGL-395). */\n org?: Partial<AglynOrgBilling>\n}\n\n/**\n * Announcement bar editor (AGL-195): site-wide banner config persisted on\n * the host doc; the tenant render gates on the marketingOverlays\n * entitlement and resolves the text through `resolveOverlayCopy`. A typed\n * `{{name}}` is stored as its variable's id token, the only variable form\n * that resolves, and a token that would still show as typed is flagged\n * under the field (AGL-2885). Starter+ (locked-state upsell below),\n * dark-launched for plan-less workspaces like the other AGL-99 gates.\n */\nexport function AnnouncementBarCard(props: AnnouncementBarCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const { data: user } = useUser()\n const { org } = props\n const { enqueueSnackbar } = useSnackbar()\n const { queueLoading } = useLoading()\n const logActivity = useHostActivityLogger(hostId)\n const {\n data: host,\n status: hostStatus,\n /**\n * The host doc this form is seeded from is unconfirmed by the server\n * (AGL-1358). The save writes the whole `announcementBar` map — a nested\n * map value REPLACES atomically, so `updateDoc` protects only the host\n * doc's other fields, never the bar's own — and every field of it comes\n * off this seed. Against a cached read, editing the text reinstates the\n * colours, link and `enabled` flag from that snapshot on a banner shown\n * on every page of a published site.\n */\n fromCache: hostFromCache,\n listen: hostListen,\n } = useFirestoreDoc<any>(\n () => doc(firestore, 'hosts', hostId),\n [firestore, hostId],\n { idField: '$id' },\n )\n const entitled = checkEntitlement(org, 'marketingOverlays')\n\n const saved = (host?.announcementBar ?? {}) as HostAnnouncementBar\n const [draft, setDraft] = useState<HostAnnouncementBar>(saved)\n // Re-seed the form when another session edits the host doc.\n const savedKey = JSON.stringify(saved)\n useEffect(() => {\n setDraft(JSON.parse(savedKey))\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [savedKey])\n\n // `draft.text` is held in its stored form; the field shows it as typed.\n const copy = useOverlayCopyEditor({\n hostId,\n host,\n usesTokens:\n entitled &&\n [saved.text, draft.text].some((text) => text?.includes('{{')),\n })\n // Compared as it would be stored, so a name typed before the variables\n // arrived still counts as the change it becomes on save.\n const dirty =\n JSON.stringify({ ...draft, text: copy.stored(draft.text) }) !== savedKey\n const patch = (partial: Partial<HostAnnouncementBar>) =>\n setDraft((previous) => ({ ...previous, ...partial }))\n const textShownAsTyped = copy.shownAsTyped(draft.text)\n\n const handleSave = async () => {\n const dequeue = queueLoading()\n try {\n /**\n * Refuse a save whose seed the server never confirmed (AGL-1358).\n *\n * There is no create path to exempt, and that is the point: unlike a\n * new row at a fresh uid, this writes a FIXED document path, so the\n * blank `draft` that `host?.announcementBar ?? {}` yields when the\n * cache has never seen a bar is not harmless — it replaces whatever\n * bar the server really holds with an empty, disabled one.\n *\n * The activity log rides inside the guard: a logged \"Updated\n * announcement bar\" whose write never happened leaves the history\n * disagreeing with the bar it claims to explain.\n *\n * The guard WRAPS the write — an early return is a shape you can keep\n * while losing the protection.\n */\n const verdict = await writeGuardedBySeed(\n {\n subject: 'announcement bar',\n unreadable: hostStatus === 'error',\n fromCache: hostFromCache,\n listen: hostListen,\n },\n async () => {\n await writeSiteWideChange({\n firestore,\n user,\n hostId,\n write: (batch) =>\n batch.update(doc(firestore, 'hosts', hostId), {\n announcementBar: {\n enabled: Boolean(draft.enabled),\n text: copy.storedWithin(draft.text, 300),\n href: (draft.href ?? '').trim(),\n backgroundColor: (draft.backgroundColor ?? '').trim(),\n textColor: (draft.textColor ?? '').trim(),\n dismissible: draft.dismissible !== false,\n },\n }),\n })\n logActivity('Updated announcement bar', { type: 'host', id: hostId })\n },\n )\n // A refusal leaves every typed value on screen. A save that silently\n // does nothing sends the user back to retype a form that will be\n // refused again just as quietly.\n if (!verdict.ok) {\n return void enqueueSnackbar(verdict.message, {\n variant: 'warning',\n persist: false,\n })\n }\n enqueueSnackbar('Announcement bar saved', {\n variant: 'success',\n persist: false,\n })\n } catch (error) {\n console.error(error)\n enqueueSnackbar('An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n } finally {\n dequeue()\n }\n }\n\n return (\n <CardDisplay\n header=\"Announcement bar\"\n help={pluginDocsHelp('marketingOverlays', {\n anchor: '#announcement-bar',\n })}\n contentGutterX\n contentGutterY\n >\n {!entitled ? (\n <Alert severity=\"info\">\n {'Announcement bars and popups are included from the Starter ' +\n 'plan — see Billing to upgrade.'}\n </Alert>\n ) : (\n <Stack spacing={2}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Switch\n checked={Boolean(draft.enabled)}\n onChange={(event) => patch({ enabled: event.target.checked })}\n />\n <Typography variant=\"body2\">\n {draft.enabled\n ? 'Shown on every page of your published site'\n : 'Hidden'}\n </Typography>\n </Stack>\n <TextField\n label=\"Text\"\n size=\"small\"\n value={copy.editable(draft.text)}\n onChange={(event) =>\n patch({ text: copy.stored(event.target.value) })\n }\n error={textShownAsTyped.length > 0}\n helperText={\n shownAsTypedHelperText(textShownAsTyped) ?? OVERLAY_COPY_HELPER_TEXT\n }\n multiline\n fullWidth\n />\n <Stack useFlexGap direction=\"row\" spacing={1} sx={{ flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Link (optional)\"\n size=\"small\"\n placeholder=\"/sale or https://…\"\n value={draft.href ?? ''}\n onChange={(event) => patch({ href: event.target.value })}\n sx={{ flex: 1, minWidth: 200 }}\n />\n <TextField\n label=\"Background\"\n size=\"small\"\n placeholder=\"#111827\"\n value={draft.backgroundColor ?? ''}\n onChange={(event) =>\n patch({ backgroundColor: event.target.value })\n }\n sx={{ width: 120 }}\n />\n <TextField\n label=\"Text color\"\n size=\"small\"\n placeholder=\"#ffffff\"\n value={draft.textColor ?? ''}\n onChange={(event) => patch({ textColor: event.target.value })}\n sx={{ width: 120 }}\n />\n </Stack>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Switch\n checked={draft.dismissible !== false}\n onChange={(event) =>\n patch({ dismissible: event.target.checked })\n }\n />\n <Typography variant=\"body2\">\n {'Visitors can dismiss it (re-shown when the text changes)'}\n </Typography>\n </Stack>\n {draft.text ? (\n <Box\n sx={{\n px: 2,\n py: 1,\n borderRadius: 1,\n textAlign: 'center',\n fontSize: 14,\n color: draft.textColor || '#fff',\n backgroundColor: draft.backgroundColor || '#111827',\n }}\n >\n {copy.preview(draft.text)}\n </Box>\n ) : null}\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={\n !dirty ||\n (Boolean(draft.enabled) && !draft.text?.trim()) ||\n copy.pending(draft.text)\n }\n onClick={handleSave}\n sx={{ alignSelf: 'flex-start' }}\n >\n {'Save'}\n </Button>\n <OverlayStatsRow\n hostId={hostId}\n actionKey=\"barClick\"\n actionLabel=\"clicks\"\n />\n </Stack>\n )}\n </CardDisplay>\n )\n}\nAnnouncementBarCard.displayName = 'AnnouncementBarCard'\n\nexport default AnnouncementBarCard\n"],"names":["checkEntitlement","pluginDocsHelp","CardDisplay","useLoading","useSnackbar","Alert","Box","Button","Stack","Switch","TextField","Typography","doc","useEffect","useState","useFirestore","useFirestoreDoc","useHostActivityLogger","useUser","writeGuardedBySeed","writeSiteWideChange","OverlayStatsRow","OVERLAY_COPY_HELPER_TEXT","shownAsTypedHelperText","useOverlayCopyEditor","AnnouncementBarCard","props","draft","hostId","firestore","data","user","org","enqueueSnackbar","queueLoading","logActivity","host","status","hostStatus","fromCache","hostFromCache","listen","hostListen","idField","entitled","saved","announcementBar","setDraft","savedKey","JSON","stringify","parse","copy","usesTokens","text","some","includes","dirty","stored","patch","partial","previous","textShownAsTyped","shownAsTyped","handleSave","dequeue","verdict","subject","unreadable","write","batch","update","enabled","Boolean","storedWithin","href","trim","backgroundColor","textColor","dismissible","type","id","ok","message","variant","persist","error","console","allowDuplicate","header","help","anchor","contentGutterX","contentGutterY","severity","spacing","direction","sx","alignItems","checked","onChange","event","target","label","size","value","editable","length","helperText","multiline","fullWidth","useFlexGap","flexWrap","rowGap","placeholder","flex","minWidth","width","px","py","borderRadius","textAlign","fontSize","color","preview","disabled","pending","onClick","alignSelf","actionKey","actionLabel","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAEEA,gBAAgB,EAEhBC,cAAc,QACT,eAAc;AACrB,SAASC,WAAW,EAAEC,UAAU,QAAQ,uBAAsB;AAC9D,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,GAAG,QAAQ,qBAAoB;AACxC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAC3C,SACEC,YAAY,EACZC,eAAe,EACfC,qBAAqB,EACrBC,OAAO,EACPC,kBAAkB,QACb,iCAAgC;AACvC,SAASC,mBAAmB,QAAQ,gEAA+D;AACnG,OAAOC,qBAAqB,mCAA+B;AAC3D,SACEC,wBAAwB,EACxBC,sBAAsB,EACtBC,oBAAoB,QACf,+BAA2B;AAQlC;;;;;;;;CAQC,GACD,OAAO,SAASC,oBAAoBC,KAA+B;cAgKrDH,yBAUOI,aAQAA,wBAUAA;QAoCqBA;IA/NxC,MAAM,EAAEC,MAAM,EAAE,GAAGF;IACnB,MAAMG,YAAYd;IAClB,MAAM,EAAEe,MAAMC,IAAI,EAAE,GAAGb;IACvB,MAAM,EAAEc,GAAG,EAAE,GAAGN;IAChB,MAAM,EAAEO,eAAe,EAAE,GAAG7B;IAC5B,MAAM,EAAE8B,YAAY,EAAE,GAAG/B;IACzB,MAAMgC,cAAclB,sBAAsBW;IAC1C,MAAM,EACJE,MAAMM,IAAI,EACVC,QAAQC,UAAU,EAClB;;;;;;;;KAQC,GACDC,WAAWC,aAAa,EACxBC,QAAQC,UAAU,EACnB,GAAG1B,gBACF,IAAMJ,IAAIiB,WAAW,SAASD,SAC9B;QAACC;QAAWD;KAAO,EACnB;QAAEe,SAAS;IAAM;IAEnB,MAAMC,WAAW5C,iBAAiBgC,KAAK;IAEvC,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qB,UAAU,CAACC,QACT1C,MAAM;oCAAEoB,aAAasB,MAAMC,MAAM,CAACH,OAAO;gCAAC;;sCAG9C,KAACxF;4BAAWyE,SAAQ;sCACjB;;;;gBAGJzD,MAAM2B,IAAI,iBACT,KAAChD;oBACC2F,IAAI;wBACFqB,IAAI;wBACJC,IAAI;wBACJC,cAAc;wBACdC,WAAW;wBACXC,UAAU;wBACVC,OAAOhG,MAAMmD,SAAS,IAAI;wBAC1BD,iBAAiBlD,MAAMkD,eAAe,IAAI;oBAC5C;8BAECzB,KAAKwE,OAAO,CAACjG,MAAM2B,IAAI;qBAExB;8BACJ,KAAC/C;oBACC6E,SAAQ;oBACRuC,OAAM;oBACNE,UACE,CAACpE,SACAgB,QAAQ9C,MAAM6C,OAAO,KAAK,GAAC7C,cAAAA,MAAM2B,IAAI,qBAAV3B,YAAYiD,IAAI,OAC5CxB,KAAK0E,OAAO,CAACnG,MAAM2B,IAAI;oBAEzByE,SAAS/D;oBACTiC,IAAI;wBAAE+B,WAAW;oBAAa;8BAE7B;;8BAEH,KAAC3G;oBACCO,QAAQA;oBACRqG,WAAU;oBACVC,aAAY;;;;;AAMxB;AACAzG,oBAAoB0G,WAAW,GAAG;AAElC,eAAe1G,oBAAmB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/marketing/src/lib/components/announcement-bar-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 type AglynOrgBilling,\n checkEntitlement,\n type HostAnnouncementBar,\n pluginDocsHelp,\n} from '@aglyn/aglyn'\nimport { CardDisplay, useLoading } from '@aglyn/shared-ui-jsx'\nimport { useSnackbar } from '@aglyn/shared-ui-snackstack'\nimport {\n Alert,\n Box,\n Button,\n Stack,\n Switch,\n TextField,\n Typography,\n} from '@mui/material'\nimport { doc } from 'firebase/firestore'\nimport {\n useFirestore,\n useFirestoreDoc,\n useHostActivityLogger,\n useUser,\n writeGuardedBySeed,\n} from '@aglyn/tenant-feature-instance'\nimport { writeSiteWideChange } from '@aglyn/tenant-feature-instance/hooks/helpers/site-wide-change'\nimport {\n heldSaveLabel,\n isSeedChecking,\n seedCheckingText,\n useHeldSave,\n useSeedEdits,\n} from '@aglyn/tenant-feature-instance/hooks/use-seed-edits'\nimport OverlayStatsRow from './overlay-stats-row.component'\nimport {\n OVERLAY_COPY_HELPER_TEXT,\n shownAsTypedHelperText,\n useOverlayCopyEditor,\n} from './use-overlay-copy-editor'\n\nexport interface AnnouncementBarCardProps {\n hostId: string\n /** Resolved entitlement source (AGL-395). */\n org?: Partial<AglynOrgBilling>\n}\n\n/**\n * Announcement bar editor (AGL-195): site-wide banner config persisted on\n * the host doc; the tenant render gates on the marketingOverlays\n * entitlement and resolves the text through `resolveOverlayCopy`. A typed\n * `{{name}}` is stored as its variable's id token, the only variable form\n * that resolves, and a token that would still show as typed is flagged\n * under the field (AGL-2885). Starter+ (locked-state upsell below),\n * dark-launched for plan-less workspaces like the other AGL-99 gates.\n */\nexport function AnnouncementBarCard(props: AnnouncementBarCardProps) {\n const { hostId } = props\n const firestore = useFirestore()\n const { data: user } = useUser()\n const { org } = props\n const { enqueueSnackbar } = useSnackbar()\n const { queueLoading } = useLoading()\n const logActivity = useHostActivityLogger(hostId)\n const {\n data: host,\n status: hostStatus,\n /**\n * The host doc this form is seeded from is unconfirmed by the server\n * (AGL-1358). The save writes the whole `announcementBar` map — a nested\n * map value REPLACES atomically, so `updateDoc` protects only the host\n * doc's other fields, never the bar's own — and every field of it comes\n * off this seed. Against a cached read, editing the text reinstates the\n * colours, link and `enabled` flag from that snapshot on a banner shown\n * on every page of a published site.\n */\n fromCache: hostFromCache,\n listen: hostListen,\n } = useFirestoreDoc<any>(\n () => doc(firestore, 'hosts', hostId),\n [firestore, hostId],\n { idField: '$id' },\n )\n const entitled = checkEntitlement(org, 'marketingOverlays')\n\n const saved = (host?.announcementBar ?? {}) as HostAnnouncementBar\n /*\n * What was typed, kept as EDITS over the stored bar (AGL-4047). Another\n * session's edit, or the server's copy arriving after a page drawn from\n * the cache, moves every field nobody touched; it used to reset the whole\n * form, typed fields included. Save is held until the server has answered\n * (`checking`).\n */\n const savedKey = JSON.stringify(saved)\n const form = useSeedEdits<HostAnnouncementBar>(saved)\n const draft = form.values\n const checking = isSeedChecking({\n fromCache: hostFromCache,\n unreadable: hostStatus === 'error',\n })\n\n // `draft.text` is held in its stored form; the field shows it as typed.\n const copy = useOverlayCopyEditor({\n hostId,\n host,\n usesTokens:\n entitled &&\n [saved.text, draft.text].some((text) => text?.includes('{{')),\n })\n // Compared as it would be stored, so a name typed before the variables\n // arrived still counts as the change it becomes on save.\n const dirty =\n JSON.stringify({ ...draft, text: copy.stored(draft.text) }) !== savedKey\n const patch = (partial: Partial<HostAnnouncementBar>) => form.edit(partial)\n const textShownAsTyped = copy.shownAsTyped(draft.text)\n\n const handleSave = async () => {\n const written = form.edits\n const dequeue = queueLoading()\n try {\n /**\n * Refuse a save whose seed the server never confirmed (AGL-1358).\n *\n * There is no create path to exempt, and that is the point: unlike a\n * new row at a fresh uid, this writes a FIXED document path, so the\n * blank `draft` that `host?.announcementBar ?? {}` yields when the\n * cache has never seen a bar is not harmless — it replaces whatever\n * bar the server really holds with an empty, disabled one.\n *\n * The activity log rides inside the guard: a logged \"Updated\n * announcement bar\" whose write never happened leaves the history\n * disagreeing with the bar it claims to explain.\n *\n * The guard WRAPS the write — an early return is a shape you can keep\n * while losing the protection.\n */\n const verdict = await writeGuardedBySeed(\n {\n subject: 'announcement bar',\n unreadable: hostStatus === 'error',\n fromCache: hostFromCache,\n listen: hostListen,\n },\n async () => {\n await writeSiteWideChange({\n firestore,\n user,\n hostId,\n write: (batch) =>\n batch.update(doc(firestore, 'hosts', hostId), {\n announcementBar: {\n enabled: Boolean(draft.enabled),\n text: copy.storedWithin(draft.text, 300),\n href: (draft.href ?? '').trim(),\n backgroundColor: (draft.backgroundColor ?? '').trim(),\n textColor: (draft.textColor ?? '').trim(),\n dismissible: draft.dismissible !== false,\n },\n }),\n })\n logActivity('Updated announcement bar', { type: 'host', id: hostId })\n },\n )\n // A refusal leaves every typed value on screen. A save that silently\n // does nothing sends the user back to retype a form that will be\n // refused again just as quietly.\n if (!verdict.ok) {\n return void enqueueSnackbar(verdict.message, {\n variant: 'warning',\n persist: false,\n })\n }\n form.settle(written)\n enqueueSnackbar('Announcement bar saved', {\n variant: 'success',\n persist: false,\n })\n } catch (error) {\n console.error(error)\n enqueueSnackbar('An error has occurred', {\n variant: 'error',\n allowDuplicate: true,\n })\n } finally {\n dequeue()\n }\n }\n\n // A press while Save is held is kept, and saves once confirmed (AGL-4047).\n const held = useHeldSave(handleSave, {\n checking,\n subject: 'announcement bar',\n onRefused: (message) => enqueueSnackbar(message, { variant: 'warning', persist: false }),\n })\n\n return (\n <CardDisplay\n header=\"Announcement bar\"\n help={pluginDocsHelp('marketingOverlays', {\n anchor: '#announcement-bar',\n })}\n contentGutterX\n contentGutterY\n >\n {!entitled ? (\n <Alert severity=\"info\">\n {'Announcement bars and popups are included from the Starter ' +\n 'plan — see Billing to upgrade.'}\n </Alert>\n ) : (\n <Stack spacing={2}>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Switch\n checked={Boolean(draft.enabled)}\n onChange={(event) => patch({ enabled: event.target.checked })}\n />\n <Typography variant=\"body2\">\n {draft.enabled\n ? 'Shown on every page of your published site'\n : 'Hidden'}\n </Typography>\n </Stack>\n <TextField\n label=\"Text\"\n size=\"small\"\n value={copy.editable(draft.text)}\n onChange={(event) =>\n patch({ text: copy.stored(event.target.value) })\n }\n error={textShownAsTyped.length > 0}\n helperText={\n shownAsTypedHelperText(textShownAsTyped) ?? OVERLAY_COPY_HELPER_TEXT\n }\n multiline\n fullWidth\n />\n <Stack useFlexGap direction=\"row\" spacing={1} sx={{ flexWrap: 'wrap', rowGap: 1 }}>\n <TextField\n label=\"Link (optional)\"\n size=\"small\"\n placeholder=\"/sale or https://…\"\n value={draft.href ?? ''}\n onChange={(event) => patch({ href: event.target.value })}\n sx={{ flex: 1, minWidth: 200 }}\n />\n <TextField\n label=\"Background\"\n size=\"small\"\n placeholder=\"#111827\"\n value={draft.backgroundColor ?? ''}\n onChange={(event) =>\n patch({ backgroundColor: event.target.value })\n }\n sx={{ width: 120 }}\n />\n <TextField\n label=\"Text color\"\n size=\"small\"\n placeholder=\"#ffffff\"\n value={draft.textColor ?? ''}\n onChange={(event) => patch({ textColor: event.target.value })}\n sx={{ width: 120 }}\n />\n </Stack>\n <Stack direction=\"row\" spacing={1} sx={{ alignItems: 'center' }}>\n <Switch\n checked={draft.dismissible !== false}\n onChange={(event) =>\n patch({ dismissible: event.target.checked })\n }\n />\n <Typography variant=\"body2\">\n {'Visitors can dismiss it (re-shown when the text changes)'}\n </Typography>\n </Stack>\n {draft.text ? (\n <Box\n sx={{\n px: 2,\n py: 1,\n borderRadius: 1,\n textAlign: 'center',\n fontSize: 14,\n color: draft.textColor || '#fff',\n backgroundColor: draft.backgroundColor || '#111827',\n }}\n >\n {copy.preview(draft.text)}\n </Box>\n ) : null}\n <Button\n variant=\"contained\"\n color=\"primary\"\n disabled={\n !dirty ||\n (Boolean(draft.enabled) && !draft.text?.trim()) ||\n copy.pending(draft.text) ||\n held.saving\n }\n onClick={held.press}\n sx={{ alignSelf: 'flex-start' }}\n >\n {heldSaveLabel(held, 'Save')}\n </Button>\n {dirty && checking ? (\n <Typography variant=\"body2\" color=\"text.secondary\" role=\"status\">\n {seedCheckingText('announcement bar')}\n </Typography>\n ) : null}\n <OverlayStatsRow\n hostId={hostId}\n actionKey=\"barClick\"\n actionLabel=\"clicks\"\n />\n </Stack>\n )}\n </CardDisplay>\n )\n}\nAnnouncementBarCard.displayName = 'AnnouncementBarCard'\n\nexport default AnnouncementBarCard\n"],"names":["checkEntitlement","pluginDocsHelp","CardDisplay","useLoading","useSnackbar","Alert","Box","Button","Stack","Switch","TextField","Typography","doc","useFirestore","useFirestoreDoc","useHostActivityLogger","useUser","writeGuardedBySeed","writeSiteWideChange","heldSaveLabel","isSeedChecking","seedCheckingText","useHeldSave","useSeedEdits","OverlayStatsRow","OVERLAY_COPY_HELPER_TEXT","shownAsTypedHelperText","useOverlayCopyEditor","AnnouncementBarCard","props","draft","hostId","firestore","data","user","org","enqueueSnackbar","queueLoading","logActivity","host","status","hostStatus","fromCache","hostFromCache","listen","hostListen","idField","entitled","saved","announcementBar","savedKey","JSON","stringify","form","values","checking","unreadable","copy","usesTokens","text","some","includes","dirty","stored","patch","partial","edit","textShownAsTyped","shownAsTyped","handleSave","written","edits","dequeue","verdict","subject","write","batch","update","enabled","Boolean","storedWithin","href","trim","backgroundColor","textColor","dismissible","type","id","ok","message","variant","persist","settle","error","console","allowDuplicate","held","onRefused","header","help","anchor","contentGutterX","contentGutterY","severity","spacing","direction","sx","alignItems","checked","onChange","event","target","label","size","value","editable","length","helperText","multiline","fullWidth","useFlexGap","flexWrap","rowGap","placeholder","flex","minWidth","width","px","py","borderRadius","textAlign","fontSize","color","preview","disabled","pending","saving","onClick","press","alignSelf","role","actionKey","actionLabel","displayName"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;AAEA,SAEEA,gBAAgB,EAEhBC,cAAc,QACT,eAAc;AACrB,SAASC,WAAW,EAAEC,UAAU,QAAQ,uBAAsB;AAC9D,SAASC,WAAW,QAAQ,8BAA6B;AACzD,SACEC,KAAK,EACLC,GAAG,EACHC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,SAAS,EACTC,UAAU,QACL,gBAAe;AACtB,SAASC,GAAG,QAAQ,qBAAoB;AAC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AAW+E,SAAQ;sCACjB;;;;gBAGJ5D,MAAM6B,IAAI,iBACT,KAACrD;oBACCoG,IAAI;wBACFqB,IAAI;wBACJC,IAAI;wBACJC,cAAc;wBACdC,WAAW;wBACXC,UAAU;wBACVC,OAAOtG,MAAMsD,SAAS,IAAI;wBAC1BD,iBAAiBrD,MAAMqD,eAAe,IAAI;oBAC5C;8BAEC1B,KAAK4E,OAAO,CAACvG,MAAM6B,IAAI;qBAExB;8BACJ,KAACpD;oBACCmF,SAAQ;oBACR0C,OAAM;oBACNE,UACE,CAACxE,SACAiB,QAAQjD,MAAMgD,OAAO,KAAK,GAAChD,cAAAA,MAAM6B,IAAI,qBAAV7B,YAAYoD,IAAI,OAC5CzB,KAAK8E,OAAO,CAACzG,MAAM6B,IAAI,KACvBqC,KAAKwC,MAAM;oBAEbC,SAASzC,KAAK0C,KAAK;oBACnBhC,IAAI;wBAAEiC,WAAW;oBAAa;8BAE7BxH,cAAc6E,MAAM;;gBAEtBlC,SAASP,yBACR,KAAC5C;oBAAW+E,SAAQ;oBAAQ0C,OAAM;oBAAiBQ,MAAK;8BACrDvH,iBAAiB;qBAElB;8BACJ,KAACG;oBACCO,QAAQA;oBACR8G,WAAU;oBACVC,aAAY;;;;;AAMxB;AACAlH,oBAAoBmH,WAAW,GAAG;AAElC,eAAenH,oBAAmB"}
|
|
@@ -38,6 +38,8 @@ import { Alert, Button, Chip, Dialog, DialogActions, DialogContent, DialogTitle,
|
|
|
38
38
|
import { collection, doc, getDocs, limit, query, where } from "firebase/firestore";
|
|
39
39
|
import { useMemo, useState } from "react";
|
|
40
40
|
import { useFirestore, useFirestoreCollection, useHostActivityLogger, writeGuardedBySeed, useUser } from "@aglyn/tenant-feature-instance";
|
|
41
|
+
import { heldSaveLabel, isSeedChecking, seedCheckingText, useHeldSave } from "@aglyn/tenant-feature-instance/hooks/use-seed-edits";
|
|
42
|
+
import { useSeedDraft } from "@aglyn/tenant-feature-instance/hooks/use-seed-draft";
|
|
41
43
|
import { writeSiteWideChange } from "@aglyn/tenant-feature-instance/hooks/helpers/site-wide-change";
|
|
42
44
|
import { useListQuery } from "@aglyn/tenant-feature-instance/hooks/use-list-query";
|
|
43
45
|
import { ExperimentResultZone, ExperimentVariantsZone, marketingExperimentVariantDrafts } from "./experiment-zones.js";
|
|
@@ -176,7 +178,16 @@ const EXPERIMENT_PAGE_SORT_HEADERS = {
|
|
|
176
178
|
}), [
|
|
177
179
|
experimentPlan.refused
|
|
178
180
|
]);
|
|
179
|
-
|
|
181
|
+
/*
|
|
182
|
+
* The editor's draft, kept as EDITS over the experiment as the list has it
|
|
183
|
+
* now (AGL-4047): opened from the cache's row, the server's copy replaces
|
|
184
|
+
* it under every field nobody touched (`status` among them), and Save is
|
|
185
|
+
* held until it has.
|
|
186
|
+
*/ const [editor, setEditor] = useSeedDraft((opened)=>opened.$id ? experiments.find((experiment)=>experiment.$id === opened.$id) : undefined);
|
|
187
|
+
const editorChecking = Boolean(editor == null ? void 0 : editor.$id) && isSeedChecking({
|
|
188
|
+
fromCache: experimentsFromCache,
|
|
189
|
+
unreadable: experimentsStatus === 'error'
|
|
190
|
+
});
|
|
180
191
|
/*
|
|
181
192
|
* The screens and their versions fill the EDITOR's pickers and nothing
|
|
182
193
|
* else on the card, so they are read while the editor is open and not
|
|
@@ -508,6 +519,15 @@ const EXPERIMENT_PAGE_SORT_HEADERS = {
|
|
|
508
519
|
items: experimentActions(experiment)
|
|
509
520
|
}))
|
|
510
521
|
];
|
|
522
|
+
// A press while Save is held is kept, and saves once confirmed (AGL-4047).
|
|
523
|
+
const held = useHeldSave(handleSave, {
|
|
524
|
+
checking: editorChecking,
|
|
525
|
+
subject: 'experiment',
|
|
526
|
+
onRefused: (message)=>enqueueSnackbar(message, {
|
|
527
|
+
variant: 'warning',
|
|
528
|
+
persist: false
|
|
529
|
+
})
|
|
530
|
+
});
|
|
511
531
|
return /*#__PURE__*/ _jsxs(CardDisplay, {
|
|
512
532
|
header: "Experiments",
|
|
513
533
|
help: pluginDocsHelp('emailCampaigns', {
|
|
@@ -893,6 +913,15 @@ const EXPERIMENT_PAGE_SORT_HEADERS = {
|
|
|
893
913
|
}),
|
|
894
914
|
/*#__PURE__*/ _jsxs(DialogActions, {
|
|
895
915
|
children: [
|
|
916
|
+
editorChecking ? /*#__PURE__*/ _jsx(Typography, {
|
|
917
|
+
variant: "body2",
|
|
918
|
+
color: "text.secondary",
|
|
919
|
+
role: "status",
|
|
920
|
+
sx: {
|
|
921
|
+
mr: 'auto'
|
|
922
|
+
},
|
|
923
|
+
children: seedCheckingText('experiment')
|
|
924
|
+
}) : null,
|
|
896
925
|
/*#__PURE__*/ _jsx(Button, {
|
|
897
926
|
color: "inherit",
|
|
898
927
|
onClick: ()=>setEditor(null),
|
|
@@ -901,8 +930,9 @@ const EXPERIMENT_PAGE_SORT_HEADERS = {
|
|
|
901
930
|
/*#__PURE__*/ _jsx(Button, {
|
|
902
931
|
variant: "contained",
|
|
903
932
|
color: "primary",
|
|
904
|
-
|
|
905
|
-
|
|
933
|
+
disabled: held.saving,
|
|
934
|
+
onClick: held.press,
|
|
935
|
+
children: heldSaveLabel(held, 'Save')
|
|
906
936
|
})
|
|
907
937
|
]
|
|
908
938
|
})
|