-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into IOBP-782-add-biz-events-migration-banner-info
- Loading branch information
Showing
27 changed files
with
502 additions
and
122 deletions.
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
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
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
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
160 changes: 160 additions & 0 deletions
160
ts/features/itwallet/common/components/ItwIssuanceMetadata.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,160 @@ | ||
import { Divider, ListItemInfo } from "@pagopa/io-app-design-system"; | ||
import React, { useMemo } from "react"; | ||
import { pipe } from "fp-ts/lib/function"; | ||
import * as O from "fp-ts/lib/Option"; | ||
import I18n from "../../../../i18n"; | ||
import { useItwInfoBottomSheet } from "../hooks/useItwInfoBottomSheet"; | ||
import { StoredCredential } from "../utils/itwTypesUtils"; | ||
import { | ||
CREDENTIALS_MAP, | ||
trackWalletCredentialShowAuthSource, | ||
trackWalletCredentialShowIssuer | ||
} from "../../analytics"; | ||
|
||
type ItwIssuanceMetadataProps = { | ||
credential: StoredCredential; | ||
isPreview?: boolean; | ||
}; | ||
|
||
type ItwMetadataIssuanceListItemProps = { | ||
label: string; | ||
value: string; | ||
bottomSheet: { | ||
contentTitle: string; | ||
contentBody: string; | ||
onPress: () => void; | ||
}; | ||
isPreview?: boolean; | ||
}; | ||
|
||
const ItwMetadataIssuanceListItem = ({ | ||
label, | ||
value, | ||
bottomSheet: bottomSheetProps, | ||
isPreview | ||
}: ItwMetadataIssuanceListItemProps) => { | ||
const bottomSheet = useItwInfoBottomSheet({ | ||
title: value, | ||
content: [ | ||
{ | ||
title: bottomSheetProps.contentTitle, | ||
body: bottomSheetProps.contentBody | ||
} | ||
] | ||
}); | ||
|
||
const endElement: ListItemInfo["endElement"] = useMemo(() => { | ||
if (isPreview) { | ||
return; | ||
} | ||
|
||
return { | ||
type: "iconButton", | ||
componentProps: { | ||
icon: "info", | ||
accessibilityLabel: `Info ${label}`, | ||
onPress: () => { | ||
bottomSheetProps.onPress(); | ||
bottomSheet.present(); | ||
} | ||
} | ||
}; | ||
}, [isPreview, bottomSheet, bottomSheetProps, label]); | ||
|
||
return ( | ||
<> | ||
<ListItemInfo | ||
endElement={endElement} | ||
label={label} | ||
value={value} | ||
accessibilityLabel={`${label} ${value}`} | ||
/> | ||
{bottomSheet.bottomSheet} | ||
</> | ||
); | ||
}; | ||
|
||
const getAuthSource = (credential: StoredCredential) => | ||
pipe( | ||
credential.issuerConf.openid_credential_issuer | ||
.credential_configurations_supported?.[credential.credentialType], | ||
O.fromNullable, | ||
O.map(config => config.authentic_source), | ||
O.toUndefined | ||
); | ||
|
||
/** | ||
* Renders additional issuance-related metadata, i.e. releaser and auth source. | ||
* They are not part of the claims list, thus they're rendered separately. | ||
* @param credential - the credential with the issuer configuration | ||
* @param isPreview - whether the component is rendered in preview mode which hides the info button. | ||
* @returns the list items with the metadata. | ||
*/ | ||
export const ItwIssuanceMetadata = ({ | ||
credential, | ||
isPreview | ||
}: ItwIssuanceMetadataProps) => { | ||
const releaserName = | ||
credential.issuerConf.federation_entity.organization_name; | ||
const authSource = getAuthSource(credential); | ||
|
||
const releaserNameBottomSheet: ItwMetadataIssuanceListItemProps["bottomSheet"] = | ||
useMemo( | ||
() => ({ | ||
contentTitle: I18n.t( | ||
"features.itWallet.issuance.credentialPreview.bottomSheet.about.title" | ||
), | ||
contentBody: I18n.t( | ||
"features.itWallet.issuance.credentialPreview.bottomSheet.about.subtitle" | ||
), | ||
onPress: () => | ||
trackWalletCredentialShowIssuer( | ||
CREDENTIALS_MAP[credential.credentialType] | ||
) | ||
}), | ||
[credential.credentialType] | ||
); | ||
|
||
const authSourceBottomSheet: ItwMetadataIssuanceListItemProps["bottomSheet"] = | ||
useMemo( | ||
() => ({ | ||
contentTitle: I18n.t( | ||
"features.itWallet.issuance.credentialPreview.bottomSheet.authSource.title" | ||
), | ||
contentBody: I18n.t( | ||
"features.itWallet.issuance.credentialPreview.bottomSheet.authSource.subtitle" | ||
), | ||
onPress: () => | ||
trackWalletCredentialShowAuthSource( | ||
CREDENTIALS_MAP[credential.credentialType] | ||
) | ||
}), | ||
[credential.credentialType] | ||
); | ||
|
||
return ( | ||
<> | ||
{authSource && ( | ||
<ItwMetadataIssuanceListItem | ||
label={I18n.t( | ||
"features.itWallet.verifiableCredentials.claims.authenticSource" | ||
)} | ||
value={authSource} | ||
isPreview={isPreview} | ||
bottomSheet={authSourceBottomSheet} | ||
/> | ||
)} | ||
{authSource && releaserName && <Divider />} | ||
{releaserName && ( | ||
<ItwMetadataIssuanceListItem | ||
label={I18n.t( | ||
"features.itWallet.verifiableCredentials.claims.releasedBy" | ||
)} | ||
value={releaserName} | ||
isPreview={isPreview} | ||
bottomSheet={releaserNameBottomSheet} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.