-
Notifications
You must be signed in to change notification settings - Fork 166
Implement React-based document capture selfie liveness step #4009
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cf5d32e
Restore original hash URL in document capture spec
aduth fd1e6bb
Remove confirmation step
aduth 9a07d63
Add support for isSecondary button style
aduth c0c433b
Add support for isUnstyled button
aduth cde3791
Rename acuant spec as acuant-spec.jsx
aduth 91ff649
Add camera support details to Acuant context
aduth 455b91d
Add SelfieStep form step
aduth 1ff6cf6
Render DocumentsStep using AcuantCapture as input
aduth ad50636
Fix typo
aduth aef63a4
Add type details for Acuant response object
aduth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
30 changes: 30 additions & 0 deletions
30
app/javascript/app/document-capture/components/acuant-capture-canvas.jsx
This file contains hidden or 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
74 changes: 54 additions & 20 deletions
74
app/javascript/app/document-capture/components/acuant-capture.jsx
This file contains hidden or 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 |
|---|---|---|
| @@ -1,46 +1,80 @@ | ||
| import React, { useContext, useState } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import AcuantContext from '../context/acuant'; | ||
| import AcuantCaptureCanvas from './acuant-capture-canvas'; | ||
| import FileInput from './file-input'; | ||
| import FullScreen from './full-screen'; | ||
| import Button from './button'; | ||
| import useI18n from '../hooks/use-i18n'; | ||
| import DeviceContext from '../context/device'; | ||
| import DataURLFile from '../models/data-url-file'; | ||
|
|
||
| function AcuantCapture() { | ||
| const { isReady, isError } = useContext(AcuantContext); | ||
| function AcuantCapture({ label, hint, bannerText, value, onChange, className }) { | ||
| const { isReady, isError, isCameraSupported } = useContext(AcuantContext); | ||
| const [isCapturing, setIsCapturing] = useState(false); | ||
| const [capture, setCapture] = useState(null); | ||
| const { isMobile } = useContext(DeviceContext); | ||
| const { t } = useI18n(); | ||
| const hasCapture = !isError && (isReady ? isCameraSupported : isMobile); | ||
|
|
||
| if (isError) { | ||
| return 'Error!'; | ||
| } | ||
|
|
||
| if (!isReady) { | ||
| return 'Loading…'; | ||
| } | ||
|
|
||
| if (capture) { | ||
| const { data, width, height } = capture.image; | ||
| return <img alt="Captured result" src={data} width={width} height={height} />; | ||
| let startCaptureIfSupported; | ||
| if (hasCapture) { | ||
| startCaptureIfSupported = (event) => { | ||
| event.preventDefault(); | ||
| setIsCapturing(true); | ||
| }; | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <div className={className}> | ||
| {isCapturing && ( | ||
| <FullScreen onRequestClose={() => setIsCapturing(false)}> | ||
| <AcuantCaptureCanvas | ||
| onImageCaptureSuccess={(nextCapture) => { | ||
| setCapture(nextCapture); | ||
| onChange(nextCapture.image.data); | ||
| setIsCapturing(false); | ||
| }} | ||
| onImageCaptureFailure={() => setIsCapturing(false)} | ||
| /> | ||
| </FullScreen> | ||
| )} | ||
| <button type="button" onClick={() => setIsCapturing(true)}> | ||
| {t('doc_auth.buttons.take_picture')} | ||
| </button> | ||
| </> | ||
| <FileInput | ||
| label={label} | ||
| hint={hint} | ||
| bannerText={bannerText} | ||
| accept={['image/*']} | ||
| value={value} | ||
| onClick={startCaptureIfSupported} | ||
| onChange={onChange} | ||
| /> | ||
| {hasCapture && ( | ||
| <Button | ||
| isSecondary={!value} | ||
| isUnstyled={!!value} | ||
| onClick={() => setIsCapturing(true)} | ||
| className="display-block margin-top-2" | ||
| > | ||
| {t(value ? 'doc_auth.buttons.take_picture_retry' : 'doc_auth.buttons.take_picture')} | ||
| </Button> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| AcuantCapture.propTypes = { | ||
| label: PropTypes.string.isRequired, | ||
| hint: PropTypes.string, | ||
| bannerText: PropTypes.string, | ||
| value: PropTypes.instanceOf(DataURLFile), | ||
| onChange: PropTypes.func, | ||
| className: PropTypes.string, | ||
| }; | ||
|
|
||
| AcuantCapture.defaultProps = { | ||
| hint: null, | ||
| value: null, | ||
| bannerText: null, | ||
| onChange: () => {}, | ||
| className: null, | ||
| }; | ||
|
|
||
| export default AcuantCapture; | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
54 changes: 54 additions & 0 deletions
54
app/javascript/app/document-capture/components/selfie-step.jsx
This file contains hidden or 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,54 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import PageHeading from './page-heading'; | ||
| import useI18n from '../hooks/use-i18n'; | ||
| import AcuantCapture from './acuant-capture'; | ||
| import DataURLFile from '../models/data-url-file'; | ||
|
|
||
| function SelfieStep({ value, onChange }) { | ||
| const { t } = useI18n(); | ||
|
|
||
| return ( | ||
| <> | ||
| <PageHeading>{t('doc_auth.headings.selfie')}</PageHeading> | ||
| <p className="margin-top-2"> | ||
| {t('doc_auth.instructions.document_capture_selfie_instructions')} | ||
| </p> | ||
| <p className="margin-bottom-0">{t('doc_auth.tips.document_capture_header_text')}</p> | ||
| <ul> | ||
| <li>{t('doc_auth.tips.document_capture_selfie_text1')}</li> | ||
| <li>{t('doc_auth.tips.document_capture_selfie_text2')}</li> | ||
| <li>{t('doc_auth.tips.document_capture_selfie_text3')}</li> | ||
| </ul> | ||
| <AcuantCapture | ||
| label={t('doc_auth.headings.document_capture_selfie')} | ||
| bannerText={t('doc_auth.headings.photo')} | ||
| value={value.selfie} | ||
| onChange={(nextSelfie) => onChange({ selfie: nextSelfie })} | ||
| /> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| SelfieStep.propTypes = { | ||
| value: PropTypes.shape({ | ||
| selfie: PropTypes.instanceOf(DataURLFile), | ||
| }), | ||
| onChange: PropTypes.func, | ||
| }; | ||
|
|
||
| SelfieStep.defaultProps = { | ||
| value: {}, | ||
| onChange: () => {}, | ||
| }; | ||
|
|
||
| /** | ||
| * Returns true if the step is valid for the given values, or false otherwise. | ||
| * | ||
| * @param {Record<string,string>} value Current form values. | ||
| * | ||
| * @return {boolean} Whether step is valid. | ||
| */ | ||
| export const isValid = (value) => Boolean(value.selfie); | ||
|
|
||
| export default SelfieStep; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.