Skip to content

Instantly share code, notes, and snippets.

@levino
Last active November 9, 2018 22:12
Show Gist options
  • Save levino/01216690952290095342b18bc0531768 to your computer and use it in GitHub Desktop.
Save levino/01216690952290095342b18bc0531768 to your computer and use it in GitHub Desktop.
Link that submits form.
import * as R from 'ramda'
import * as React from 'react'
import { ReactElement } from 'react'
import { connect } from 'react-redux'
import { State } from 'src/selectors'
import * as urlJoin from 'url-join'
import * as selectors from '../../../selectors'
const API_URL =
process.env.REACT_APP_API_URL ||
`https://api.example.com/.netlify/functions`
const IDENTIFICATION_URL: string = urlJoin(API_URL, 'identification')
interface IdNowLinkProps {
address: string
}
const IDNowLink: (props: IdNowLinkProps) => ReactElement<IdNowLinkProps> = ({
address,
}) => {
let form: any
return (
<form action={IDENTIFICATION_URL} ref={(el) => (form = el)} method="POST">
<input type="text" name="address" hidden value={address} />
<a
href="javascript:void(0);"
onClick={() => form && form.submit()}
target="_blank"
>
Verify now!
</a>
</form>
)
}
const mapStateToProps: (state: State) => IdNowLinkProps = R.applySpec({
address: selectors.getAddress,
})
export default connect(mapStateToProps)(IDNowLink)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment