@drawbridge/components 0.1.25 → 0.1.27

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.
@@ -46,6 +46,7 @@ __export(form_organization_workflow_exports, {
46
46
  stepReason: () => stepReason,
47
47
  stepRow: () => stepRow,
48
48
  stepVariables: () => stepVariables,
49
+ useStepPrefill: () => useStepPrefill,
49
50
  webhookSample: () => webhookSample,
50
51
  workflowSchema: () => workflowSchema
51
52
  });
@@ -158,6 +159,17 @@ const prefillRow = ({ entry, step, steps = [] }) => {
158
159
  type: step
159
160
  });
160
161
  };
162
+ const useStepPrefill = ({ catalog, disabled, getValues, loading, setValue, step }) => {
163
+ const [settled, setSettled] = (0, import_react.useState)(false);
164
+ (0, import_react.useEffect)(() => setSettled(!loading), [loading]);
165
+ const prefilled = (0, import_react.useRef)(false);
166
+ (0, import_react.useEffect)(() => {
167
+ if (!settled || loading || disabled || prefilled.current) return;
168
+ prefilled.current = true;
169
+ const row = prefillRow({ entry: catalog, step, steps: getValues("steps") });
170
+ if (row) setValue("steps", [...getValues("steps"), row], { shouldDirty: true });
171
+ }, [catalog, disabled, getValues, loading, settled, setValue, step]);
172
+ };
161
173
  const pickedCopy = ({ row, type }) => {
162
174
  const previous = stepPrefills[row == null ? void 0 : row.type];
163
175
  const untouched = !!(previous == null ? void 0 : previous.subject) && (row == null ? void 0 : row.subject) === previous.subject && (row == null ? void 0 : row.message) === previous.message;
@@ -955,13 +967,7 @@ const FormOrganizationWorkflowEdit = ({
955
967
  const issueIndex = issueRow({ issue: values == null ? void 0 : values.issue, steps: watchedSteps || [] });
956
968
  const getAvailableVariables = (index) => stepVariables(catalog, watchedSteps, index);
957
969
  const loading = membersLoading || commerceConnection.isLoading;
958
- const prefilled = (0, import_react.useRef)(false);
959
- (0, import_react.useEffect)(() => {
960
- if (loading || disabled || prefilled.current) return;
961
- prefilled.current = true;
962
- const row = prefillRow({ entry: catalog, step: values == null ? void 0 : values.step, steps: getValues("steps") });
963
- if (row) setValue("steps", [...getValues("steps"), row], { shouldDirty: true });
964
- }, [catalog, disabled, getValues, loading, setValue, values == null ? void 0 : values.step]);
970
+ useStepPrefill({ catalog, disabled, getValues, loading, setValue, step: values == null ? void 0 : values.step });
965
971
  const getStepOptions = (index) => {
966
972
  const usedTypes = (watchedSteps || []).map((s, i) => i !== index ? s.type : null).filter(Boolean);
967
973
  return [
@@ -1637,6 +1643,7 @@ const FormOrganizationWorkflowEdit = ({
1637
1643
  stepReason,
1638
1644
  stepRow,
1639
1645
  stepVariables,
1646
+ useStepPrefill,
1640
1647
  webhookSample,
1641
1648
  workflowSchema
1642
1649
  });
@@ -106,6 +106,17 @@ const prefillRow = ({ entry, step, steps = [] }) => {
106
106
  type: step
107
107
  });
108
108
  };
109
+ const useStepPrefill = ({ catalog, disabled, getValues, loading, setValue, step }) => {
110
+ const [settled, setSettled] = useState(false);
111
+ useEffect(() => setSettled(!loading), [loading]);
112
+ const prefilled = useRef(false);
113
+ useEffect(() => {
114
+ if (!settled || loading || disabled || prefilled.current) return;
115
+ prefilled.current = true;
116
+ const row = prefillRow({ entry: catalog, step, steps: getValues("steps") });
117
+ if (row) setValue("steps", [...getValues("steps"), row], { shouldDirty: true });
118
+ }, [catalog, disabled, getValues, loading, settled, setValue, step]);
119
+ };
109
120
  const pickedCopy = ({ row, type }) => {
110
121
  const previous = stepPrefills[row == null ? void 0 : row.type];
111
122
  const untouched = !!(previous == null ? void 0 : previous.subject) && (row == null ? void 0 : row.subject) === previous.subject && (row == null ? void 0 : row.message) === previous.message;
@@ -903,13 +914,7 @@ const FormOrganizationWorkflowEdit = ({
903
914
  const issueIndex = issueRow({ issue: values == null ? void 0 : values.issue, steps: watchedSteps || [] });
904
915
  const getAvailableVariables = (index) => stepVariables(catalog, watchedSteps, index);
905
916
  const loading = membersLoading || commerceConnection.isLoading;
906
- const prefilled = useRef(false);
907
- useEffect(() => {
908
- if (loading || disabled || prefilled.current) return;
909
- prefilled.current = true;
910
- const row = prefillRow({ entry: catalog, step: values == null ? void 0 : values.step, steps: getValues("steps") });
911
- if (row) setValue("steps", [...getValues("steps"), row], { shouldDirty: true });
912
- }, [catalog, disabled, getValues, loading, setValue, values == null ? void 0 : values.step]);
917
+ useStepPrefill({ catalog, disabled, getValues, loading, setValue, step: values == null ? void 0 : values.step });
913
918
  const getStepOptions = (index) => {
914
919
  const usedTypes = (watchedSteps || []).map((s, i) => i !== index ? s.type : null).filter(Boolean);
915
920
  return [
@@ -1584,6 +1589,7 @@ export {
1584
1589
  stepReason,
1585
1590
  stepRow,
1586
1591
  stepVariables,
1592
+ useStepPrefill,
1587
1593
  webhookSample,
1588
1594
  workflowSchema
1589
1595
  };
@@ -363,6 +363,9 @@ const TemplateSocketOrganization = ({
363
363
  queryClient.invalidateQueries({
364
364
  queryKey: ["organization-segments", params.organization]
365
365
  });
366
+ queryClient.invalidateQueries({
367
+ queryKey: ["menu", "organization", params.organization]
368
+ });
366
369
  },
367
370
  "organization.export": () => {
368
371
  queryClient.invalidateQueries({
@@ -328,6 +328,9 @@ const TemplateSocketOrganization = ({
328
328
  queryClient.invalidateQueries({
329
329
  queryKey: ["organization-segments", params.organization]
330
330
  });
331
+ queryClient.invalidateQueries({
332
+ queryKey: ["menu", "organization", params.organization]
333
+ });
331
334
  },
332
335
  "organization.export": () => {
333
336
  queryClient.invalidateQueries({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drawbridge/components",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "exports": {
5
5
  "./advertisement": {
6
6
  "types": "./types/advertisement.d.ts",
@@ -132,6 +132,9 @@ export declare const stepVariables: ( entry: WorkflowCatalogEntry | null | undef
132
132
  // the catalog does not offer it to this member.
133
133
  export declare const prefillRow: ( options: { entry?: WorkflowCatalogEntry | null; step?: string | null; steps?: { type?: string }[] } ) => FormOrganizationWorkflowRow | null;
134
134
 
135
+ // Adds prefillRow's row to `steps` once, one render after `loading` ends.
136
+ export declare const useStepPrefill: ( options: { catalog?: WorkflowCatalogEntry | null; disabled?: boolean; getValues: ( name: 'steps' ) => FormOrganizationWorkflowRow[]; loading?: boolean; setValue: ( name: 'steps', value: FormOrganizationWorkflowRow[], options?: { shouldDirty?: boolean } ) => void; step?: string | null } ) => void;
137
+
135
138
  // "Needs a phone field" when the campaign's form cannot feed a step of `type`,
136
139
  // from the catalog entry or the saved steps; null when the step can run.
137
140
  export declare const stepReason: ( options: { entry?: WorkflowCatalogEntry | null; saved?: Array<{ reason?: string; type?: string; [ key: string ]: unknown }>; type?: string } ) => string | null;