Skip to content

Add onFinishSigning prop & upgrade all minor version deps #5

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

Merged
merged 13 commits into from
Oct 20, 2021

Conversation

Winggo
Copy link
Contributor

@Winggo Winggo commented Oct 19, 2021

Description of the change

Add onFinishSigning as a prop of AnvilSignatureFrame that calls after signing.

Very similar to the onFinish func prop, except it takes a payload as input instead of the redirectURL.
The payload is constructed from redirectURL query params.

Updated docs with onFinishSigning and removed onFinish.

Example:

onFinishSigning={(payload) => console.log(payload)}

/*
{
  action: "signerComplete"
  documentGroupEid: "9fQnvfy51p7oKrEYajMh"
  documentGroupStatus: "partial"
  etchPacketEid: "J1phQTO6WQH6gZcMJAG5"
  nextSignerEid: "HRLhx4khticpfxsUFSpj"
  signerEid: "kJzR6mcIWKoZs6KOxV4w"
  signerStatus: "completed"
  weldDataEid: undefined
}
*/

Also bumped minor versions for dependencies, seeing a lot of vulnerabilities: https://github.com/anvilco/react-ui/security/dependabot

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Related issues

Fixes anvilco/anvil#2733

Dev Checklist

  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development
  • No previous tests unrelated to the changed code fail in development

@Winggo Winggo added the enhancement New feature or request label Oct 19, 2021
@Winggo Winggo requested a review from benogle October 19, 2021 23:50
@Winggo Winggo self-assigned this Oct 19, 2021
@Winggo Winggo changed the title Add onFinishSigning prop Add onFinishSigning prop & update all minor version deps Oct 19, 2021
@Winggo Winggo changed the title Add onFinishSigning prop & update all minor version deps Add onFinishSigning prop & upgrade all minor version deps Oct 19, 2021

// parse query params into an object
const searchStr = data.split('?')[1]
const searchObj = JSON.parse('{"' + decodeURI(searchStr).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd do 2 things here that feel a little safer

  1. Use URLSearchParams if it exists. You can do something like if (typeof URLSearchParams !== 'undefined') {...} then use it
  2. Fallback to what you have. It also feels safer to decodeURI on each value component after you have the object, since often URLs will have their non-alpha characters encoded like %20

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, IE doesnt support URLSearchParams, so IE users would fallback to the json parse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented

const searchStr = data.split('?')[1]
const searchObj = JSON.parse('{"' + decodeURI(searchStr).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
const { signerStatus, signerEid, nextSignerEid, documentGroupStatus, documentGroupEid, etchPacketEid, weldDataEid } = searchObj
this.props.onFinishSigning({
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also make sure there is no error or errorType in the searchObj before calling this? This callback should only be called on signer success. I'll add an error handler mirroring this in the next pass

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.12.5",
"@babel/core": "^7.15.8",
Copy link
Contributor

Choose a reason for hiding this comment

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

yay for upgraded deps!

@@ -53,14 +53,27 @@ Example:
onLoad={() => setLoading(false)}
```

#### onFinish
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should keep onFinish in the docs, but say it is deprecated as people are still using it. I'd also remove the redirect bits from the example, and maybe just log it as an example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Left onFinish in docs and noted as deprecated

Copy link
Contributor

@benogle benogle left a comment

Choose a reason for hiding this comment

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

I think just need to address the error case on URLSearchParams, but other than that, good to go

}
}

if (!searchObj.error && !searchObj.errorType) this.props.onFinishSigning(payload)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work in the URLSearchParams case? Or would it need to call .get()? Would it make more sense to put those things into the payload?

Copy link
Contributor Author

@Winggo Winggo Oct 20, 2021

Choose a reason for hiding this comment

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

Yeah, would need to call .get(). Good catch. Fixed!

@Winggo Winggo merged commit f0dafc1 into main Oct 20, 2021
@Winggo Winggo deleted the wt/add-onFinishSigning branch October 20, 2021 18:52
@Winggo
Copy link
Contributor Author

Winggo commented Oct 20, 2021

Tested the new components with onFinishSigning on a local release in anvil-etch-example. Looks good and merged. Making a minor release...

@Winggo
Copy link
Contributor Author

Winggo commented Oct 20, 2021

@anvilco/react-signature-frame v1.5.0 & @anvilco/react-signature-modal v1.5.0 released. v1.4.6 -> v1.5.0

https://www.npmjs.com/package/@anvilco/react-signature-frame
https://www.npmjs.com/package/@anvilco/react-signature-modal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants