This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add lambda invocation form preset
- Loading branch information
1 parent
4ae93d8
commit fbda554
Showing
4 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,3 @@ | ||
import { extend, extract } from '../../../src/index.js' | ||
|
||
export default [extend('presets/base/typescript-cdk'), extract()] |
25 changes: 25 additions & 0 deletions
25
presets/library/lambda-invocation-form/templates/README.md
This file contains 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,25 @@ | ||
<p align="center"> | ||
<a href="https://buttonize.io"> | ||
<img width="350" alt="Buttonize.io" src="https://user-images.githubusercontent.com/6282843/212024942-9fd50774-ea26-48ba-b2cf-ca2584498c9a.png"> | ||
</a> | ||
</p> | ||
|
||
--- | ||
|
||
## Lambda Invocation Form | ||
|
||
[![Lambda Invocation Form](https://github.com/buttonize/create-buttonize/assets/6282843/97f71c7d-6a04-431d-bc0f-185019fbc056)](https://buttonize.io/library/lambda-invocation-form) | ||
|
||
Learn more about Lambda Invocation Form Construct [here](https://buttonize.io/library/lambda-invocation-form). | ||
|
||
## CDK | ||
|
||
The `cdk.json` file tells the CDK Toolkit how to execute your app. | ||
|
||
### Useful commands | ||
|
||
* `npm run build` compile typescript to js | ||
* `npm run watch` watch for changes and compile | ||
* `npx cdk deploy` deploy this stack to your default AWS account/region | ||
* `npx cdk diff` compare deployed stack with current state | ||
* `npx cdk synth` emits the synthesized CloudFormation template |
43 changes: 43 additions & 0 deletions
43
presets/library/lambda-invocation-form/templates/lib/example-stack.ts
This file contains 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,43 @@ | ||
import * as cdk from 'aws-cdk-lib' | ||
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs' | ||
import { Buttonize, Input } from 'buttonize/cdk' | ||
import { LambdaInvocationForm } from 'buttonize/library' | ||
import { Construct } from 'constructs' | ||
|
||
export class ExampleStack extends cdk.Stack { | ||
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props) | ||
|
||
Buttonize.init(this, { | ||
apiKey: '@@apiKey' | ||
}) | ||
|
||
const discountGenerator = new NodejsFunction(this, 'DiscountGenerator', { | ||
entry: 'src/discount-generator.ts' | ||
}) | ||
|
||
new LambdaInvocationForm(this, 'DiscountGeneratorForm', { | ||
lambda: discountGenerator, | ||
name: 'Discount code generator', | ||
description: 'Generate discount for unhappy customers', | ||
fields: [ | ||
Input.text({ | ||
id: 'email', | ||
label: `Customer's email address`, | ||
placeholder: 'example@domain.com' | ||
}), | ||
Input.select({ | ||
id: 'discount', | ||
label: 'Discount value', | ||
options: [ | ||
{ label: '30%', value: 30 }, | ||
{ label: '60%', value: 60 } | ||
] | ||
}) | ||
], | ||
instructions: `Sometimes there is bug in our e-commerce system and we need to offer our customers a discount to keep them **happy**. | ||
This tool generates a discount code for the customer and displays it on the following page.` | ||
}) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
presets/library/lambda-invocation-form/templates/src/discount-generator.ts
This file contains 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,15 @@ | ||
interface FormEvent { | ||
email: string | ||
discount: { | ||
label: string | ||
value: number | ||
} | ||
} | ||
export const handler = async (event: FormEvent) => { | ||
console.log(`Generating discount of value ${event.discount.value} for customer ${event.email}`) | ||
|
||
return { | ||
discountValuePercent: event.discount.value, | ||
discountCode: `${Math.random()}`.split('.')[1] | ||
} | ||
} |