tooot/src/components/Timelines/Timeline/Shared/HeaderActions/Domain.tsx

88 lines
2.5 KiB
TypeScript
Raw Normal View History

2021-01-24 02:25:43 +01:00
import analytics from '@components/analytics'
2020-12-13 14:04:25 +01:00
import MenuContainer from '@components/Menu/Container'
import MenuHeader from '@components/Menu/Header'
import MenuRow from '@components/Menu/Row'
import { toast } from '@components/toast'
2021-01-11 21:36:57 +01:00
import {
QueryKeyTimeline,
useTimelineMutation
} from '@utils/queryHooks/timeline'
import React from 'react'
2021-01-01 23:10:47 +01:00
import { useTranslation } from 'react-i18next'
2021-01-11 21:36:57 +01:00
import { Alert } from 'react-native'
import { useQueryClient } from 'react-query'
2020-12-03 01:28:56 +01:00
export interface Props {
2021-01-07 19:13:09 +01:00
queryKey: QueryKeyTimeline
2020-12-03 01:28:56 +01:00
domain: string
setBottomSheetVisible: React.Dispatch<React.SetStateAction<boolean>>
}
2021-01-12 00:12:44 +01:00
const HeaderActionsDomain: React.FC<Props> = ({
2020-12-03 01:28:56 +01:00
queryKey,
domain,
setBottomSheetVisible
}) => {
2021-01-19 01:13:45 +01:00
const { t } = useTranslation('componentTimeline')
2020-12-18 23:58:53 +01:00
const queryClient = useQueryClient()
2021-01-11 21:36:57 +01:00
const mutation = useTimelineMutation({
queryClient,
2020-12-03 01:28:56 +01:00
onSettled: () => {
2021-01-01 23:10:47 +01:00
toast({
type: 'success',
message: t('common:toastMessage.success.message', {
2021-01-19 01:13:45 +01:00
function: t(`shared.header.actions.domain.block.function`)
2021-01-01 23:10:47 +01:00
})
})
2020-12-18 23:58:53 +01:00
queryClient.invalidateQueries(queryKey)
2020-12-03 01:28:56 +01:00
}
})
return (
<MenuContainer>
2021-01-19 01:13:45 +01:00
<MenuHeader heading={t(`shared.header.actions.domain.heading`)} />
2020-12-03 01:28:56 +01:00
<MenuRow
onPress={() => {
2021-01-24 02:25:43 +01:00
analytics('timeline_shared_headeractions_domain_block_press', {
page: queryKey[1].page
})
2021-01-11 21:36:57 +01:00
Alert.alert(
2021-01-19 01:13:45 +01:00
t('shared.header.actions.domain.alert.title', { domain }),
t('shared.header.actions.domain.alert.message'),
2021-01-11 21:36:57 +01:00
[
{
2021-01-19 01:13:45 +01:00
text: t('shared.header.actions.domain.alert.buttons.cancel'),
style: 'cancel'
},
{
text: t('shared.header.actions.domain.alert.buttons.confirm'),
2021-01-11 21:36:57 +01:00
style: 'destructive',
onPress: () => {
2021-01-24 02:25:43 +01:00
analytics(
'timeline_shared_headeractions_domain_block_confirm',
{
page: queryKey && queryKey[1].page
}
)
2021-01-11 21:36:57 +01:00
setBottomSheetVisible(false)
mutation.mutate({
type: 'domainBlock',
queryKey,
domain: domain
})
}
}
]
)
2020-12-03 01:28:56 +01:00
}}
iconFront='CloudOff'
2021-01-19 01:13:45 +01:00
title={t(`shared.header.actions.domain.block.button`, {
2021-01-01 23:10:47 +01:00
domain
})}
2020-12-03 01:28:56 +01:00
/>
</MenuContainer>
)
}
2021-01-12 00:12:44 +01:00
export default HeaderActionsDomain