Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 25bbbae

Browse files
committed
feat: add sns topic message form
1 parent bd8e5f0 commit 25bbbae

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { extend, extract } from '../../../src/index.js'
2+
3+
export default [extend('presets/base/typescript-cdk'), extract()]
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<p align="center">
2+
<a href="https://buttonize.io">
3+
<img width="350" alt="Buttonize.io" src="https://user-images.githubusercontent.com/6282843/212024942-9fd50774-ea26-48ba-b2cf-ca2584498c9a.png">
4+
</a>
5+
</p>
6+
7+
---
8+
9+
## SNS Topic Message Form
10+
11+
[![SNS Topic Message Form](https://github.com/buttonize/create-buttonize/assets/6282843/d7413ee8-ce95-4b81-a351-2740103aab65)](https://buttonize.io/library/sns-topic-message-form)
12+
13+
Learn more about SNS Topic Message Form Construct [here](https://buttonize.io/library/sns-topic-message-form).
14+
15+
## CDK
16+
17+
The `cdk.json` file tells the CDK Toolkit how to execute your app.
18+
19+
### Useful commands
20+
21+
* `npm run build` compile typescript to js
22+
* `npm run watch` watch for changes and compile
23+
* `npx cdk deploy` deploy this stack to your default AWS account/region
24+
* `npx cdk diff` compare deployed stack with current state
25+
* `npx cdk synth` emits the synthesized CloudFormation template
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import * as cdk from 'aws-cdk-lib'
2+
import { Topic } from 'aws-cdk-lib/aws-sns'
3+
import { EmailSubscription } from 'aws-cdk-lib/aws-sns-subscriptions'
4+
import { Buttonize, Input } from 'buttonize/cdk'
5+
import { SnsTopicMessageForm } from 'buttonize/library'
6+
import { Construct } from 'constructs'
7+
8+
export class ExampleStack extends cdk.Stack {
9+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
10+
super(scope, id, props)
11+
12+
Buttonize.init(this, {
13+
apiKey: '@@apiKey'
14+
})
15+
16+
const topic = new Topic(this, 'SnsTopic')
17+
18+
new SnsTopicMessageForm(this, 'TopicMessageForm', {
19+
name: 'Product cache invalidation panel',
20+
description:
21+
'Trigger invalidation of a product in all the caches in the in the company systems',
22+
topic,
23+
submitButtonLabel: 'Invalidate',
24+
fields: [
25+
Input.text({
26+
id: 'id',
27+
label: 'Product ID'
28+
}),
29+
Input.select({
30+
id: 'reason',
31+
options: [
32+
{
33+
label: 'New manual update',
34+
value: 'manual_update'
35+
},
36+
{
37+
label: 'System bug',
38+
value: 'bug'
39+
}
40+
]
41+
})
42+
],
43+
messagePayload: {
44+
operation: 'invalidate',
45+
product: {
46+
pid: '{{id}}'
47+
},
48+
metadata: {
49+
reasonStatement: '{{reason.value}}'
50+
}
51+
}
52+
})
53+
54+
topic.addSubscription(new EmailSubscription('[email protected]'))
55+
}
56+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
interface FormEvent {
2+
email: string
3+
discount: {
4+
label: string
5+
value: number
6+
}
7+
}
8+
export const handler = async (event: FormEvent) => {
9+
console.log(`Generating discount of value ${event.discount.value} for customer ${event.email}`)
10+
11+
return {
12+
discountValuePercent: event.discount.value,
13+
discountCode: `${Math.random()}`.split('.')[1]
14+
}
15+
}

0 commit comments

Comments
 (0)