diff --git a/lib/shared/dm-ops/process-dm-ops.js b/lib/shared/dm-ops/process-dm-ops.js --- a/lib/shared/dm-ops/process-dm-ops.js +++ b/lib/shared/dm-ops/process-dm-ops.js @@ -26,15 +26,12 @@ queueDMOpsActionType, dmOperationValidator, } from '../../types/dm-ops.js'; -import type { DMOperation } from '../../types/dm-ops.js'; import type { NotificationsCreationData } from '../../types/notif-types.js'; import type { DispatchMetadata } from '../../types/redux-types.js'; import type { OutboundP2PMessage } from '../../types/sqlite-types.js'; -import { getConfig } from '../../utils/config.js'; import { extractUserIDsFromPayload } from '../../utils/conversion-utils.js'; -import { isDev } from '../../utils/dev-utils.js'; import { useSelector, useDispatch } from '../../utils/redux-utils.js'; -import { useIsCurrentUserStaff } from '../staff-utils.js'; +import { useStaffAlert } from '../staff-utils.js'; function useProcessDMOperation(): ( dmOperationSpecification: DMOperationSpecification, @@ -48,16 +45,7 @@ const dispatch = useDispatch(); - const isCurrentUserStaff = useIsCurrentUserStaff(); - const showOperationAlertToStaff = React.useCallback( - (description: string, operation: DMOperation) => { - if (!isCurrentUserStaff && !isDev) { - return; - } - getConfig().showAlert(description, JSON.stringify(operation)); - }, - [isCurrentUserStaff], - ); + const { showOperationAlertToStaff } = useStaffAlert(); return React.useCallback( async ( diff --git a/lib/shared/staff-utils.js b/lib/shared/staff-utils.js --- a/lib/shared/staff-utils.js +++ b/lib/shared/staff-utils.js @@ -1,7 +1,11 @@ // @flow +import * as React from 'react'; import bots from '../facts/bots.js'; import staff from '../facts/staff.js'; +import type { DMOperation } from '../types/dm-ops.js'; +import { getConfig } from '../utils/config.js'; +import { isDev } from '../utils/dev-utils.js'; import { useSelector } from '../utils/redux-utils.js'; function isStaff(userID: string): boolean { @@ -24,4 +28,35 @@ return isCurrentUserStaff; } -export { isStaff, useIsCurrentUserStaff }; +type StaffAlertHook = { + +showOperationAlertToStaff: ( + description: string, + operation: DMOperation, + ) => void, + +showAlertToStaff: (title: string, message: string) => void, +}; + +function useStaffAlert(): StaffAlertHook { + const isCurrentUserStaff = useIsCurrentUserStaff(); + + const showAlertToStaff = React.useCallback( + (title: string, message: string) => { + if (!isCurrentUserStaff && !isDev) { + return; + } + getConfig().showAlert(title, message); + }, + [isCurrentUserStaff], + ); + + const showOperationAlertToStaff = React.useCallback( + (description: string, operation: DMOperation) => { + showAlertToStaff(description, JSON.stringify(operation)); + }, + [showAlertToStaff], + ); + + return { showOperationAlertToStaff, showAlertToStaff }; +} + +export { isStaff, useIsCurrentUserStaff, useStaffAlert };