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

Commit fbda554

Browse files
committed
feat: add lambda invocation form preset
1 parent 4ae93d8 commit fbda554

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-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+
## Lambda Invocation Form
10+
11+
[![Lambda Invocation Form](https://github.com/buttonize/create-buttonize/assets/6282843/97f71c7d-6a04-431d-bc0f-185019fbc056)](https://buttonize.io/library/lambda-invocation-form)
12+
13+
Learn more about Lambda Invocation Form Construct [here](https://buttonize.io/library/lambda-invocation-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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as cdk from 'aws-cdk-lib'
2+
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs'
3+
import { Buttonize, Input } from 'buttonize/cdk'
4+
import { LambdaInvocationForm } from 'buttonize/library'
5+
import { Construct } from 'constructs'
6+
7+
export class ExampleStack extends cdk.Stack {
8+
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
9+
super(scope, id, props)
10+
11+
Buttonize.init(this, {
12+
apiKey: '@@apiKey'
13+
})
14+
15+
const discountGenerator = new NodejsFunction(this, 'DiscountGenerator', {
16+
entry: 'src/discount-generator.ts'
17+
})
18+
19+
new LambdaInvocationForm(this, 'DiscountGeneratorForm', {
20+
lambda: discountGenerator,
21+
name: 'Discount code generator',
22+
description: 'Generate discount for unhappy customers',
23+
fields: [
24+
Input.text({
25+
id: 'email',
26+
label: `Customer's email address`,
27+
placeholder: 'example@domain.com'
28+
}),
29+
Input.select({
30+
id: 'discount',
31+
label: 'Discount value',
32+
options: [
33+
{ label: '30%', value: 30 },
34+
{ label: '60%', value: 60 }
35+
]
36+
})
37+
],
38+
instructions: `Sometimes there is bug in our e-commerce system and we need to offer our customers a discount to keep them **happy**.
39+
40+
This tool generates a discount code for the customer and displays it on the following page.`
41+
})
42+
}
43+
}
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)