Skip to content

Commit

Permalink
Implement deletion of revocation notifications with history
Browse files Browse the repository at this point in the history
Signed-off-by: ZouidiSamih <[email protected]>
  • Loading branch information
ZouidiSamih committed Jan 27, 2025
1 parent 5e4d51d commit 2d233ca
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 110 deletions.
25 changes: 3 additions & 22 deletions app/src/screens/activities/BiometricChangeDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { formatTime } from '@hyperledger/aries-bifold-core/App/utils/helpers'
import { StackScreenProps } from '@react-navigation/stack'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { SafeAreaView, View, Text, TouchableOpacity, Alert } from 'react-native'
import { SafeAreaView, View, Text, TouchableOpacity } from 'react-native'
import { ScrollView } from 'react-native-gesture-handler'
import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons'

import HeaderText from '../../components/HeaderText'
import useHistoryDetailPageStyles from '../../hooks/useHistoryDetailPageStyles'
import { ActivitiesStackParams, Screens } from '../../navigators/navigators'
import { handleDeleteHistory } from '../../utils/historyUtils'
import { handleDeleteHistoryWithConfirmation } from '../../utils/historyUtils'

type BiometricChangeDetailsProp = StackScreenProps<ActivitiesStackParams, Screens.BiometricChangeDetails>

Expand All @@ -29,25 +29,6 @@ const BiometricChangeDetails: React.FC<BiometricChangeDetailsProp> = ({ route, n

const iconSize = 24

const confirmDeleteHistory = () => {
Alert.alert(
t('History.Button.DeleteHistory'),
t('History.ConfirmDeleteHistory'),
[
{ text: t('Global.Cancel'), style: 'cancel' },
{
text: t('Global.Confirm'),
style: 'destructive',
onPress: async () => {
await handleDeleteHistory(item.content.id || '', agent, loadHistory, t)
navigation.goBack()
},
},
],
{ cancelable: true }
)
}

return (
<SafeAreaView style={styles.container}>
<ScrollView contentContainerStyle={[styles.contentContainer, styles.headerStyle]}>
Expand All @@ -62,7 +43,7 @@ const BiometricChangeDetails: React.FC<BiometricChangeDetailsProp> = ({ route, n

<TouchableOpacity
style={styles.deleteContainer}
onPress={confirmDeleteHistory}
onPress={() => handleDeleteHistoryWithConfirmation(item.content.id || '', agent, loadHistory, t, navigation)}
accessibilityLabel={t('History.Button.DeleteHistory')}
accessibilityRole="button"
>
Expand Down
25 changes: 3 additions & 22 deletions app/src/screens/activities/CardHistoryDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import { Attribute, CredentialOverlay } from '@hyperledger/aries-oca/build/legac
import { StackScreenProps } from '@react-navigation/stack'
import { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { SafeAreaView, View, Text, TouchableOpacity, ActivityIndicator, Alert } from 'react-native'
import { SafeAreaView, View, Text, TouchableOpacity, ActivityIndicator } from 'react-native'
import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons'

import HeaderText from '../../components/HeaderText'
import useHistoryDetailPageStyles from '../../hooks/useHistoryDetailPageStyles'
import { ActivitiesStackParams, Screens } from '../../navigators/navigators'
import { ColorPallet } from '../../theme'
import { handleDeleteHistory } from '../../utils/historyUtils'
import { handleDeleteHistoryWithConfirmation } from '../../utils/historyUtils'
import { startCaseUnicode } from '../../utils/stringUtils'

type CardHistorydDetailsProp = StackScreenProps<ActivitiesStackParams, Screens.CardHistoryDetails>
Expand Down Expand Up @@ -97,25 +97,6 @@ const CardHistorydDetails: React.FC<CardHistorydDetailsProp> = ({ route, navigat
}
}, [recordId])

const confirmDeleteHistory = () => {
Alert.alert(
t('History.Button.DeleteHistory'),
t('History.ConfirmDeleteHistory'),
[
{ text: t('Global.Cancel'), style: 'cancel' },
{
text: t('Global.Confirm'),
style: 'destructive',
onPress: async () => {
await handleDeleteHistory(item.content.id || '', agent, loadHistory, t)
navigation.goBack()
},
},
],
{ cancelable: true }
)
}

const operationDate = itemContent?.createdAt
? formatTime(new Date(itemContent?.createdAt), { shortMonth: true, trim: true })
: t('Record.InvalidDate')
Expand Down Expand Up @@ -160,7 +141,7 @@ const CardHistorydDetails: React.FC<CardHistorydDetailsProp> = ({ route, navigat

<TouchableOpacity
style={styles.deleteContainer}
onPress={confirmDeleteHistory}
onPress={() => handleDeleteHistoryWithConfirmation(item.content.id || '', agent, loadHistory, t, navigation)}
accessibilityRole="button"
accessibilityLabel={t('History.Button.DeleteHistory')}
>
Expand Down
25 changes: 3 additions & 22 deletions app/src/screens/activities/ContactHistoryDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { formatTime } from '@hyperledger/aries-bifold-core/App/utils/helpers'
import { StackScreenProps } from '@react-navigation/stack'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { SafeAreaView, View, Text, TouchableOpacity, Alert } from 'react-native'
import { SafeAreaView, View, Text, TouchableOpacity } from 'react-native'
import { ScrollView } from 'react-native-gesture-handler'
import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons'

import HeaderText from '../../components/HeaderText'
import useHistoryDetailPageStyles from '../../hooks/useHistoryDetailPageStyles'
import { ActivitiesStackParams, Screens } from '../../navigators/navigators'
import { handleDeleteHistory } from '../../utils/historyUtils'
import { handleDeleteHistoryWithConfirmation } from '../../utils/historyUtils'
import { startCaseUnicode } from '../../utils/stringUtils'

type ContactHistoryDetailsProp = StackScreenProps<ActivitiesStackParams, Screens.ContactHistoryDetails>
Expand All @@ -31,25 +31,6 @@ const ContactHistoryDetails: React.FC<ContactHistoryDetailsProp> = ({ route, nav

const iconSize = 24

const confirmDeleteHistory = () => {
Alert.alert(
t('History.Button.DeleteHistory'),
t('History.ConfirmDeleteHistory'),
[
{ text: t('Global.Cancel'), style: 'cancel' },
{
text: t('Global.Confirm'),
style: 'destructive',
onPress: async () => {
await handleDeleteHistory(item.content.id || '', agent, loadHistory, t)
navigation.goBack()
},
},
],
{ cancelable: true }
)
}

return (
<SafeAreaView style={styles.container}>
<ScrollView contentContainerStyle={[styles.contentContainer, styles.headerStyle]}>
Expand All @@ -70,7 +51,7 @@ const ContactHistoryDetails: React.FC<ContactHistoryDetailsProp> = ({ route, nav

<TouchableOpacity
style={styles.deleteContainer}
onPress={confirmDeleteHistory}
onPress={() => handleDeleteHistoryWithConfirmation(item.content.id || '', agent, loadHistory, t, navigation)}
accessibilityRole="button"
accessibilityLabel={t('History.Button.DeleteHistory')}
>
Expand Down
25 changes: 3 additions & 22 deletions app/src/screens/activities/PinChangeDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { formatTime } from '@hyperledger/aries-bifold-core/App/utils/helpers'
import { StackScreenProps } from '@react-navigation/stack'
import React from 'react'
import { useTranslation } from 'react-i18next'
import { SafeAreaView, View, Text, TouchableOpacity, Alert } from 'react-native'
import { SafeAreaView, View, Text, TouchableOpacity } from 'react-native'
import { ScrollView } from 'react-native-gesture-handler'
import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons'

import HeaderText from '../../components/HeaderText'
import useHistoryDetailPageStyles from '../../hooks/useHistoryDetailPageStyles'
import { ActivitiesStackParams, Screens } from '../../navigators/navigators'
import { handleDeleteHistory } from '../../utils/historyUtils'
import { handleDeleteHistoryWithConfirmation } from '../../utils/historyUtils'

type PinChangeDetailsProp = StackScreenProps<ActivitiesStackParams, Screens.PinChangeDetails>

Expand All @@ -29,25 +29,6 @@ const PinChangeDetails: React.FC<PinChangeDetailsProp> = ({ route, navigation })

const iconSize = 24

const confirmDeleteHistory = () => {
Alert.alert(
t('History.Button.DeleteHistory'),
t('History.ConfirmDeleteHistory'),
[
{ text: t('Global.Cancel'), style: 'cancel' },
{
text: t('Global.Confirm'),
style: 'destructive',
onPress: async () => {
await handleDeleteHistory(item.content.id || '', agent, loadHistory, t)
navigation.goBack()
},
},
],
{ cancelable: true }
)
}

return (
<SafeAreaView style={styles.container}>
<ScrollView contentContainerStyle={[styles.contentContainer, styles.headerStyle]}>
Expand All @@ -62,7 +43,7 @@ const PinChangeDetails: React.FC<PinChangeDetailsProp> = ({ route, navigation })

<TouchableOpacity
style={styles.deleteContainer}
onPress={confirmDeleteHistory}
onPress={() => handleDeleteHistoryWithConfirmation(item.content.id || '', agent, loadHistory, t, navigation)}
accessibilityRole="button"
accessibilityLabel={t('History.Button.DeleteHistory')}
>
Expand Down
25 changes: 3 additions & 22 deletions app/src/screens/activities/ProofHistoryDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { GroupedSharedProofDataItem } from '@hyperledger/aries-bifold-verifier'
import { StackScreenProps } from '@react-navigation/stack'
import { useCallback, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { SafeAreaView, View, Text, TouchableOpacity, ScrollView, ActivityIndicator, Alert } from 'react-native'
import { SafeAreaView, View, Text, TouchableOpacity, ScrollView, ActivityIndicator } from 'react-native'
import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons'

import HeaderText from '../../components/HeaderText'
import useHistoryDetailPageStyles from '../../hooks/useHistoryDetailPageStyles'
import { ActivitiesStackParams, Screens } from '../../navigators/navigators'
import { ColorPallet } from '../../theme'
import { handleDeleteHistory } from '../../utils/historyUtils'
import { handleDeleteHistoryWithConfirmation } from '../../utils/historyUtils'
import { startCaseUnicode } from '../../utils/stringUtils'

type ProofHistoryDetailsProp = StackScreenProps<ActivitiesStackParams, Screens.ProofHistoryDetails>
Expand All @@ -41,25 +41,6 @@ const ProofHistoryDetails: React.FC<ProofHistoryDetailsProp> = ({ route, navigat
}
}, [record])

const confirmDeleteHistory = () => {
Alert.alert(
t('History.Button.DeleteHistory'),
t('History.ConfirmDeleteHistory'),
[
{ text: t('Global.Cancel'), style: 'cancel' },
{
text: t('Global.Confirm'),
style: 'destructive',
onPress: async () => {
await handleDeleteHistory(item.content.id || '', agent, loadHistory, t)
navigation.goBack()
},
},
],
{ cancelable: true }
)
}

const onSharedProofDataLoad = useCallback((data: GroupedSharedProofDataItem[]) => {
setSharedProofDataItems(data)
setIsLoading(false)
Expand Down Expand Up @@ -99,7 +80,7 @@ const ProofHistoryDetails: React.FC<ProofHistoryDetailsProp> = ({ route, navigat

<TouchableOpacity
style={styles.deleteContainer}
onPress={confirmDeleteHistory}
onPress={() => handleDeleteHistoryWithConfirmation(item.content.id || '', agent, loadHistory, t, navigation)}
accessibilityRole="button"
accessibilityLabel={t('History.Button.DeleteHistory')}
>
Expand Down
45 changes: 45 additions & 0 deletions app/src/utils/historyUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Agent } from '@credo-ts/core'
import { HistoryCardType, IHistoryManager } from '@hyperledger/aries-bifold-core/App/modules/history/types'
import { CredentialMetadata } from '@hyperledger/aries-bifold-core/App/types/metadata'
import { Alert } from 'react-native'
import Toast from 'react-native-toast-message'

// SVG Imports
Expand Down Expand Up @@ -57,6 +58,50 @@ export const handleDeleteHistory = async (
}
}

/**
* Handles the deletion of a history event with a confirmation alert.
*
* @param itemId - The identifier of the item to be deleted.
* @param agent - The agent used to interact with the history manager.
* @param loadHistory - Function to load the history manager for the given agent.
* @param t - Translation function from the `useTranslation` hook to handle localization.
* @param navigation - Navigation object to navigate after deletion (optional).
*/
export const handleDeleteHistoryWithConfirmation = (
itemId: string,
agent: Agent | undefined,
loadHistory: (agent: Agent) => IHistoryManager | undefined,
t: (key: string, options?: Record<string, unknown>) => string,
navigation?: { goBack: () => void }
): void => {
Alert.alert(
t('History.Button.DeleteHistory'),
t('History.ConfirmDeleteHistory'),
[
{ text: t('Global.Cancel'), style: 'cancel' },
{
text: t('Global.Confirm'),
style: 'destructive',
onPress: async () => {
try {
await handleDeleteHistory(itemId, agent, loadHistory, t)
if (navigation) {
navigation.goBack()
}
} catch (error) {
Toast.show({
type: 'error',
text1: t('Error.FailedToDelete'),
text2: t('Error.UnexpectedError'),
})
}
},
},
],
{ cancelable: true }
)
}

/**
* Renders the appropriate icon based on the history card type.
*
Expand Down

0 comments on commit 2d233ca

Please sign in to comment.