-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathActionsExtension.tsx
169 lines (157 loc) · 4.14 KB
/
ActionsExtension.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import React, { useState } from "react";
import {
Divider,
Text,
Flex,
hubspot,
Form,
Select,
} 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" },
];
const Extension = ({ context, runServerless, sendAlert }) => {
const [scenario, setScenario] = useState<any>("engagement");
const currentObjectId = context.crm.objectId;
const currentObjectTypeId = context.crm.objectTypeId;
const actionsToPropertiesMap = {
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,
},
},
};
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">
<Form>
<Select
label="Property Group"
name="property-group"
tooltip="Please select a property group to view."
value={scenario}
onChange={(value) => setScenario(value)}
options={options}
/>
</Form>
<CrmActionButton
actionType={actionType}
actionContext={actionContext}
variant="primary"
type="button"
>
{label}
</CrmActionButton>
</Flex>
<Divider />
<CrmPropertyList
properties={scenariosToPropertiesMap[scenario]}
direction="row"
/>
</>
);
};