@drawbridge/components 0.1.26 → 0.1.28

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
  };
@@ -158,6 +158,14 @@ const TemplateSocketCampaign = ({
158
158
  };
159
159
  }
160
160
  );
161
+ if (leads) {
162
+ queryClient.invalidateQueries({
163
+ queryKey: ["campaign-sections", {
164
+ campaign: params == null ? void 0 : params.campaign
165
+ }]
166
+ });
167
+ }
168
+ ;
161
169
  },
162
170
  "campaign.advertisements": () => {
163
171
  queryClient.invalidateQueries({
@@ -186,6 +194,9 @@ const TemplateSocketCampaign = ({
186
194
  // the room after any time away has the same blind spot as an outage.
187
195
  resync: [
188
196
  ["campaign", params == null ? void 0 : params.campaign],
197
+ ["campaign-sections", {
198
+ campaign: params == null ? void 0 : params.campaign
199
+ }],
189
200
  ["campaign-advertisements", params == null ? void 0 : params.organization, params == null ? void 0 : params.campaign],
190
201
  ["organization-campaign-advertisement"],
191
202
  ["organization-campaign-prizes", params == null ? void 0 : params.organization, params == null ? void 0 : params.campaign]
@@ -123,6 +123,14 @@ const TemplateSocketCampaign = ({
123
123
  };
124
124
  }
125
125
  );
126
+ if (leads) {
127
+ queryClient.invalidateQueries({
128
+ queryKey: ["campaign-sections", {
129
+ campaign: params == null ? void 0 : params.campaign
130
+ }]
131
+ });
132
+ }
133
+ ;
126
134
  },
127
135
  "campaign.advertisements": () => {
128
136
  queryClient.invalidateQueries({
@@ -151,6 +159,9 @@ const TemplateSocketCampaign = ({
151
159
  // the room after any time away has the same blind spot as an outage.
152
160
  resync: [
153
161
  ["campaign", params == null ? void 0 : params.campaign],
162
+ ["campaign-sections", {
163
+ campaign: params == null ? void 0 : params.campaign
164
+ }],
154
165
  ["campaign-advertisements", params == null ? void 0 : params.organization, params == null ? void 0 : params.campaign],
155
166
  ["organization-campaign-advertisement"],
156
167
  ["organization-campaign-prizes", params == null ? void 0 : params.organization, params == null ? void 0 : params.campaign]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drawbridge/components",
3
- "version": "0.1.26",
3
+ "version": "0.1.28",
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;