import analytics from '@components/analytics' import Button from '@components/Button' import haptics from '@components/haptics' import { displayMessage } from '@components/Message' import { QueryKeyRelationship, useRelationshipMutation } from '@utils/queryHooks/relationship' import { QueryKeyTimeline } from '@utils/queryHooks/timeline' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React from 'react' import { useTranslation } from 'react-i18next' import { StyleSheet, View } from 'react-native' import { useQueryClient } from 'react-query' export interface Props { id: Mastodon.Account['id'] } const RelationshipIncoming: React.FC = ({ id }) => { const { theme } = useTheme() const { t } = useTranslation() const queryKeyRelationship: QueryKeyRelationship = ['Relationship', { id }] const queryKeyNotification: QueryKeyTimeline = [ 'Timeline', { page: 'Notifications' } ] const queryClient = useQueryClient() const mutation = useRelationshipMutation({ onSuccess: res => { haptics('Success') queryClient.setQueryData(queryKeyRelationship, [ res ]) queryClient.refetchQueries(queryKeyNotification) }, onError: (err: any, { type }) => { haptics('Error') displayMessage({ type: 'error', theme, message: t('common:message.error.message', { function: t(`relationship:${type}.function`) }), ...(err.status && typeof err.status === 'number' && err.data && err.data.error && typeof err.data.error === 'string' && { description: err.data.error }) }) } }) return (