@drawbridge/components 0.1.34 → 0.1.35

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.
Files changed (328) hide show
  1. package/components/styles.css +68 -355
  2. package/dist/advertisement.js +15 -20
  3. package/dist/advertisement.mjs +15 -20
  4. package/dist/bridge/advertisements.js +4 -2
  5. package/dist/bridge/advertisements.mjs +5 -3
  6. package/dist/bridge/fields.js +89 -6
  7. package/dist/bridge/fields.mjs +89 -7
  8. package/dist/bridge/form-subdomain-agreement.js +165 -0
  9. package/dist/bridge/form-subdomain-agreement.mjs +132 -0
  10. package/dist/bridge/form-subdomain-embed.js +5 -1
  11. package/dist/bridge/form-subdomain-embed.mjs +5 -1
  12. package/dist/bridge/form-subdomain-header.js +21 -14
  13. package/dist/bridge/form-subdomain-header.mjs +20 -14
  14. package/dist/bridge/form-subdomain-issue.js +17 -8
  15. package/dist/bridge/form-subdomain-issue.mjs +17 -8
  16. package/dist/bridge/form-subdomain-missions.js +58 -52
  17. package/dist/bridge/form-subdomain-missions.mjs +60 -54
  18. package/dist/bridge/form-subdomain.js +223 -94
  19. package/dist/bridge/form-subdomain.mjs +222 -96
  20. package/dist/bridge/lib/entry.js +61 -6
  21. package/dist/bridge/lib/entry.mjs +51 -5
  22. package/dist/bridge/lib/order.js +23 -0
  23. package/dist/bridge/lib/order.mjs +20 -0
  24. package/dist/bridge/template-layout.js +5 -2
  25. package/dist/bridge/template-layout.mjs +6 -3
  26. package/dist/bridge/template-modal.js +82 -15
  27. package/dist/bridge/template-modal.mjs +83 -16
  28. package/dist/bridge/template-subdomain-gallery.js +126 -75
  29. package/dist/bridge/template-subdomain-gallery.mjs +122 -75
  30. package/dist/bridge/template-subdomain.js +16 -14
  31. package/dist/bridge/template-subdomain.mjs +17 -15
  32. package/dist/dashboard/avatar.js +5 -0
  33. package/dist/dashboard/avatar.mjs +5 -0
  34. package/dist/dashboard/campaign-form.js +1798 -0
  35. package/dist/dashboard/campaign-form.mjs +1769 -0
  36. package/dist/dashboard/card-affiliate.js +3 -2
  37. package/dist/dashboard/card-affiliate.mjs +3 -2
  38. package/dist/dashboard/card-campaign-agreement.js +172 -0
  39. package/dist/dashboard/card-campaign-agreement.mjs +139 -0
  40. package/dist/dashboard/card-campaign-switch.js +34 -9
  41. package/dist/dashboard/card-campaign-switch.mjs +32 -8
  42. package/dist/dashboard/card-order.js +6 -14
  43. package/dist/dashboard/card-order.mjs +6 -14
  44. package/dist/dashboard/card-section.js +69 -26
  45. package/dist/dashboard/card-section.mjs +65 -26
  46. package/dist/dashboard/card-shortcut.js +181 -0
  47. package/dist/dashboard/card-shortcut.mjs +152 -0
  48. package/dist/dashboard/card-tile.js +3 -35
  49. package/dist/dashboard/card-tile.mjs +3 -34
  50. package/dist/dashboard/document-blocks.js +305 -0
  51. package/dist/dashboard/document-blocks.mjs +270 -0
  52. package/dist/dashboard/drawer-subscription.js +52 -14
  53. package/dist/dashboard/drawer-subscription.mjs +52 -14
  54. package/dist/dashboard/drawer.js +20 -3
  55. package/dist/dashboard/drawer.mjs +21 -4
  56. package/dist/dashboard/dropdown.js +6 -2
  57. package/dist/dashboard/dropdown.mjs +6 -2
  58. package/dist/dashboard/form-admin-subscription-custom.js +72 -8
  59. package/dist/dashboard/form-admin-subscription-custom.mjs +72 -8
  60. package/dist/dashboard/form-ai.js +0 -148
  61. package/dist/dashboard/form-ai.mjs +1 -148
  62. package/dist/dashboard/form-filters-analytics.js +88 -37
  63. package/dist/dashboard/form-filters-analytics.mjs +85 -38
  64. package/dist/dashboard/form-organization-brand.js +30 -13
  65. package/dist/dashboard/form-organization-brand.mjs +30 -13
  66. package/dist/dashboard/form-organization-campaign-advertisement.js +38 -112
  67. package/dist/dashboard/form-organization-campaign-advertisement.mjs +38 -112
  68. package/dist/dashboard/form-organization-campaign-advertisements.js +374 -0
  69. package/dist/dashboard/form-organization-campaign-advertisements.mjs +345 -0
  70. package/dist/dashboard/form-organization-campaign-agreement.js +414 -210
  71. package/dist/dashboard/form-organization-campaign-agreement.mjs +411 -212
  72. package/dist/dashboard/form-organization-campaign-design.js +258 -0
  73. package/dist/dashboard/form-organization-campaign-design.mjs +223 -0
  74. package/dist/dashboard/form-organization-campaign-field-item.js +585 -0
  75. package/dist/dashboard/form-organization-campaign-field-item.mjs +552 -0
  76. package/dist/dashboard/form-organization-campaign-field-number.js +48 -7
  77. package/dist/dashboard/form-organization-campaign-field-number.mjs +48 -7
  78. package/dist/dashboard/form-organization-campaign-field-select.js +15 -4
  79. package/dist/dashboard/form-organization-campaign-field-select.mjs +15 -4
  80. package/dist/dashboard/form-organization-campaign-field-skill.js +359 -0
  81. package/dist/dashboard/form-organization-campaign-field-skill.mjs +330 -0
  82. package/dist/dashboard/form-organization-campaign-field-text.js +46 -6
  83. package/dist/dashboard/form-organization-campaign-field-text.mjs +46 -6
  84. package/dist/dashboard/form-organization-campaign-field-textarea.js +22 -13
  85. package/dist/dashboard/form-organization-campaign-field-textarea.mjs +22 -13
  86. package/dist/dashboard/form-organization-campaign-footer.js +178 -0
  87. package/dist/dashboard/form-organization-campaign-footer.mjs +149 -0
  88. package/dist/dashboard/form-organization-campaign-integration-age.js +2 -35
  89. package/dist/dashboard/form-organization-campaign-integration-age.mjs +2 -35
  90. package/dist/dashboard/form-organization-campaign-integration-geocode.js +4 -1
  91. package/dist/dashboard/form-organization-campaign-integration-geocode.mjs +4 -1
  92. package/dist/dashboard/form-organization-campaign-page-embed.js +1 -1
  93. package/dist/dashboard/form-organization-campaign-page-embed.mjs +1 -1
  94. package/dist/dashboard/form-organization-campaign-page-preview.js +1 -2
  95. package/dist/dashboard/form-organization-campaign-page-preview.mjs +1 -2
  96. package/dist/dashboard/form-organization-campaign-page-qr.js +2 -2
  97. package/dist/dashboard/form-organization-campaign-page-qr.mjs +2 -2
  98. package/dist/dashboard/form-organization-campaign-page-share.js +5 -5
  99. package/dist/dashboard/form-organization-campaign-page-share.mjs +5 -5
  100. package/dist/dashboard/form-organization-campaign-page-slug.js +2 -3
  101. package/dist/dashboard/form-organization-campaign-page-slug.mjs +2 -3
  102. package/dist/dashboard/form-organization-campaign-page.js +168 -265
  103. package/dist/dashboard/form-organization-campaign-page.mjs +170 -266
  104. package/dist/dashboard/form-organization-campaign-section.js +125 -107
  105. package/dist/dashboard/form-organization-campaign-section.mjs +121 -107
  106. package/dist/dashboard/form-organization-campaign.js +119 -9
  107. package/dist/dashboard/form-organization-campaign.mjs +118 -9
  108. package/dist/dashboard/form-organization-file-frame.js +7 -1
  109. package/dist/dashboard/form-organization-file-frame.mjs +7 -1
  110. package/dist/dashboard/form-organization-workflow.js +587 -530
  111. package/dist/dashboard/form-organization-workflow.mjs +588 -531
  112. package/dist/dashboard/form-organization.js +22 -0
  113. package/dist/dashboard/form-organization.mjs +22 -0
  114. package/dist/dashboard/form-reposition.js +396 -0
  115. package/dist/dashboard/form-reposition.mjs +359 -0
  116. package/dist/dashboard/form-support.js +189 -0
  117. package/dist/dashboard/form-support.mjs +160 -0
  118. package/dist/dashboard/form-tests.js +683 -0
  119. package/dist/dashboard/form-tests.mjs +646 -0
  120. package/dist/dashboard/form-verify-prize.js +114 -34
  121. package/dist/dashboard/form-verify-prize.mjs +111 -34
  122. package/dist/dashboard/google.js +8 -1
  123. package/dist/dashboard/google.mjs +8 -1
  124. package/dist/dashboard/input-array.js +2 -0
  125. package/dist/dashboard/input-array.mjs +2 -0
  126. package/dist/dashboard/input-editor.js +17 -6
  127. package/dist/dashboard/input-editor.mjs +17 -6
  128. package/dist/dashboard/input-fields.js +287 -437
  129. package/dist/dashboard/input-fields.mjs +287 -436
  130. package/dist/dashboard/input-file.js +70 -2
  131. package/dist/dashboard/input-file.mjs +70 -2
  132. package/dist/dashboard/input-font.js +64 -55
  133. package/dist/dashboard/input-font.mjs +64 -55
  134. package/dist/dashboard/input-resource.js +4 -1
  135. package/dist/dashboard/input-resource.mjs +4 -1
  136. package/dist/dashboard/lib/ab-tests.js +130 -0
  137. package/dist/dashboard/lib/ab-tests.mjs +94 -0
  138. package/dist/dashboard/lib/features.js +1 -1
  139. package/dist/dashboard/lib/features.mjs +1 -1
  140. package/dist/dashboard/lib/focus.js +93 -0
  141. package/dist/dashboard/lib/focus.mjs +69 -0
  142. package/dist/dashboard/lib/form-page.js +203 -0
  143. package/dist/dashboard/lib/form-page.mjs +155 -0
  144. package/dist/dashboard/lib/item-list.js +0 -15
  145. package/dist/dashboard/lib/item-list.mjs +0 -14
  146. package/dist/dashboard/lib/rail.js +16 -17
  147. package/dist/dashboard/lib/rail.mjs +15 -16
  148. package/dist/dashboard/lib/sms.js +8 -2
  149. package/dist/dashboard/lib/sms.mjs +6 -1
  150. package/dist/dashboard/list-resource.js +2 -0
  151. package/dist/dashboard/list-resource.mjs +2 -0
  152. package/dist/dashboard/menu.js +54 -5
  153. package/dist/dashboard/menu.mjs +53 -5
  154. package/dist/dashboard/modal.js +19 -4
  155. package/dist/dashboard/modal.mjs +20 -5
  156. package/dist/dashboard/order-sections.js +4 -0
  157. package/dist/dashboard/order-sections.mjs +4 -0
  158. package/dist/dashboard/preview.js +838 -324
  159. package/dist/dashboard/preview.mjs +826 -324
  160. package/dist/dashboard/provider-ui.js +20 -12
  161. package/dist/dashboard/provider-ui.mjs +21 -13
  162. package/dist/dashboard/recharts.js +53 -28
  163. package/dist/dashboard/recharts.mjs +53 -28
  164. package/dist/dashboard/swatch.js +35 -0
  165. package/dist/dashboard/swatch.mjs +31 -0
  166. package/dist/dashboard/table-contacts.js +6 -10
  167. package/dist/dashboard/table-contacts.mjs +6 -10
  168. package/dist/dashboard/table.js +10 -3
  169. package/dist/dashboard/table.mjs +9 -3
  170. package/dist/dashboard/template-dashboard.js +12 -7
  171. package/dist/dashboard/template-dashboard.mjs +11 -7
  172. package/dist/dashboard/template-design.js +564 -0
  173. package/dist/dashboard/template-design.mjs +531 -0
  174. package/dist/dashboard/template-rail.js +198 -126
  175. package/dist/dashboard/template-rail.mjs +196 -125
  176. package/dist/dashboard/template-socket.js +0 -3
  177. package/dist/dashboard/template-socket.mjs +0 -3
  178. package/dist/dashboard/template-test-page.js +436 -0
  179. package/dist/dashboard/template-test-page.mjs +407 -0
  180. package/dist/dashboard/template-tests.js +141 -0
  181. package/dist/dashboard/template-tests.mjs +112 -0
  182. package/dist/dashboard/template-ui.js +20 -11
  183. package/dist/dashboard/template-ui.mjs +22 -13
  184. package/dist/dashboard/template-variant.js +185 -0
  185. package/dist/dashboard/template-variant.mjs +156 -0
  186. package/dist/icons/arrow-down-long.js +47 -0
  187. package/dist/icons/arrow-down-long.mjs +28 -0
  188. package/dist/icons/arrows-pointing-out.js +46 -0
  189. package/dist/icons/arrows-pointing-out.mjs +27 -0
  190. package/dist/icons/beaker.js +46 -0
  191. package/dist/icons/beaker.mjs +27 -0
  192. package/dist/icons/identification.js +46 -0
  193. package/dist/icons/identification.mjs +27 -0
  194. package/dist/icons/lifebuoy.js +46 -0
  195. package/dist/icons/lifebuoy.mjs +27 -0
  196. package/dist/icons/rectangle-group.js +46 -0
  197. package/dist/icons/rectangle-group.mjs +27 -0
  198. package/dist/icons/rectangle-stack.js +46 -0
  199. package/dist/icons/rectangle-stack.mjs +27 -0
  200. package/dist/icons/shopping-bag.js +46 -0
  201. package/dist/icons/shopping-bag.mjs +27 -0
  202. package/dist/icons/swatch.js +46 -0
  203. package/dist/icons/swatch.mjs +27 -0
  204. package/dist/icons/window.js +46 -0
  205. package/dist/icons/window.mjs +27 -0
  206. package/dist/icons/zoom-in.js +46 -0
  207. package/dist/icons/zoom-in.mjs +27 -0
  208. package/dist/input-answer.js +60 -0
  209. package/dist/input-answer.mjs +27 -0
  210. package/dist/input-checkbox.js +7 -1
  211. package/dist/input-checkbox.mjs +7 -1
  212. package/dist/input-name.js +3 -3
  213. package/dist/input-name.mjs +3 -3
  214. package/dist/input-select.js +3 -1
  215. package/dist/input-select.mjs +3 -1
  216. package/dist/provider-font.js +4 -3
  217. package/dist/provider-font.mjs +4 -3
  218. package/dist/shared/badge.js +15 -0
  219. package/dist/shared/badge.mjs +11 -0
  220. package/dist/shared/carousel.js +11 -7
  221. package/dist/shared/carousel.mjs +11 -7
  222. package/dist/shared/document-pieces.js +295 -0
  223. package/dist/shared/document-pieces.mjs +260 -0
  224. package/dist/shared/lib/campaign.js +3 -9
  225. package/dist/shared/lib/campaign.mjs +3 -9
  226. package/dist/shared/lib/helpers.js +24 -0
  227. package/dist/shared/lib/helpers.mjs +22 -0
  228. package/dist/shared/lib/video.js +6 -0
  229. package/dist/shared/lib/video.mjs +5 -0
  230. package/dist/shared/sortable.js +27 -10
  231. package/dist/shared/sortable.mjs +27 -10
  232. package/dist/shared/tabs.js +1 -1
  233. package/dist/shared/tabs.mjs +1 -1
  234. package/dist/video.js +127 -9
  235. package/dist/video.mjs +125 -11
  236. package/package.json +176 -20
  237. package/types/bridge/fields.d.ts +6 -1
  238. package/types/bridge/form-subdomain-agreement.d.ts +27 -0
  239. package/types/bridge/form-subdomain-missions.d.ts +2 -0
  240. package/types/bridge/form-subdomain.d.ts +62 -3
  241. package/types/bridge/lib/entry.d.ts +44 -7
  242. package/types/bridge/lib/order.d.ts +13 -2
  243. package/types/bridge/subdomain-content.d.ts +1 -0
  244. package/types/bridge/template-subdomain-gallery.d.ts +13 -1
  245. package/types/dashboard/campaign-form.d.ts +42 -0
  246. package/types/dashboard/card-campaign-agreement.d.ts +26 -0
  247. package/types/dashboard/card-campaign-switch.d.ts +20 -1
  248. package/types/dashboard/card-order.d.ts +2 -2
  249. package/types/dashboard/card-section.d.ts +9 -1
  250. package/types/dashboard/card-shortcut.d.ts +38 -0
  251. package/types/dashboard/card-tile.d.ts +4 -9
  252. package/types/dashboard/document-blocks.d.ts +14 -0
  253. package/types/dashboard/drawer.d.ts +3 -0
  254. package/types/dashboard/form-ai.d.ts +0 -17
  255. package/types/dashboard/form-organization-brand.d.ts +3 -0
  256. package/types/dashboard/form-organization-campaign-advertisements.d.ts +15 -0
  257. package/types/dashboard/form-organization-campaign-agreement.d.ts +53 -10
  258. package/types/dashboard/form-organization-campaign-design.d.ts +46 -0
  259. package/types/dashboard/form-organization-campaign-field-item.d.ts +36 -0
  260. package/types/dashboard/form-organization-campaign-field-number.d.ts +4 -1
  261. package/types/dashboard/form-organization-campaign-field-select.d.ts +6 -1
  262. package/types/dashboard/form-organization-campaign-field-skill.d.ts +36 -0
  263. package/types/dashboard/form-organization-campaign-field-text.d.ts +5 -1
  264. package/types/dashboard/form-organization-campaign-field-textarea.d.ts +4 -1
  265. package/types/dashboard/form-organization-campaign-footer.d.ts +23 -0
  266. package/types/dashboard/form-organization-campaign-integration-age.d.ts +2 -1
  267. package/types/dashboard/form-organization-campaign-integration-geocode.d.ts +2 -0
  268. package/types/dashboard/form-organization-campaign-page.d.ts +9 -15
  269. package/types/dashboard/form-organization-campaign-section.d.ts +24 -8
  270. package/types/dashboard/form-organization-campaign.d.ts +3 -0
  271. package/types/dashboard/form-organization-workflow.d.ts +3 -0
  272. package/types/dashboard/form-organization.d.ts +2 -2
  273. package/types/dashboard/form-reposition.d.ts +29 -0
  274. package/types/dashboard/form-support.d.ts +14 -0
  275. package/types/dashboard/form-tests.d.ts +78 -0
  276. package/types/dashboard/form-verify-prize.d.ts +30 -3
  277. package/types/dashboard/input-editor.d.ts +9 -0
  278. package/types/dashboard/input-fields.d.ts +8 -5
  279. package/types/dashboard/input-file.d.ts +4 -0
  280. package/types/dashboard/input-resource.d.ts +1 -0
  281. package/types/dashboard/lib/ab-tests.d.ts +50 -0
  282. package/types/dashboard/lib/escape.d.ts +4 -0
  283. package/types/dashboard/lib/focus.d.ts +16 -0
  284. package/types/dashboard/lib/form-page.d.ts +25 -0
  285. package/types/dashboard/lib/item-list.d.ts +10 -5
  286. package/types/dashboard/lib/rail.d.ts +0 -1
  287. package/types/dashboard/lib/sms.d.ts +7 -0
  288. package/types/dashboard/modal.d.ts +3 -1
  289. package/types/dashboard/preview.d.ts +65 -10
  290. package/types/dashboard/recharts.d.ts +3 -0
  291. package/types/dashboard/swatch.d.ts +4 -0
  292. package/types/dashboard/template-dashboard.d.ts +3 -0
  293. package/types/dashboard/template-design.d.ts +30 -0
  294. package/types/dashboard/template-test-page.d.ts +69 -0
  295. package/types/dashboard/template-tests.d.ts +30 -0
  296. package/types/dashboard/template-variant.d.ts +18 -0
  297. package/types/icons/arrow-down-long.d.ts +5 -0
  298. package/types/icons/arrows-pointing-out.d.ts +5 -0
  299. package/types/icons/beaker.d.ts +5 -0
  300. package/types/icons/identification.d.ts +5 -0
  301. package/types/icons/lifebuoy.d.ts +5 -0
  302. package/types/icons/rectangle-group.d.ts +5 -0
  303. package/types/icons/rectangle-stack.d.ts +5 -0
  304. package/types/icons/shopping-bag.d.ts +5 -0
  305. package/types/icons/swatch.d.ts +5 -0
  306. package/types/icons/window.d.ts +5 -0
  307. package/types/icons/zoom-in.d.ts +5 -0
  308. package/types/input-answer.d.ts +15 -0
  309. package/types/input-select.d.ts +2 -0
  310. package/types/shared/button.d.ts +1 -1
  311. package/types/shared/document-pieces.d.ts +34 -0
  312. package/types/shared/lib/helpers.d.ts +22 -1
  313. package/types/shared/lib/motion.d.ts +2 -0
  314. package/types/shared/lib/video.d.ts +3 -0
  315. package/types/shared/sortable.d.ts +6 -0
  316. package/types/video.d.ts +18 -2
  317. package/dist/bridge/template-preview.js +0 -208
  318. package/dist/bridge/template-preview.mjs +0 -173
  319. package/dist/dashboard/device.js +0 -95
  320. package/dist/dashboard/device.mjs +0 -72
  321. package/dist/dashboard/form-organization-campaign-field-list.js +0 -425
  322. package/dist/dashboard/form-organization-campaign-field-list.mjs +0 -396
  323. package/dist/dashboard/item-row.js +0 -92
  324. package/dist/dashboard/item-row.mjs +0 -63
  325. package/types/bridge/template-preview.d.ts +0 -10
  326. package/types/dashboard/device.d.ts +0 -12
  327. package/types/dashboard/form-organization-campaign-field-list.d.ts +0 -36
  328. package/types/dashboard/item-row.d.ts +0 -25
@@ -1,273 +1,472 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { useEffect } from "react";
2
+ import { useContext, useEffect, useRef } from "react";
3
+ import { useQueryClient } from "@tanstack/react-query";
3
4
  import { request } from "@drawbridge/drawbridge-utils/fetch";
4
- import { useForm, Controller, useWatch } from "../shared/lib/form.mjs";
5
- import yup, { resolver } from "../shared/lib/yup.mjs";
6
5
  import { regex } from "@drawbridge/drawbridge-utils";
6
+ import { FormScope, useForm, Controller, useWatch } from "../shared/lib/form.mjs";
7
+ import yup, { resolver } from "../shared/lib/yup.mjs";
7
8
  import Form from "../shared/form.mjs";
8
9
  import Fieldset from "../shared/fieldset.mjs";
9
10
  import InputGroup from "../input-group.mjs";
10
11
  import InputSwitch from "../shared/input-switch.mjs";
11
12
  import InputText from "../input-text.mjs";
12
13
  import InputUrl from "../shared/input-url.mjs";
13
- import Badge from "../shared/badge.mjs";
14
+ import InputCheckbox from "../input-checkbox.mjs";
15
+ import InputEditor from "./input-editor.mjs";
16
+ import documentBlocks from "./document-blocks.mjs";
17
+ import { useDrawer } from "./lib/hooks.mjs";
18
+ import InputRadio from "./input-radio.mjs";
14
19
  import Button from "../shared/button.mjs";
15
- const schema = (enforceLink) => yup.object({
20
+ import DocumentIcon from "../icons/document.mjs";
21
+ import LinkIcon from "../icons/link.mjs";
22
+ import CardCampaignAgreement, { CardCampaignAgreementChild } from "./card-campaign-agreement.mjs";
23
+ const TABS = ["document", "link"];
24
+ const TYPES = {
25
+ document: "Document",
26
+ link: "Link"
27
+ };
28
+ const content = (value) => JSON.stringify([value == null ? void 0 : value.type, (value == null ? void 0 : value.type) === "link" ? (value == null ? void 0 : value.link) || "" : (value == null ? void 0 : value.document) || "", (value == null ? void 0 : value.type) === "link" ? null : value == null ? void 0 : value.claimWindow]);
29
+ const hasText = (value) => Boolean(String(value || "").replace(/<div data-piece="[a-zA-Z]+"><\/div>/g, " piece ").replace(/<[^>]*>/g, "").trim());
30
+ const date = (at) => new Date(at).toLocaleDateString("en-US", {
31
+ day: "numeric",
32
+ month: "short",
33
+ year: "numeric"
34
+ });
35
+ const describe = (values) => {
36
+ if ((values == null ? void 0 : values.type) === "link") return (values == null ? void 0 : values.link) ? values.link.replace(/^https?:\/\//, "") : null;
37
+ return (values == null ? void 0 : values.saved) ? "Saved " + date(values.saved) : null;
38
+ };
39
+ const schema = (id) => yup.object({
40
+ claimWindow: yup.number().nullable(),
41
+ confirm: yup.boolean().when("enabled", ([enabled], field) => Boolean(enabled) ? field.oneOf([true], "Confirm this is correct before saving") : field),
42
+ document: yup.string().nullable().when(["enabled", "type"], ([enabled, type], field) => Boolean(enabled) && type === "document" ? field.test("text", "Document is a required field", hasText) : field),
16
43
  enabled: yup.boolean(),
17
- label: yup.string().label("Label").when("enabled", ([enabled], field) => Boolean(enabled) ? field.required().max(300) : field),
18
- link: yup.string().nullable().label("Link").when("enabled", ([enabled], field) => {
19
- if (!Boolean(enabled)) return field;
20
- const matches = [regex.url, "Url must start with https"];
21
- return enforceLink ? field.required().matches(...matches).url().max(300) : field.transform((value) => value ? value : null).matches(...matches).url().max(300);
22
- })
44
+ label: id === "privacy" ? yup.string().nullable().label("Label").max(300) : yup.string().nullable().label("Label").when("enabled", ([enabled], field) => Boolean(enabled) ? field.required().max(300) : field.max(300)),
45
+ link: yup.string().nullable().label("Link").when(["enabled", "type"], ([enabled, type], field) => Boolean(enabled) && type === "link" ? field.required().matches(regex.url, "Url must start with https").url().max(300) : field),
46
+ type: yup.string().oneOf(TABS)
23
47
  });
48
+ const Field = ({ control, error, label, message, name, render }) => /* @__PURE__ */ jsx(
49
+ Controller,
50
+ {
51
+ ...{
52
+ control,
53
+ name,
54
+ render: ({ field: { value, onChange } }) => /* @__PURE__ */ jsx(
55
+ InputGroup,
56
+ {
57
+ ...{
58
+ error,
59
+ input: render({ onChange, value }),
60
+ label,
61
+ message
62
+ }
63
+ }
64
+ )
65
+ }
66
+ }
67
+ );
24
68
  const FormOrganizationCampaignAgreement = ({
25
- agreements = {},
26
- defaultLabels = {},
27
- disabled,
28
- onChange,
69
+ agreement,
70
+ data,
71
+ defaultLabel,
72
+ enabledLock,
73
+ id,
29
74
  onError,
30
- onFocus,
31
75
  onSuccess,
32
- params
76
+ params,
77
+ readOnly
33
78
  }) => {
34
- const ids = Object.keys(agreements);
35
- const { control, getValues, handleSubmit, formState, reset } = useForm({
36
- defaultValues: Object.fromEntries(ids.map((id) => {
37
- var _a;
38
- return [id, ((_a = agreements[id]) == null ? void 0 : _a.values) || {}];
39
- })),
40
- resolver: resolver(
41
- yup.object(Object.fromEntries(ids.map((id) => {
42
- var _a;
43
- return [id, schema((_a = agreements[id]) == null ? void 0 : _a.enforceLink)];
44
- })))
45
- )
79
+ var _a, _b, _c, _d;
80
+ const { document: standard, types, values = {} } = agreement || {};
81
+ const queryClient = useQueryClient();
82
+ const scope = useContext(FormScope);
83
+ const tabs = TABS.filter((tab) => (types || TABS).includes(tab));
84
+ const saved = values.type || (values.link ? "link" : "document");
85
+ const { control, formState, handleSubmit, setValue } = useForm({
86
+ defaultValues: {
87
+ claimWindow: (data == null ? void 0 : data.claim) ?? null,
88
+ confirm: Boolean(values.confirmed),
89
+ document: values.document || (standard == null ? void 0 : standard.standard) || "",
90
+ enabled: Boolean(values.enabled),
91
+ label: values.label || "",
92
+ link: values.link || "",
93
+ type: tabs.includes(saved) ? saved : tabs[0]
94
+ },
95
+ resolver: resolver(schema(id))
46
96
  });
47
- const watched = useWatch({
97
+ const current = useWatch({
48
98
  control
49
99
  });
50
- const typed = JSON.stringify(watched);
100
+ const signature = content(current);
101
+ const first = useRef(signature);
51
102
  useEffect(
52
103
  () => {
53
- onChange == null ? void 0 : onChange(watched);
104
+ if (signature !== first.current) {
105
+ first.current = signature;
106
+ setValue("confirm", false);
107
+ }
54
108
  },
55
109
  // eslint-disable-next-line react-hooks/exhaustive-deps
56
- [typed]
110
+ [signature]
57
111
  );
58
- const onSubmit = async (values) => {
112
+ const editing = (current == null ? void 0 : current.type) === "document";
113
+ useEffect(
114
+ () => {
115
+ if (scope !== "modal") return;
116
+ queryClient.setQueryData(["modal"], (modal) => (modal == null ? void 0 : modal.active) ? {
117
+ ...modal,
118
+ wide: editing
119
+ } : modal);
120
+ },
121
+ [editing, queryClient, scope]
122
+ );
123
+ const claim = useRef();
124
+ claim.current = (days) => setValue("claimWindow", days, { shouldDirty: true });
125
+ const blocks = useRef(null);
126
+ blocks.current ??= documentBlocks({
127
+ data,
128
+ insertable: standard == null ? void 0 : standard.pieces,
129
+ onClaim: (days) => {
130
+ var _a2;
131
+ return (_a2 = claim.current) == null ? void 0 : _a2.call(claim, days);
132
+ }
133
+ });
134
+ const onSubmit = async ({ claimWindow, confirm, document, enabled, label, link, type }) => {
59
135
  try {
60
- let response;
61
- for (const id of ids.filter((id2) => {
62
- var _a;
63
- return (_a = formState == null ? void 0 : formState.dirtyFields) == null ? void 0 : _a[id2];
64
- })) {
65
- const { enabled, label, link } = values[id];
66
- response = await request({
67
- body: {
68
- enabled,
69
- label,
70
- link
136
+ const response = await request({
137
+ body: {
138
+ ...id === "terms" && Number.isInteger(claimWindow) && {
139
+ claimWindow
71
140
  },
72
- endpoint: "/organization/" + (params == null ? void 0 : params.organization) + "/campaign/" + (params == null ? void 0 : params.campaign) + "/agreement/" + id,
73
- method: "PUT"
74
- });
75
- }
76
- ;
77
- reset(getValues());
78
- if (response) onSuccess(response);
141
+ confirm,
142
+ document,
143
+ enabled,
144
+ label,
145
+ link,
146
+ type
147
+ },
148
+ endpoint: "/organization/" + (params == null ? void 0 : params.organization) + "/campaign/" + (params == null ? void 0 : params.campaign) + "/agreement/" + id,
149
+ method: "PUT"
150
+ });
151
+ onSuccess(response);
79
152
  } catch (error) {
80
153
  onError(error);
81
154
  }
82
155
  };
83
- const section = (id) => {
84
- var _a;
85
- const { active, title, warning } = agreements[id];
86
- const enabled = (_a = watched == null ? void 0 : watched[id]) == null ? void 0 : _a.enabled;
87
- const focus = () => onFocus == null ? void 0 : onFocus(id);
88
- return /* @__PURE__ */ jsxs(
89
- "section",
90
- {
91
- ...{
92
- className: "space-y-6",
93
- "data-guide": "section-" + id
94
- },
95
- children: [
96
- /* @__PURE__ */ jsxs(
97
- "h3",
98
- {
99
- ...{
100
- className: "flex items-center gap-2"
101
- },
102
- children: [
103
- title,
104
- warning && /* @__PURE__ */ jsx(
105
- Badge,
106
- {
107
- ...{
108
- size: "small",
109
- type: "error"
110
- },
111
- children: "Required"
112
- }
113
- )
114
- ]
115
- }
116
- ),
117
- /* @__PURE__ */ jsxs(
118
- Fieldset,
119
- {
120
- ...{
121
- // An agreement the api marks inactive can't be changed.
122
- disabled: disabled || !active || (formState == null ? void 0 : formState.isSubmitting)
123
- },
124
- children: [
125
- /* @__PURE__ */ jsx(
126
- Controller,
127
- {
128
- ...{
129
- control,
130
- name: id + ".enabled",
131
- render: ({ field: { value, onChange: change } }) => /* @__PURE__ */ jsx(
132
- InputGroup,
133
- {
134
- ...{
135
- input: /* @__PURE__ */ jsx(
136
- "span",
137
- {
138
- ...{
139
- className: "inline-flex",
140
- onFocus: focus
141
- },
142
- children: /* @__PURE__ */ jsx(
143
- InputSwitch,
144
- {
145
- ...{
146
- onChange: (next) => {
147
- focus();
148
- change(next);
149
- },
150
- value: value || false
151
- }
152
- }
153
- )
154
- }
155
- ),
156
- label: "Enabled"
156
+ const errors = (formState == null ? void 0 : formState.errors) || {};
157
+ const disabled = readOnly || (formState == null ? void 0 : formState.isSubmitting);
158
+ return /* @__PURE__ */ jsxs(
159
+ Form,
160
+ {
161
+ ...{
162
+ className: "flex flex-col gap-6 p-6",
163
+ onSubmit: handleSubmit(onSubmit)
164
+ },
165
+ children: [
166
+ /* @__PURE__ */ jsxs(
167
+ Fieldset,
168
+ {
169
+ ...{
170
+ className: "flex flex-col gap-6",
171
+ disabled
172
+ },
173
+ children: [
174
+ /* @__PURE__ */ jsx(
175
+ Field,
176
+ {
177
+ ...{
178
+ control,
179
+ label: "Enabled",
180
+ message: enabledLock,
181
+ name: "enabled",
182
+ render: ({ onChange, value }) => /* @__PURE__ */ jsx(
183
+ "span",
184
+ {
185
+ ...{
186
+ className: "inline-flex"
187
+ },
188
+ children: /* @__PURE__ */ jsx(
189
+ InputSwitch,
190
+ {
191
+ ...{
192
+ disabled: Boolean(enabledLock),
193
+ onChange,
194
+ value: value || false
195
+ }
157
196
  }
197
+ )
198
+ }
199
+ )
200
+ }
201
+ }
202
+ ),
203
+ /* @__PURE__ */ jsx(
204
+ Field,
205
+ {
206
+ ...{
207
+ control,
208
+ error: (_a = errors.label) == null ? void 0 : _a.message,
209
+ label: "Label",
210
+ name: "label",
211
+ render: ({ onChange, value }) => /* @__PURE__ */ jsx(
212
+ InputText,
213
+ {
214
+ ...{
215
+ onChange,
216
+ // The wording entrants see while SMS consent has no label of
217
+ // its own; Privacy's link text under Submit.
218
+ placeholder: id === "privacy" ? "Privacy policy" : defaultLabel,
219
+ value: value || ""
158
220
  }
159
- )
160
- }
221
+ }
222
+ )
161
223
  }
162
- ),
163
- (enabled || defaultLabels[id]) && /* @__PURE__ */ jsx(
164
- Controller,
165
- {
166
- ...{
167
- control,
168
- name: id + ".label",
169
- render: ({ field: { value, onChange: change } }) => {
170
- var _a2, _b, _c;
171
- return /* @__PURE__ */ jsx(
172
- InputGroup,
224
+ }
225
+ ),
226
+ tabs.length > 1 && /* @__PURE__ */ jsx(
227
+ InputGroup,
228
+ {
229
+ ...{
230
+ input: /* @__PURE__ */ jsx(
231
+ "div",
232
+ {
233
+ ...{
234
+ className: "flex gap-8"
235
+ },
236
+ children: TABS.map((tab) => /* @__PURE__ */ jsx(
237
+ "span",
173
238
  {
174
239
  ...{
175
- error: (_c = (_b = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2[id]) == null ? void 0 : _b.label) == null ? void 0 : _c.message,
176
- input: /* @__PURE__ */ jsx(
177
- InputText,
178
- {
179
- ...{
180
- onChange: change,
181
- onFocus: focus,
182
- ...enabled ? {
183
- value: value || ""
184
- } : {
185
- disabled: true,
186
- value: defaultLabels[id]
187
- }
188
- }
240
+ className: "w-auto"
241
+ },
242
+ children: /* @__PURE__ */ jsx(
243
+ InputRadio,
244
+ {
245
+ ...{
246
+ "aria-label": TYPES[tab],
247
+ checked: (current == null ? void 0 : current.type) === tab,
248
+ disabled: readOnly,
249
+ label: TYPES[tab],
250
+ onChange: () => setValue("type", tab, { shouldDirty: true }),
251
+ value: tab
189
252
  }
190
- ),
191
- label: "Label"
192
- }
193
- }
194
- );
253
+ }
254
+ )
255
+ },
256
+ tab
257
+ ))
195
258
  }
196
- }
259
+ ),
260
+ label: "Content"
197
261
  }
198
- ),
199
- enabled && /* @__PURE__ */ jsx(
200
- Controller,
201
- {
202
- ...{
203
- control,
204
- name: id + ".link",
205
- render: ({ field: { value, onChange: change } }) => {
206
- var _a2, _b, _c;
207
- return /* @__PURE__ */ jsx(
208
- InputGroup,
262
+ }
263
+ ),
264
+ editing ? /* @__PURE__ */ jsx(
265
+ Field,
266
+ {
267
+ ...{
268
+ control,
269
+ error: (_b = errors.document) == null ? void 0 : _b.message,
270
+ name: "document",
271
+ render: ({ onChange, value }) => /* @__PURE__ */ jsx(
272
+ "div",
273
+ {
274
+ ...{
275
+ // What the screen leaves under the modal's other rows ( 38rem ), so the
276
+ // tick and Save stay in view on a laptop:
277
+ // the editor's toolbar stays and only the text scrolls.
278
+ className: "document h-[calc(100vh-38rem)] min-h-[12rem] flex flex-col [&>div]:flex-1 [&>div]:min-h-0 [&>div]:flex [&>div]:flex-col [&>div>div:has(>.ProseMirror)]:flex-1 [&>div>div:has(>.ProseMirror)]:min-h-0 [&>div>div:has(>.ProseMirror)]:overflow-y-auto",
279
+ "data-document": true
280
+ },
281
+ children: /* @__PURE__ */ jsx(
282
+ InputEditor,
209
283
  {
210
284
  ...{
211
- error: (_c = (_b = (_a2 = formState == null ? void 0 : formState.errors) == null ? void 0 : _a2[id]) == null ? void 0 : _b.link) == null ? void 0 : _c.message,
212
- input: /* @__PURE__ */ jsx(
213
- InputUrl,
214
- {
215
- ...{
216
- onChange: change,
217
- onFocus: focus,
218
- value: value || ""
219
- }
220
- }
221
- ),
222
- label: "Link"
285
+ blocks: blocks.current,
286
+ disabled: readOnly,
287
+ onChange: ({ html }) => onChange(html),
288
+ value: value || ""
223
289
  }
224
290
  }
225
- );
291
+ )
226
292
  }
227
- }
293
+ )
228
294
  }
229
- )
230
- ]
231
- }
232
- )
233
- ]
234
- },
235
- id
236
- );
237
- };
238
- return /* @__PURE__ */ jsxs(
239
- Form,
295
+ },
296
+ "document"
297
+ ) : /* @__PURE__ */ jsx(
298
+ Field,
299
+ {
300
+ ...{
301
+ control,
302
+ error: (_c = errors.link) == null ? void 0 : _c.message,
303
+ label: "Link",
304
+ name: "link",
305
+ render: ({ onChange, value }) => /* @__PURE__ */ jsx(
306
+ InputUrl,
307
+ {
308
+ ...{
309
+ onChange,
310
+ value: value || ""
311
+ }
312
+ }
313
+ )
314
+ }
315
+ },
316
+ "link"
317
+ )
318
+ ]
319
+ }
320
+ ),
321
+ !readOnly && /* @__PURE__ */ jsxs(
322
+ Fieldset,
323
+ {
324
+ ...{
325
+ className: "flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 pt-6 border-t border-gray",
326
+ disabled
327
+ },
328
+ children: [
329
+ /* @__PURE__ */ jsx(
330
+ Field,
331
+ {
332
+ ...{
333
+ control,
334
+ error: (_d = errors.confirm) == null ? void 0 : _d.message,
335
+ name: "confirm",
336
+ render: ({ onChange, value }) => /* @__PURE__ */ jsx(
337
+ InputCheckbox,
338
+ {
339
+ ...{
340
+ id: "agreement-confirm-" + id,
341
+ label: "I confirm this is correct",
342
+ onChange,
343
+ value: Boolean(value)
344
+ }
345
+ }
346
+ )
347
+ }
348
+ }
349
+ ),
350
+ /* @__PURE__ */ jsx(
351
+ "span",
352
+ {
353
+ ...{
354
+ className: "sm:w-40 shrink-0"
355
+ },
356
+ children: /* @__PURE__ */ jsx(
357
+ Button,
358
+ {
359
+ ...{
360
+ loading: formState == null ? void 0 : formState.isSubmitting,
361
+ type: "submit"
362
+ },
363
+ children: "Save"
364
+ }
365
+ )
366
+ }
367
+ )
368
+ ]
369
+ }
370
+ )
371
+ ]
372
+ }
373
+ );
374
+ };
375
+ const FormOrganizationCampaignAgreements = ({
376
+ agreements = {},
377
+ data,
378
+ defaultLabels = {},
379
+ disabled,
380
+ onError,
381
+ onFocus,
382
+ onSuccess,
383
+ params
384
+ }) => {
385
+ const drawer = useDrawer({
386
+ queryClient: useQueryClient()
387
+ });
388
+ return /* @__PURE__ */ jsx(
389
+ "div",
240
390
  {
241
391
  ...{
242
- // Divided as the Page editor's form, Save under the last section.
243
- className: "relative w-full divide-y divide-gray [&>*]:py-6 [&>*:first-child]:pt-0 [&>*:last-child]:pb-0",
244
- onSubmit: handleSubmit(onSubmit)
392
+ className: "w-full divide-y divide-gray [&>*]:py-6 [&>*:first-child]:pt-0 [&>*:last-child]:pb-0"
245
393
  },
246
- children: [
247
- ids.map(section),
248
- /* @__PURE__ */ jsx(
249
- Fieldset,
394
+ children: Object.keys(agreements).map((id) => {
395
+ const agreement = agreements[id];
396
+ const { active, description, document: standard, title, values = {}, warning } = agreement;
397
+ const type = values.type || (values.link ? "link" : "document");
398
+ const manage = () => {
399
+ onFocus == null ? void 0 : onFocus(id);
400
+ drawer.open({
401
+ children: /* @__PURE__ */ jsx(
402
+ FormOrganizationCampaignAgreement,
403
+ {
404
+ ...{
405
+ agreement,
406
+ data,
407
+ defaultLabel: defaultLabels[id],
408
+ id,
409
+ onError,
410
+ onSuccess: (response) => {
411
+ drawer.close();
412
+ onSuccess(response);
413
+ },
414
+ params,
415
+ readOnly: disabled
416
+ }
417
+ }
418
+ ),
419
+ title
420
+ });
421
+ };
422
+ return /* @__PURE__ */ jsx(
423
+ CardCampaignAgreement,
250
424
  {
251
425
  ...{
252
- disabled: disabled || (formState == null ? void 0 : formState.isSubmitting)
426
+ "data-guide": "section-" + id,
427
+ description,
428
+ title
253
429
  },
254
430
  children: /* @__PURE__ */ jsx(
255
- Button,
431
+ "div",
256
432
  {
257
433
  ...{
258
- loading: formState == null ? void 0 : formState.isSubmitting,
259
- type: "submit"
434
+ "data-content": id
260
435
  },
261
- children: "Save"
436
+ children: /* @__PURE__ */ jsx(
437
+ CardCampaignAgreementChild,
438
+ {
439
+ ...{
440
+ badge: warning ? {
441
+ text: "Required",
442
+ type: "error"
443
+ } : values.enabled ? {
444
+ text: "On",
445
+ type: "success"
446
+ } : {
447
+ text: "Off",
448
+ type: "secondary"
449
+ },
450
+ disabled: !active,
451
+ icon: type === "link" ? LinkIcon : DocumentIcon,
452
+ line: describe({ ...values, type }),
453
+ onManage: manage,
454
+ title: type === "link" ? "Link" : standard == null ? void 0 : standard.name
455
+ }
456
+ }
457
+ )
262
458
  }
263
459
  )
264
- }
265
- )
266
- ]
460
+ },
461
+ id
462
+ );
463
+ })
267
464
  }
268
465
  );
269
466
  };
270
- var form_organization_campaign_agreement_default = FormOrganizationCampaignAgreement;
467
+ var form_organization_campaign_agreement_default = FormOrganizationCampaignAgreements;
271
468
  export {
272
- form_organization_campaign_agreement_default as default
469
+ FormOrganizationCampaignAgreement,
470
+ form_organization_campaign_agreement_default as default,
471
+ describe
273
472
  };