Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QRcode block #1142

Merged
merged 5 commits into from
Jan 11, 2024
Merged

QRcode block #1142

merged 5 commits into from
Jan 11, 2024

Conversation

dkashikar
Copy link
Contributor

@dkashikar dkashikar commented Jan 10, 2024

This block is able to :

  1. Show a QrCode
  2. Optionally link to an external url

Summary by CodeRabbit

  • New Features
    • Introduced QR code creation and display capabilities in the app.
    • Added a new component for rendering QR code images.

Copy link

vercel bot commented Jan 10, 2024

@dkashikar is attempting to deploy a commit to the Typebot Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Jan 10, 2024

Walkthrough

The @typebot.io/forge package has been updated to include functionality for creating a QR code block and associated actions for generating and displaying QR codes. A new React component, QrCodeLogo, has been introduced to render SVG images of QR codes. The package's repository and schemas have been updated to enable the 'qr-code' block within the forge framework.

Changes

Files Change Summary
.../blocks/qrcode/index.ts
.../blocks/qrcode/actions/
Introduced functionality for creating and converting QR codes. Moved functionality from convertQr.ts to generateQrCodeImage.ts.
.../blocks/qrcode/logo.tsx Added a new QrCodeLogo React component to render SVG QR code images.
.../repository/index.ts
.../schemas/index.ts
Updated to include 'qr-code' in enabledBlocks and in the forgedBlocks array.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 73d68f0 and e3bdd33.
Files ignored due to filter (4)
  • packages/forge/blocks/qrcode/package.json
  • packages/forge/blocks/qrcode/tsconfig.json
  • packages/forge/schemas/package.json
  • pnpm-lock.yaml
Files selected for processing (5)
  • packages/forge/blocks/qrcode/actions/displayQr.ts (1 hunks)
  • packages/forge/blocks/qrcode/index.ts (1 hunks)
  • packages/forge/blocks/qrcode/logo.tsx (1 hunks)
  • packages/forge/repository/index.ts (1 hunks)
  • packages/forge/schemas/index.ts (2 hunks)
Files skipped from review due to trivial changes (2)
  • packages/forge/blocks/qrcode/logo.tsx
  • packages/forge/repository/index.ts
Additional comments: 2
packages/forge/blocks/qrcode/index.ts (1)
  • 1-11: The block definition for qrcode looks correct and follows the expected structure for defining a new block within the @typebot.io/forge package. The use of createBlock with the appropriate properties such as id, name, tags, LightLogo, and actions is consistent with the package's design patterns.
packages/forge/schemas/index.ts (1)
  • 1-5: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [2-20]

The import of qrcode from @typebot.io/qrcode-block and its addition to the forgedBlocks array are correctly implemented. This change will ensure that the qrcode block is registered and available for use within the forge package.

Comment on lines 5 to 37
export const displayQr = createAction({
name: 'Display Qr',
options: option.object({
qrvalue: option.string.layout({
label: 'Qr Code',
helperText: 'QR code to show'
}),
qrlink: option.string.layout({
label: 'Qr link',
helperText: 'Link to goto on tapping QR code'
}),
}),
run: {
web: {
displayEmbedBubble: {
parseInitFunction: ({ options }) => {
if (!options.qrvalue) throw new Error('Missing Qr Code')
var qr = qrcode(8, 'L');
qr.addData(options.qrvalue);
qr.make();
const qrvalue = qr.createDataURL();
return {
args: {
qrvalue: qrvalue,
qrlink: options.qrlink ?? null
},
content: `let qr = document.createElement("img");qr.src = qrvalue;qr.classList.add('w-full');; let link = document.createElement("a"); link.href = qrlink; link.target = '_blank'; link.appendChild(qr); typebotElement.appendChild(qrlink ? link : qr);`,
}
},
},
}
},
})
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The displayQr action is well-defined with clear options for qrvalue and qrlink. The error handling for a missing qrvalue is appropriate. However, the run method's parseInitFunction contains a script that is directly manipulating the DOM, which could be improved for maintainability and security reasons. It's recommended to abstract this logic into a separate, sanitized function or use a framework-specific way to manipulate the DOM if available.

- content: `let qr = document.createElement("img");qr.src = qrvalue;qr.classList.add('w-full');; let link = document.createElement("a"); link.href = qrlink; link.target = '_blank'; link.appendChild(qr); typebotElement.appendChild(qrlink ? link : qr);`,
+ // It's recommended to abstract this logic into a separate function or use a framework-specific way to manipulate the DOM.

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
export const displayQr = createAction({
name: 'Display Qr',
options: option.object({
qrvalue: option.string.layout({
label: 'Qr Code',
helperText: 'QR code to show'
}),
qrlink: option.string.layout({
label: 'Qr link',
helperText: 'Link to goto on tapping QR code'
}),
}),
run: {
web: {
displayEmbedBubble: {
parseInitFunction: ({ options }) => {
if (!options.qrvalue) throw new Error('Missing Qr Code')
var qr = qrcode(8, 'L');
qr.addData(options.qrvalue);
qr.make();
const qrvalue = qr.createDataURL();
return {
args: {
qrvalue: qrvalue,
qrlink: options.qrlink ?? null
},
content: `let qr = document.createElement("img");qr.src = qrvalue;qr.classList.add('w-full');; let link = document.createElement("a"); link.href = qrlink; link.target = '_blank'; link.appendChild(qr); typebotElement.appendChild(qrlink ? link : qr);`,
}
},
},
}
},
})
export const displayQr = createAction({
name: 'Display Qr',
options: option.object({
qrvalue: option.string.layout({
label: 'Qr Code',
helperText: 'QR code to show'
}),
qrlink: option.string.layout({
label: 'Qr link',
helperText: 'Link to goto on tapping QR code'
}),
}),
run: {
web: {
displayEmbedBubble: {
parseInitFunction: ({ options }) => {
if (!options.qrvalue) throw new Error('Missing Qr Code')
var qr = qrcode(8, 'L');
qr.addData(options.qrvalue);
qr.make();
const qrvalue = qr.createDataURL();
return {
args: {
qrvalue: qrvalue,
qrlink: options.qrlink ?? null
},
// It's recommended to abstract this logic into a separate function or use a framework-specific way to manipulate the DOM.
}
},
},
}
},
})

@baptisteArno
Copy link
Owner

Hey!

That's a nice idea 👍

The qrcode-generator package (https://github.com/kazuhikoarase/qrcode-generator#readme) was not update since 3 years. I'd prefer we use the most recent and popular package: https://github.com/soldair/node-qrcode

@baptisteArno
Copy link
Owner

I also think it would be better to generate the QR Code as an image URL that can be then used in an Image bubble. So that we can use this block on other environment like whatsapp

@dkashikar
Copy link
Contributor Author

Thanks.

Hey!

That's a nice idea 👍

The qrcode-generator package (https://github.com/kazuhikoarase/qrcode-generator#readme) was not update since 3 years. I'd prefer we use the most recent and popular package: https://github.com/soldair/node-qrcode

i can rewrite using this package

I also think it would be better to generate the QR Code as an image URL that can be then used in an Image bubble. So that we can use this block on other environment like whatsapp

super. have done this.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e3bdd33 and c44fd07.
Files ignored due to filter (2)
  • packages/forge/blocks/qrcode/package.json
  • pnpm-lock.yaml
Files selected for processing (3)
  • packages/forge/blocks/qrcode/actions/convertQr.ts (1 hunks)
  • packages/forge/blocks/qrcode/index.ts (1 hunks)
  • packages/forge/blocks/qrcode/logo.tsx (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/forge/blocks/qrcode/logo.tsx
Additional comments: 1
packages/forge/blocks/qrcode/index.ts (1)
  • 1-11: The implementation of the qrcode block appears to be correct and follows the expected pattern for block creation within the @typebot.io/forge framework. The use of createBlock with the appropriate properties and the inclusion of QrcodeLogo and convertQr suggest that the block is well-integrated with the necessary functionality for QR code generation and display.

packages/forge/blocks/qrcode/actions/convertQr.ts Outdated Show resolved Hide resolved
Made the error messages more user-friendly

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c44fd07 and 2ef763b.
Files selected for processing (1)
  • packages/forge/blocks/qrcode/actions/convertQr.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/forge/blocks/qrcode/actions/convertQr.ts

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2ef763b and f9d3571.
Files selected for processing (7)
  • packages/forge/blocks/qrcode/actions/generateQrCodeImage.ts (1 hunks)
  • packages/forge/blocks/qrcode/index.ts (1 hunks)
  • packages/forge/blocks/qrcode/logo.tsx (1 hunks)
  • packages/forge/core/index.ts (2 hunks)
  • packages/forge/core/types.ts (2 hunks)
  • packages/forge/repository/index.ts (1 hunks)
  • packages/forge/schemas/index.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • packages/forge/repository/index.ts
Files skipped from review as they are similar to previous changes (2)
  • packages/forge/blocks/qrcode/index.ts
  • packages/forge/blocks/qrcode/logo.tsx
Additional comments: 8
packages/forge/schemas/index.ts (2)
  • 2-2: The import of qrCode is correctly added and follows the existing pattern of imports.

  • 20-20: The addition of qrCode to the forgedBlocks array aligns with the PR objectives to integrate QR code functionality into the forge package.

packages/forge/blocks/qrcode/actions/generateQrCodeImage.ts (2)
  • 1-4: The import statements are correctly added and follow the existing pattern of imports.

  • 6-40: The generateQrCode action is well-defined with clear options and error handling, aligning with the PR objectives to generate and display QR codes.

packages/forge/core/types.ts (2)
  • 3-3: The import of ZodRawShape is correctly added and is necessary for the modifications made to the ActionDefinition type.

  • 32-33: The modifications to the ActionDefinition type, specifying default generic types for BaseOptions and Options, are appropriate and align with the PR objectives.

packages/forge/core/index.ts (2)
  • 1-1: The import of ZodRawShape is correctly added and is necessary for the modifications made to the createAction function.

  • 22-23: The modifications to the createAction function's type declarations, specifically for the BaseOptions and O parameters, are appropriate and align with the PR objectives.

@baptisteArno
Copy link
Owner

@dkashikar I've renamed things to proper camel case when necessary and I also properly set up the image generation so that it is uploaded to S3 instance. Otherwise, a data URI can't be used in WhatsApp.

Thanks again for your work!

Copy link

vercel bot commented Jan 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
builder-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 10, 2024 5:05pm

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f9d3571 and f3f71e3.
Files selected for processing (1)
  • packages/forge/blocks/qrcode/actions/generateQrCodeImage.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/forge/blocks/qrcode/actions/generateQrCodeImage.ts

@baptisteArno baptisteArno merged commit 799c694 into baptisteArno:main Jan 11, 2024
1 of 4 checks passed
@baptisteArno
Copy link
Owner

Thanks again for your work @dkashikar. 🙏

Let me know if there's anything we can improve in terms of DX.

@dkashikar
Copy link
Contributor Author

Thank you @baptisteArno
I was also thinking of having a password kind of input field. Basically masking the input with *.
I am planning to use the bot on kiosks. So having some input hidden would be a good idea.

@baptisteArno
Copy link
Owner

Thank you @baptisteArno I was also thinking of having a password kind of input field. Basically masking the input with *. I am planning to use the bot on kiosks. So having some input hidden would be a good idea.

That would be nice, we need a system to encrypt the value then because I don't want to make the user think his value is private when it's not in reality. I'll work on that ASAP (#627)

@dkashikar dkashikar deleted the Qrcode-Block branch January 12, 2024 08:27
thercd pushed a commit to thercd/typebot.io that referenced this pull request Feb 2, 2024
thercd pushed a commit to thercd/typebot.io that referenced this pull request Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants