import React, { useCallback, useContext, useEffect, useState } from 'react' import { IdentityDataProcessingConsentContent } from '@sudoplatform/sudo-secure-id-verification' import { Button, Input, VSpace } from '@sudoplatform/web-ui' import { message, Collapse } from 'antd' import { Input as AntdInput } from 'antd' import { AppContext } from '../containers/AppContext' /** * Component for handling identity verification consent functionality */ export const IdentityVerificationConsent: React.FC = () => { const { identityVerificationClient } = useContext(AppContext) const [consentRequired, setConsentRequired] = useState(null) const [preferredLanguage, setPreferredLanguage] = useState('en-US') const [preferredContentType, setPreferredContentType] = useState('text/plain') const [consentContent, setConsentContent] = useState(null) const [isFetchingConsentContent, setIsFetchingConsentContent] = useState(false) const [isProvidingConsent, setIsProvidingConsent] = useState(false) const [isCheckingConsentStatus, setIsCheckingConsentStatus] = useState(true) const [consentStatus, setConsentStatus] = useState(false) const [isWithdrawingConsent, setIsWithdrawingConsent] = useState(false) const fetchConsentStatus = useCallback(async () => { try { const status = await identityVerificationClient.getIdentityDataProcessingConsentStatus() setConsentStatus(status?.consented ?? false) } catch (e) { setConsentStatus(false) } finally { setIsCheckingConsentStatus(false) } }, [identityVerificationClient]) useEffect(() => { // Fetch consent requirement const fetchConsentRequired = async () => { try { const required = await identityVerificationClient.isConsentRequiredForVerification() setConsentRequired(required) } catch (e) { setConsentRequired(false) } } void fetchConsentRequired() // Fetch consent status void fetchConsentStatus() }, [fetchConsentStatus, identityVerificationClient]) const handleFetchConsentContent = async () => { setIsFetchingConsentContent(true) setConsentContent(null) try { const content = await identityVerificationClient.getIdentityDataProcessingConsentContent( { preferredLanguage, preferredContentType, }, ) setConsentContent(content ?? null) } catch (e) { setConsentContent({ content: 'Failed to fetch consent content.', language: preferredLanguage, contentType: preferredContentType, }) } finally { setIsFetchingConsentContent(false) } } const handleProvideConsent = async () => { if (!consentContent) { return } setIsProvidingConsent(true) try { await identityVerificationClient.provideIdentityDataProcessingConsent({ content: consentContent.content, contentType: consentContent.contentType, language: consentContent.language, }) void message.success('Consent provided successfully.') await fetchConsentStatus() } catch (e) { void message.error('Failed to provide consent.') } finally { setIsProvidingConsent(false) } } const handleWithdrawConsent = async () => { setIsWithdrawingConsent(true) try { await identityVerificationClient.withdrawIdentityDataProcessingConsent() void message.success('Consent withdrawn successfully.') await fetchConsentStatus() } catch (e) { void message.error('Failed to withdraw consent.') } finally { setIsWithdrawingConsent(false) } } return (

To perform identity verification, we may need your consent to use personal data. This is required in some environments to comply with privacy regulations.

Consent Required Status:{' '} {consentRequired === null ? 'Checking...' : consentRequired ? 'Consent Required' : 'Consent Not Required'} {' '} in this environment

{isCheckingConsentStatus ? ( Checking consent status... ) : consentStatus ? (
Consented
) : ( Not Consented )}
{consentContent?.content && (
Consent Content {consentContent.language && consentContent.contentType ? ` (${consentContent.language}, ${consentContent.contentType})` : ''} :
)}
) }