Skip to content

Commit 737e016

Browse files
committed
Take example app from getting started template
1 parent c5b10de commit 737e016

File tree

6 files changed

+43
-1939
lines changed

6 files changed

+43
-1939
lines changed

components/example-app/app.functions/example-function.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
exports.main = async (context = {}, sendResponse) => {
1+
exports.main = (context = {}, sendResponse) => {
22
const { text } = context.parameters;
33

4-
const ret = `This is coming from a serverless function! You entered: ${text}`;
4+
const response = `This is coming from a serverless function! You entered: ${text}`;
5+
56
try {
6-
sendResponse(ret);
7+
sendResponse(response);
78
} catch (error) {
89
sendResponse(error);
910
}

components/example-app/app.functions/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2-
"name": "example-function",
2+
"name": "hubspot-example-function",
33
"version": "0.1.0",
4-
"description": "",
5-
"main": "example-function.js",
64
"author": "HubSpot",
75
"license": "MIT",
86
"dependencies": {

components/example-app/app.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "Get started App with React",
3-
"description": "This is an example of private app that shows a custom card on the Contact record tab built with React-based frontend. This card demonstrates simple handshake with HubSpot's serverless backend.",
2+
"name": "Get started App",
3+
"description": "This is an example private app that shows a custom card on the Contact record tab built with React-based frontend. This card demonstrates a simple handshake with HubSpot's serverless backend.",
44
"uid": "get_started_app",
55
"scopes": ["crm.objects.contacts.read", "crm.objects.contacts.write"],
66
"public": false,
Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import React, { useState } from 'react';
1+
import React, { useState } from "react";
22
import {
33
Divider,
44
Link,
55
Button,
66
Text,
77
Input,
8-
Stack,
8+
Flex,
99
hubspot,
10-
} from '@hubspot/ui-extensions';
10+
} from "@hubspot/ui-extensions";
1111

1212
// Define the extension to be run within the Hubspot CRM
1313
hubspot.extend(({ context, runServerlessFunction, actions }) => (
@@ -20,60 +20,57 @@ hubspot.extend(({ context, runServerlessFunction, actions }) => (
2020

2121
// Define the Extension component, taking in runServerless, context, & sendAlert as props
2222
const Extension = ({ context, runServerless, sendAlert }) => {
23-
const [text, setText] = useState('');
23+
const [text, setText] = useState("");
2424

2525
// Call serverless function to execute with parameters.
26-
// The name `myFunc` as per configurations inside `serverless.json`
27-
28-
const run = () => {
29-
runServerless({ name: 'myFunc', parameters: { text: text } }).then((resp) =>
26+
// The `myFunc` function name is configured inside `serverless.json`
27+
const handleClick = () => {
28+
runServerless({ name: "myFunc", parameters: { text: text } }).then((resp) =>
3029
sendAlert({ message: resp.response })
3130
);
3231
};
3332

3433
return (
3534
<>
3635
<Text>
37-
<Text format={{ fontWeight: 'bold' }}>
36+
<Text format={{ fontWeight: "bold" }}>
3837
Your first UI extension is ready!
3938
</Text>
4039
Congratulations, {context.user.firstName}! You just deployed your first
4140
HubSpot UI extension. This example demonstrates how you would send
4241
parameters from your React frontend to the serverless function and get a
4342
response back.
4443
</Text>
45-
<Stack>
44+
<Flex direction="row" align="end" gap="small">
4645
<Input name="text" label="Send" onInput={(t) => setText(t)} />
47-
<Button type="submit" onClick={run}>
46+
<Button type="submit" onClick={handleClick}>
4847
Click me
4948
</Button>
50-
</Stack>
49+
</Flex>
5150
<Divider />
52-
<Stack>
53-
<Text>
54-
What now? Explore all available{' '}
55-
<Link href="https://developers.hubspot.com/docs/platform/ui-extension-components">
56-
UI components
57-
</Link>
58-
, get an overview of{' '}
59-
<Link href="https://developers.hubspot.com/docs/platform/ui-extensions-overview">
60-
UI extensions
61-
</Link>
62-
, learn how to{' '}
63-
<Link href="https://developers.hubspot.com/docs/platform/create-ui-extensions">
64-
add a new custom card
65-
</Link>
66-
, jump right in with our{' '}
67-
<Link href="https://developers.hubspot.com/docs/platform/ui-extensions-quickstart">
68-
Quickstart Guide
69-
</Link>
70-
, or check out our{' '}
71-
<Link href="https://github.com/HubSpot/ui-extensions-react-examples">
72-
code Samples
73-
</Link>
74-
.
75-
</Text>
76-
</Stack>
51+
<Text>
52+
What now? Explore all available{" "}
53+
<Link href="https://developers.hubspot.com/docs/platform/ui-extension-components">
54+
UI components
55+
</Link>
56+
, get an overview of{" "}
57+
<Link href="https://developers.hubspot.com/docs/platform/ui-extensions-overview">
58+
UI extensions
59+
</Link>
60+
, learn how to{" "}
61+
<Link href="https://developers.hubspot.com/docs/platform/create-ui-extensions">
62+
add a new custom card
63+
</Link>
64+
, jump right in with our{" "}
65+
<Link href="https://developers.hubspot.com/docs/platform/ui-extensions-quickstart">
66+
Quickstart Guide
67+
</Link>
68+
, or check out our{" "}
69+
<Link href="https://github.com/HubSpot/ui-extensions-react-examples">
70+
code Samples
71+
</Link>
72+
.
73+
</Text>
7774
</>
7875
);
7976
};

0 commit comments

Comments
 (0)