diff --git a/native/profile/relationship-list-item-tooltip-modal.react.js b/native/profile/relationship-list-item-tooltip-modal.react.js
index 8568fa359..e1f3ff7cf 100644
--- a/native/profile/relationship-list-item-tooltip-modal.react.js
+++ b/native/profile/relationship-list-item-tooltip-modal.react.js
@@ -1,141 +1,150 @@
// @flow
import * as React from 'react';
import { TouchableOpacity } from 'react-native';
import {
updateRelationshipsActionTypes,
updateRelationships,
} from 'lib/actions/relationship-actions.js';
import { stringForUser } from 'lib/shared/user-utils.js';
import type { RelativeUserInfo } from 'lib/types/user-types.js';
import {
useDispatchActionPromise,
useServerCall,
} from 'lib/utils/action-utils.js';
import PencilIcon from '../components/pencil-icon.react.js';
import type { AppNavigationProp } from '../navigation/app-navigator.react.js';
import {
createTooltip,
type TooltipParams,
type BaseTooltipProps,
type TooltipMenuProps,
} from '../tooltip/tooltip.react.js';
import Alert from '../utils/alert.js';
-type Action = 'unfriend' | 'unblock';
+type Action = 'unfriend' | 'block' | 'unblock';
export type RelationshipListItemTooltipModalParams = TooltipParams<{
+relativeUserInfo: RelativeUserInfo,
}>;
type OnRemoveUserProps = {
...RelationshipListItemTooltipModalParams,
+action: Action,
};
function useRelationshipAction(input: OnRemoveUserProps) {
const boundRemoveRelationships = useServerCall(updateRelationships);
const dispatchActionPromise = useDispatchActionPromise();
const userText = stringForUser(input.relativeUserInfo);
return React.useCallback(() => {
const callRemoveRelationships = async () => {
try {
return await boundRemoveRelationships({
action: input.action,
userIDs: [input.relativeUserInfo.id],
});
} catch (e) {
Alert.alert('Unknown error', 'Uhh... try again?', [{ text: 'OK' }], {
cancelable: true,
});
throw e;
}
};
const onConfirmRemoveUser = () => {
const customKeyName = `${updateRelationshipsActionTypes.started}:${input.relativeUserInfo.id}`;
dispatchActionPromise(
updateRelationshipsActionTypes,
callRemoveRelationships(),
{ customKeyName },
);
};
const action = {
unfriend: 'removal',
+ block: 'block',
unblock: 'unblock',
}[input.action];
const message = {
unfriend: `remove ${userText} from friends?`,
+ block: `block ${userText}`,
unblock: `unblock ${userText}?`,
}[input.action];
Alert.alert(
`Confirm ${action}`,
`Are you sure you want to ${message}`,
[
{ text: 'Cancel', style: 'cancel' },
{ text: 'OK', onPress: onConfirmRemoveUser },
],
{ cancelable: true },
);
}, [boundRemoveRelationships, dispatchActionPromise, userText, input]);
}
function TooltipMenu(
props: TooltipMenuProps<'RelationshipListItemTooltipModal'>,
): React.Node {
const { route, tooltipItem: TooltipItem } = props;
const onRemoveUser = useRelationshipAction({
...route.params,
action: 'unfriend',
});
+
+ const onBlockUser = useRelationshipAction({
+ ...route.params,
+ action: 'block',
+ });
+
const onUnblockUser = useRelationshipAction({
...route.params,
action: 'unblock',
});
return (
<>
+
>
);
}
type Props = {
+navigation: AppNavigationProp<'RelationshipListItemTooltipModal'>,
...
};
class RelationshipListItemTooltipButton extends React.PureComponent {
render() {
return (
);
}
onPress = () => {
this.props.navigation.goBackOnce();
};
}
const RelationshipListItemTooltipModal: React.ComponentType<
BaseTooltipProps<'RelationshipListItemTooltipModal'>,
> = createTooltip<'RelationshipListItemTooltipModal'>(
RelationshipListItemTooltipButton,
TooltipMenu,
);
export default RelationshipListItemTooltipModal;