-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - helpspot #14153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Components - helpspot #14153
Changes from all commits
a332e95
44ee8d9
1fe704f
674529d
9b86c1a
c6f56d4
4fb6cfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { | ||
NOTE_IS_HTML, | ||
NOTE_TYPE_OPTIONS, | ||
OPENED_VIA_OPTIONS, | ||
} from "../../common/constants.mjs"; | ||
import helpspot from "../../helpspot.app.mjs"; | ||
|
||
export default { | ||
props: { | ||
helpspot, | ||
tNote: { | ||
type: "string", | ||
label: "Note", | ||
description: "The note of the request", | ||
}, | ||
xCategory: { | ||
propDefinition: [ | ||
helpspot, | ||
"xCategory", | ||
], | ||
}, | ||
fNoteType: { | ||
type: "string", | ||
label: "Note Type", | ||
description: "The type of the note", | ||
options: NOTE_TYPE_OPTIONS, | ||
optional: true, | ||
}, | ||
fNoteIsHTML: { | ||
type: "string", | ||
label: "Note Is HTML?", | ||
description: "whether the note is HTML or text", | ||
optional: true, | ||
options: NOTE_IS_HTML, | ||
}, | ||
sTitle: { | ||
type: "string", | ||
label: "Subject", | ||
description: "The title used as email subject", | ||
optional: true, | ||
}, | ||
xStatus: { | ||
propDefinition: [ | ||
helpspot, | ||
"xStatus", | ||
], | ||
optional: true, | ||
}, | ||
sUserId: { | ||
type: "string", | ||
label: "User Id", | ||
description: "The Id of the customer", | ||
optional: true, | ||
}, | ||
sFirstName: { | ||
type: "string", | ||
label: "First Name", | ||
description: "The first name of the request creator", | ||
optional: true, | ||
}, | ||
sLastName: { | ||
type: "string", | ||
label: "Last Name", | ||
description: "The last name of the request creator", | ||
optional: true, | ||
}, | ||
sEmail: { | ||
type: "string", | ||
label: "Email", | ||
description: "The email of the request creator", | ||
optional: true, | ||
Comment on lines
+68
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Ensure valid email format for The |
||
}, | ||
sPhone: { | ||
type: "string", | ||
label: "Phone", | ||
description: "The phone number of the request creator", | ||
optional: true, | ||
}, | ||
fUrgent: { | ||
type: "boolean", | ||
label: "Urgent", | ||
description: "Whether the request is urgent or not", | ||
optional: true, | ||
}, | ||
fOpenedVia: { | ||
type: "integer", | ||
label: "Opened Via", | ||
description: "Request opened via", | ||
options: OPENED_VIA_OPTIONS, | ||
optional: true, | ||
}, | ||
emailFrom: { | ||
propDefinition: [ | ||
helpspot, | ||
"emailFrom", | ||
], | ||
optional: true, | ||
}, | ||
emailCC: { | ||
type: "string[]", | ||
label: "Email CC", | ||
description: "A list of emails to CC on the request", | ||
optional: true, | ||
}, | ||
emailBCC: { | ||
type: "string[]", | ||
label: "Email BCC", | ||
description: "A list of emails to BCC on the request", | ||
optional: true, | ||
}, | ||
Comment on lines
+99
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate email arrays The |
||
emailStaff: { | ||
propDefinition: [ | ||
helpspot, | ||
"emailStaff", | ||
], | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
await this.getValidation(); | ||
|
||
const fn = this.getFunction(); | ||
const response = await fn({ | ||
$, | ||
data: this.getData(), | ||
}); | ||
Comment on lines
+124
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential errors from the function call When invoking Consider wrapping the function call in a try-catch block: const fn = this.getFunction();
- const response = await fn({
- $,
- data: this.getData(),
- });
+ let response;
+ try {
+ response = await fn({
+ $,
+ data: this.getData(),
+ });
+ } catch (error) {
+ throw new Error(`Failed to execute function: ${error.message}`);
+ }
|
||
|
||
$.export("$summary", this.getSummary(response)); | ||
return response; | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { parseObject } from "../../common/utils.mjs"; | ||
import common from "../common/request-base.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "helpspot-create-request", | ||
name: "Create Request", | ||
description: "Creates a new user request. [See the documentation](https://support.helpspot.com/index.php?pg=kb.page&id=164#private.request.create)", | ||
version: "0.0.1", | ||
type: "action", | ||
methods: { | ||
getValidation() { | ||
if (!this.sFirstName && !this.sLastName && !this.sUserId && !this.sEmail && !this.sPhone) { | ||
throw new Error("You must provide at least one of the following: First Name, Last Name, User ID, Email, or Phone."); | ||
} | ||
}, | ||
getFunction() { | ||
return this.helpspot.createRequest; | ||
}, | ||
getData() { | ||
return { | ||
tNote: this.tNote, | ||
xCategory: this.xCategory, | ||
fNoteType: this.fNoteType && parseInt(this.fNoteType), | ||
fNoteIsHTML: this.fNoteIsHTML && parseInt(this.fNoteIsHTML), | ||
sTitle: this.sTitle, | ||
xStatus: this.xStatus, | ||
sUserId: this.sUserId, | ||
sFirstName: this.sFirstName, | ||
sLastName: this.sLastName, | ||
sEmail: this.sEmail, | ||
sPhone: this.sPhone, | ||
fUrgent: +this.fUrgent, | ||
fOpenedVia: this.fOpenedVia, | ||
email_from: this.emailFrom, | ||
email_cc: parseObject(this.emailCC)?.join(), | ||
email_bcc: parseObject(this.emailBCC)?.join(), | ||
email_staff: parseObject(this.emailStaff)?.join(), | ||
}; | ||
}, | ||
getSummary(response) { | ||
return `Successfully created request with Id: ${response.xRequest}`; | ||
}, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { parseObject } from "../../common/utils.mjs"; | ||
import common from "../common/request-base.mjs"; | ||
|
||
export default { | ||
...common, | ||
key: "helpspot-update-request", | ||
name: "Update Request", | ||
description: "Updates an existing user request. [See the documentation](https://support.helpspot.com/index.php?pg=kb.page&id=164#private.request.update)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
...common.props, | ||
xRequest: { | ||
propDefinition: [ | ||
common.props.helpspot, | ||
"xRequest", | ||
], | ||
}, | ||
}, | ||
methods: { | ||
getValidation() { | ||
return true; | ||
}, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
getFunction() { | ||
return this.helpspot.updateRequest; | ||
}, | ||
getData() { | ||
return { | ||
xRequest: this.xRequest, | ||
tNote: this.tNote, | ||
xCategory: this.xCategory, | ||
fNoteType: this.fNoteType && parseInt(this.fNoteType), | ||
fNoteIsHTML: this.fNoteIsHTML && parseInt(this.fNoteIsHTML), | ||
sTitle: this.sTitle, | ||
xStatus: this.xStatus, | ||
sUserId: this.sUserId, | ||
sFirstName: this.sFirstName, | ||
sLastName: this.sLastName, | ||
sEmail: this.sEmail, | ||
sPhone: this.sPhone, | ||
fUrgent: +this.fUrgent, | ||
fOpenedVia: this.fOpenedVia, | ||
email_from: this.emailFrom, | ||
email_cc: parseObject(this.emailCC)?.join(), | ||
email_bcc: parseObject(this.emailBCC)?.join(), | ||
email_staff: parseObject(this.emailStaff)?.join(), | ||
}; | ||
}, | ||
getSummary() { | ||
return `Successfully updated request with ID ${this.xRequest}`; | ||
}, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
export const LIMIT = 100; | ||
|
||
export const NOTE_TYPE_OPTIONS = [ | ||
{ | ||
label: "Private", | ||
value: "0", | ||
}, | ||
{ | ||
label: "Public", | ||
value: "1", | ||
}, | ||
{ | ||
label: "External", | ||
value: "2", | ||
}, | ||
]; | ||
|
||
export const NOTE_IS_HTML = [ | ||
{ | ||
label: "Text", | ||
value: "0", | ||
}, | ||
{ | ||
label: "HTML", | ||
value: "1", | ||
}, | ||
]; | ||
|
||
export const OPENED_VIA_OPTIONS = [ | ||
{ | ||
label: "Email", | ||
value: 1, | ||
}, | ||
{ | ||
label: "Phone", | ||
value: 2, | ||
}, | ||
{ | ||
label: "Walk In", | ||
value: 3, | ||
}, | ||
{ | ||
label: "Mail", | ||
value: 4, | ||
}, | ||
{ | ||
label: "Other", | ||
value: 5, | ||
}, | ||
{ | ||
label: "Web Service", | ||
value: 6, | ||
}, | ||
{ | ||
label: "Web Form", | ||
value: 7, | ||
}, | ||
{ | ||
label: "Forum", | ||
value: 8, | ||
}, | ||
{ | ||
label: "Instant Messenger", | ||
value: 9, | ||
}, | ||
{ | ||
label: "Fax", | ||
value: 10, | ||
}, | ||
{ | ||
label: "Voicemail", | ||
value: 11, | ||
}, | ||
{ | ||
label: "Staff Initiated", | ||
value: 12, | ||
}, | ||
{ | ||
label: "Tab Widget", | ||
value: 13, | ||
}, | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export const parseObject = (obj) => { | ||
if (!obj) return undefined; | ||
|
||
if (Array.isArray(obj)) { | ||
return obj.map((item) => { | ||
if (typeof item === "string") { | ||
try { | ||
return JSON.parse(item); | ||
} catch (e) { | ||
return item; | ||
} | ||
} | ||
return item; | ||
}); | ||
} | ||
if (typeof obj === "string") { | ||
try { | ||
return JSON.parse(obj); | ||
} catch (e) { | ||
return obj; | ||
} | ||
} | ||
return obj; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider changing
fNoteIsHTML
type toboolean
The
fNoteIsHTML
property indicates whether the note is HTML or text. Currently, its type is set to"string"
, but since it represents a boolean value, it would be more appropriate to set its type to"boolean"
. This enhances type correctness and improves clarity.Apply this diff to adjust the type:
📝 Committable suggestion