Skip to content

Commit 871cd64

Browse files
committed
soem adjusts
1 parent aa0e4ce commit 871cd64

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

components/sendgrid/actions/create-send/create-send.mjs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,22 @@ export default {
3636
],
3737
description: "The recipient List IDs that will receive the Single Send.",
3838
optional: true,
39+
hidden: true,
3940
},
4041
segmentIds: {
4142
propDefinition: [
4243
common.props.sendgrid,
4344
"segmentIds",
4445
],
4546
optional: true,
47+
hidden: true,
4648
},
4749
all: {
4850
type: "boolean",
4951
label: "All",
5052
description: "Set to `true` to send to All Contacts. If set to `false`, at least one `List Ids` or `Segment Ids` value must be provided before the Single Send is scheduled to be sent to recipients.",
51-
optional: true,
53+
default: true,
54+
reloadProps: true,
5255
},
5356
subject: {
5457
type: "string",
@@ -92,9 +95,10 @@ export default {
9295
optional: true,
9396
},
9497
suppressionGroupId: {
95-
type: "integer",
96-
label: "Suppression Group Id",
97-
description: "The ID of the Suppression Group to allow recipients to unsubscribe — you must provide this or the `Custom Unsubscribe URL`.",
98+
propDefinition: [
99+
common.props.sendgrid,
100+
"asmGroupId",
101+
],
98102
optional: true,
99103
},
100104
customUnsubscribeUrl: {
@@ -117,9 +121,14 @@ export default {
117121
optional: true,
118122
},
119123
},
124+
async additionalProps(props) {
125+
props.listIds.hidden = this.all;
126+
props.segmentIds.hidden = this.all;
127+
return {};
128+
},
120129
async run({ $ }) {
121130
if (!this.suppressionGroupId && !this.customUnsubscribeUrl) {
122-
throw new ConfigurationError("You must provide either `Suppression Group Id` or the `Custom Unsubscribe URL`.");
131+
throw new ConfigurationError("You must provide either `ASM Group ID` or the `Custom Unsubscribe URL`.");
123132
}
124133
try {
125134
const resp = await this.sendgrid.createSingleSend({
@@ -129,8 +138,12 @@ export default {
129138
categories: parseObject(this.categoryIds),
130139
send_at: this.sendAt,
131140
send_to: {
132-
list_ids: parseObject(this.listIds),
133-
segment_ids: parseObject(this.segmentIds),
141+
list_ids: !this.all
142+
? parseObject(this.listIds)
143+
: null,
144+
segment_ids: !this.all
145+
? parseObject(this.segmentIds)
146+
: null,
134147
all: this.all,
135148
},
136149
email_config: {
@@ -150,16 +163,10 @@ export default {
150163
$.export("$summary", `Successfully created single send ${this.name}`);
151164
return resp;
152165
} catch (e) {
153-
if (
154-
e.response
155-
&& e.response.data
156-
&& e.response.data.errors
157-
&& e.response.data.errors.length > 0
158-
) {
159-
throw new ConfigurationError(e.response.data.errors[0].message);
160-
} else {
161-
throw new ConfigurationError("An unexpected error occurred.");
162-
}
166+
const errors = e.split("Unexpected error (status code: ERR_BAD_REQUEST):")[1];
167+
const errorJson = JSON.parse(errors);
168+
169+
throw new ConfigurationError(errorJson.data.errors[0].message);
163170
}
164171
},
165172
};

0 commit comments

Comments
 (0)