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

feat: show badge on review section #8530

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 65 additions & 33 deletions packages/client/src/components/form/IDVerificationBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,68 @@ import { useIntl } from 'react-intl'
import { Pill, Banner, Icon, Button, Text } from '@opencrvs/components'
import { messages } from '@client/i18n/messages/views/id-verification-banner'

function Pending() {
const intl = useIntl()
return (
<Pill
type="pending"
size="small"
pillTheme="dark"
label={
<>
<Icon name="QrCode" size="small" />
{intl.formatMessage(messages.pending.title)}
</>
}
/>
)
}

function Verified() {
const intl = useIntl()
return (
<Pill
type="default"
size="small"
pillTheme="dark"
label={
<>
<Icon name="CircleWavyCheck" size="small" />
{intl.formatMessage(messages.success.title)}
</>
}
/>
)
}

function Failed() {
const intl = useIntl()
return (
<Pill
type="inactive"
size="small"
pillTheme="dark"
label={
<>
<Icon name="X" size="small" />
{intl.formatMessage(messages.failed.title)}
</>
}
/>
)
}

export function VerificationPill({ type }: { type: string }) {
if (type === 'pending') {
return <Pending />
} else if (type === 'verified') {
return <Verified />
} else if (type === 'failed') {
return <Failed />
}
return null
}

Comment on lines +68 to +78
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice 👍🏼

export const IDVerificationBanner = ({
type,
idFieldName,
Expand All @@ -31,17 +93,7 @@ export const IDVerificationBanner = ({
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)}
</>
}
/>
<Pending />
<Icon name="Clock" size="large" />
</Banner.Header>
<Banner.Body>
Expand All @@ -60,17 +112,7 @@ export const IDVerificationBanner = ({
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)}
</>
}
/>
<Verified />
<Icon name="FilledCheck" size="large" />
</Banner.Header>
<Banner.Body>
Expand All @@ -89,17 +131,7 @@ export const IDVerificationBanner = ({
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)}
</>
}
/>
<Failed />
<Icon name="Close" size="large" />
</Banner.Header>
<Banner.Body>
Expand Down
39 changes: 24 additions & 15 deletions packages/client/src/views/RegisterForm/review/ReviewSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import {
RouteComponentProps,
withRouter
} from '@client/components/WithRouterProps'
import { VerificationPill } from '@client/components/form/IDVerificationBanner'

const Deleted = styled.del`
color: ${({ theme }) => theme.colors.negative};
Expand Down Expand Up @@ -1505,6 +1506,12 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
this.closePreviewSection(() => this.removeAttachmentFromDraft(file))
}

includesVerificationStatus = (section: IFormSection) => {
return section.groups.some((group) =>
group.fields.some((field) => field.name === 'verified')
)
}

shouldShowChangeAll = (section: IFormSection) => {
const {
draft: { data, event, duplicates },
Expand Down Expand Up @@ -1623,13 +1630,23 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
id: section.id,
title: section.title ? intl.formatMessage(section.title) : '',
items: items.filter((item) => item),
action: this.shouldShowChangeAll(section)
? {
label: intl.formatMessage(buttonMessages.replace),
handler: () =>
action:
this.includesVerificationStatus(section) &&
Boolean(declaration.data[section.id].verified) ? (
<VerificationPill
type={declaration.data[section.id].verified as string}
/>
) : this.shouldShowChangeAll(section) &&
declaration.registrationStatus !== RegStatus.CorrectionRequested ? (
<Link
font="reg16"
onClick={() =>
this.replaceHandler(section.id, visibleGroups[0].id)
}
: undefined
}
>
{intl.formatMessage(buttonMessages.replace)}
</Link>
) : undefined
}
})
}
Expand Down Expand Up @@ -1785,15 +1802,7 @@ class ReviewSectionComp extends React.Component<FullProps, State> {
<Accordion
name={sec.id}
label={sec.title}
action={
sec.action &&
declaration.registrationStatus !==
RegStatus.CorrectionRequested && (
<Link font="reg16" onClick={sec.action.handler}>
{sec.action.label}
</Link>
)
}
action={sec.action}
labelForHideAction={intl.formatMessage(
messages.hideLabel
)}
Expand Down
Loading