-
Notifications
You must be signed in to change notification settings - Fork 73
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
Feat/ocrvs 7978/qr reader #8196
Open
tahmidrahman-dsi
wants to merge
62
commits into
develop
Choose a base branch
from
feat/ocrvs-7978/qr-reader
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
62 commits
Select commit
Hold shift + click to select a range
7330f51
feat: create a qr code scanner component
tahmidrahman-dsi 4c01e21
chore: remove unnecessary comment
tahmidrahman-dsi 2801173
chore: interim changes
tahmidrahman-dsi 01718e5
chore: add a separate form field type for qr scanner
tahmidrahman-dsi 322dc1f
Merge branch 'develop' into feat/ocrvs-7955/qr-code-scanner-poc
tahmidrahman-dsi d5cfb67
fix: remove testing related changes
tahmidrahman-dsi 2a99bf9
feat: qr scanner with multiple variants
tahmidrahman-dsi 4112f58
fix: minor fixes
tahmidrahman-dsi bda1f8f
Merge branch 'develop' into feat/ocrvs-7955/qr-code-scanner-poc
tahmidrahman-dsi 952dbee
chore: style amends and add a validation
tahmidrahman-dsi 29076fa
feat: create id reader UI component
tahmidrahman-dsi 80f5d99
feat: allow divider component to take in children to show label
tahmidrahman-dsi 5037cf3
fix: cleanup client
tahmidrahman-dsi c214ce8
feat: add scanner component
tahmidrahman-dsi 8d60581
feat: add titleIcon to Dialog
tahmidrahman-dsi 9879729
chore: add info component
tahmidrahman-dsi 4ec4f56
fix: close modal on successful scan
tahmidrahman-dsi 4350011
feat: add support for taking translatable labels
tahmidrahman-dsi e892be2
fix: organize code a bit
tahmidrahman-dsi d298fd9
fix: use `useWindowSize` hook
tahmidrahman-dsi 9b41a69
chore: create a `ReaderGenerator` that renders different types of rea…
tahmidrahman-dsi 4399fad
feat: add a story to divider component having a label
tahmidrahman-dsi f994875
fix: take `children` instead of prop `label`
tahmidrahman-dsi 61fbc7e
fix: use `Button` component in place of `SecondaryButton`
tahmidrahman-dsi 41bfb99
refactor(wip): re-organize `ReaderGenerator`
tahmidrahman-dsi 91062cd
chore: internationalize qr-reader field object
tahmidrahman-dsi 425ee00
refactor: redirect component to make it fetch on mount
tahmidrahman-dsi 354bc8e
feat: add ability to use redirect component inside id reader
tahmidrahman-dsi 5e9ecb7
refactor: UI improvements
tahmidrahman-dsi fb482ef
fix: amend config validations
tahmidrahman-dsi 290228a
refactor: do not take unnecessary labels in prop
tahmidrahman-dsi a3d468b
fix: improve styles
tahmidrahman-dsi f134c23
Merge branch 'develop' into feat/ocrvs-7978/qr-reader
tahmidrahman-dsi 1bc9ea0
fix: put button inside link
tahmidrahman-dsi 28edf58
chore: supported configuring icon to redirect button
tahmidrahman-dsi d2f7beb
fix: replace hardcoded breakpoint with theme defined breakpoint
tahmidrahman-dsi 841dbad
fix: styles to align with the responsive design
tahmidrahman-dsi d4c1c57
fix: improve data handling
tahmidrahman-dsi 400b303
feat: add new field `scannedFields` to gql input to track which field…
tahmidrahman-dsi 70dd226
fix: minor amends
tahmidrahman-dsi 892cc6a
Revert "fix: minor amends"
tahmidrahman-dsi 7c55040
Revert "feat: add new field `scannedFields` to gql input to track whi…
tahmidrahman-dsi 6589f9e
Merge branch 'develop' into feat/ocrvs-7978/qr-reader
tahmidrahman-dsi 67fa6d5
wip: handle different status in reader component
tahmidrahman-dsi 4f3e8e2
fix: remove usages of additional component
tahmidrahman-dsi 3ce87c9
Merge branch 'develop' into feat/ocrvs-7978/qr-reader
tahmidrahman-dsi 0723fb6
fix: remove status in id reader
tahmidrahman-dsi 0996d0a
feat: introduce a `ID_VERIFICATION_BANNER` component
tahmidrahman-dsi 745a2d9
fix: minor cleanup
tahmidrahman-dsi 1b6b5f6
fix: remove hardcoded verified status modification
tahmidrahman-dsi 271fdc9
refactor: REDIRECT -> LINK_BUTTON
tahmidrahman-dsi 17145de
Merge branch 'develop' into feat/ocrvs-7978/qr-reader
tahmidrahman-dsi 61c48f6
fix: forward params received from redirection to the callback request
tahmidrahman-dsi 945cacd
refactor: interface names
tahmidrahman-dsi c7b1ce9
fix: misc amends
tahmidrahman-dsi 633e8fd
Merge branch 'develop' into feat/ocrvs-7978/qr-reader
tahmidrahman-dsi 57d0318
fix: typo and update code
tahmidrahman-dsi 82b4601
fix: improve naming
tahmidrahman-dsi 7e0dc81
fix: also eval params
tahmidrahman-dsi 02c283f
Merge branch 'develop' into feat/ocrvs-7978/qr-reader
tahmidrahman-dsi f2368f5
fix: styles
tahmidrahman-dsi d6ea209
Merge branch 'develop' into feat/ocrvs-7978/qr-reader
tahmidrahman-dsi 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 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 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
118 changes: 118 additions & 0 deletions
118
packages/client/src/components/form/IDVerificationBanner.tsx
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,118 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* OpenCRVS is also distributed under the terms of the Civil Registration | ||
* & Healthcare Disclaimer located at http://opencrvs.org/license. | ||
* | ||
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. | ||
*/ | ||
import React from 'react' | ||
import { BannerType, IFormFieldValue } from '@client/forms' | ||
import { useIntl } from 'react-intl' | ||
import { Pill, Banner, Icon, Button, Text } from '@opencrvs/components' | ||
import { messages } from '@client/i18n/messages/views/id-verification-banner' | ||
|
||
export const IDVerificationBanner = ({ | ||
type, | ||
idFieldName, | ||
setFieldValue | ||
}: { | ||
type: BannerType | ||
setFieldValue: (name: string, value: IFormFieldValue) => void | ||
idFieldName: string | ||
}) => { | ||
const intl = useIntl() | ||
const handleReset = () => { | ||
setFieldValue(idFieldName, '') | ||
} | ||
if (type === 'pending') { | ||
return ( | ||
<Banner.Container> | ||
<Banner.Header type="pending"> | ||
<Pill | ||
type="pending" | ||
size="small" | ||
pillTheme="dark" | ||
label={ | ||
<> | ||
<Icon name="QrCode" size="small" /> | ||
{intl.formatMessage(messages.pending.title)} | ||
</> | ||
} | ||
/> | ||
<Icon name="Clock" size="large" /> | ||
</Banner.Header> | ||
<Banner.Body> | ||
<Text variant="reg16" element="span"> | ||
{intl.formatMessage(messages.pending.description)} | ||
</Text> | ||
</Banner.Body> | ||
<Banner.Footer justifyContent="flex-end"> | ||
<Button type="secondary" onClick={handleReset}> | ||
{intl.formatMessage(messages.actions.reset)} | ||
</Button> | ||
</Banner.Footer> | ||
</Banner.Container> | ||
) | ||
} else if (type === 'verified') { | ||
return ( | ||
<Banner.Container> | ||
<Banner.Header type="default"> | ||
<Pill | ||
type="default" | ||
size="small" | ||
pillTheme="dark" | ||
label={ | ||
<> | ||
<Icon name="CircleWavyCheck" size="small" /> | ||
{intl.formatMessage(messages.success.title)} | ||
</> | ||
} | ||
/> | ||
<Icon name="FilledCheck" size="large" /> | ||
</Banner.Header> | ||
<Banner.Body> | ||
<Text variant="reg16" element="span"> | ||
{intl.formatMessage(messages.success.description)} | ||
</Text> | ||
</Banner.Body> | ||
<Banner.Footer justifyContent="flex-end"> | ||
<Button type="secondary" onClick={handleReset}> | ||
{intl.formatMessage(messages.actions.revoke)} | ||
</Button> | ||
</Banner.Footer> | ||
</Banner.Container> | ||
) | ||
} else if (type === 'failed') { | ||
return ( | ||
<Banner.Container> | ||
<Banner.Header type="inactive"> | ||
<Pill | ||
type="inactive" | ||
size="small" | ||
pillTheme="dark" | ||
label={ | ||
<> | ||
<Icon name="X" size="small" /> | ||
{intl.formatMessage(messages.failed.title)} | ||
</> | ||
} | ||
/> | ||
<Icon name="Close" size="large" /> | ||
</Banner.Header> | ||
<Banner.Body> | ||
<Text variant="reg16" element="span"> | ||
{intl.formatMessage(messages.failed.description)} | ||
</Text> | ||
</Banner.Body> | ||
<Banner.Footer justifyContent="flex-end"> | ||
<Button type="secondary" onClick={handleReset}> | ||
{intl.formatMessage(messages.actions.reset)} | ||
</Button> | ||
</Banner.Footer> | ||
</Banner.Container> | ||
) | ||
} else return null | ||
} |
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,114 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* OpenCRVS is also distributed under the terms of the Civil Registration | ||
* & Healthcare Disclaimer located at http://opencrvs.org/license. | ||
* | ||
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. | ||
*/ | ||
import { | ||
IFormData, | ||
IFormField, | ||
IFormFieldValue, | ||
IFormSectionData, | ||
IHttpFormField, | ||
Ii18nLinkButtonFormField | ||
} from '@client/forms' | ||
import { evalExpressionInFieldDefinition } from '@client/forms/utils' | ||
import { getOfflineData } from '@client/offline/selectors' | ||
import { getUserDetails } from '@client/profile/profileSelectors' | ||
import React, { useEffect, useState } from 'react' | ||
import { useSelector } from 'react-redux' | ||
import { useHttp } from './http' | ||
import { Button, getTheme, Icon } from '@opencrvs/components' | ||
import { useWindowSize } from '@opencrvs/components/src/hooks' | ||
|
||
export const LinkButtonField = ({ | ||
fields, | ||
form, | ||
draft, | ||
fieldDefinition, | ||
setFieldValue, | ||
isDisabled | ||
}: { | ||
fields: IFormField[] | ||
form: IFormSectionData | ||
draft: IFormData | ||
fieldDefinition: Ii18nLinkButtonFormField | ||
setFieldValue: (name: string, value: IFormFieldValue) => void | ||
isDisabled?: boolean | ||
}) => { | ||
const config = useSelector(getOfflineData) | ||
const user = useSelector(getUserDetails) | ||
const windowSize = useWindowSize() | ||
const theme = getTheme() | ||
const { | ||
options: { | ||
url: to, | ||
callback: { params } | ||
} | ||
} = fieldDefinition | ||
const trigger = fields.find( | ||
(f) => f.name === fieldDefinition.options.callback.trigger | ||
)! | ||
const onChange: Parameters<typeof useHttp>[1] = ({ data, error, loading }) => | ||
setFieldValue(trigger.name, { loading, data, error } as IFormFieldValue) | ||
const [hasCallbackRequestBeenMade, setCallbackRequestBeenMade] = | ||
useState(false) | ||
|
||
const { call } = useHttp<string>( | ||
trigger as IHttpFormField, | ||
onChange, | ||
form, | ||
config, | ||
draft, | ||
user | ||
) | ||
|
||
useEffect(() => { | ||
const urlParams = new URLSearchParams(window.location.search) | ||
function checkParamsPresentInURL() { | ||
for (const [key, value] of Object.entries(params)) { | ||
if (urlParams.get(key) !== value) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
if (checkParamsPresentInURL() && !hasCallbackRequestBeenMade) { | ||
call({ | ||
// forward params which are received after redirection to the callback request | ||
params: Object.fromEntries(urlParams) | ||
}) | ||
setCallbackRequestBeenMade(true) | ||
} | ||
}, [call, params, form, trigger, hasCallbackRequestBeenMade]) | ||
Comment on lines
+72
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tahmidrahman-dsi how / where is this call/params functionality documented? It's a good method, but can be confusing for someone wanting to use the component. |
||
return ( | ||
<Button | ||
type="secondary" | ||
size="large" | ||
element="a" | ||
fullWidth | ||
disabled={isDisabled} | ||
onClick={() => { | ||
window.location.href = evalExpressionInFieldDefinition( | ||
'`' + to + '`', | ||
form, | ||
config, | ||
draft, | ||
user | ||
) | ||
}} | ||
> | ||
{fieldDefinition.icon && | ||
(windowSize.width <= theme.grid.breakpoints.md ? ( | ||
<Icon name={fieldDefinition.icon.mobile} size="medium" /> | ||
) : ( | ||
<Icon name={fieldDefinition.icon.desktop} size="medium" /> | ||
))} | ||
{fieldDefinition.label} | ||
</Button> | ||
) | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is form field component