-
Notifications
You must be signed in to change notification settings - Fork 77
Add Example to Crm Data Components to Demonstrate CrmCardActions
& CrmActionButton
#75
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
Open
breehall
wants to merge
3
commits into
main
Choose a base branch
from
bhall/crm-actions-examples
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
203 changes: 203 additions & 0 deletions
203
crm-data-components/src/app/extensions/ActionsExtension.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
import React, { useState, useMemo } from 'react'; | ||
import { | ||
Divider, | ||
Text, | ||
Flex, | ||
hubspot, | ||
Button, | ||
Select, | ||
ErrorState, | ||
} from '@hubspot/ui-extensions'; | ||
import { | ||
CrmPropertyList, | ||
CrmCardActions, | ||
CrmActionButton, | ||
} from '@hubspot/ui-extensions/crm'; | ||
|
||
// Define the extension to be run within the Hubspot CRM | ||
hubspot.extend(({ context, runServerlessFunction, actions }) => ( | ||
<Extension | ||
context={context} | ||
runServerless={runServerlessFunction} | ||
sendAlert={actions.addAlert} | ||
/> | ||
)); | ||
|
||
const scenariosToPropertiesMap: { [key: string]: string[] } = { | ||
contact: [ | ||
'jobtitle', | ||
'industry', | ||
'date_of_birth', | ||
'hs_language', | ||
'favorite_color', | ||
], | ||
engagement: [ | ||
'hs_sa_first_engagement_date', | ||
'hs_latest_source_data_1', | ||
'engagements_last_meeting_booked', | ||
'hs_email_sends_since_last_engagement', | ||
'hs_time_to_first_engagement', | ||
], | ||
deals: [ | ||
'hs_buying_role', | ||
'num_associated_deals', | ||
'recent_deal_amount', | ||
'recent_deal_close_date', | ||
], | ||
nps: [ | ||
'hs_feedback_show_nps_web_survey', | ||
'hs_feedback_last_survey_date', | ||
'hs_feedback_last_nps_rating', | ||
'hs_feedback_last_nps_follow_up', | ||
], | ||
}; | ||
|
||
const options: Array<{ label: string; value: string }> = [ | ||
{ label: 'Contact', value: 'contact' }, | ||
{ label: 'Engagement', value: 'engagement' }, | ||
{ label: 'Deal Summary', value: 'deals' }, | ||
{ label: 'NPS', value: 'nps' }, | ||
{ label: 'View Action Button Error', value: 'error' }, | ||
]; | ||
|
||
const Extension = ({ context, runServerless, sendAlert }) => { | ||
const [scenario, setScenario] = useState<string>('engagement'); | ||
const [error, setError] = useState<string[]>(); | ||
|
||
const currentObjectId = context.crm.objectId; | ||
const currentObjectTypeId = context.crm.objectTypeId; | ||
|
||
const actionsToPropertiesMap = useMemo(() => { | ||
return { | ||
contact: { | ||
label: 'View full record', | ||
actionType: 'PREVIEW_OBJECT', | ||
actionContext: { | ||
objectTypeId: currentObjectTypeId, | ||
objectId: currentObjectId, | ||
}, | ||
}, | ||
engagement: { | ||
label: 'Schedule an engagement call', | ||
actionType: 'SCHEDULE_MEETING', | ||
actionContext: { | ||
objectTypeId: currentObjectTypeId, | ||
objectId: currentObjectId, | ||
}, | ||
}, | ||
deals: { | ||
label: 'View the latest deal', | ||
actionType: 'PREVIEW_OBJECT', | ||
actionContext: { | ||
objectTypeId: '0-3', | ||
objectId: 18899287678, | ||
}, | ||
}, | ||
nps: { | ||
label: 'Email NPS Survey', | ||
actionType: 'SEND_EMAIL', | ||
actionContext: { | ||
objectTypeId: currentObjectTypeId, | ||
objectId: currentObjectId, | ||
}, | ||
}, | ||
error: { | ||
label: 'Action button is disabled', | ||
actionType: 'ADD_NOTE', | ||
actionContext: { | ||
// Missing actionContext will cause an error within CrmActionButton and disable the button | ||
}, | ||
}, | ||
}; | ||
}, [currentObjectTypeId, currentObjectId]); | ||
|
||
const { label, actionContext, actionType } = actionsToPropertiesMap[scenario]; | ||
|
||
return ( | ||
<> | ||
<CrmCardActions | ||
actionConfigs={[ | ||
{ | ||
type: 'dropdown', | ||
label: 'More', | ||
options: [ | ||
{ | ||
type: 'action-library-button', | ||
label: 'Send email', | ||
actionType: 'SEND_EMAIL', | ||
actionContext: { | ||
objectTypeId: currentObjectTypeId, | ||
objectId: currentObjectId, | ||
}, | ||
}, | ||
{ | ||
type: 'action-library-button', | ||
label: 'Add Note', | ||
actionType: 'ADD_NOTE', | ||
actionContext: { | ||
objectTypeId: currentObjectTypeId, | ||
objectId: currentObjectId, | ||
}, | ||
}, | ||
], | ||
}, | ||
]} | ||
/> | ||
|
||
<Text variant="microcopy"> | ||
This is example is a card to show different groups of properties based | ||
on the selected scenario. | ||
</Text> | ||
|
||
<Flex direction="row" align="end" gap="small"> | ||
<Select | ||
label="Property Group" | ||
name="property-group" | ||
tooltip="Please select a property group to view." | ||
value={scenario} | ||
onChange={(value) => { | ||
if (value.toString() !== 'error' && error) { | ||
setError(undefined); | ||
} | ||
|
||
setScenario(value.toString()); | ||
}} | ||
options={options} | ||
/> | ||
|
||
<CrmActionButton | ||
actionType={actionType} | ||
actionContext={actionContext} | ||
variant="primary" | ||
type="button" | ||
onError={(error) => { | ||
setError(error); | ||
}} | ||
> | ||
{label} | ||
</CrmActionButton> | ||
</Flex> | ||
|
||
<Divider /> | ||
|
||
{!error ? ( | ||
<CrmPropertyList | ||
properties={scenariosToPropertiesMap[scenario]} | ||
direction="row" | ||
/> | ||
) : ( | ||
<ErrorState title="Trouble fetching properties."> | ||
<Text>{error[0]}</Text> | ||
<Button | ||
onClick={() => { | ||
setError(undefined); | ||
setScenario('engagement'); | ||
}} | ||
> | ||
Reset Error State | ||
</Button> | ||
</ErrorState> | ||
)} | ||
</> | ||
); | ||
}; |
16 changes: 16 additions & 0 deletions
16
crm-data-components/src/app/extensions/actions-example-card.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"type": "crm-card", | ||
"data": { | ||
"title": "CRM Data: Crm Actions", | ||
"uid": "actions_example", | ||
"location": "crm.record.tab", | ||
"module": { | ||
"file": "ActionsExtension.tsx" | ||
}, | ||
"objectTypes": [ | ||
{ | ||
"name": "contacts" | ||
} | ||
] | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Probably don't need these if they aren't being used in your extension?
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.
It looks like all three props are required for
Extension
per its type. Even though they're not used, we may still want to leave them to prevent TS errors