diff --git a/webapp/channels/src/actions/admin_actions.jsx b/webapp/channels/src/actions/admin_actions.jsx index a3bfecd744..472b96fde8 100644 --- a/webapp/channels/src/actions/admin_actions.jsx +++ b/webapp/channels/src/actions/admin_actions.jsx @@ -15,7 +15,6 @@ import store from 'stores/redux_store'; import {ActionTypes} from 'utils/constants'; const dispatch = store.dispatch; -const getState = store.getState; export async function reloadConfig(success, error) { const {data, error: err} = await dispatch(AdminActions.reloadConfig()); @@ -29,7 +28,7 @@ export async function reloadConfig(success, error) { } export async function adminResetMfa(userId, success, error) { - const {data, error: err} = await UserActions.updateUserMfa(userId, false)(dispatch, getState); + const {data, error: err} = await dispatch(UserActions.updateUserMfa(userId, false)); if (data && success) { success(data); } else if (err && error) { @@ -38,7 +37,7 @@ export async function adminResetMfa(userId, success, error) { } export async function getClusterStatus(success, error) { - const {data, error: err} = await AdminActions.getClusterStatus()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.getClusterStatus()); if (data && success) { success(data); } else if (err && error) { @@ -47,7 +46,7 @@ export async function getClusterStatus(success, error) { } export async function ldapTest(success, error) { - const {data, error: err} = await AdminActions.testLdap()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.testLdap()); if (data && success) { success(data); } else if (err && error) { @@ -56,7 +55,7 @@ export async function ldapTest(success, error) { } export async function invalidateAllCaches(success, error) { - const {data, error: err} = await AdminActions.invalidateCaches()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.invalidateCaches()); if (data && success) { success(data); } else if (err && error) { @@ -65,7 +64,7 @@ export async function invalidateAllCaches(success, error) { } export async function recycleDatabaseConnection(success, error) { - const {data, error: err} = await AdminActions.recycleDatabase()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.recycleDatabase()); if (data && success) { success(data); } else if (err && error) { @@ -74,7 +73,7 @@ export async function recycleDatabaseConnection(success, error) { } export async function adminResetEmail(user, success, error) { - const {data, error: err} = await UserActions.patchUser(user)(dispatch, getState); + const {data, error: err} = await dispatch(UserActions.patchUser(user)); if (data && success) { success(data); } else if (err && error) { @@ -83,7 +82,7 @@ export async function adminResetEmail(user, success, error) { } export async function samlCertificateStatus(success, error) { - const {data, error: err} = await AdminActions.getSamlCertificateStatus()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.getSamlCertificateStatus()); if (data && success) { success(data); } else if (err && error) { @@ -92,7 +91,7 @@ export async function samlCertificateStatus(success, error) { } export async function getIPFilters(success, error) { - const {data, error: err} = await AdminActions.getIPFilters()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.getIPFilters()); if (data && success) { success(data); } else if (err && error) { @@ -101,7 +100,7 @@ export async function getIPFilters(success, error) { } export async function getCurrentIP(success, error) { - const {data, error: err} = await AdminActions.getCurrentIP()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.getCurrentIP()); if (data && success) { success(data); } else if (err && error) { @@ -110,7 +109,7 @@ export async function getCurrentIP(success, error) { } export async function applyIPFilters(ipList, success, error) { - const {data, error: err} = await AdminActions.applyIPFilters(ipList)(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.applyIPFilters(ipList)); if (data && success) { success(data); } else if (err && error) { @@ -118,6 +117,10 @@ export async function applyIPFilters(ipList, success, error) { } } +/** + * @param {string | null} clientId + * @returns {ActionResult} + */ export function getOAuthAppInfo(clientId) { return bindClientFunc({ clientFunc: Client4.getOAuthAppInfo, @@ -125,6 +128,10 @@ export function getOAuthAppInfo(clientId) { }); } +/** + * @param {*} + * @returns {ActionResult<{redirect: string}>} + */ export function allowOAuth2({responseType, clientId, redirectUri, state, scope}) { return bindClientFunc({ clientFunc: Client4.authorizeOAuthApp, @@ -133,7 +140,7 @@ export function allowOAuth2({responseType, clientId, redirectUri, state, scope}) } export async function emailToLdap(loginId, password, token, ldapId, ldapPassword, success, error) { - const {data, error: err} = await UserActions.switchEmailToLdap(loginId, password, ldapId, ldapPassword, token)(dispatch, getState); + const {data, error: err} = await dispatch(UserActions.switchEmailToLdap(loginId, password, ldapId, ldapPassword, token)); if (data && success) { success(data); } else if (err && error) { @@ -142,7 +149,7 @@ export async function emailToLdap(loginId, password, token, ldapId, ldapPassword } export async function emailToOAuth(loginId, password, token, newType, success, error) { - const {data, error: err} = await UserActions.switchEmailToOAuth(newType, loginId, password, token)(dispatch, getState); + const {data, error: err} = await dispatch(UserActions.switchEmailToOAuth(newType, loginId, password, token)); if (data && success) { success(data); } else if (err && error) { @@ -151,7 +158,7 @@ export async function emailToOAuth(loginId, password, token, newType, success, e } export async function oauthToEmail(currentService, email, password, success, error) { - const {data, error: err} = await UserActions.switchOAuthToEmail(currentService, email, password)(dispatch, getState); + const {data, error: err} = await dispatch(UserActions.switchOAuthToEmail(currentService, email, password)); if (data) { if (data.follow_link) { emitUserLoggedOutEvent(data.follow_link); @@ -165,7 +172,7 @@ export async function oauthToEmail(currentService, email, password, success, err } export async function uploadBrandImage(brandImage, success, error) { - const {data, error: err} = await AdminActions.uploadBrandImage(brandImage)(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.uploadBrandImage(brandImage)); if (data && success) { success(data); } else if (err && error) { @@ -174,7 +181,7 @@ export async function uploadBrandImage(brandImage, success, error) { } export async function deleteBrandImage(success, error) { - const {data, error: err} = await AdminActions.deleteBrandImage()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.deleteBrandImage()); if (data && success) { success(data); } else if (err && error) { @@ -183,7 +190,7 @@ export async function deleteBrandImage(success, error) { } export async function uploadPublicSamlCertificate(file, success, error) { - const {data, error: err} = await AdminActions.uploadPublicSamlCertificate(file)(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.uploadPublicSamlCertificate(file)); if (data && success) { success('saml-public.crt'); } else if (err && error) { @@ -192,7 +199,7 @@ export async function uploadPublicSamlCertificate(file, success, error) { } export async function uploadPrivateSamlCertificate(file, success, error) { - const {data, error: err} = await AdminActions.uploadPrivateSamlCertificate(file)(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.uploadPrivateSamlCertificate(file)); if (data && success) { success('saml-private.key'); } else if (err && error) { @@ -201,7 +208,7 @@ export async function uploadPrivateSamlCertificate(file, success, error) { } export async function uploadPublicLdapCertificate(file, success, error) { - const {data, error: err} = await AdminActions.uploadPublicLdapCertificate(file)(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.uploadPublicLdapCertificate(file)); if (data && success) { success('ldap-public.crt'); } else if (err && error) { @@ -209,7 +216,7 @@ export async function uploadPublicLdapCertificate(file, success, error) { } } export async function uploadPrivateLdapCertificate(file, success, error) { - const {data, error: err} = await AdminActions.uploadPrivateLdapCertificate(file)(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.uploadPrivateLdapCertificate(file)); if (data && success) { success('ldap-private.key'); } else if (err && error) { @@ -218,7 +225,7 @@ export async function uploadPrivateLdapCertificate(file, success, error) { } export async function uploadIdpSamlCertificate(file, success, error) { - const {data, error: err} = await AdminActions.uploadIdpSamlCertificate(file)(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.uploadIdpSamlCertificate(file)); if (data && success) { success('saml-idp.crt'); } else if (err && error) { @@ -227,7 +234,7 @@ export async function uploadIdpSamlCertificate(file, success, error) { } export async function removePublicSamlCertificate(success, error) { - const {data, error: err} = await AdminActions.removePublicSamlCertificate()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.removePublicSamlCertificate()); if (data && success) { success(data); } else if (err && error) { @@ -236,7 +243,7 @@ export async function removePublicSamlCertificate(success, error) { } export async function removePrivateSamlCertificate(success, error) { - const {data, error: err} = await AdminActions.removePrivateSamlCertificate()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.removePrivateSamlCertificate()); if (data && success) { success(data); } else if (err && error) { @@ -245,7 +252,7 @@ export async function removePrivateSamlCertificate(success, error) { } export async function removePublicLdapCertificate(success, error) { - const {data, error: err} = await AdminActions.removePublicLdapCertificate()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.removePublicLdapCertificate()); if (data && success) { success(data); } else if (err && error) { @@ -254,7 +261,7 @@ export async function removePublicLdapCertificate(success, error) { } export async function removePrivateLdapCertificate(success, error) { - const {data, error: err} = await AdminActions.removePrivateLdapCertificate()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.removePrivateLdapCertificate()); if (data && success) { success(data); } else if (err && error) { @@ -263,7 +270,7 @@ export async function removePrivateLdapCertificate(success, error) { } export async function removeIdpSamlCertificate(success, error) { - const {data, error: err} = await AdminActions.removeIdpSamlCertificate()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.removeIdpSamlCertificate()); if (data && success) { success(data); } else if (err && error) { @@ -272,27 +279,27 @@ export async function removeIdpSamlCertificate(success, error) { } export async function getStandardAnalytics(teamId) { - await AdminActions.getStandardAnalytics(teamId)(dispatch, getState); + await dispatch(AdminActions.getStandardAnalytics(teamId)); } export async function getAdvancedAnalytics(teamId) { - await AdminActions.getAdvancedAnalytics(teamId)(dispatch, getState); + await dispatch(AdminActions.getAdvancedAnalytics(teamId)); } export async function getBotPostsPerDayAnalytics(teamId) { - await AdminActions.getBotPostsPerDayAnalytics(teamId)(dispatch, getState); + await dispatch(AdminActions.getBotPostsPerDayAnalytics(teamId)); } export async function getPostsPerDayAnalytics(teamId) { - await AdminActions.getPostsPerDayAnalytics(teamId)(dispatch, getState); + await dispatch(AdminActions.getPostsPerDayAnalytics(teamId)); } export async function getUsersPerDayAnalytics(teamId) { - await AdminActions.getUsersPerDayAnalytics(teamId)(dispatch, getState); + await dispatch(AdminActions.getUsersPerDayAnalytics(teamId)); } export async function elasticsearchTest(config, success, error) { - const {data, error: err} = await AdminActions.testElasticsearch(config)(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.testElasticsearch(config)); if (data && success) { success(data); } else if (err && error) { @@ -301,7 +308,7 @@ export async function elasticsearchTest(config, success, error) { } export async function testS3Connection(success, error) { - const {data, error: err} = await AdminActions.testS3Connection()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.testS3Connection()); if (data && success) { success(data); } else if (err && error) { @@ -310,7 +317,7 @@ export async function testS3Connection(success, error) { } export async function elasticsearchPurgeIndexes(success, error) { - const {data, error: err} = await AdminActions.purgeElasticsearchIndexes()(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.purgeElasticsearchIndexes()); if (data && success) { success(data); } else if (err && error) { @@ -441,7 +448,7 @@ export async function getSamlMetadataFromIdp(success, error, samlMetadataURL) { } export async function setSamlIdpCertificateFromMetadata(success, error, certData) { - const {data, error: err} = await AdminActions.setSamlIdpCertificateFromMetadata(certData)(dispatch, getState); + const {data, error: err} = await dispatch(AdminActions.setSamlIdpCertificateFromMetadata(certData)); if (data && success) { success('saml-idp.crt'); } else if (err && error) { diff --git a/webapp/channels/src/actions/apps.ts b/webapp/channels/src/actions/apps.ts index 863b88e01b..7d89627aa7 100644 --- a/webapp/channels/src/actions/apps.ts +++ b/webapp/channels/src/actions/apps.ts @@ -1,13 +1,16 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import type {AnyAction, Action as ReduxAction} from 'redux'; +import type {ThunkAction} from 'redux-thunk'; + import type {AppCallResponse, AppForm, AppCallRequest, AppContext, AppBinding} from '@mattermost/types/apps'; import type {CommandArgs} from '@mattermost/types/integrations'; import type {Post} from '@mattermost/types/posts'; import {Client4} from 'mattermost-redux/client'; import {AppCallResponseTypes} from 'mattermost-redux/constants/apps'; -import type {Action, ActionFunc, DispatchFunc} from 'mattermost-redux/types/actions'; +import type {ActionFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {cleanForm} from 'mattermost-redux/utils/apps'; import {openModal} from 'actions/views/modals'; @@ -19,10 +22,15 @@ import {getHistory} from 'utils/browser_history'; import {ModalIdentifiers} from 'utils/constants'; import {getSiteURL, shouldOpenInNewTab} from 'utils/url'; +import type {DoAppCallResult} from 'types/apps'; +import type {GlobalState} from 'types/store'; + import {sendEphemeralPost} from './global_actions'; -export function handleBindingClick(binding: AppBinding, context: AppContext, intl: any): ActionFunc { - return async (dispatch: DispatchFunc) => { +export type AppsActionFunc = ThunkAction, GlobalState, unknown, ReduxAction>; + +export function handleBindingClick(binding: AppBinding, context: AppContext, intl: any): AppsActionFunc> { + return async (dispatch) => { // Fetch form let form = binding.form; if (form?.source) { @@ -31,7 +39,7 @@ export function handleBindingClick(binding: AppBinding, context: Ap if (res.error) { return res; } - form = res.data.form; + form = res.data!.form; } // Open form @@ -45,7 +53,7 @@ export function handleBindingClick(binding: AppBinding, context: Ap return {error: makeCallErrorResponse(errMsg)}; } - const res: AppCallResponse = { + const res: AppCallResponse = { type: AppCallResponseTypes.FORM, form, }; @@ -72,7 +80,7 @@ export function handleBindingClick(binding: AppBinding, context: Ap }; } -export function doAppSubmit(inCall: AppCallRequest, intl: any): ActionFunc { +export function doAppSubmit(inCall: AppCallRequest, intl: any): ThunkAction>, GlobalState, unknown, ReduxAction> { return async () => { try { const call: AppCallRequest = { @@ -136,7 +144,7 @@ export function doAppSubmit(inCall: AppCallRequest, intl: any): Act }; } -export function doAppFetchForm(call: AppCallRequest, intl: any): ActionFunc { +export function doAppFetchForm(call: AppCallRequest, intl: any): ThunkAction>, GlobalState, unknown, ReduxAction> { return async () => { try { const res = await Client4.executeAppCall(call, false) as AppCallResponse; @@ -173,7 +181,7 @@ export function doAppFetchForm(call: AppCallRequest, intl: any): Ac }; } -export function doAppLookup(call: AppCallRequest, intl: any): ActionFunc { +export function doAppLookup(call: AppCallRequest, intl: any): ThunkAction>, GlobalState, unknown, ReduxAction> { return async () => { try { const res = await Client4.executeAppCall(call, false) as AppCallResponse; @@ -203,8 +211,8 @@ export function doAppLookup(call: AppCallRequest, intl: any): Actio }; } -export function makeFetchBindings(location: string): (channelId: string, teamId: string) => ActionFunc { - return (channelId: string, teamId: string): ActionFunc => { +export function makeFetchBindings(location: string): (channelId: string, teamId: string) => NewActionFuncAsync { + return (channelId: string, teamId: string): NewActionFuncAsync => { return async () => { try { const allBindings = await Client4.getAppsBindings(channelId, teamId); @@ -218,7 +226,7 @@ export function makeFetchBindings(location: string): (channelId: string, teamId: }; } -export function openAppsModal(form: AppForm, context: AppContext): Action { +export function openAppsModal(form: AppForm, context: AppContext): AnyAction { return openModal({ modalId: ModalIdentifiers.APPS_MODAL, dialogType: AppsForm, diff --git a/webapp/channels/src/actions/channel_actions.ts b/webapp/channels/src/actions/channel_actions.ts index e7c0d2b0ec..9ed3124524 100644 --- a/webapp/channels/src/actions/channel_actions.ts +++ b/webapp/channels/src/actions/channel_actions.ts @@ -14,7 +14,7 @@ import {getChannelByName, getUnreadChannelIds, getChannel} from 'mattermost-redu import {getMyChannelMemberships} from 'mattermost-redux/selectors/entities/common'; import {getCurrentTeamUrl, getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {trackEvent} from 'actions/telemetry_actions.jsx'; import {loadNewDMIfNeeded, loadNewGMIfNeeded, loadProfilesForSidebar} from 'actions/user_actions'; @@ -23,7 +23,7 @@ import {getHistory} from 'utils/browser_history'; import {Constants, Preferences, NotificationLevels} from 'utils/constants'; import {getDirectChannelName} from 'utils/utils'; -export function openDirectChannelToUserId(userId: UserProfile['id']): ActionFunc { +export function openDirectChannelToUserId(userId: UserProfile['id']): NewActionFuncAsync { return async (dispatch, getState) => { const state = getState(); const currentUserId = getCurrentUserId(state); @@ -31,7 +31,7 @@ export function openDirectChannelToUserId(userId: UserProfile['id']): ActionFunc const channel = getChannelByName(state, channelName); if (!channel) { - return dispatch(ChannelActions.createDirectChannel(currentUserId, userId)); + return dispatch(ChannelActions.createDirectChannel(currentUserId, userId) as any); // HARRISONTODO ActionFunc needs migration } trackEvent('api', 'api_channels_join_direct'); @@ -64,7 +64,7 @@ export function openDirectChannelToUserId(userId: UserProfile['id']): ActionFunc }; } -export function openGroupChannelToUserIds(userIds: Array): ActionFunc { +export function openGroupChannelToUserIds(userIds: Array): NewActionFuncAsync { return async (dispatch, getState) => { const result = await dispatch(ChannelActions.createGroupChannel(userIds)); @@ -116,7 +116,7 @@ export function searchMoreChannels(term: string, showArchivedChannels: boolean, }; } -export function autocompleteChannels(term: string, success: (channels: Channel[]) => void, error?: (err: ServerError) => void): ActionFunc { +export function autocompleteChannels(term: string, success: (channels: Channel[]) => void, error?: (err: ServerError) => void): NewActionFuncAsync { return async (dispatch, getState) => { const state = getState(); const teamId = getCurrentTeamId(state); @@ -135,7 +135,7 @@ export function autocompleteChannels(term: string, success: (channels: Channel[] }; } -export function autocompleteChannelsForSearch(term: string, success: (channels: Channel[]) => void, error: (err: ServerError) => void): ActionFunc { +export function autocompleteChannelsForSearch(term: string, success?: (channels: Channel[]) => void, error?: (err: ServerError) => void): NewActionFuncAsync { return async (dispatch, getState) => { const state = getState(); const teamId = getCurrentTeamId(state); @@ -154,12 +154,12 @@ export function autocompleteChannelsForSearch(term: string, success: (channels: }; } -export function addUsersToChannel(channelId: Channel['id'], userIds: Array): ActionFunc { +export function addUsersToChannel(channelId: Channel['id'], userIds: Array): NewActionFuncAsync { return async (dispatch) => { try { const requests = userIds.map((uId) => dispatch(ChannelActions.addChannelMember(channelId, uId))); - return await Promise.all(requests); + return await Promise.all(requests) as any; // HARRISONTODO This incorrectly returns an ActionResult[] } catch (error) { return {error}; } diff --git a/webapp/channels/src/actions/cloud.tsx b/webapp/channels/src/actions/cloud.tsx index 671f1b11d5..c4582f0f68 100644 --- a/webapp/channels/src/actions/cloud.tsx +++ b/webapp/channels/src/actions/cloud.tsx @@ -272,7 +272,7 @@ export function retryFailedCloudFetches() { } if (errors.limits) { - getCloudLimits()(dispatch, getState); + dispatch(getCloudLimits()); } return {data: true}; diff --git a/webapp/channels/src/actions/command.ts b/webapp/channels/src/actions/command.ts index c1bd3a5edb..2ff60f4ad5 100644 --- a/webapp/channels/src/actions/command.ts +++ b/webapp/channels/src/actions/command.ts @@ -15,7 +15,7 @@ import {isMarketplaceEnabled} from 'mattermost-redux/selectors/entities/general' import {haveICurrentTeamPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentRelativeTeamUrl, getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {NewActionFuncAsync} from 'mattermost-redux/types/actions'; import * as GlobalActions from 'actions/global_actions'; import * as PostActions from 'actions/post_actions'; @@ -34,14 +34,13 @@ import {isUrlSafe, getSiteURL} from 'utils/url'; import * as UserAgent from 'utils/user_agent'; import {localizeMessage, getUserIdFromChannelName} from 'utils/utils'; -import type {DoAppCallResult} from 'types/apps'; import type {GlobalState} from 'types/store'; import {doAppSubmit, openAppsModal, postEphemeralCallResponseForCommandArgs} from './apps'; import {trackEvent} from './telemetry_actions'; -export function executeCommand(message: string, args: CommandArgs): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function executeCommand(message: string, args: CommandArgs): NewActionFuncAsync { + return async (dispatch, getState) => { const state = getState() as GlobalState; let msg = message; @@ -155,7 +154,7 @@ export function executeCommand(message: string, args: CommandArgs): ActionFunc { return createErrorMessage(errorMessage!); } - const res = await dispatch(doAppSubmit(creq, intlShim)) as DoAppCallResult; + const res = await dispatch(doAppSubmit(creq, intlShim)); if (res.error) { const errorResponse = res.error; diff --git a/webapp/channels/src/actions/hooks.js b/webapp/channels/src/actions/hooks.js index 52d2e6bc57..5a220ef5f2 100644 --- a/webapp/channels/src/actions/hooks.js +++ b/webapp/channels/src/actions/hooks.js @@ -1,6 +1,10 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +/** + * @param {Post} originalPost + * @returns {NewActionFuncAsync} + */ export function runMessageWillBePostedHooks(originalPost) { return async (dispatch, getState) => { const hooks = getState().plugins.components.MessageWillBePosted; diff --git a/webapp/channels/src/actions/integration_actions.tsx b/webapp/channels/src/actions/integration_actions.tsx index ab0457b38b..2f036c0d5f 100644 --- a/webapp/channels/src/actions/integration_actions.tsx +++ b/webapp/channels/src/actions/integration_actions.tsx @@ -7,11 +7,11 @@ import * as IntegrationActions from 'mattermost-redux/actions/integrations'; import {getProfilesByIds} from 'mattermost-redux/actions/users'; import {appsEnabled} from 'mattermost-redux/selectors/entities/apps'; import {getUser} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; const DEFAULT_PAGE_SIZE = 100; -export function loadIncomingHooksAndProfilesForTeam(teamId: string, page = 0, perPage = DEFAULT_PAGE_SIZE): ActionFunc { +export function loadIncomingHooksAndProfilesForTeam(teamId: string, page = 0, perPage = DEFAULT_PAGE_SIZE): NewActionFuncAsync { return async (dispatch) => { const {data} = await dispatch(IntegrationActions.getIncomingHooks(teamId, page, perPage)); if (data) { @@ -42,7 +42,7 @@ export function loadProfilesForIncomingHooks(hooks: IncomingWebhook[]): ActionFu }; } -export function loadOutgoingHooksAndProfilesForTeam(teamId: string, page = 0, perPage = DEFAULT_PAGE_SIZE): ActionFunc { +export function loadOutgoingHooksAndProfilesForTeam(teamId: string, page = 0, perPage = DEFAULT_PAGE_SIZE): NewActionFuncAsync { return async (dispatch) => { const {data} = await dispatch(IntegrationActions.getOutgoingHooks('', teamId, page, perPage)); if (data) { @@ -104,7 +104,7 @@ export function loadProfilesForCommands(commands: Command[]): ActionFunc { }; } -export function loadOAuthAppsAndProfiles(page = 0, perPage = DEFAULT_PAGE_SIZE): ActionFunc { +export function loadOAuthAppsAndProfiles(page = 0, perPage = DEFAULT_PAGE_SIZE): NewActionFuncAsync { return async (dispatch, getState) => { if (appsEnabled(getState())) { dispatch(IntegrationActions.getAppsOAuthAppIDs()); diff --git a/webapp/channels/src/actions/invite_actions.test.ts b/webapp/channels/src/actions/invite_actions.test.ts index caf7e342b5..941a78714a 100644 --- a/webapp/channels/src/actions/invite_actions.test.ts +++ b/webapp/channels/src/actions/invite_actions.test.ts @@ -4,8 +4,6 @@ import type {Channel} from '@mattermost/types/channels'; import type {UserProfile} from '@mattermost/types/users'; -import type {DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; - import {sendMembersInvites, sendGuestsInvites} from 'actions/invite_actions'; import mockStore from 'tests/test_store'; @@ -124,7 +122,7 @@ describe('actions/invite_actions', () => { describe('sendMembersInvites', () => { it('should generate and empty list if nothing is passed', async () => { - const response = await sendMembersInvites('correct', [], [])(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendMembersInvites('correct', [], [])); expect(response).toEqual({ data: { sent: [], @@ -135,7 +133,7 @@ describe('actions/invite_actions', () => { it('should generate list of success for emails', async () => { const emails = ['email-one@email-one.com', 'email-two@email-two.com', 'email-three@email-three.com']; - const response = await sendMembersInvites('correct', [], emails)(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendMembersInvites('correct', [], emails)); expect(response).toEqual({ data: { notSent: [], @@ -159,7 +157,7 @@ describe('actions/invite_actions', () => { it('should generate list of failures for emails on invite fails', async () => { const emails = ['email-one@email-one.com', 'email-two@email-two.com', 'email-three@email-three.com']; - const response = await sendMembersInvites('error', [], emails)(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendMembersInvites('error', [], emails)); expect(response).toEqual({ data: { sent: [], @@ -188,7 +186,7 @@ describe('actions/invite_actions', () => { {id: 'other-user', roles: 'system_user'}, {id: 'other-guest', roles: 'system_guest'}, ] as UserProfile[]; - const response = await sendMembersInvites('correct', users, [])(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendMembersInvites('correct', users, [])); expect(response).toEqual({ data: { sent: [ @@ -234,7 +232,7 @@ describe('actions/invite_actions', () => { {id: 'other-user', roles: 'system_user'}, {id: 'other-guest', roles: 'system_guest'}, ] as UserProfile[]; - const response = await sendMembersInvites('error', users, [])(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendMembersInvites('error', users, [])); expect(response).toEqual({ data: { sent: [{user: {id: 'other-user', roles: 'system_user'}, reason: 'This member has been added to the team.'}], @@ -275,7 +273,7 @@ describe('actions/invite_actions', () => { reason: 'Invite emails rate limit exceeded.', }); } - const response = await sendMembersInvites('correct', [], emails)(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendMembersInvites('correct', [], emails)); expect(response).toEqual({ data: { notSent: expectedNotSent, @@ -286,7 +284,7 @@ describe('actions/invite_actions', () => { it('should generate a failure for smtp config', async () => { const emails = ['email-one@email-one.com']; - const response = await sendMembersInvites('incorrect-default-smtp', [], emails)(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendMembersInvites('incorrect-default-smtp', [], emails)); expect(response).toEqual({ data: { notSent: [ @@ -306,7 +304,7 @@ describe('actions/invite_actions', () => { describe('sendGuestsInvites', () => { it('should generate and empty list if nothing is passed', async () => { - const response = await sendGuestsInvites('correct', [], [], [], '')(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendGuestsInvites('correct', [], [], [], '')); expect(response).toEqual({ data: { sent: [], @@ -318,7 +316,7 @@ describe('actions/invite_actions', () => { it('should generate list of success for emails', async () => { const channels = [{id: 'correct'}] as Channel[]; const emails = ['email-one@email-one.com', 'email-two@email-two.com', 'email-three@email-three.com']; - const response = await sendGuestsInvites('correct', channels, [], emails, 'message')(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendGuestsInvites('correct', channels, [], emails, 'message')); expect(response).toEqual({ data: { notSent: [], @@ -343,7 +341,7 @@ describe('actions/invite_actions', () => { it('should generate list of failures for emails on invite fails', async () => { const channels = [{id: 'correct'}] as Channel[]; const emails = ['email-one@email-one.com', 'email-two@email-two.com', 'email-three@email-three.com']; - const response = await sendGuestsInvites('error', channels, [], emails, 'message')(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendGuestsInvites('error', channels, [], emails, 'message')); expect(response).toEqual({ data: { sent: [], @@ -373,7 +371,7 @@ describe('actions/invite_actions', () => { {id: 'other-user', roles: 'system_user'}, {id: 'other-guest', roles: 'system_guest'}, ] as UserProfile[]; - const response = await sendGuestsInvites('correct', channels, users, [], 'message')(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendGuestsInvites('correct', channels, users, [], 'message')); expect(response).toEqual({ data: { sent: [ @@ -425,7 +423,7 @@ describe('actions/invite_actions', () => { {id: 'guest2', roles: 'system_guest'}, {id: 'guest3', roles: 'system_guest'}, ] as UserProfile[]; - const response = await sendGuestsInvites('correct', [{id: 'correct'}, {id: 'correct2'}] as Channel[], users, [], 'message')(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendGuestsInvites('correct', [{id: 'correct'}, {id: 'correct2'}] as Channel[], users, [], 'message')); expect(response).toEqual({ data: { sent: [], @@ -456,7 +454,7 @@ describe('actions/invite_actions', () => { {id: 'other-user', roles: 'system_user'}, {id: 'other-guest', roles: 'system_guest'}, ] as UserProfile[]; - const response = await sendGuestsInvites('error', [{id: 'correct'}] as Channel[], users, [], 'message')(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendGuestsInvites('error', [{id: 'correct'}] as Channel[], users, [], 'message')); expect(response).toEqual({ data: { @@ -515,7 +513,7 @@ describe('actions/invite_actions', () => { {id: 'other-user', roles: 'system_user'}, {id: 'other-guest', roles: 'system_guest'}, ] as UserProfile[]; - const response = await sendGuestsInvites('correct', [{id: 'error'}] as Channel[], users, [], 'message')(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendGuestsInvites('correct', [{id: 'error'}] as Channel[], users, [], 'message')); expect(response).toEqual({ data: { sent: [], @@ -564,7 +562,7 @@ describe('actions/invite_actions', () => { }); } - const response = await sendGuestsInvites('correct', [{id: 'correct'}] as Channel[], [], emails, 'message')(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendGuestsInvites('correct', [{id: 'correct'}] as Channel[], [], emails, 'message')); expect(response).toEqual({ data: { notSent: expectedNotSent, @@ -575,7 +573,7 @@ describe('actions/invite_actions', () => { it('should generate a failure for smtp config', async () => { const emails = ['email-one@email-one.com']; - const response = await sendGuestsInvites('incorrect-default-smtp', [{id: 'error'}] as Channel[], [], emails, 'message')(store.dispatch as DispatchFunc, store.getState as GetStateFunc); + const response = await store.dispatch(sendGuestsInvites('incorrect-default-smtp', [{id: 'error'}] as Channel[], [], emails, 'message')); expect(response).toEqual({ data: { notSent: [ diff --git a/webapp/channels/src/actions/invite_actions.ts b/webapp/channels/src/actions/invite_actions.ts index 44ba62c57c..95c50c1c96 100644 --- a/webapp/channels/src/actions/invite_actions.ts +++ b/webapp/channels/src/actions/invite_actions.ts @@ -11,17 +11,19 @@ import * as TeamActions from 'mattermost-redux/actions/teams'; import {getChannelMembersInChannels} from 'mattermost-redux/selectors/entities/channels'; import {getTeamMember} from 'mattermost-redux/selectors/entities/teams'; import {isCurrentUserSystemAdmin} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {DispatchFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {isGuest} from 'mattermost-redux/utils/user_utils'; import {addUsersToTeam} from 'actions/team_actions'; +import type {InviteResults} from 'components/invitation_modal/result_view'; + import {ConsolePages} from 'utils/constants'; import {t} from 'utils/i18n'; import {localizeMessage} from 'utils/utils'; -export function sendMembersInvites(teamId: string, users: UserProfile[], emails: string[]): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function sendMembersInvites(teamId: string, users: UserProfile[], emails: string[]): NewActionFuncAsync { + return async (dispatch, getState) => { if (users.length > 0) { await dispatch(TeamActions.getTeamMembersByIds(teamId, users.map((u) => u.id))); } @@ -62,7 +64,12 @@ export function sendMembersInvites(teamId: string, users: UserProfile[], emails: try { response = await dispatch(TeamActions.sendEmailInvitesToTeamGracefully(teamId, emails)); } catch (e) { - response = {data: emails.map((email) => ({email, error: {error: localizeMessage('invite.members.unable-to-add-the-user-to-the-team', 'Unable to add the user to the team.')}}))}; + response = { + data: emails.map((email) => ({ + email, + error: {error: localizeMessage('invite.members.unable-to-add-the-user-to-the-team', 'Unable to add the user to the team.')}, + })) as any, // HARRISONTODO These error handling cases return slightly different types + }; } const invitesWithErrors = response.data || []; if (response.error) { @@ -151,8 +158,8 @@ export function sendGuestsInvites( users: UserProfile[], emails: string[], message: string, -): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +): NewActionFuncAsync { + return async (dispatch, getState) => { const state = getState(); const sent = []; const notSent = []; @@ -173,7 +180,12 @@ export function sendGuestsInvites( try { response = await dispatch(TeamActions.sendEmailGuestInvitesToChannelsGracefully(teamId, channels.map((x) => x.id), emails, message)); } catch (e) { - response = {data: emails.map((email) => ({email, error: {error: localizeMessage('invite.guests.unable-to-add-the-user-to-the-channels', 'Unable to add the guest to the channels.')}}))}; + response = { + data: emails.map((email) => ({ + email, + error: {error: localizeMessage('invite.guests.unable-to-add-the-user-to-the-channels', 'Unable to add the guest to the channels.')}, + })), + } as any; // HARRISONTODO These error handling cases return slightly different types } if (response.error) { @@ -214,8 +226,8 @@ export function sendMembersInvitesToChannels( users: UserProfile[], emails: string[], message: string, -): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +): NewActionFuncAsync { + return async (dispatch, getState) => { if (users.length > 0) { // used to preload in the global store the teammembers info, used later to validate // if one of the invites is already part of the team by getTeamMembers > getMembersInTeam. @@ -265,7 +277,12 @@ export function sendMembersInvitesToChannels( ), ); } catch (e) { - response = {data: emails.map((email) => ({email, error: {error: localizeMessage('invite.members.unable-to-add-the-user-to-the-team', 'Unable to add the user to the team.')}}))}; + response = { + data: emails.map((email) => ({ + email, + error: {error: localizeMessage('invite.members.unable-to-add-the-user-to-the-team', 'Unable to add the user to the team.')}, + })) as any, // HARRISONTODO These error handling cases return slightly different types + }; } const invitesWithErrors = response.data || []; if (response.error) { diff --git a/webapp/channels/src/actions/post_actions.ts b/webapp/channels/src/actions/post_actions.ts index a6e9ab38f0..60b4ac8d96 100644 --- a/webapp/channels/src/actions/post_actions.ts +++ b/webapp/channels/src/actions/post_actions.ts @@ -15,7 +15,7 @@ import * as PostSelectors from 'mattermost-redux/selectors/entities/posts'; import {isCollapsedThreadsEnabled} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId, isCurrentUserSystemAdmin} from 'mattermost-redux/selectors/entities/users'; -import type {DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {DispatchFunc, GetStateFunc, NewActionFunc, NewActionFuncAsync, NewActionFuncOldVariantDoNotUse} from 'mattermost-redux/types/actions'; import {canEditPost, comparePosts} from 'mattermost-redux/utils/post_utils'; import {addRecentEmoji, addRecentEmojis} from 'actions/emoji_actions'; @@ -146,8 +146,8 @@ function storeCommentDraft(rootPostId: string, draft: null) { }; } -export function submitReaction(postId: string, action: string, emojiName: string) { - return (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function submitReaction(postId: string, action: string, emojiName: string): NewActionFuncOldVariantDoNotUse { + return (dispatch, getState) => { const state = getState() as GlobalState; const getIsReactionAlreadyAddedToPost = makeGetIsReactionAlreadyAddedToPost(); @@ -162,8 +162,8 @@ export function submitReaction(postId: string, action: string, emojiName: string }; } -export function toggleReaction(postId: string, emojiName: string) { - return (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function toggleReaction(postId: string, emojiName: string): NewActionFuncOldVariantDoNotUse { + return (dispatch, getState) => { const state = getState() as GlobalState; const getIsReactionAlreadyAddedToPost = makeGetIsReactionAlreadyAddedToPost(); @@ -176,9 +176,9 @@ export function toggleReaction(postId: string, emojiName: string) { }; } -export function addReaction(postId: string, emojiName: string) { +export function addReaction(postId: string, emojiName: string): NewActionFunc { const getUniqueEmojiNameReactionsForPost = makeGetUniqueEmojiNameReactionsForPost(); - return (dispatch: DispatchFunc, getState: GetStateFunc) => { + return (dispatch, getState) => { const state = getState() as GlobalState; const config = getConfig(state); const uniqueEmojiNames = getUniqueEmojiNameReactionsForPost(state, postId) ?? []; @@ -277,8 +277,8 @@ export function unpinPost(postId: string) { }; } -export function setEditingPost(postId = '', refocusId = '', title = '', isRHS = false) { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function setEditingPost(postId = '', refocusId = '', title = '', isRHS = false): NewActionFunc { + return (dispatch, getState) => { const state = getState(); const post = PostSelectors.getPost(state, postId); @@ -316,8 +316,8 @@ export function unsetEditingPost() { }; } -export function markPostAsUnread(post: Post, location: string) { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function markPostAsUnread(post: Post, location?: string): NewActionFuncAsync { + return async (dispatch, getState) => { const state = getState(); const userId = getCurrentUserId(state); const currentTeamId = getCurrentTeamId(state); @@ -355,8 +355,8 @@ export function markMostRecentPostInChannelAsUnread(channelId: string) { } // Action called by DeletePostModal when the post is deleted -export function deleteAndRemovePost(post: Post) { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function deleteAndRemovePost(post: Post): NewActionFuncAsync { + return async (dispatch, getState) => { const {error} = await dispatch(PostActions.deletePost(post)); if (error) { return {error}; @@ -425,7 +425,7 @@ export function resetInlineImageVisibility() { * * @param {string} emittedFrom - It can be either "CENTER", "RHS_ROOT" or "NO_WHERE" */ -export function emitShortcutReactToLastPostFrom(emittedFrom: 'CENTER' | 'RHS_ROOT' | 'NO_WHERE') { +export function emitShortcutReactToLastPostFrom(emittedFrom: keyof typeof Constants.Locations) { return { type: ActionTypes.EMITTED_SHORTCUT_REACT_TO_LAST_POST, payload: emittedFrom, diff --git a/webapp/channels/src/actions/status_actions.ts b/webapp/channels/src/actions/status_actions.ts index 4b35ee0035..c2363760c4 100644 --- a/webapp/channels/src/actions/status_actions.ts +++ b/webapp/channels/src/actions/status_actions.ts @@ -8,7 +8,7 @@ import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels' import {getPostsInCurrentChannel} from 'mattermost-redux/selectors/entities/posts'; import {getDirectShowPreferences} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {ActionFunc, DispatchFunc, GetStateFunc, NewActionFunc} from 'mattermost-redux/types/actions'; import {loadCustomEmojisForCustomStatusesByUserIds} from 'actions/emoji_actions'; @@ -49,8 +49,8 @@ export function loadStatusesForChannelAndSidebar(): ActionFunc { }; } -export function loadStatusesForProfilesList(users: UserProfile[] | null) { - return (dispatch: DispatchFunc) => { +export function loadStatusesForProfilesList(users: UserProfile[] | null): NewActionFunc { + return (dispatch) => { if (users == null) { return {data: false}; } diff --git a/webapp/channels/src/actions/team_actions.ts b/webapp/channels/src/actions/team_actions.ts index 414c883578..92ead15fa8 100644 --- a/webapp/channels/src/actions/team_actions.ts +++ b/webapp/channels/src/actions/team_actions.ts @@ -2,7 +2,7 @@ // See LICENSE.txt for license information. import type {ServerError} from '@mattermost/types/errors'; -import type {Team} from '@mattermost/types/teams'; +import type {Team, TeamMemberWithError} from '@mattermost/types/teams'; import type {UserProfile} from '@mattermost/types/users'; import {TeamTypes} from 'mattermost-redux/action_types'; @@ -15,12 +15,12 @@ import {getUser} from 'mattermost-redux/actions/users'; import {Client4} from 'mattermost-redux/client'; import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {ActionFunc, DispatchFunc, GetStateFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {getHistory} from 'utils/browser_history'; import {Preferences} from 'utils/constants'; -export function removeUserFromTeamAndGetStats(teamId: Team['id'], userId: UserProfile['id']): ActionFunc { +export function removeUserFromTeamAndGetStats(teamId: Team['id'], userId: UserProfile['id']): NewActionFuncAsync { return async (dispatch, getState) => { const response = await dispatch(TeamActions.removeUserFromTeam(teamId, userId)); dispatch(getUser(userId)); @@ -30,7 +30,7 @@ export function removeUserFromTeamAndGetStats(teamId: Team['id'], userId: UserPr }; } -export function addUserToTeamFromInvite(token: string, inviteId: string): ActionFunc { +export function addUserToTeamFromInvite(token: string, inviteId: string): NewActionFuncAsync { return async (dispatch) => { const {data: member, error} = await dispatch(TeamActions.addUserToTeamFromInvite(token, inviteId)); if (member) { @@ -52,7 +52,7 @@ export function addUserToTeamFromInvite(token: string, inviteId: string): Action }; } -export function addUserToTeam(teamId: Team['id'], userId: UserProfile['id']): ActionFunc { +export function addUserToTeam(teamId: Team['id'], userId: UserProfile['id']): NewActionFuncAsync { return async (dispatch) => { const {data: member, error} = await dispatch(TeamActions.addUserToTeam(teamId, userId)); if (member) { @@ -74,7 +74,7 @@ export function addUserToTeam(teamId: Team['id'], userId: UserProfile['id']): Ac }; } -export function addUsersToTeam(teamId: Team['id'], userIds: Array): ActionFunc { +export function addUsersToTeam(teamId: Team['id'], userIds: Array): NewActionFuncAsync { return async (dispatch, getState) => { const {data, error} = await dispatch(TeamActions.addUsersToTeamGracefully(teamId, userIds)); diff --git a/webapp/channels/src/actions/user_actions.ts b/webapp/channels/src/actions/user_actions.ts index bd8e7f745b..d10aa40ced 100644 --- a/webapp/channels/src/actions/user_actions.ts +++ b/webapp/channels/src/actions/user_actions.ts @@ -22,7 +22,7 @@ import { import {getBool, isCollapsedThreadsEnabled} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentTeamId, getTeamMember} from 'mattermost-redux/selectors/entities/teams'; import * as Selectors from 'mattermost-redux/selectors/entities/users'; -import type {ActionResult, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult, DispatchFunc, GetStateFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {calculateUnreadCount} from 'mattermost-redux/utils/channel_utils'; import {loadCustomEmojisForCustomStatusesByUserIds} from 'actions/emoji_actions'; @@ -79,8 +79,8 @@ export function loadProfilesAndReloadChannelMembers(page: number, perPage?: numb }; } -export function loadProfilesAndTeamMembers(page: number, perPage: number, teamId: string, options?: Record) { - return async (doDispatch: DispatchFunc, doGetState: GetStateFunc) => { +export function loadProfilesAndTeamMembers(page: number, perPage: number, teamId: string, options?: Record): NewActionFuncAsync { + return async (doDispatch, doGetState) => { const newTeamId = teamId || getCurrentTeamId(doGetState()); const {data} = await doDispatch(UserActions.getProfilesInTeam(newTeamId, page, perPage, '', options)); if (data) { @@ -122,8 +122,8 @@ export function searchProfilesAndChannelMembers(term: string, options: Record { +export function loadProfilesAndTeamMembersAndChannelMembers(page: number, perPage: number, teamId: string, channelId: string, options?: {active?: boolean}): NewActionFuncAsync { + return async (doDispatch, doGetState) => { const state = doGetState(); const teamIdParam = teamId || getCurrentTeamId(state); const channelIdParam = channelId || getCurrentChannelId(state); @@ -227,10 +227,10 @@ export function loadNewDMIfNeeded(channelId: string) { const pref = getBool(state, Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, userId, false); if (pref === false) { const now = Utils.getTimestamp(); - savePreferences(currentUserId, [ + doDispatch(savePreferences(currentUserId, [ {user_id: currentUserId, category: Preferences.CATEGORY_DIRECT_CHANNEL_SHOW, name: userId, value: 'true'}, {user_id: currentUserId, category: Preferences.CATEGORY_CHANNEL_OPEN_TIME, name: channelId, value: now.toString()}, - ])(doDispatch); + ])); loadProfilesForDM(); return {data: true}; } @@ -243,7 +243,7 @@ export function loadNewDMIfNeeded(channelId: string) { if (channel) { result = checkPreference(channel); } else { - result = await getChannelAndMyMember(channelId)(doDispatch, doGetState) as ActionResult; + result = await doDispatch(getChannelAndMyMember(channelId)); if (result.data) { result = checkPreference(result.data.channel); } @@ -269,7 +269,7 @@ export function loadNewGMIfNeeded(channelId: string) { const channel = getChannel(state, channelId); if (!channel) { - await getChannelAndMyMember(channelId)(doDispatch, doGetState); + await doDispatch(getChannelAndMyMember(channelId)); } return checkPreference(); }; @@ -406,13 +406,13 @@ export async function loadProfilesForDM() { } if (newPreferences.length > 0) { - savePreferences(currentUserId, newPreferences)(dispatch); + dispatch(savePreferences(currentUserId, newPreferences)); } if (profilesToLoad.length > 0) { - await UserActions.getProfilesByIds(profilesToLoad)(dispatch, getState); + await dispatch(UserActions.getProfilesByIds(profilesToLoad)); } - await loadCustomEmojisForCustomStatusesByUserIds(profileIds)(dispatch, getState); + await dispatch(loadCustomEmojisForCustomStatusesByUserIds(profileIds)); } export function autocompleteUsersInTeam(username: string) { @@ -431,9 +431,9 @@ export function autocompleteUsers(username: string) { } export function autoResetStatus() { - return async (doDispatch: DispatchFunc, doGetState: GetStateFunc): Promise<{data: UserStatus}> => { + return async (doDispatch: DispatchFunc): Promise<{data: UserStatus}> => { const {currentUserId} = getState().entities.users; - const {data: userStatus} = await (UserActions.getStatus(currentUserId)(doDispatch, doGetState) as Promise<{data: UserStatus}>); + const {data: userStatus} = await doDispatch(UserActions.getStatus(currentUserId)); if (userStatus.status === UserStatuses.OUT_OF_OFFICE || !userStatus.manual) { return {data: userStatus}; @@ -442,7 +442,7 @@ export function autoResetStatus() { const autoReset = getBool(getState(), PreferencesRedux.CATEGORY_AUTO_RESET_MANUAL_STATUS, currentUserId, false); if (autoReset) { - UserActions.setStatus({user_id: currentUserId, status: 'online'})(doDispatch, doGetState); + doDispatch(UserActions.setStatus({user_id: currentUserId, status: 'online'})); return {data: userStatus}; } diff --git a/webapp/channels/src/actions/views/browser.ts b/webapp/channels/src/actions/views/browser.ts index afb3e8023f..528b22ef42 100644 --- a/webapp/channels/src/actions/views/browser.ts +++ b/webapp/channels/src/actions/views/browser.ts @@ -1,11 +1,9 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import type {GenericAction} from 'mattermost-redux/types/actions'; - import {Constants, ActionTypes, WindowSizes} from 'utils/constants'; -export function emitBrowserWindowResized(windowSize?: string): GenericAction { +export function emitBrowserWindowResized(windowSize?: string) { let newWindowSize = windowSize; if (!windowSize) { const width = window.innerWidth; diff --git a/webapp/channels/src/actions/views/channel.ts b/webapp/channels/src/actions/views/channel.ts index f0783eda35..e6f9e4a3d0 100644 --- a/webapp/channels/src/actions/views/channel.ts +++ b/webapp/channels/src/actions/views/channel.ts @@ -41,7 +41,7 @@ import { } from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId, getUserByUsername} from 'mattermost-redux/selectors/entities/users'; import {makeAddLastViewAtToProfiles} from 'mattermost-redux/selectors/entities/utils'; -import type {DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {DispatchFunc, GetStateFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {getChannelByName} from 'mattermost-redux/utils/channel_utils'; import EventEmitter from 'mattermost-redux/utils/event_emitter'; @@ -98,8 +98,8 @@ export function loadIfNecessaryAndSwitchToChannelById(channelId: string) { }; } -export function switchToChannel(channel: Channel & {userId?: string}) { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function switchToChannel(channel: Channel & {userId?: string}): NewActionFuncAsync { + return async (dispatch, getState) => { const state = getState(); const selectedTeamId = channel.team_id; const teamUrl = selectedTeamId ? `/${getTeam(state, selectedTeamId).name}` : getCurrentRelativeTeamUrl(state); @@ -234,8 +234,8 @@ export function autocompleteUsersInChannel(prefix: string, channelId: string) { }; } -export function loadUnreads(channelId: string, prefetch = false) { - return async (dispatch: DispatchFunc) => { +export function loadUnreads(channelId: string, prefetch = false): NewActionFuncAsync<{atLatestMessage: boolean; atOldestMessage: boolean}> { + return async (dispatch) => { const time = Date.now(); if (prefetch) { dispatch({ @@ -259,13 +259,13 @@ export function loadUnreads(channelId: string, prefetch = false) { atOldestmessage: false, }; } - dispatch(loadCustomStatusEmojisForPostList(data.posts)); + dispatch(loadCustomStatusEmojisForPostList(data!.posts)); const actions = []; actions.push({ type: ActionTypes.INCREASE_POST_VISIBILITY, data: channelId, - amount: data.order.length, + amount: data!.order.length, }); if (prefetch) { @@ -276,7 +276,7 @@ export function loadUnreads(channelId: string, prefetch = false) { }); } - if (data.next_post_id === '') { + if (data!.next_post_id === '') { actions.push({ type: ActionTypes.RECEIVED_POSTS_FOR_CHANNEL_AT_TIME, channelId, @@ -286,8 +286,8 @@ export function loadUnreads(channelId: string, prefetch = false) { dispatch(batchActions(actions)); return { - atLatestMessage: data.next_post_id === '', - atOldestmessage: data.prev_post_id === '', + atLatestMessage: data!.next_post_id === '', + atOldestmessage: data!.prev_post_id === '', }; }; } @@ -460,8 +460,8 @@ export function syncPostsInChannel(channelId: string, since: number, prefetch = }; } -export function prefetchChannelPosts(channelId: string, jitter: number) { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function prefetchChannelPosts(channelId: string, jitter?: number): NewActionFuncAsync { + return async (dispatch, getState) => { const state = getState(); const recentPostIdInChannel = getMostRecentPostIdInChannel(state, channelId); diff --git a/webapp/channels/src/actions/views/channel_sidebar.ts b/webapp/channels/src/actions/views/channel_sidebar.ts index b62a6f62b9..4b5abe5e45 100644 --- a/webapp/channels/src/actions/views/channel_sidebar.ts +++ b/webapp/channels/src/actions/views/channel_sidebar.ts @@ -6,7 +6,7 @@ import {General} from 'mattermost-redux/constants'; import {CategoryTypes} from 'mattermost-redux/constants/channel_categories'; import {getCategory, makeGetChannelIdsForCategory} from 'mattermost-redux/selectors/entities/channel_categories'; import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels'; -import type {DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {DispatchFunc, GetStateFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {insertMultipleWithoutDuplicates} from 'mattermost-redux/utils/array_utils'; import {getCategoriesForCurrentTeam, getChannelsInCategoryOrder, getDisplayedChannels} from 'selectors/views/channel_sidebar'; @@ -33,8 +33,8 @@ export function stopDragging() { return {type: ActionTypes.SIDEBAR_DRAGGING_STOP}; } -export function createCategory(teamId: string, displayName: string, channelIds?: string[]) { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function createCategory(teamId: string, displayName: string, channelIds?: string[]): NewActionFuncAsync { + return async (dispatch, getState) => { if (channelIds) { const state = getState() as GlobalState; const multiSelectedChannelIds = state.views.channelSidebar.multiSelectedChannelIds; diff --git a/webapp/channels/src/actions/views/create_comment.tsx b/webapp/channels/src/actions/views/create_comment.tsx index bbddbe904f..97c3ca0902 100644 --- a/webapp/channels/src/actions/views/create_comment.tsx +++ b/webapp/channels/src/actions/views/create_comment.tsx @@ -18,7 +18,7 @@ import { } from 'mattermost-redux/selectors/entities/posts'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {DispatchFunc, GetStateFunc, NewActionFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {isPostPendingOrFailed} from 'mattermost-redux/utils/post_utils'; import {executeCommand} from 'actions/command'; @@ -143,8 +143,8 @@ export function submitCommand(channelId: string, rootId: string, draft: PostDraf }; } -export function makeOnSubmit(channelId: string, rootId: string, latestPostId: string) { - return (draft: PostDraft, options: {ignoreSlash?: boolean} = {}) => async (dispatch: DispatchFunc, getState: () => GlobalState) => { +export function makeOnSubmit(channelId: string, rootId: string, latestPostId: string): (draft: PostDraft, options?: {ignoreSlash?: boolean}) => NewActionFuncAsync { + return (draft, options = {}) => async (dispatch, getState) => { const {message} = draft; dispatch(addMessageIntoHistory(message)); @@ -218,10 +218,10 @@ function makeGetCurrentUsersLatestReply() { ); } -export function makeOnEditLatestPost(rootId: string) { +export function makeOnEditLatestPost(rootId: string): () => NewActionFunc { const getCurrentUsersLatestPost = makeGetCurrentUsersLatestReply(); - return () => (dispatch: DispatchFunc, getState: GetStateFunc) => { + return () => (dispatch, getState) => { const state = getState(); const lastPost = getCurrentUsersLatestPost(state, rootId); diff --git a/webapp/channels/src/actions/views/modals.ts b/webapp/channels/src/actions/views/modals.ts index f2fd2bdde9..83d4c22246 100644 --- a/webapp/channels/src/actions/views/modals.ts +++ b/webapp/channels/src/actions/views/modals.ts @@ -19,7 +19,7 @@ export type CloseModalType = { modalId: string; } -export function closeModal(modalId: string): CloseModalType { +export function closeModal(modalId: string) { return { type: ActionTypes.MODAL_CLOSE, modalId, diff --git a/webapp/channels/src/actions/views/posts.js b/webapp/channels/src/actions/views/posts.js index 4c35f180e5..ddf52eec2a 100644 --- a/webapp/channels/src/actions/views/posts.js +++ b/webapp/channels/src/actions/views/posts.js @@ -21,8 +21,8 @@ import {getTimestamp} from 'utils/utils'; import {runMessageWillBePostedHooks} from '../hooks'; export function editPost(post) { - return async (dispatch, getState) => { - const result = await PostActions.editPost(post)(dispatch, getState); + return async (dispatch) => { + const result = await dispatch(PostActions.editPost(post)); // Send to error bar if it's an edit post error about time limit. if (result.error && result.error.server_error_id === 'api.post.update_post.permissions_time_limit.app_error') { diff --git a/webapp/channels/src/actions/views/profile_popover.ts b/webapp/channels/src/actions/views/profile_popover.ts index f6debb6aaf..c2fb462a87 100644 --- a/webapp/channels/src/actions/views/profile_popover.ts +++ b/webapp/channels/src/actions/views/profile_popover.ts @@ -3,10 +3,10 @@ import {getChannelMember} from 'mattermost-redux/actions/channels'; import {getTeamMember} from 'mattermost-redux/actions/teams'; -import type {DispatchFunc} from 'mattermost-redux/types/actions'; +import type {NewActionFuncOldVariantDoNotUse} from 'mattermost-redux/types/actions'; -export function getMembershipForEntities(teamId: string, userId: string, channelId?: string) { - return (dispatch: DispatchFunc) => { +export function getMembershipForEntities(teamId: string, userId: string, channelId?: string): NewActionFuncOldVariantDoNotUse { + return (dispatch) => { return Promise.all([ dispatch(getTeamMember(teamId, userId)), channelId && dispatch(getChannelMember(channelId, userId)), diff --git a/webapp/channels/src/actions/views/rhs.ts b/webapp/channels/src/actions/views/rhs.ts index f337c62ece..8eb00877ed 100644 --- a/webapp/channels/src/actions/views/rhs.ts +++ b/webapp/channels/src/actions/views/rhs.ts @@ -24,7 +24,7 @@ import {getPost} from 'mattermost-redux/selectors/entities/posts'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentTimezone} from 'mattermost-redux/selectors/entities/timezone'; import {getCurrentUser, getCurrentUserMentionKeys} from 'mattermost-redux/selectors/entities/users'; -import type {Action, ActionResult, DispatchFunc, GenericAction, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; import {trackEvent} from 'actions/telemetry_actions.jsx'; import {getSearchTerms, getRhsState, getPluggableId, getFilesSearchExtFilter, getPreviousRhsState} from 'selectors/rhs'; @@ -72,10 +72,10 @@ function selectPostCardFromRightHandSideSearchWithPreviousState(post: Post, prev export function updateRhsState(rhsState: string, channelId?: string, previousRhsState?: RhsState) { return (dispatch: DispatchFunc, getState: GetStateFunc) => { - const action = { + const action: AnyAction = { type: ActionTypes.UPDATE_RHS_STATE, state: rhsState, - } as GenericAction; + }; if ([ RHSStates.PIN, @@ -130,7 +130,7 @@ export function selectPostCardFromRightHandSideSearch(post: Post) { export function selectPostFromRightHandSideSearchByPostId(postId: string) { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { const post = getPost(getState(), postId); - return selectPostFromRightHandSideSearch(post)(dispatch, getState); + return dispatch(selectPostFromRightHandSideSearch(post)); }; } @@ -393,7 +393,7 @@ export function showPinnedPosts(channelId?: string) { } export function showChannelFiles(channelId: string) { - return async (dispatch: (action: Action, getState?: GetStateFunc | null) => Promise, getState: GetStateFunc) => { + return async (dispatch: DispatchFunc, getState: GetStateFunc) => { const state = getState() as GlobalState; const teamId = getCurrentTeamId(state); @@ -614,39 +614,39 @@ export function openRHSSearch() { export function openAtPrevious(previous: any) { // TODO Could not find the proper type. Seems to be in several props around return (dispatch: DispatchFunc, getState: GetStateFunc) => { if (!previous) { - return openRHSSearch()(dispatch); + return dispatch(openRHSSearch()); } if (previous.isChannelInfo) { const currentChannelId = getCurrentChannelId(getState()); - return showChannelInfo(currentChannelId)(dispatch); + return dispatch(showChannelInfo(currentChannelId)); } if (previous.isChannelMembers) { const currentChannelId = getCurrentChannelId(getState()); - return showChannelMembers(currentChannelId)(dispatch, getState); + return dispatch(showChannelMembers(currentChannelId)); } if (previous.isMentionSearch) { - return showMentions()(dispatch, getState); + return dispatch(showMentions()); } if (previous.isPinnedPosts) { - return showPinnedPosts()(dispatch, getState); + return dispatch(showPinnedPosts()); } if (previous.isFlaggedPosts) { - return showFlaggedPosts()(dispatch, getState); + return dispatch(showFlaggedPosts()); } if (previous.selectedPostId) { const post = getPost(getState(), previous.selectedPostId); - return post ? selectPostFromRightHandSideSearchWithPreviousState(post, previous.previousRhsState)(dispatch, getState) : openRHSSearch()(dispatch); + return post ? dispatch(selectPostFromRightHandSideSearchWithPreviousState(post, previous.previousRhsState)) : dispatch(openRHSSearch()); } if (previous.selectedPostCardId) { const post = getPost(getState(), previous.selectedPostCardId); - return post ? selectPostCardFromRightHandSideSearchWithPreviousState(post, previous.previousRhsState)(dispatch, getState) : openRHSSearch()(dispatch); + return post ? dispatch(selectPostCardFromRightHandSideSearchWithPreviousState(post, previous.previousRhsState)) : dispatch(openRHSSearch()); } if (previous.searchVisible) { - return showSearchResults()(dispatch, getState); + return dispatch(showSearchResults()); } - return openRHSSearch()(dispatch); + return dispatch(openRHSSearch()); }; } diff --git a/webapp/channels/src/actions/websocket_actions.jsx b/webapp/channels/src/actions/websocket_actions.jsx index 2452adfd4e..de1e1b701b 100644 --- a/webapp/channels/src/actions/websocket_actions.jsx +++ b/webapp/channels/src/actions/websocket_actions.jsx @@ -1278,7 +1278,7 @@ function handleStatusChangedEvent(msg) { } function handleHelloEvent(msg) { - setServerVersion(msg.data.server_version)(dispatch, getState); + dispatch(setServerVersion(msg.data.server_version)); dispatch(setConnectionId(msg.data.connection_id)); } diff --git a/webapp/channels/src/components/actions_menu/actions_menu.tsx b/webapp/channels/src/components/actions_menu/actions_menu.tsx index 74337bcf0f..b154b0f76b 100644 --- a/webapp/channels/src/components/actions_menu/actions_menu.tsx +++ b/webapp/channels/src/components/actions_menu/actions_menu.tsx @@ -12,6 +12,7 @@ import type {Post} from '@mattermost/types/posts'; import {AppCallResponseTypes} from 'mattermost-redux/constants/apps'; import Permissions from 'mattermost-redux/constants/permissions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import FormattedMarkdownMessage from 'components/formatted_markdown_message'; import OverlayTrigger from 'components/overlay_trigger'; @@ -83,7 +84,7 @@ export type Props = { /** * Function to get the post menu bindings for this post. */ - fetchBindings: (channelId: string, teamId: string) => Promise<{data: AppBinding[]}>; + fetchBindings: (channelId: string, teamId: string) => Promise>; }; // TechDebt: Made non-mandatory while converting to typescript } diff --git a/webapp/channels/src/components/actions_menu/index.ts b/webapp/channels/src/components/actions_menu/index.ts index d6f1e9528b..47b822bd29 100644 --- a/webapp/channels/src/components/actions_menu/index.ts +++ b/webapp/channels/src/components/actions_menu/index.ts @@ -4,7 +4,7 @@ import type {ComponentProps} from 'react'; import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {AppBinding} from '@mattermost/types/apps'; import type {Post} from '@mattermost/types/posts'; @@ -25,8 +25,6 @@ import {makeFetchBindings, postEphemeralCallResponseForPost, handleBindingClick, import {openModal} from 'actions/views/modals'; import {getIsMobileView} from 'selectors/views/browser'; -import type {ModalData} from 'types/actions'; -import type {HandleBindingClick, OpenAppsModal, PostEphemeralCallResponseForPost} from 'types/apps'; import type {GlobalState} from 'types/store'; import ActionsMenu from './actions_menu'; @@ -75,17 +73,9 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { }; } -type Actions = { - handleBindingClick: HandleBindingClick; - fetchBindings: (channelId: string, teamId: string) => Promise<{data: AppBinding[]}>; - openModal:

(modalData: ModalData

) => void; - openAppsModal: OpenAppsModal; - postEphemeralCallResponseForPost: PostEphemeralCallResponseForPost; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ handleBindingClick, fetchBindings, openModal, diff --git a/webapp/channels/src/components/activity_log_modal/activity_log_modal.tsx b/webapp/channels/src/components/activity_log_modal/activity_log_modal.tsx index 09cc2b6f3d..50d5e40b6b 100644 --- a/webapp/channels/src/components/activity_log_modal/activity_log_modal.tsx +++ b/webapp/channels/src/components/activity_log_modal/activity_log_modal.tsx @@ -7,7 +7,7 @@ import {FormattedMessage} from 'react-intl'; import type {Session} from '@mattermost/types/sessions'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import ActivityLog from 'components/activity_log_modal/components/activity_log'; @@ -38,12 +38,12 @@ export type Props = { /** * Function to refresh sessions from server */ - getSessions: (userId: string) => ActionFunc; + getSessions: (userId: string) => void; /** * Function to revoke a particular session */ - revokeSession: (userId: string, sessionId: string) => Promise<{ data: boolean }>; + revokeSession: (userId: string, sessionId: string) => Promise; }; } diff --git a/webapp/channels/src/components/activity_log_modal/index.ts b/webapp/channels/src/components/activity_log_modal/index.ts index 255443fb33..5faaf917e6 100644 --- a/webapp/channels/src/components/activity_log_modal/index.ts +++ b/webapp/channels/src/components/activity_log_modal/index.ts @@ -3,18 +3,16 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getSessions, revokeSession} from 'mattermost-redux/actions/users'; import {getCurrentUserId, getUserSessions} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {getCurrentLocale} from 'selectors/i18n'; import type {GlobalState} from 'types/store'; import ActivityLogModal from './activity_log_modal'; -import type {Props} from './activity_log_modal'; function mapStateToProps(state: GlobalState) { return { @@ -24,9 +22,9 @@ function mapStateToProps(state: GlobalState) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ getSessions, revokeSession, }, dispatch), diff --git a/webapp/channels/src/components/add_groups_to_channel_modal/add_groups_to_channel_modal.tsx b/webapp/channels/src/components/add_groups_to_channel_modal/add_groups_to_channel_modal.tsx index a69f8fd0d8..a6bfce7679 100644 --- a/webapp/channels/src/components/add_groups_to_channel_modal/add_groups_to_channel_modal.tsx +++ b/webapp/channels/src/components/add_groups_to_channel_modal/add_groups_to_channel_modal.tsx @@ -10,7 +10,7 @@ import type {ServerError} from '@mattermost/types/errors'; import type {Group, SyncablePatch} from '@mattermost/types/groups'; import {SyncableType} from '@mattermost/types/groups'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import MultiSelect from 'components/multiselect/multiselect'; import type {Value} from 'components/multiselect/multiselect'; @@ -38,12 +38,12 @@ export type Props = { onAddCallback?: (groupIDs: string[]) => void; actions: { - getGroupsNotAssociatedToChannel: (channelID: string, q?: string, page?: number | null, perPage?: number | null, filterParentTeamPermitted?: boolean) => Promise; - setModalSearchTerm: (term: string) => { type: string; data: string}; - linkGroupSyncable: (groupID: string, syncableID: string, syncableType: string, patch: Partial) => Promise<{error?: ServerError; data?: null}>; - getAllGroupsAssociatedToChannel: (channelID: string, filterAllowReference: boolean, includeMemberCount: boolean) => ActionFunc; - getTeam: (teamId: string) => ActionFunc; - getAllGroupsAssociatedToTeam: (teamID: string, filterAllowReference: boolean, includeMemberCount: boolean) => ActionFunc; + getGroupsNotAssociatedToChannel: (channelID: string, q?: string, page?: number, perPage?: number, filterParentTeamPermitted?: boolean) => Promise; + setModalSearchTerm: (term: string) => void; + linkGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType, patch: Partial) => Promise; + getAllGroupsAssociatedToChannel: (channelID: string, filterAllowReference: boolean, includeMemberCount: boolean) => Promise; + getTeam: (teamId: string) => Promise; + getAllGroupsAssociatedToTeam: (teamID: string, filterAllowReference: boolean, includeMemberCount: boolean) => Promise; }; } @@ -100,7 +100,7 @@ export class AddGroupsToChannelModal extends React.PureComponent { this.searchTimeoutId = window.setTimeout( async () => { this.setGroupsLoadingState(true); - await this.props.actions.getGroupsNotAssociatedToChannel(this.props.currentChannelId, searchTerm, null, null, true); + await this.props.actions.getGroupsNotAssociatedToChannel(this.props.currentChannelId, searchTerm, undefined, undefined, true); this.setGroupsLoadingState(false); }, Constants.SEARCH_TIMEOUT_MILLISECONDS, diff --git a/webapp/channels/src/components/add_groups_to_channel_modal/index.ts b/webapp/channels/src/components/add_groups_to_channel_modal/index.ts index 3c4e60b5f6..d11315d376 100644 --- a/webapp/channels/src/components/add_groups_to_channel_modal/index.ts +++ b/webapp/channels/src/components/add_groups_to_channel_modal/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {Channel} from '@mattermost/types/channels'; import type {Group} from '@mattermost/types/groups'; @@ -12,14 +12,12 @@ import {getGroupsNotAssociatedToChannel, linkGroupSyncable, getAllGroupsAssociat import {getTeam} from 'mattermost-redux/actions/teams'; import {getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'; import {getGroupsNotAssociatedToChannel as selectGroupsNotAssociatedToChannel} from 'mattermost-redux/selectors/entities/groups'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {setModalSearchTerm} from 'actions/views/search'; import type {GlobalState} from 'types/store'; import AddGroupsToChannelModal from './add_groups_to_channel_modal'; -import type {Props} from './add_groups_to_channel_modal'; type OwnProps = { channel: Channel; @@ -51,9 +49,9 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ getGroupsNotAssociatedToChannel, setModalSearchTerm, linkGroupSyncable, diff --git a/webapp/channels/src/components/add_groups_to_team_modal/add_groups_to_team_modal.tsx b/webapp/channels/src/components/add_groups_to_team_modal/add_groups_to_team_modal.tsx index 11dbb52149..f6e88db2f6 100644 --- a/webapp/channels/src/components/add_groups_to_team_modal/add_groups_to_team_modal.tsx +++ b/webapp/channels/src/components/add_groups_to_team_modal/add_groups_to_team_modal.tsx @@ -7,9 +7,11 @@ import {Modal} from 'react-bootstrap'; import type {IntlShape} from 'react-intl'; import {injectIntl, FormattedMessage} from 'react-intl'; -import type {Group, GroupsWithCount, SyncablePatch} from '@mattermost/types/groups'; +import type {Group, SyncablePatch} from '@mattermost/types/groups'; import {SyncableType} from '@mattermost/types/groups'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import Nbsp from 'components/html_entities/nbsp'; import MultiSelect from 'components/multiselect/multiselect'; import type {Value} from 'components/multiselect/multiselect'; @@ -40,10 +42,10 @@ type Props = { } export type Actions = { - getGroupsNotAssociatedToTeam: (teamID: string, q?: string, page?: number, perPage?: number) => Promise<{ data: Group[] } | { error: Error }>; + getGroupsNotAssociatedToTeam: (teamID: string, q?: string, page?: number, perPage?: number) => Promise; setModalSearchTerm: (term: string) => void; - linkGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType, patch: SyncablePatch) => Promise<{ data?: boolean; error?: Error }>; - getAllGroupsAssociatedToTeam: (teamID: string, filterAllowReference: boolean, includeMemberCount: boolean) => Promise<{ data: GroupsWithCount } | { error: Error }>; + linkGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType, patch: SyncablePatch) => Promise; + getAllGroupsAssociatedToTeam: (teamID: string, filterAllowReference: boolean, includeMemberCount: boolean) => Promise; }; type State = { diff --git a/webapp/channels/src/components/add_groups_to_team_modal/index.ts b/webapp/channels/src/components/add_groups_to_team_modal/index.ts index 3031a7a761..8582c37cf6 100644 --- a/webapp/channels/src/components/add_groups_to_team_modal/index.ts +++ b/webapp/channels/src/components/add_groups_to_team_modal/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {Group} from '@mattermost/types/groups'; import type {Team} from '@mattermost/types/teams'; @@ -11,14 +11,13 @@ import type {Team} from '@mattermost/types/teams'; import {getGroupsNotAssociatedToTeam, linkGroupSyncable, getAllGroupsAssociatedToTeam} from 'mattermost-redux/actions/groups'; import {getGroupsNotAssociatedToTeam as selectGroupsNotAssociatedToTeam} from 'mattermost-redux/selectors/entities/groups'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; +import type {GenericAction} from 'mattermost-redux/types/actions'; import {setModalSearchTerm} from 'actions/views/search'; import type {GlobalState} from 'types/store'; import AddGroupsToTeamModal from './add_groups_to_team_modal'; -import type {Actions} from './add_groups_to_team_modal'; type Props = { team?: Team; @@ -51,7 +50,7 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getGroupsNotAssociatedToTeam, setModalSearchTerm, linkGroupSyncable, diff --git a/webapp/channels/src/components/add_user_to_channel_modal/index.ts b/webapp/channels/src/components/add_user_to_channel_modal/index.ts index 2d7232487f..53e517c621 100644 --- a/webapp/channels/src/components/add_user_to_channel_modal/index.ts +++ b/webapp/channels/src/components/add_user_to_channel_modal/index.ts @@ -3,16 +3,14 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import {addChannelMember, getChannelMember, autocompleteChannelsForSearch} from 'mattermost-redux/actions/channels'; import {getChannelMembersInChannels} from 'mattermost-redux/selectors/entities/channels'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import AddUserToChannelModal from './add_user_to_channel_modal'; -import type {Props} from './add_user_to_channel_modal'; function mapStateToProps(state: GlobalState) { const channelMembers = getChannelMembersInChannels(state) || {}; @@ -23,7 +21,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ addChannelMember, getChannelMember, autocompleteChannelsForSearch, diff --git a/webapp/channels/src/components/add_user_to_group_multiselect/index.ts b/webapp/channels/src/components/add_user_to_group_multiselect/index.ts index a21cff859a..031bf4fb40 100644 --- a/webapp/channels/src/components/add_user_to_group_multiselect/index.ts +++ b/webapp/channels/src/components/add_user_to_group_multiselect/index.ts @@ -3,13 +3,12 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {UserProfile} from '@mattermost/types/users'; import {getProfilesNotInGroup, searchProfiles, getProfiles} from 'mattermost-redux/actions/users'; import {getProfilesNotInCurrentGroup, getUserStatuses, getProfiles as getUsers} from 'mattermost-redux/selectors/entities/users'; -import type {Action, ActionResult} from 'mattermost-redux/types/actions'; import {loadStatusesForProfilesList} from 'actions/status_actions'; @@ -42,16 +41,9 @@ function mapStateToProps(state: GlobalState, props: OwnProps) { }; } -type Actions = { - getProfiles: (page?: number, perPage?: number) => Promise; - getProfilesNotInGroup: (groupId: string, page?: number, perPage?: number) => Promise; - loadStatusesForProfilesList: (users: UserProfile[]) => void; - searchProfiles: (term: string, options: any) => Promise; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getProfiles, getProfilesNotInGroup, loadStatusesForProfilesList, diff --git a/webapp/channels/src/components/add_users_to_group_modal/index.ts b/webapp/channels/src/components/add_users_to_group_modal/index.ts index d37daee8b7..de398fe3dd 100644 --- a/webapp/channels/src/components/add_users_to_group_modal/index.ts +++ b/webapp/channels/src/components/add_users_to_group_modal/index.ts @@ -3,24 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {addUsersToGroup} from 'mattermost-redux/actions/groups'; import {getGroup} from 'mattermost-redux/selectors/entities/groups'; -import type {Action, ActionResult} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import AddUsersToGroupModal from './add_users_to_group_modal'; -type Actions = { - addUsersToGroup: (groupId: string, userIds: string[]) => Promise; - openModal:

(modalData: ModalData

) => void; -} - type OwnProps = { groupId: string; } @@ -35,7 +28,7 @@ function mapStateToProps(state: GlobalState, props: OwnProps) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ addUsersToGroup, openModal, }, dispatch), diff --git a/webapp/channels/src/components/add_users_to_team_modal/add_users_to_team_modal.tsx b/webapp/channels/src/components/add_users_to_team_modal/add_users_to_team_modal.tsx index abd51afb0f..8677577028 100644 --- a/webapp/channels/src/components/add_users_to_team_modal/add_users_to_team_modal.tsx +++ b/webapp/channels/src/components/add_users_to_team_modal/add_users_to_team_modal.tsx @@ -10,6 +10,7 @@ import type {Team} from '@mattermost/types/teams'; import type {UserProfile} from '@mattermost/types/users'; import {Client4} from 'mattermost-redux/client'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {isGuest} from 'mattermost-redux/utils/user_utils'; import MultiSelect from 'components/multiselect/multiselect'; @@ -36,8 +37,8 @@ type Props = { onExited?: () => void; actions: { - getProfilesNotInTeam: (teamId: string, groupConstrained: boolean, page: number, perPage?: number, options?: Record) => Promise<{ data: UserProfile[] }>; - searchProfiles: (term: string, options?: Record) => Promise<{ data: UserProfile[] }>; + getProfilesNotInTeam: (teamId: string, groupConstrained: boolean, page: number, perPage?: number, options?: Record) => Promise>; + searchProfiles: (term: string, options?: Record) => Promise>; }; } @@ -91,7 +92,7 @@ export class AddUsersToTeamModal extends React.PureComponent { const search = term !== ''; if (search) { const {data} = await this.props.actions.searchProfiles(term, {not_in_team_id: this.props.team.id, replace: true, ...this.state.filterOptions}); - searchResults = data; + searchResults = data!; } else { await this.props.actions.getProfilesNotInTeam(this.props.team.id, false, 0, USERS_PER_PAGE * 2); } diff --git a/webapp/channels/src/components/add_users_to_team_modal/index.ts b/webapp/channels/src/components/add_users_to_team_modal/index.ts index dc19090ae7..b935c3f159 100644 --- a/webapp/channels/src/components/add_users_to_team_modal/index.ts +++ b/webapp/channels/src/components/add_users_to_team_modal/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import type {Team} from '@mattermost/types/teams'; @@ -11,7 +11,6 @@ import type {UserProfile} from '@mattermost/types/users'; import {getProfilesNotInTeam, searchProfiles} from 'mattermost-redux/actions/users'; import {getProfilesNotInTeam as selectProfilesNotInTeam} from 'mattermost-redux/selectors/entities/users'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import AddUsersToTeamModal from './add_users_to_team_modal'; @@ -20,11 +19,6 @@ type Props = { filterExcludeGuests?: boolean; }; -type Actions = { - getProfilesNotInTeam: (teamId: string, groupConstrained: boolean, page: number, perPage?: number, options?: {[key: string]: any}) => Promise<{ data: UserProfile[] }>; - searchProfiles: (term: string, options?: any) => Promise<{ data: UserProfile[] }>; -}; - function mapStateToProps(state: GlobalState, props: Props) { const {id: teamId} = props.team; @@ -40,9 +34,9 @@ function mapStateToProps(state: GlobalState, props: Props) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getProfilesNotInTeam, searchProfiles, }, dispatch), diff --git a/webapp/channels/src/components/admin_console/admin_console.tsx b/webapp/channels/src/components/admin_console/admin_console.tsx index a8e51e79a0..9d1219880f 100644 --- a/webapp/channels/src/components/admin_console/admin_console.tsx +++ b/webapp/channels/src/components/admin_console/admin_console.tsx @@ -10,7 +10,7 @@ import type {AdminConfig, EnvironmentConfig} from '@mattermost/types/config'; import type {Role} from '@mattermost/types/roles'; import type {DeepPartial} from '@mattermost/types/utilities'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import SchemaAdminSettings from 'components/admin_console/schema_admin_settings'; import AnnouncementBarController from 'components/announcement_bar'; @@ -45,7 +45,7 @@ type ExtraProps = { setNavigationBlocked?: () => void; roles?: Record; editRole?: (role: Role) => void; - updateConfig?: (config: AdminConfig) => ActionFunc; + updateConfig?: (config: AdminConfig) => Promise; cloud: CloudState; isCurrentUserSystemAdmin: boolean; } diff --git a/webapp/channels/src/components/admin_console/admin_sidebar/index.ts b/webapp/channels/src/components/admin_console/admin_sidebar/index.ts index d35ffc9087..03c11dabeb 100644 --- a/webapp/channels/src/components/admin_console/admin_sidebar/index.ts +++ b/webapp/channels/src/components/admin_console/admin_sidebar/index.ts @@ -4,16 +4,13 @@ import {connect} from 'react-redux'; import type {ConnectedProps} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {PluginsResponse} from '@mattermost/types/plugins'; +import type {Dispatch} from 'redux'; import {getPlugins} from 'mattermost-redux/actions/admin'; import {getSubscriptionProduct} from 'mattermost-redux/selectors/entities/cloud'; import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general'; import {getBool} from 'mattermost-redux/selectors/entities/preferences'; import {isFirstAdmin} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import {getAdminDefinition, getConsoleAccess} from 'selectors/admin_console'; import {getNavigationBlocked} from 'selectors/views/admin'; @@ -53,13 +50,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - getPlugins: () => Promise<{data: PluginsResponse}>; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getPlugins, }, dispatch), }; diff --git a/webapp/channels/src/components/admin_console/audits/audits.tsx b/webapp/channels/src/components/admin_console/audits/audits.tsx index b6085b38ba..d3e6264225 100644 --- a/webapp/channels/src/components/admin_console/audits/audits.tsx +++ b/webapp/channels/src/components/admin_console/audits/audits.tsx @@ -7,6 +7,8 @@ import {FormattedMessage} from 'react-intl'; import type {Audit} from '@mattermost/types/audits'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import ComplianceReports from 'components/admin_console/compliance_reports'; import AuditTable from 'components/audit_table'; import LoadingScreen from 'components/loading_screen'; @@ -17,7 +19,7 @@ type Props = { audits: Audit[]; isDisabled?: boolean; actions: { - getAudits: () => Promise<{data: Audit[]}>; + getAudits: () => Promise>; }; }; diff --git a/webapp/channels/src/components/admin_console/audits/index.ts b/webapp/channels/src/components/admin_console/audits/index.ts index 44094a216b..af8c002511 100644 --- a/webapp/channels/src/components/admin_console/audits/index.ts +++ b/webapp/channels/src/components/admin_console/audits/index.ts @@ -3,23 +3,16 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {Audit} from '@mattermost/types/audits'; +import type {Dispatch} from 'redux'; import {getAudits} from 'mattermost-redux/actions/admin'; import * as Selectors from 'mattermost-redux/selectors/entities/admin'; import {getLicense} from 'mattermost-redux/selectors/entities/general'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import Audits from './audits'; -type Actions = { - getAudits: () => Promise<{data: Audit[]}>; -} - function mapStateToProps(state: GlobalState) { const license = getLicense(state); const isLicensed = license.Compliance === 'true'; @@ -30,9 +23,9 @@ function mapStateToProps(state: GlobalState) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getAudits, }, dispatch), }; diff --git a/webapp/channels/src/components/admin_console/compliance_reports/compliance_reports.tsx b/webapp/channels/src/components/admin_console/compliance_reports/compliance_reports.tsx index 84e768c929..16b534c8a2 100644 --- a/webapp/channels/src/components/admin_console/compliance_reports/compliance_reports.tsx +++ b/webapp/channels/src/components/admin_console/compliance_reports/compliance_reports.tsx @@ -8,6 +8,7 @@ import type {Compliance} from '@mattermost/types/compliance'; import type {UserProfile} from '@mattermost/types/users'; import {Client4} from 'mattermost-redux/client'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import LoadingScreen from 'components/loading_screen'; import ReloadIcon from 'components/widgets/icons/fa_reload_icon'; @@ -44,12 +45,12 @@ type Props = { /* * Function to get compliance reports */ - getComplianceReports: () => Promise<{data: Compliance[]}>; + getComplianceReports: () => Promise>; /* * Function to save compliance reports */ - createComplianceReport: (job: Partial) => Promise<{data: Compliance; error?: Error}>; + createComplianceReport: (job: Partial) => Promise>; }; } diff --git a/webapp/channels/src/components/admin_console/compliance_reports/index.ts b/webapp/channels/src/components/admin_console/compliance_reports/index.ts index 143a6e1ec1..1100639c13 100644 --- a/webapp/channels/src/components/admin_console/compliance_reports/index.ts +++ b/webapp/channels/src/components/admin_console/compliance_reports/index.ts @@ -3,9 +3,8 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {Compliance} from '@mattermost/types/compliance'; import type {GlobalState} from '@mattermost/types/store'; import type {UserProfile} from '@mattermost/types/users'; @@ -13,15 +12,9 @@ import {createComplianceReport, getComplianceReports} from 'mattermost-redux/act import {createSelector} from 'mattermost-redux/selectors/create_selector'; import {getComplianceReports as selectComplianceReports, getConfig} from 'mattermost-redux/selectors/entities/admin'; import {getLicense} from 'mattermost-redux/selectors/entities/general'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import ComplianceReports from './compliance_reports'; -type Actions = { - getComplianceReports: () => Promise<{data: Compliance[]}>; - createComplianceReport: (job: Partial) => Promise<{data: Compliance; error?: Error}>; -} - const getUsersForReports = createSelector( 'getUsersForReports', (state: GlobalState) => state.entities.users.profiles, @@ -67,9 +60,9 @@ function mapStateToProps(state: GlobalState) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getComplianceReports, createComplianceReport, }, dispatch), diff --git a/webapp/channels/src/components/admin_console/custom_terms_of_service_settings/custom_terms_of_service_settings.tsx b/webapp/channels/src/components/admin_console/custom_terms_of_service_settings/custom_terms_of_service_settings.tsx index 8d666c7448..db1fc907d2 100644 --- a/webapp/channels/src/components/admin_console/custom_terms_of_service_settings/custom_terms_of_service_settings.tsx +++ b/webapp/channels/src/components/admin_console/custom_terms_of_service_settings/custom_terms_of_service_settings.tsx @@ -7,6 +7,8 @@ import {FormattedMessage} from 'react-intl'; import type {AdminConfig, ClientLicense} from '@mattermost/types/config'; import type {TermsOfService} from '@mattermost/types/terms_of_service'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import AdminSettings from 'components/admin_console/admin_settings'; import type {BaseProps, BaseState} from 'components/admin_console/admin_settings'; import BooleanSetting from 'components/admin_console/boolean_setting'; @@ -19,8 +21,8 @@ import {Constants} from 'utils/constants'; type Props = BaseProps & { actions: { - getTermsOfService: () => Promise<{data: TermsOfService}>; - createTermsOfService: (text: string) => Promise<{data: TermsOfService; error?: Error}>; + getTermsOfService: () => Promise>; + createTermsOfService: (text: string) => Promise>; }; config: AdminConfig; license: ClientLicense; diff --git a/webapp/channels/src/components/admin_console/custom_terms_of_service_settings/index.ts b/webapp/channels/src/components/admin_console/custom_terms_of_service_settings/index.ts index 1d04fe1130..9003eefd6b 100644 --- a/webapp/channels/src/components/admin_console/custom_terms_of_service_settings/index.ts +++ b/webapp/channels/src/components/admin_console/custom_terms_of_service_settings/index.ts @@ -3,23 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {TermsOfService} from '@mattermost/types/terms_of_service'; +import type {Dispatch} from 'redux'; import {getTermsOfService, createTermsOfService} from 'mattermost-redux/actions/users'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import CustomTermsOfServiceSettings from './custom_terms_of_service_settings'; -type Actions = { - getTermsOfService: () => Promise<{data: TermsOfService}>; - createTermsOfService: (text: string) => Promise<{data: TermsOfService; error?: Error}>; -}; - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getTermsOfService, createTermsOfService, }, dispatch), diff --git a/webapp/channels/src/components/admin_console/data_retention_settings/channel_list/channel_list.tsx b/webapp/channels/src/components/admin_console/data_retention_settings/channel_list/channel_list.tsx index 37c0851831..a52464ed01 100644 --- a/webapp/channels/src/components/admin_console/data_retention_settings/channel_list/channel_list.tsx +++ b/webapp/channels/src/components/admin_console/data_retention_settings/channel_list/channel_list.tsx @@ -36,10 +36,10 @@ type Props = { channelsToAdd: Record; actions: { - searchChannels: (id: string, term: string, opts: ChannelSearchOpts) => Promise<{ data: ChannelWithTeamData[] }>; - getDataRetentionCustomPolicyChannels: (id: string, page: number, perPage: number) => Promise<{ data: ChannelWithTeamData[] }>; - setChannelListSearch: (term: string) => ActionResult; - setChannelListFilters: (filters: ChannelSearchOpts) => ActionResult; + searchChannels: (id: string, term: string, opts: ChannelSearchOpts) => Promise; + getDataRetentionCustomPolicyChannels: (id: string, page: number, perPage: number) => Promise; + setChannelListSearch: (term: string) => void; + setChannelListFilters: (filters: ChannelSearchOpts) => void; }; } diff --git a/webapp/channels/src/components/admin_console/data_retention_settings/channel_list/index.ts b/webapp/channels/src/components/admin_console/data_retention_settings/channel_list/index.ts index 4cfef835c2..d26f1422b4 100644 --- a/webapp/channels/src/components/admin_console/data_retention_settings/channel_list/index.ts +++ b/webapp/channels/src/components/admin_console/data_retention_settings/channel_list/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {Channel, ChannelSearchOpts, ChannelWithTeamData} from '@mattermost/types/channels'; import type {DataRetentionCustomPolicy} from '@mattermost/types/data_retention'; @@ -11,7 +11,6 @@ import type {DataRetentionCustomPolicy} from '@mattermost/types/data_retention'; import {getDataRetentionCustomPolicyChannels, searchDataRetentionCustomPolicyChannels as searchChannels} from 'mattermost-redux/actions/admin'; import {getDataRetentionCustomPolicy} from 'mattermost-redux/selectors/entities/admin'; import {filterChannelList, getChannelsInPolicy, searchChannelsInPolicy} from 'mattermost-redux/selectors/entities/channels'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {filterChannelsMatchingTerm, channelListToMap} from 'mattermost-redux/utils/channel_utils'; import {setChannelListSearch, setChannelListFilters} from 'actions/views/search'; @@ -25,13 +24,6 @@ type OwnProps = { channelsToAdd: Record; } -type Actions = { - searchChannels: (id: string, term: string, opts: ChannelSearchOpts) => Promise<{ data: ChannelWithTeamData[] }>; - getDataRetentionCustomPolicyChannels: (id: string, page: number, perPage: number) => Promise<{ data: ChannelWithTeamData[] }>; - setChannelListSearch: (term: string) => ActionResult; - setChannelListFilters: (filters: ChannelSearchOpts) => ActionResult; -} - function searchChannelsToAdd(channels: Record, term: string, filters: ChannelSearchOpts): Record { let filteredTeams = filterChannelsMatchingTerm(Object.keys(channels).map((key) => channels[key]), term); filteredTeams = filterChannelList(filteredTeams, filters); @@ -72,7 +64,7 @@ function mapStateToProps() { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getDataRetentionCustomPolicyChannels, searchChannels, setChannelListSearch, diff --git a/webapp/channels/src/components/admin_console/data_retention_settings/custom_policy_form/custom_policy_form.tsx b/webapp/channels/src/components/admin_console/data_retention_settings/custom_policy_form/custom_policy_form.tsx index 7c09043b8b..c7270cacd4 100644 --- a/webapp/channels/src/components/admin_console/data_retention_settings/custom_policy_form/custom_policy_form.tsx +++ b/webapp/channels/src/components/admin_console/data_retention_settings/custom_policy_form/custom_policy_form.tsx @@ -13,6 +13,8 @@ import type { import type {Team} from '@mattermost/types/teams'; import type {IDMappedObjects} from '@mattermost/types/utilities'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import BlockableLink from 'components/admin_console/blockable_link'; import ChannelList from 'components/admin_console/data_retention_settings/channel_list'; import {keepForeverOption, yearsOption, daysOption, FOREVER, YEARS} from 'components/admin_console/data_retention_settings/dropdown_options/dropdown_options'; @@ -37,14 +39,14 @@ type Props = { policy?: DataRetentionCustomPolicy | null; teams?: Team[]; actions: { - fetchPolicy: (id: string) => Promise<{ data: DataRetentionCustomPolicy; error?: Error }>; - fetchPolicyTeams: (id: string, page: number, perPage: number) => Promise<{ data: Team[]; error?: Error }>; - createDataRetentionCustomPolicy: (policy: CreateDataRetentionCustomPolicy) => Promise<{ data: DataRetentionCustomPolicy; error?: Error }>; - updateDataRetentionCustomPolicy: (id: string, policy: PatchDataRetentionCustomPolicy) => Promise<{ data: DataRetentionCustomPolicy; error?: Error }>; - addDataRetentionCustomPolicyTeams: (id: string, policy: string[]) => Promise<{ data?: {status: string}; error?: Error }>; - removeDataRetentionCustomPolicyTeams: (id: string, policy: string[]) => Promise<{ data?: {status: string}; error?: Error }>; - addDataRetentionCustomPolicyChannels: (id: string, policy: string[]) => Promise<{ data?: {status: string}; error?: Error }>; - removeDataRetentionCustomPolicyChannels: (id: string, policy: string[]) => Promise<{ data?: {status: string}; error?: Error }>; + fetchPolicy: (id: string) => Promise; + fetchPolicyTeams: (id: string, page: number, perPage: number) => Promise; + createDataRetentionCustomPolicy: (policy: CreateDataRetentionCustomPolicy) => Promise; + updateDataRetentionCustomPolicy: (id: string, policy: PatchDataRetentionCustomPolicy) => Promise; + addDataRetentionCustomPolicyTeams: (id: string, policy: string[]) => Promise; + removeDataRetentionCustomPolicyTeams: (id: string, policy: string[]) => Promise; + addDataRetentionCustomPolicyChannels: (id: string, policy: string[]) => Promise; + removeDataRetentionCustomPolicyChannels: (id: string, policy: string[]) => Promise; setNavigationBlocked: (blocked: boolean) => void; }; }; diff --git a/webapp/channels/src/components/admin_console/data_retention_settings/custom_policy_form/index.ts b/webapp/channels/src/components/admin_console/data_retention_settings/custom_policy_form/index.ts index a89944697c..174c21c3dd 100644 --- a/webapp/channels/src/components/admin_console/data_retention_settings/custom_policy_form/index.ts +++ b/webapp/channels/src/components/admin_console/data_retention_settings/custom_policy_form/index.ts @@ -3,14 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type { - DataRetentionCustomPolicy, - CreateDataRetentionCustomPolicy, - PatchDataRetentionCustomPolicy, -} from '@mattermost/types/data_retention'; -import type {Team} from '@mattermost/types/teams'; +import type {Dispatch} from 'redux'; import { getDataRetentionCustomPolicy as fetchPolicy, @@ -24,7 +17,6 @@ import { } from 'mattermost-redux/actions/admin'; import {getDataRetentionCustomPolicy} from 'mattermost-redux/selectors/entities/admin'; import {getTeamsInPolicy} from 'mattermost-redux/selectors/entities/teams'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import {setNavigationBlocked} from 'actions/admin_actions.jsx'; @@ -32,18 +24,6 @@ import type {GlobalState} from 'types/store'; import CustomPolicyForm from './custom_policy_form'; -type Actions = { - fetchPolicy: (id: string) => Promise<{ data: DataRetentionCustomPolicy }>; - fetchPolicyTeams: (id: string, page: number, perPage: number) => Promise<{ data: Team[] }>; - createDataRetentionCustomPolicy: (policy: CreateDataRetentionCustomPolicy) => Promise<{ data: DataRetentionCustomPolicy }>; - updateDataRetentionCustomPolicy: (id: string, policy: PatchDataRetentionCustomPolicy) => Promise<{ data: DataRetentionCustomPolicy }>; - addDataRetentionCustomPolicyTeams: (id: string, teams: string[]) => Promise<{ data?: {status: string}; error?: Error }>; - removeDataRetentionCustomPolicyTeams: (id: string, teams: string[]) => Promise<{ data?: {status: string}; error?: Error }>; - addDataRetentionCustomPolicyChannels: (id: string, channels: string[]) => Promise<{ data?: {status: string}; error?: Error }>; - removeDataRetentionCustomPolicyChannels: (id: string, channels: string[]) => Promise<{ data?: {status: string}; error?: Error }>; - setNavigationBlocked: (blocked: boolean) => void; -}; - type OwnProps = { match: { params: { @@ -66,9 +46,9 @@ function mapStateToProps() { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ fetchPolicy, fetchPolicyTeams, createDataRetentionCustomPolicy, diff --git a/webapp/channels/src/components/admin_console/data_retention_settings/data_retention_settings.tsx b/webapp/channels/src/components/admin_console/data_retention_settings/data_retention_settings.tsx index b692609941..e621e0b142 100644 --- a/webapp/channels/src/components/admin_console/data_retention_settings/data_retention_settings.tsx +++ b/webapp/channels/src/components/admin_console/data_retention_settings/data_retention_settings.tsx @@ -40,11 +40,11 @@ type Props = { globalMessageRetentionHours: string | undefined; globalFileRetentionHours: string | undefined; actions: { - getDataRetentionCustomPolicies: (page: number) => Promise<{ data: DataRetentionCustomPolicies }>; - createJob: (job: JobTypeBase) => Promise<{ data: any }>; - getJobsByType: (job: JobType) => Promise<{ data: any}>; + getDataRetentionCustomPolicies: (page: number) => Promise; + createJob: (job: JobTypeBase) => Promise; + getJobsByType: (job: JobType) => Promise; deleteDataRetentionCustomPolicy: (id: string) => Promise; - updateConfig: (config: Record) => Promise<{ data: any}>; + updateConfig: (config: Record) => Promise; }; }; diff --git a/webapp/channels/src/components/admin_console/data_retention_settings/global_policy_form/global_policy_form.tsx b/webapp/channels/src/components/admin_console/data_retention_settings/global_policy_form/global_policy_form.tsx index 708402d272..eeb1b73867 100644 --- a/webapp/channels/src/components/admin_console/data_retention_settings/global_policy_form/global_policy_form.tsx +++ b/webapp/channels/src/components/admin_console/data_retention_settings/global_policy_form/global_policy_form.tsx @@ -5,9 +5,10 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; import type {AdminConfig, EnvironmentConfig} from '@mattermost/types/config'; -import type {ServerError} from '@mattermost/types/errors'; import type {DeepPartial} from '@mattermost/types/utilities'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import BlockableLink from 'components/admin_console/blockable_link'; import {keepForeverOption, yearsOption, daysOption, FOREVER, YEARS, DAYS, hoursOption} from 'components/admin_console/data_retention_settings/dropdown_options/dropdown_options'; import SetByEnv from 'components/admin_console/set_by_env'; @@ -31,7 +32,7 @@ type Props = { fileRetentionHours: string | undefined; environmentConfig: Partial; actions: { - updateConfig: (config: Record) => Promise<{ data?: AdminConfig; error?: ServerError }>; + updateConfig: (config: Record) => Promise; setNavigationBlocked: (blocked: boolean) => void; }; }; diff --git a/webapp/channels/src/components/admin_console/data_retention_settings/global_policy_form/index.ts b/webapp/channels/src/components/admin_console/data_retention_settings/global_policy_form/index.ts index e8fa89326d..89d8670a8b 100644 --- a/webapp/channels/src/components/admin_console/data_retention_settings/global_policy_form/index.ts +++ b/webapp/channels/src/components/admin_console/data_retention_settings/global_policy_form/index.ts @@ -3,17 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {AdminConfig} from '@mattermost/types/config'; -import type {ServerError} from '@mattermost/types/errors'; +import type {Dispatch} from 'redux'; import { updateConfig, } from 'mattermost-redux/actions/admin'; import {getEnvironmentConfig} from 'mattermost-redux/selectors/entities/admin'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import {setNavigationBlocked} from 'actions/admin_actions.jsx'; @@ -21,11 +17,6 @@ import type {GlobalState} from 'types/store'; import GlobalPolicyForm from './global_policy_form'; -type Actions = { - updateConfig: (config: Record) => Promise<{ data?: AdminConfig; error?: ServerError }>; - setNavigationBlocked: (blocked: boolean) => void; -}; - function mapStateToProps(state: GlobalState) { const messageRetentionHours = getConfig(state).DataRetentionMessageRetentionHours; const fileRetentionHours = getConfig(state).DataRetentionFileRetentionHours; @@ -37,9 +28,9 @@ function mapStateToProps(state: GlobalState) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ updateConfig, setNavigationBlocked, }, dispatch), diff --git a/webapp/channels/src/components/admin_console/data_retention_settings/index.ts b/webapp/channels/src/components/admin_console/data_retention_settings/index.ts index ca5fe9bf3a..aa3e990f01 100644 --- a/webapp/channels/src/components/admin_console/data_retention_settings/index.ts +++ b/webapp/channels/src/components/admin_console/data_retention_settings/index.ts @@ -3,29 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {DataRetentionCustomPolicies} from '@mattermost/types/data_retention'; -import type {JobTypeBase, JobType} from '@mattermost/types/jobs'; +import type {Dispatch} from 'redux'; import {getDataRetentionCustomPolicies as fetchDataRetentionCustomPolicies, deleteDataRetentionCustomPolicy, updateConfig} from 'mattermost-redux/actions/admin'; import {createJob, getJobsByType} from 'mattermost-redux/actions/jobs'; import {getDataRetentionCustomPolicies, getDataRetentionCustomPoliciesCount} from 'mattermost-redux/selectors/entities/admin'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; -import type {GenericAction, ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import DataRetentionSettings from './data_retention_settings'; -type Actions = { - getDataRetentionCustomPolicies: () => Promise<{ data: DataRetentionCustomPolicies}>; - deleteDataRetentionCustomPolicy: (id: string) => Promise; - createJob: (job: JobTypeBase) => Promise<{ data: any}>; - getJobsByType: (job: JobType) => Promise<{ data: any}>; - updateConfig: (config: Record) => Promise<{ data: any}>; -}; - function mapStateToProps(state: GlobalState) { const customPolicies = getDataRetentionCustomPolicies(state); const customPoliciesCount = getDataRetentionCustomPoliciesCount(state); @@ -40,9 +28,9 @@ function mapStateToProps(state: GlobalState) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getDataRetentionCustomPolicies: fetchDataRetentionCustomPolicies, createJob, getJobsByType, diff --git a/webapp/channels/src/components/admin_console/data_retention_settings/team_list/index.ts b/webapp/channels/src/components/admin_console/data_retention_settings/team_list/index.ts index 332e392fbc..9ff17f4ba6 100644 --- a/webapp/channels/src/components/admin_console/data_retention_settings/team_list/index.ts +++ b/webapp/channels/src/components/admin_console/data_retention_settings/team_list/index.ts @@ -3,15 +3,14 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {DataRetentionCustomPolicy} from '@mattermost/types/data_retention'; -import type {Team, TeamSearchOpts} from '@mattermost/types/teams'; +import type {Team} from '@mattermost/types/teams'; import {getDataRetentionCustomPolicyTeams, searchDataRetentionCustomPolicyTeams as searchTeams} from 'mattermost-redux/actions/admin'; import {getDataRetentionCustomPolicy} from 'mattermost-redux/selectors/entities/admin'; import {getTeamsInPolicy, searchTeamsInPolicy} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {teamListToMap, filterTeamsStartingWithTerm} from 'mattermost-redux/utils/team_utils'; import {setTeamListSearch} from 'actions/views/search'; @@ -25,12 +24,6 @@ type OwnProps = { teamsToAdd: Record; } -type Actions = { - getDataRetentionCustomPolicyTeams: (id: string, page: number, perPage: number) => Promise<{ data: Team[] }>; - searchTeams: (id: string, term: string, opts: TeamSearchOpts) => Promise<{ data: Team[] }>; - setTeamListSearch: (term: string) => ActionResult; -} - function searchTeamsToAdd(teams: Record, term: string): Record { const filteredTeams = filterTeamsStartingWithTerm(Object.keys(teams).map((key) => teams[key]), term); return teamListToMap(filteredTeams); @@ -66,7 +59,7 @@ function mapStateToProps() { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getDataRetentionCustomPolicyTeams, searchTeams, setTeamListSearch, diff --git a/webapp/channels/src/components/admin_console/data_retention_settings/team_list/team_list.tsx b/webapp/channels/src/components/admin_console/data_retention_settings/team_list/team_list.tsx index 26e9da75c2..c37ddb0d7c 100644 --- a/webapp/channels/src/components/admin_console/data_retention_settings/team_list/team_list.tsx +++ b/webapp/channels/src/components/admin_console/data_retention_settings/team_list/team_list.tsx @@ -31,8 +31,8 @@ type Props = { teamsToAdd: Record; actions: { - searchTeams: (id: string, term: string, opts: TeamSearchOpts) => Promise<{ data: Team[] }>; - getDataRetentionCustomPolicyTeams: (id: string, page: number, perPage: number) => Promise<{ data: Team[] }>; + searchTeams: (id: string, term: string, opts: TeamSearchOpts) => Promise; + getDataRetentionCustomPolicyTeams: (id: string, page: number, perPage: number) => Promise; setTeamListSearch: (term: string) => ActionResult; }; } diff --git a/webapp/channels/src/components/admin_console/database/index.tsx b/webapp/channels/src/components/admin_console/database/index.tsx index 1a0ff8aedc..1a8a0ab8f4 100644 --- a/webapp/channels/src/components/admin_console/database/index.tsx +++ b/webapp/channels/src/components/admin_console/database/index.tsx @@ -3,20 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {getAppliedSchemaMigrations} from 'mattermost-redux/actions/admin'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import MigrationsTable from './migrations_table'; -type Actions = { - getAppliedSchemaMigrations: () => Promise; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getAppliedSchemaMigrations, }, dispatch), }; diff --git a/webapp/channels/src/components/admin_console/feature_discovery/index.tsx b/webapp/channels/src/components/admin_console/feature_discovery/index.tsx index b4fc8b99ed..51b9fb91a5 100644 --- a/webapp/channels/src/components/admin_console/feature_discovery/index.tsx +++ b/webapp/channels/src/components/admin_console/feature_discovery/index.tsx @@ -3,14 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {getPrevTrialLicense} from 'mattermost-redux/actions/admin'; import {getCloudSubscription} from 'mattermost-redux/actions/cloud'; import {checkHadPriorTrial, getCloudCustomer} from 'mattermost-redux/selectors/entities/cloud'; import {getLicense} from 'mattermost-redux/selectors/entities/general'; import {deprecateCloudFree} from 'mattermost-redux/selectors/entities/preferences'; -import type {Action, GenericAction} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; @@ -19,7 +18,6 @@ import withGetCloudSubscription from 'components/common/hocs/cloud/with_get_clou import {LicenseSkus} from 'utils/constants'; import {isCloudLicense} from 'utils/license_utils'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import FeatureDiscovery from './feature_discovery'; @@ -45,15 +43,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - getPrevTrialLicense: () => void; - getCloudSubscription: () => void; - openModal:

(modalData: ModalData

) => void; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getPrevTrialLicense, getCloudSubscription, openModal, diff --git a/webapp/channels/src/components/admin_console/filter/team_filter_dropdown/team_filter_dropdown.tsx b/webapp/channels/src/components/admin_console/filter/team_filter_dropdown/team_filter_dropdown.tsx index 277821299d..1b8f6ce504 100644 --- a/webapp/channels/src/components/admin_console/filter/team_filter_dropdown/team_filter_dropdown.tsx +++ b/webapp/channels/src/components/admin_console/filter/team_filter_dropdown/team_filter_dropdown.tsx @@ -6,7 +6,7 @@ import {useIntl} from 'react-intl'; import type {ActionMeta, OptionsType, ValueType} from 'react-select'; import AsyncSelect from 'react-select/async'; -import type {Team} from '@mattermost/types/teams'; +import type {PagedTeamSearchOpts, Team} from '@mattermost/types/teams'; import type {ActionResult} from 'mattermost-redux/types/actions'; @@ -57,7 +57,7 @@ function TeamFilterDropdown(props: Props) { async function searchInList(term: string, callBack: (options: OptionsType<{label: string; value: string}>) => void) { try { - const response = await props.searchTeams(term, {page: 0, per_page: TEAMS_PER_PAGE}) as ActionResult<{teams: Team[]}>; + const response = await props.searchTeams(term, {page: 0, per_page: TEAMS_PER_PAGE} as PagedTeamSearchOpts); if (response && response.data && response.data.teams && response.data.teams.length > 0) { const teams = response.data.teams.map((team: Team) => ({ value: team.id, diff --git a/webapp/channels/src/components/admin_console/group_settings/group_details/index.ts b/webapp/channels/src/components/admin_console/group_settings/group_details/index.ts index 00547a186b..a5dffcadab 100644 --- a/webapp/channels/src/components/admin_console/group_settings/group_details/index.ts +++ b/webapp/channels/src/components/admin_console/group_settings/group_details/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; @@ -24,12 +24,10 @@ import { getGroupTeams, } from 'mattermost-redux/selectors/entities/groups'; import {getProfilesInGroup as selectProfilesInGroup} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {setNavigationBlocked} from 'actions/admin_actions'; import GroupDetails from './group_details'; -import type {Props} from './group_details'; type OwnProps = { match: { @@ -57,12 +55,9 @@ function mapStateToProps(state: GlobalState, props: OwnProps) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators< - ActionCreatorsMapObject, - Props['actions'] - >( + actions: bindActionCreators( { setNavigationBlocked, getGroup: fetchGroup, diff --git a/webapp/channels/src/components/admin_console/group_settings/groups_list/groups_list.tsx b/webapp/channels/src/components/admin_console/group_settings/groups_list/groups_list.tsx index 5e7e26f354..01a2947d91 100644 --- a/webapp/channels/src/components/admin_console/group_settings/groups_list/groups_list.tsx +++ b/webapp/channels/src/components/admin_console/group_settings/groups_list/groups_list.tsx @@ -6,6 +6,8 @@ import {FormattedMessage} from 'react-intl'; import type {GroupSearchOpts, MixedUnlinkedGroupRedux} from '@mattermost/types/groups'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import GroupRow from 'components/admin_console/group_settings/group_row'; import CheckboxCheckedIcon from 'components/widgets/icons/checkbox_checked_icon'; import NextIcon from 'components/widgets/icons/fa_next_icon'; @@ -22,9 +24,9 @@ type Props = { total: number; readOnly?: boolean; actions: { - getLdapGroups: (page?: number, perPage?: number, opts?: GroupSearchOpts) => Promise; - link: (key: string) => Promise; - unlink: (key: string) => Promise; + getLdapGroups: (page?: number, perPage?: number, opts?: GroupSearchOpts) => Promise; + link: (key: string) => Promise; + unlink: (key: string) => Promise; }; } @@ -445,7 +447,7 @@ export default class GroupsList extends React.PureComponent { this.props.actions.getLdapGroups(this.state.page, LDAP_GROUPS_PAGE_SIZE, {q: ''}).then(this.handleGetGroupsResponse); }; - handleGetGroupsResponse = (response: any) => { + handleGetGroupsResponse = (response: ActionResult) => { if (response?.error) { this.setState({fetchError: true}); } else { diff --git a/webapp/channels/src/components/admin_console/group_settings/groups_list/index.ts b/webapp/channels/src/components/admin_console/group_settings/groups_list/index.ts index d331e164f3..15b74d9c86 100644 --- a/webapp/channels/src/components/admin_console/group_settings/groups_list/index.ts +++ b/webapp/channels/src/components/admin_console/group_settings/groups_list/index.ts @@ -3,14 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import {linkLdapGroup, unlinkLdapGroup, getLdapGroups as fetchLdapGroups} from 'mattermost-redux/actions/admin'; import {createSelector} from 'mattermost-redux/selectors/create_selector'; import {getLdapGroups, getLdapGroupsCount} from 'mattermost-redux/selectors/entities/admin'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import GroupsList from './groups_list'; @@ -33,7 +32,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, any>({ + actions: bindActionCreators({ getLdapGroups: fetchLdapGroups, link: linkLdapGroup, unlink: unlinkLdapGroup, diff --git a/webapp/channels/src/components/admin_console/index.ts b/webapp/channels/src/components/admin_console/index.ts index 6d95201aef..2435a57737 100644 --- a/webapp/channels/src/components/admin_console/index.ts +++ b/webapp/channels/src/components/admin_console/index.ts @@ -4,10 +4,7 @@ import {connect} from 'react-redux'; import type {ConnectedProps} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {AdminConfig} from '@mattermost/types/config'; -import type {Role} from '@mattermost/types/roles'; +import type {Dispatch} from 'redux'; import {getConfig, getEnvironmentConfig, updateConfig} from 'mattermost-redux/actions/admin'; import {loadRolesIfNeeded, editRole} from 'mattermost-redux/actions/roles'; @@ -19,7 +16,6 @@ import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; import {getRoles} from 'mattermost-redux/selectors/entities/roles'; import {getTeam} from 'mattermost-redux/selectors/entities/teams'; import {isCurrentUserSystemAdmin, currentUserHasAnAdminRole, getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {setNavigationBlocked, deferNavigation, cancelNavigation, confirmNavigation} from 'actions/admin_actions.jsx'; import {selectLhsItem} from 'actions/views/lhs'; @@ -28,7 +24,6 @@ import {showNavigationPrompt} from 'selectors/views/admin'; import LocalStorageStore from 'stores/local_storage_store'; import type {GlobalState} from 'types/store'; -import type {LhsItemType} from 'types/store/lhs'; import AdminConsole from './admin_console'; @@ -59,22 +54,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - getConfig: () => ActionFunc; - getEnvironmentConfig: () => ActionFunc; - setNavigationBlocked: () => void; - confirmNavigation: () => void; - cancelNavigation: () => void; - loadRolesIfNeeded: (roles: Iterable) => ActionFunc; - selectLhsItem: (type: LhsItemType, id?: string) => void; - selectTeam: (teamId: string) => void; - editRole: (role: Role) => void; - updateConfig?: (config: AdminConfig) => ActionFunc; -}; - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ getConfig, getEnvironmentConfig, updateConfig, diff --git a/webapp/channels/src/components/admin_console/jobs/index.tsx b/webapp/channels/src/components/admin_console/jobs/index.tsx index 44c8cf8f73..222307afd8 100644 --- a/webapp/channels/src/components/admin_console/jobs/index.tsx +++ b/webapp/channels/src/components/admin_console/jobs/index.tsx @@ -3,14 +3,11 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {JobType} from '@mattermost/types/jobs'; +import type {Dispatch} from 'redux'; import {getJobsByType, createJob, cancelJob} from 'mattermost-redux/actions/jobs'; import {getConfig} from 'mattermost-redux/selectors/entities/admin'; import {makeGetJobsByType} from 'mattermost-redux/selectors/entities/jobs'; -import type {GenericAction, ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; @@ -26,15 +23,9 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { }; } -type Actions = { - getJobsByType: (type: JobType) => Promise; - createJob: (job: {type: JobType}) => Promise; - cancelJob: (id: string) => Promise; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getJobsByType, createJob, cancelJob, diff --git a/webapp/channels/src/components/admin_console/license_settings/index.ts b/webapp/channels/src/components/admin_console/license_settings/index.ts index d8918f141b..41c9a80a2f 100644 --- a/webapp/channels/src/components/admin_console/license_settings/index.ts +++ b/webapp/channels/src/components/admin_console/license_settings/index.ts @@ -3,23 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {StatusOK} from '@mattermost/types/client4'; -import type {ServerError} from '@mattermost/types/errors'; -import type {GetFilteredUsersStatsOpts, UsersStats} from '@mattermost/types/users'; +import type {Dispatch} from 'redux'; import {uploadLicense, removeLicense, getPrevTrialLicense} from 'mattermost-redux/actions/admin'; import {getLicenseConfig} from 'mattermost-redux/actions/general'; import {getFilteredUsersStats} from 'mattermost-redux/actions/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getFilteredUsersStats as selectFilteredUserStats} from 'mattermost-redux/selectors/entities/users'; -import type {Action, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {requestTrialLicense, upgradeToE0Status, upgradeToE0, restartServer, ping} from 'actions/admin_actions'; import {openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import LicenseSettings from './license_settings'; @@ -34,27 +28,9 @@ function mapStateToProps(state: GlobalState) { }; } -type StatusOKFunc = () => Promise; -type PromiseStatusFunc = () => Promise<{status: string}>; -type ActionCreatorTypes = Action | PromiseStatusFunc | StatusOKFunc; - -type Actions = { - getLicenseConfig: () => void; - uploadLicense: (file: File) => Promise; - removeLicense: () => Promise; - getPrevTrialLicense: () => void; - upgradeToE0: StatusOKFunc; - upgradeToE0Status: () => Promise<{percentage: number; error: string | JSX.Element}>; - restartServer: StatusOKFunc; - ping: PromiseStatusFunc; - requestTrialLicense: (users: number, termsAccepted: boolean, receiveEmailsAccepted: boolean, featureName: string) => Promise; - openModal:

(modalData: ModalData

) => void; - getFilteredUsersStats: (filters: GetFilteredUsersStatsOpts) => Promise<{ data?: UsersStats | undefined; error?: ServerError | undefined}>; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getLicenseConfig, uploadLicense, removeLicense, diff --git a/webapp/channels/src/components/admin_console/license_settings/license_settings.tsx b/webapp/channels/src/components/admin_console/license_settings/license_settings.tsx index 68cb0003cf..ecab1e29fd 100644 --- a/webapp/channels/src/components/admin_console/license_settings/license_settings.tsx +++ b/webapp/channels/src/components/admin_console/license_settings/license_settings.tsx @@ -49,7 +49,7 @@ type Props = { removeLicense: () => Promise; getPrevTrialLicense: () => void; upgradeToE0: () => Promise; - upgradeToE0Status: () => Promise<{percentage: number; error: string | JSX.Element}>; + upgradeToE0Status: () => Promise<{percentage: number; error: string | JSX.Element | null}>; restartServer: () => Promise; ping: () => Promise<{status: string}>; requestTrialLicense: (users: number, termsAccepted: boolean, receiveEmailsAccepted: boolean, featureName: string) => Promise; diff --git a/webapp/channels/src/components/admin_console/manage_roles_modal/index.ts b/webapp/channels/src/components/admin_console/manage_roles_modal/index.ts index 832e8dc6cd..39fbbb87a6 100644 --- a/webapp/channels/src/components/admin_console/manage_roles_modal/index.ts +++ b/webapp/channels/src/components/admin_console/manage_roles_modal/index.ts @@ -3,15 +3,14 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {updateUserRoles} from 'mattermost-redux/actions/users'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; +import type {GenericAction} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import ManageRolesModal from './manage_roles_modal'; -import type {Props} from './manage_roles_modal'; function mapStateToProps(state: GlobalState) { return { @@ -21,7 +20,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ updateUserRoles, }, dispatch), }; diff --git a/webapp/channels/src/components/admin_console/manage_teams_modal/index.tsx b/webapp/channels/src/components/admin_console/manage_teams_modal/index.tsx index d14495b549..dc2035127f 100644 --- a/webapp/channels/src/components/admin_console/manage_teams_modal/index.tsx +++ b/webapp/channels/src/components/admin_console/manage_teams_modal/index.tsx @@ -3,17 +3,16 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {updateTeamMemberSchemeRoles, getTeamMembersForUser, getTeamsForUser, removeUserFromTeam} from 'mattermost-redux/actions/teams'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; +import type {GenericAction} from 'mattermost-redux/types/actions'; import {getCurrentLocale} from 'selectors/i18n'; import type {GlobalState} from 'types/store'; import ManageTeamsModal from './manage_teams_modal'; -import type {Props} from './manage_teams_modal'; function mapStateToProps(state: GlobalState) { return { @@ -23,7 +22,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ getTeamMembersForUser, getTeamsForUser, updateTeamMemberSchemeRoles, diff --git a/webapp/channels/src/components/admin_console/manage_tokens_modal/index.ts b/webapp/channels/src/components/admin_console/manage_tokens_modal/index.ts index a6f01bb203..445ef08b06 100644 --- a/webapp/channels/src/components/admin_console/manage_tokens_modal/index.ts +++ b/webapp/channels/src/components/admin_console/manage_tokens_modal/index.ts @@ -3,17 +3,21 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; + +import type {UserProfile} from '@mattermost/types/users'; import {getUserAccessTokensForUser} from 'mattermost-redux/actions/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import ManageTokensModal from './manage_tokens_modal'; -import type {Props} from './manage_tokens_modal'; -function mapStateToProps(state: GlobalState, ownProps: Props) { +type OwnProps = { + user?: UserProfile; +} + +function mapStateToProps(state: GlobalState, ownProps: OwnProps) { const userId = ownProps.user ? ownProps.user.id : ''; const userAccessTokens = state.entities.admin.userAccessTokensByUser; @@ -25,7 +29,7 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ getUserAccessTokensForUser, }, dispatch), }; diff --git a/webapp/channels/src/components/admin_console/manage_tokens_modal/manage_tokens_modal.tsx b/webapp/channels/src/components/admin_console/manage_tokens_modal/manage_tokens_modal.tsx index 66c283461d..fc37fdbb5e 100644 --- a/webapp/channels/src/components/admin_console/manage_tokens_modal/manage_tokens_modal.tsx +++ b/webapp/channels/src/components/admin_console/manage_tokens_modal/manage_tokens_modal.tsx @@ -8,7 +8,6 @@ import {FormattedMessage} from 'react-intl'; import type {UserAccessToken, UserProfile} from '@mattermost/types/users'; import {Client4} from 'mattermost-redux/client'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import * as UserUtils from 'mattermost-redux/utils/user_utils'; import RevokeTokenButton from 'components/admin_console/revoke_token_button'; @@ -44,7 +43,7 @@ export type Props = { /** * Function to get a user's access tokens */ - getUserAccessTokensForUser: (userId: string, page: number, perPage: number) => ActionFunc; + getUserAccessTokensForUser: (userId: string, page: number, perPage: number) => void; }; }; diff --git a/webapp/channels/src/components/admin_console/member_list_group/index.ts b/webapp/channels/src/components/admin_console/member_list_group/index.ts index 00d2132d30..fa57e81c53 100644 --- a/webapp/channels/src/components/admin_console/member_list_group/index.ts +++ b/webapp/channels/src/components/admin_console/member_list_group/index.ts @@ -3,20 +3,18 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {getGroupStats} from 'mattermost-redux/actions/groups'; import {searchProfiles, getProfilesInGroup} from 'mattermost-redux/actions/users'; import {getGroupMemberCount} from 'mattermost-redux/selectors/entities/groups'; import {getProfilesInGroup as selectProfiles, searchProfilesInGroup} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {setModalSearchTerm} from 'actions/views/search'; import type {GlobalState} from 'types/store'; import MemberListGroup from './member_list_group'; -import type {Props as MemberListGroupProps} from './member_list_group'; type Props = { groupID: string; @@ -41,7 +39,7 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, MemberListGroupProps['actions']>({ + actions: bindActionCreators({ getProfilesInGroup, searchProfiles, setModalSearchTerm, diff --git a/webapp/channels/src/components/admin_console/member_list_group/member_list_group.tsx b/webapp/channels/src/components/admin_console/member_list_group/member_list_group.tsx index 26c6737536..35d9f3ceaa 100644 --- a/webapp/channels/src/components/admin_console/member_list_group/member_list_group.tsx +++ b/webapp/channels/src/components/admin_console/member_list_group/member_list_group.tsx @@ -7,6 +7,8 @@ import {FormattedMessage} from 'react-intl'; import type {GroupStats} from '@mattermost/types/groups'; import type {UserProfile} from '@mattermost/types/users'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import DataGrid from 'components/admin_console/data_grid/data_grid'; import type {Row, Column} from 'components/admin_console/data_grid/data_grid'; import UserGridName from 'components/admin_console/user_grid/user_grid_name'; @@ -23,10 +25,10 @@ export type Props = { groupID: string; total: number; actions: { - getProfilesInGroup: (groupID: string, page: number, perPage: number) => Promise<{data: UserProfile[]}>; - getGroupStats: (groupID: string) => Promise<{data: GroupStats}>; - searchProfiles: (term: string, options?: Record) => Promise<{data: UserProfile[]}>; - setModalSearchTerm: (term: string) => Promise<{data: boolean}>; + getProfilesInGroup: (groupID: string, page: number, perPage: number) => Promise>; + getGroupStats: (groupID: string) => Promise>; + searchProfiles: (term: string, options?: Record) => Promise>; + setModalSearchTerm: (term: string) => void; }; } diff --git a/webapp/channels/src/components/admin_console/openid_convert/index.ts b/webapp/channels/src/components/admin_console/openid_convert/index.ts index 04e5a5d2f1..67abedc589 100644 --- a/webapp/channels/src/components/admin_console/openid_convert/index.ts +++ b/webapp/channels/src/components/admin_console/openid_convert/index.ts @@ -3,22 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {AdminConfig} from '@mattermost/types/config'; +import type {Dispatch} from 'redux'; import {updateConfig} from 'mattermost-redux/actions/admin'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import OpenIdConvert from './openid_convert'; -type Actions = { - updateConfig: (config: AdminConfig) => ActionFunc; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ updateConfig, }, dispatch), }; diff --git a/webapp/channels/src/components/admin_console/openid_convert/openid_convert.tsx b/webapp/channels/src/components/admin_console/openid_convert/openid_convert.tsx index 93969ddc2f..95dfc332ed 100644 --- a/webapp/channels/src/components/admin_console/openid_convert/openid_convert.tsx +++ b/webapp/channels/src/components/admin_console/openid_convert/openid_convert.tsx @@ -6,7 +6,7 @@ import {FormattedMessage} from 'react-intl'; import type {AdminConfig} from '@mattermost/types/config'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import type {BaseProps} from 'components/admin_console/admin_settings'; import ExternalLink from 'components/external_link'; @@ -21,18 +21,13 @@ import './openid_convert.scss'; type Props = BaseProps & { disabled?: boolean; actions: { - updateConfig: (config: AdminConfig) => ActionFunc & Partial<{error?: ClientErrorPlaceholder}>; + updateConfig: (config: AdminConfig) => Promise; }; }; type State = { serverError?: string; } -type ClientErrorPlaceholder = { - message: string; - server_error_id: string; -} - export default class OpenIdConvert extends React.PureComponent { constructor(props: Props) { super(props); diff --git a/webapp/channels/src/components/admin_console/permission_schemes_settings/edit_post_time_limit_modal/edit_post_time_limit_modal.tsx b/webapp/channels/src/components/admin_console/permission_schemes_settings/edit_post_time_limit_modal/edit_post_time_limit_modal.tsx index 8fc18a07a7..bb3d2acb26 100644 --- a/webapp/channels/src/components/admin_console/permission_schemes_settings/edit_post_time_limit_modal/edit_post_time_limit_modal.tsx +++ b/webapp/channels/src/components/admin_console/permission_schemes_settings/edit_post_time_limit_modal/edit_post_time_limit_modal.tsx @@ -7,7 +7,7 @@ import {FormattedMessage} from 'react-intl'; import type {AdminConfig} from '@mattermost/types/config'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import FormattedMarkdownMessage from 'components/formatted_markdown_message'; @@ -22,15 +22,10 @@ type Props ={ show: boolean; onClose: () => void; actions: { - updateConfig: (config: AdminConfig) => ActionFunc & {error?: ClientErrorPlaceholder}; + updateConfig: (config: AdminConfig) => Promise; }; } -type ClientErrorPlaceholder = { - message: string; - server_error_id: string; -} - export default function EditPostTimeLimitModal(props: Props) { const {ServiceSettings} = props.config; diff --git a/webapp/channels/src/components/admin_console/permission_schemes_settings/edit_post_time_limit_modal/index.tsx b/webapp/channels/src/components/admin_console/permission_schemes_settings/edit_post_time_limit_modal/index.tsx index 34a1b76b0a..054a8b1ba8 100644 --- a/webapp/channels/src/components/admin_console/permission_schemes_settings/edit_post_time_limit_modal/index.tsx +++ b/webapp/channels/src/components/admin_console/permission_schemes_settings/edit_post_time_limit_modal/index.tsx @@ -3,31 +3,24 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {AdminConfig} from '@mattermost/types/config'; +import type {Dispatch} from 'redux'; import {updateConfig} from 'mattermost-redux/actions/admin'; import {getConfig} from 'mattermost-redux/selectors/entities/admin'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import EditPostTimeLimitModal from './edit_post_time_limit_modal'; -type Actions = { - updateConfig: (config: AdminConfig) => ActionFunc; -} - function mapStateToProps(state: GlobalState) { return { config: getConfig(state), }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({updateConfig}, dispatch), + actions: bindActionCreators({updateConfig}, dispatch), }; } diff --git a/webapp/channels/src/components/admin_console/permission_schemes_settings/index.tsx b/webapp/channels/src/components/admin_console/permission_schemes_settings/index.tsx index 0200602dab..041f111371 100644 --- a/webapp/channels/src/components/admin_console/permission_schemes_settings/index.tsx +++ b/webapp/channels/src/components/admin_console/permission_schemes_settings/index.tsx @@ -3,17 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getSchemeTeams as loadSchemeTeams, getSchemes as loadSchemes} from 'mattermost-redux/actions/schemes'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getSchemes} from 'mattermost-redux/selectors/entities/schemes'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import PermissionSchemesSettings from './permission_schemes_settings'; -import type {Props} from './permission_schemes_settings'; function mapStateToProps(state: GlobalState) { const schemes = getSchemes(state); @@ -26,9 +24,9 @@ function mapStateToProps(state: GlobalState) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ loadSchemes, loadSchemeTeams, }, dispatch), diff --git a/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_system_scheme_settings/index.tsx b/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_system_scheme_settings/index.tsx index 908a450a0d..568413706c 100644 --- a/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_system_scheme_settings/index.tsx +++ b/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_system_scheme_settings/index.tsx @@ -3,15 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {Role} from '@mattermost/types/roles'; import type {GlobalState} from '@mattermost/types/store'; import {loadRolesIfNeeded, editRole} from 'mattermost-redux/actions/roles'; import {getLicense, getConfig} from 'mattermost-redux/selectors/entities/general'; import {getRoles} from 'mattermost-redux/selectors/entities/roles'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions.js'; import {setNavigationBlocked} from 'actions/admin_actions.jsx'; @@ -24,15 +22,10 @@ function mapStateToProps(state: GlobalState) { roles: getRoles(state), }; } -type Actions = { - loadRolesIfNeeded: (roles: Iterable) => void; - editRole: (role: Partial) => Promise; - setNavigationBlocked: (blocked: boolean) => void; -}; -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ loadRolesIfNeeded, editRole, setNavigationBlocked, diff --git a/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_system_scheme_settings/permission_system_scheme_settings.tsx b/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_system_scheme_settings/permission_system_scheme_settings.tsx index ec29cc595f..abb7a3b913 100644 --- a/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_system_scheme_settings/permission_system_scheme_settings.tsx +++ b/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_system_scheme_settings/permission_system_scheme_settings.tsx @@ -33,7 +33,7 @@ type Props = { license: ClientLicense; isDisabled?: boolean; actions: { - loadRolesIfNeeded: (roles: Iterable) => void; + loadRolesIfNeeded: (roles: string[]) => void; editRole: (role: Partial) => Promise; setNavigationBlocked: (blocked: boolean) => void; }; diff --git a/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_team_scheme_settings/index.tsx b/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_team_scheme_settings/index.tsx index f61a9fe00b..c1cfc7a190 100644 --- a/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_team_scheme_settings/index.tsx +++ b/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_team_scheme_settings/index.tsx @@ -3,11 +3,8 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {ServerError} from '@mattermost/types/errors'; -import type {Role} from '@mattermost/types/roles'; -import type {Scheme, SchemePatch} from '@mattermost/types/schemes'; import type {GlobalState} from '@mattermost/types/store'; import {loadRolesIfNeeded, editRole} from 'mattermost-redux/actions/roles'; @@ -16,12 +13,10 @@ import {updateTeamScheme} from 'mattermost-redux/actions/teams'; import {getLicense, getConfig} from 'mattermost-redux/selectors/entities/general'; import {getRoles} from 'mattermost-redux/selectors/entities/roles'; import {getScheme, makeGetSchemeTeams} from 'mattermost-redux/selectors/entities/schemes'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {setNavigationBlocked} from 'actions/admin_actions'; import PermissionTeamSchemeSettings from './permission_team_scheme_settings'; -import type {Props} from './permission_team_scheme_settings'; type OwnProps = { match: { @@ -47,20 +42,9 @@ function makeMapStateToProps() { }; } -type Actions = { - loadRolesIfNeeded: (roles: Iterable) => ActionFunc; - loadScheme: (schemeId: string) => Promise; - loadSchemeTeams: (schemeId: string, page?: number, perPage?: number) => ActionFunc; - editRole: (role: Role) => Promise<{error: ServerError}>; - patchScheme: (schemeId: string, scheme: SchemePatch) => ActionFunc; - updateTeamScheme: (teamId: string, schemeId: string) => Promise<{error: ServerError; data: Scheme}>; - createScheme: (scheme: Scheme) => Promise<{error: ServerError; data: Scheme}>; - setNavigationBlocked: (blocked: boolean) => void; -}; - -function mapDispatchToProps(dispatch: Dispatch): Props { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ loadRolesIfNeeded, loadScheme, loadSchemeTeams, @@ -70,7 +54,7 @@ function mapDispatchToProps(dispatch: Dispatch): Props { createScheme, setNavigationBlocked, }, dispatch), - } as Props; + }; } export default connect(makeMapStateToProps, mapDispatchToProps)(PermissionTeamSchemeSettings); diff --git a/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_team_scheme_settings/permission_team_scheme_settings.tsx b/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_team_scheme_settings/permission_team_scheme_settings.tsx index 5967b471d2..e00207abc0 100644 --- a/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_team_scheme_settings/permission_team_scheme_settings.tsx +++ b/webapp/channels/src/components/admin_console/permission_schemes_settings/permission_team_scheme_settings/permission_team_scheme_settings.tsx @@ -6,13 +6,12 @@ import {FormattedMessage, injectIntl, type IntlShape} from 'react-intl'; import type {RouteComponentProps} from 'react-router-dom'; import type {ClientConfig, ClientLicense} from '@mattermost/types/config'; -import type {ServerError} from '@mattermost/types/errors'; import type {Role} from '@mattermost/types/roles'; import type {Scheme, SchemePatch} from '@mattermost/types/schemes'; import type {Team} from '@mattermost/types/teams'; import GeneralConstants from 'mattermost-redux/constants/general'; -import type {ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import BlockableLink from 'components/admin_console/blockable_link'; import ExternalLink from 'components/external_link'; @@ -44,18 +43,18 @@ export type Props = { scheme: Scheme | null; roles: RolesMap; license: ClientLicense; - teams: Team[]; + teams: Team[] | null; isDisabled: boolean; config: Partial; intl: IntlShape; actions: { - loadRolesIfNeeded: (roles: Iterable) => ActionFunc; + loadRolesIfNeeded: (roles: Iterable) => Promise; loadScheme: (schemeId: string) => Promise; - loadSchemeTeams: (schemeId: string, page?: number, perPage?: number) => ActionFunc; - editRole: (role: Role) => Promise<{error: ServerError}>; - patchScheme: (schemeId: string, scheme: SchemePatch) => ActionFunc; - updateTeamScheme: (teamId: string, schemeId: string) => Promise<{error: ServerError; data: Scheme}>; - createScheme: (scheme: Scheme) => Promise<{error: ServerError; data: Scheme}>; + loadSchemeTeams: (schemeId: string, page?: number, perPage?: number) => Promise; + editRole: (role: Role) => Promise; + patchScheme: (schemeId: string, scheme: SchemePatch) => Promise; + updateTeamScheme: (teamId: string, schemeId: string) => Promise; + createScheme: (scheme: Scheme) => Promise; setNavigationBlocked: (blocked: boolean) => void; }; } @@ -548,7 +547,7 @@ export class PermissionTeamSchemeSettings extends React.PureComponent { - const teams = (this.state.teams || this.props.teams).filter((team) => team.id !== teamId); + const teams = (this.state.teams || this.props.teams)?.filter((team) => team.id !== teamId) ?? null; this.setState({teams, saveNeeded: true}); this.props.actions.setNavigationBlocked(true); }; diff --git a/webapp/channels/src/components/admin_console/permission_schemes_settings/permissions_scheme_summary/index.tsx b/webapp/channels/src/components/admin_console/permission_schemes_settings/permissions_scheme_summary/index.tsx index c47ce68dc4..9d0390aa61 100644 --- a/webapp/channels/src/components/admin_console/permission_schemes_settings/permissions_scheme_summary/index.tsx +++ b/webapp/channels/src/components/admin_console/permission_schemes_settings/permissions_scheme_summary/index.tsx @@ -4,13 +4,12 @@ import {connect} from 'react-redux'; import type {RouteComponentProps} from 'react-router-dom'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import {deleteScheme} from 'mattermost-redux/actions/schemes'; import {makeGetSchemeTeams} from 'mattermost-redux/selectors/entities/schemes'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import PermissionsSchemeSummary from './permissions_scheme_summary'; import type {Props} from './permissions_scheme_summary'; @@ -25,13 +24,9 @@ function makeMapStateToProps() { }; } -type Actions = { - deleteScheme: (schemeId: string) => Promise; -}; - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ deleteScheme, }, dispatch), }; diff --git a/webapp/channels/src/components/admin_console/reset_email_modal/index.ts b/webapp/channels/src/components/admin_console/reset_email_modal/index.ts index c17ed6d691..e8726cf52c 100644 --- a/webapp/channels/src/components/admin_console/reset_email_modal/index.ts +++ b/webapp/channels/src/components/admin_console/reset_email_modal/index.ts @@ -3,22 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {UserProfile} from '@mattermost/types/users'; +import type {Dispatch} from 'redux'; import {patchUser} from 'mattermost-redux/actions/users'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/common'; -import type {ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import ResetEmailModal from './reset_email_modal'; -type Actions = { - patchUser: (user: UserProfile) => ActionResult; -} - function mapStateToProps(state: GlobalState) { return { currentUserId: getCurrentUserId(state), @@ -27,7 +20,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ patchUser, }, dispatch), }; diff --git a/webapp/channels/src/components/admin_console/reset_email_modal/reset_email_modal.test.tsx b/webapp/channels/src/components/admin_console/reset_email_modal/reset_email_modal.test.tsx index c31ab1288c..16a75e39a2 100644 --- a/webapp/channels/src/components/admin_console/reset_email_modal/reset_email_modal.test.tsx +++ b/webapp/channels/src/components/admin_console/reset_email_modal/reset_email_modal.test.tsx @@ -20,7 +20,7 @@ describe('components/admin_console/reset_email_modal/reset_email_modal.tsx', () }); const baseProps = { - actions: {patchUser: jest.fn(() => ({data: ''}))}, + actions: {patchUser: jest.fn(() => Promise.resolve({}))}, user, currentUserId: 'random_user_id', show: true, @@ -46,14 +46,12 @@ describe('components/admin_console/reset_email_modal/reset_email_modal.tsx', () }); test('should not update email since the email is empty', () => { - const patchUser = jest.fn(() => ({data: ''})); - const props = {...baseProps, actions: {patchUser}}; - const wrapper = mountWithIntl(); + const wrapper = mountWithIntl(); (wrapper.find('input[type=\'email\']').first().instance() as unknown as HTMLInputElement).value = ''; wrapper.find('button[type=\'submit\']').first().simulate('click', {preventDefault: jest.fn()}); - expect(patchUser.mock.calls.length).toBe(0); + expect(baseProps.actions.patchUser.mock.calls.length).toBe(0); expect(wrapper.state('error')).toStrictEqual( { - const patchUser = jest.fn(() => ({data: ''})); - const props = {...baseProps, actions: {patchUser}}; - const wrapper = mountWithIntl(); + const wrapper = mountWithIntl(); (wrapper.find('input[type=\'email\']').first().instance() as unknown as HTMLInputElement).value = 'invalid-email'; wrapper.find('button[type=\'submit\']').first().simulate('click', {preventDefault: jest.fn()}); - expect(patchUser.mock.calls.length).toBe(0); + expect(baseProps.actions.patchUser.mock.calls.length).toBe(0); expect(wrapper.state('error')).toStrictEqual( { - const patchUser = jest.fn(() => ({data: ''})); - const props = {...baseProps, actions: {patchUser}, currentUserId: user.id}; + const props = {...baseProps, currentUserId: user.id}; const wrapper = mountWithIntl(); (wrapper.find('input[type=\'email\']').first().instance() as unknown as HTMLInputElement).value = 'currentUser@test.com'; wrapper.find('button[type=\'submit\']').first().simulate('click', {preventDefault: jest.fn()}); - expect(patchUser.mock.calls.length).toBe(0); + expect(baseProps.actions.patchUser.mock.calls.length).toBe(0); expect(wrapper.state('error')).toStrictEqual( { - const patchUser = jest.fn(() => ({data: ''})); - const props = {...baseProps, actions: {patchUser}}; - const wrapper = mountWithIntl(); + const wrapper = mountWithIntl(); (wrapper.find('input[type=\'email\']').first().instance() as unknown as HTMLInputElement).value = 'user@test.com'; wrapper.find('button[type=\'submit\']').first().simulate('click', {preventDefault: jest.fn()}); - expect(patchUser.mock.calls.length).toBe(1); + expect(baseProps.actions.patchUser.mock.calls.length).toBe(1); expect(wrapper.state('error')).toBeNull(); }); test('should update email since the email is valid of the current user', () => { - const patchUser = jest.fn(() => ({data: ''})); - const props = {...baseProps, actions: {patchUser}, currentUserId: user.id}; + const props = {...baseProps, currentUserId: user.id}; const wrapper = mountWithIntl(); (wrapper.find('input[type=\'email\']').first().instance() as unknown as HTMLInputElement).value = 'currentUser@test.com'; (wrapper.find('input[type=\'password\']').first().instance() as unknown as HTMLInputElement).value = 'password'; wrapper.find('button[type=\'submit\']').first().simulate('click', {preventDefault: jest.fn()}); - expect(patchUser.mock.calls.length).toBe(1); + expect(baseProps.actions.patchUser.mock.calls.length).toBe(1); expect(wrapper.state('error')).toBeNull(); }); }); diff --git a/webapp/channels/src/components/admin_console/reset_email_modal/reset_email_modal.tsx b/webapp/channels/src/components/admin_console/reset_email_modal/reset_email_modal.tsx index e6f6c7fba1..2887a29a4f 100644 --- a/webapp/channels/src/components/admin_console/reset_email_modal/reset_email_modal.tsx +++ b/webapp/channels/src/components/admin_console/reset_email_modal/reset_email_modal.tsx @@ -23,7 +23,7 @@ type Props = { onModalSubmit: (user?: UserProfile) => void; onModalDismissed: () => void; actions: { - patchUser: (user: UserProfile) => ActionResult; + patchUser: (user: UserProfile) => Promise; }; } diff --git a/webapp/channels/src/components/admin_console/reset_password_modal/index.ts b/webapp/channels/src/components/admin_console/reset_password_modal/index.ts index 0be8be05b7..a673774f43 100644 --- a/webapp/channels/src/components/admin_console/reset_password_modal/index.ts +++ b/webapp/channels/src/components/admin_console/reset_password_modal/index.ts @@ -3,12 +3,11 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {updateUserPassword} from 'mattermost-redux/actions/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import {getPasswordConfig} from 'utils/utils'; @@ -16,10 +15,6 @@ import type {GlobalState} from 'types/store'; import ResetPasswordModal from './reset_password_modal'; -type Actions = { - updateUserPassword: (userId: string, currentPassword: string, password: string) => ActionResult; -} - function mapStateToProps(state: GlobalState) { const config = getConfig(state); @@ -31,7 +26,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ updateUserPassword, }, dispatch), }; diff --git a/webapp/channels/src/components/admin_console/reset_password_modal/reset_password_modal.test.tsx b/webapp/channels/src/components/admin_console/reset_password_modal/reset_password_modal.test.tsx index d8d904cb08..58289d7149 100644 --- a/webapp/channels/src/components/admin_console/reset_password_modal/reset_password_modal.test.tsx +++ b/webapp/channels/src/components/admin_console/reset_password_modal/reset_password_modal.test.tsx @@ -7,8 +7,6 @@ import {FormattedMessage} from 'react-intl'; import type {UserNotifyProps, UserProfile} from '@mattermost/types/users'; -import type {ActionResult} from 'mattermost-redux/types/actions'; - import {mountWithIntl} from 'tests/helpers/intl-test-helper'; import {TestHelper} from 'utils/test_helper'; @@ -36,8 +34,7 @@ describe('components/admin_console/reset_password_modal/reset_password_modal.tsx }); const baseProps = { - // eslint-disable-next-line @typescript-eslint/ban-types - actions: {updateUserPassword: jest.fn>(() => ({data: ''}))}, + actions: {updateUserPassword: jest.fn(() => Promise.resolve({data: ''}))}, currentUserId: user.id, user, show: true, @@ -68,8 +65,7 @@ describe('components/admin_console/reset_password_modal/reset_password_modal.tsx }); test('should call updateUserPassword', () => { - // eslint-disable-next-line @typescript-eslint/ban-types - const updateUserPassword = jest.fn>(() => ({data: ''})); + const updateUserPassword = jest.fn(() => Promise.resolve({data: ''})); const oldPassword = 'oldPassword123!'; const newPassword = 'newPassword123!'; const props = {...baseProps, actions: {updateUserPassword}}; @@ -85,8 +81,7 @@ describe('components/admin_console/reset_password_modal/reset_password_modal.tsx }); test('should not call updateUserPassword when the old password is not provided', () => { - // eslint-disable-next-line @typescript-eslint/ban-types - const updateUserPassword = jest.fn>(() => ({data: ''})); + const updateUserPassword = jest.fn(() => Promise.resolve({data: ''})); const newPassword = 'newPassword123!'; const props = {...baseProps, actions: {updateUserPassword}}; const wrapper = mountWithIntl(); @@ -104,8 +99,7 @@ describe('components/admin_console/reset_password_modal/reset_password_modal.tsx }); test('should call updateUserPassword', () => { - // eslint-disable-next-line @typescript-eslint/ban-types - const updateUserPassword = jest.fn>(() => ({data: ''})); + const updateUserPassword = jest.fn(() => Promise.resolve({data: ''})); const password = 'Password123!'; const props = {...baseProps, currentUserId: '2', actions: {updateUserPassword}}; diff --git a/webapp/channels/src/components/admin_console/reset_password_modal/reset_password_modal.tsx b/webapp/channels/src/components/admin_console/reset_password_modal/reset_password_modal.tsx index 44c8fe22c3..05d0cb067e 100644 --- a/webapp/channels/src/components/admin_console/reset_password_modal/reset_password_modal.tsx +++ b/webapp/channels/src/components/admin_console/reset_password_modal/reset_password_modal.tsx @@ -24,7 +24,7 @@ type State = { serverErrorCurrentPass: React.ReactNode; } -type Props = { +export type Props = { user?: UserProfile; currentUserId: string; show: boolean; @@ -32,7 +32,7 @@ type Props = { onModalDismissed: () => void; passwordConfig: PasswordConfig; actions: { - updateUserPassword: (userId: string, currentPassword: string, password: string) => ActionResult; + updateUserPassword: (userId: string, currentPassword: string, password: string) => Promise; }; } diff --git a/webapp/channels/src/components/admin_console/revoke_token_button/revoke_token_button.tsx b/webapp/channels/src/components/admin_console/revoke_token_button/revoke_token_button.tsx index fe1be0edef..7e747865fd 100644 --- a/webapp/channels/src/components/admin_console/revoke_token_button/revoke_token_button.tsx +++ b/webapp/channels/src/components/admin_console/revoke_token_button/revoke_token_button.tsx @@ -4,15 +4,15 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; -import type {ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {trackEvent} from 'actions/telemetry_actions.jsx'; -interface RevokeTokenButtonProps { +export interface RevokeTokenButtonProps { actions: { revokeUserAccessToken: ( tokenId: string - ) => Promise | ActionFunc | ActionResult; + ) => Promise; }; tokenId: string; onError: (errorMessage: string) => void; diff --git a/webapp/channels/src/components/admin_console/server_logs/logs.tsx b/webapp/channels/src/components/admin_console/server_logs/logs.tsx index de02cfc51e..e43ba8dd3f 100644 --- a/webapp/channels/src/components/admin_console/server_logs/logs.tsx +++ b/webapp/channels/src/components/admin_console/server_logs/logs.tsx @@ -12,8 +12,6 @@ import type { LogServerNames, } from '@mattermost/types/admin'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; - import AdminHeader from 'components/widgets/admin_console/admin_header'; import LogList from './log_list'; @@ -24,11 +22,11 @@ type Props = { plainLogs: string[]; isPlainLogs: boolean; actions: { - getLogs: (logFilter: LogFilter) => ActionFunc; + getLogs: (logFilter: LogFilter) => Promise; getPlainLogs: ( page?: number | undefined, perPage?: number | undefined - ) => ActionFunc; + ) => Promise; }; }; diff --git a/webapp/channels/src/components/admin_console/system_roles/system_role/add_users_to_role_modal/add_users_to_role_modal.tsx b/webapp/channels/src/components/admin_console/system_roles/system_role/add_users_to_role_modal/add_users_to_role_modal.tsx index d89aeca75f..78c56a32d2 100644 --- a/webapp/channels/src/components/admin_console/system_roles/system_role/add_users_to_role_modal/add_users_to_role_modal.tsx +++ b/webapp/channels/src/components/admin_console/system_roles/system_role/add_users_to_role_modal/add_users_to_role_modal.tsx @@ -11,6 +11,7 @@ import type {UserProfile} from '@mattermost/types/users'; import {Client4} from 'mattermost-redux/client'; import {filterProfiles} from 'mattermost-redux/selectors/entities/users'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {filterProfilesStartingWithTerm, profileListToMap, isGuest} from 'mattermost-redux/utils/user_utils'; import MultiSelect from 'components/multiselect/multiselect'; @@ -36,8 +37,8 @@ export type Props = { onExited: () => void; actions: { - getProfiles: (page: number, perPage?: number, options?: Record) => Promise<{ data: UserProfile[] }>; - searchProfiles: (term: string, options?: Record) => Promise<{ data: UserProfile[] }>; + getProfiles: (page: number, perPage?: number, options?: Record) => Promise>; + searchProfiles: (term: string, options?: Record) => Promise>; }; } @@ -87,7 +88,7 @@ export class AddUsersToRoleModal extends React.PureComponent { const search = term !== ''; if (search) { const {data} = await this.props.actions.searchProfiles(term, {replace: true}); - data.forEach((user) => { + data!.forEach((user) => { if (!user.is_bot) { searchResults.push(user); } diff --git a/webapp/channels/src/components/admin_console/system_roles/system_role/add_users_to_role_modal/index.tsx b/webapp/channels/src/components/admin_console/system_roles/system_role/add_users_to_role_modal/index.tsx index 9ad92d9c35..676b70d857 100644 --- a/webapp/channels/src/components/admin_console/system_roles/system_role/add_users_to_role_modal/index.tsx +++ b/webapp/channels/src/components/admin_console/system_roles/system_role/add_users_to_role_modal/index.tsx @@ -3,14 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import type {UserProfile} from '@mattermost/types/users'; import {getProfiles, searchProfiles} from 'mattermost-redux/actions/users'; import {getProfiles as selectProfiles} from 'mattermost-redux/selectors/entities/users'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import AddUsersToRoleModal from './add_users_to_role_modal'; import type {Props} from './add_users_to_role_modal'; @@ -24,9 +23,9 @@ function mapStateToProps(state: GlobalState, props: Props) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ getProfiles, searchProfiles, }, dispatch), diff --git a/webapp/channels/src/components/admin_console/system_roles/system_role/index.tsx b/webapp/channels/src/components/admin_console/system_roles/system_role/index.tsx index 0a8c224e9a..ac5cdb2f99 100644 --- a/webapp/channels/src/components/admin_console/system_roles/system_role/index.tsx +++ b/webapp/channels/src/components/admin_console/system_roles/system_role/index.tsx @@ -3,15 +3,12 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {Role} from '@mattermost/types/roles'; +import type {Dispatch} from 'redux'; import {editRole} from 'mattermost-redux/actions/roles'; import {updateUserRoles} from 'mattermost-redux/actions/users'; import {getLicense} from 'mattermost-redux/selectors/entities/general'; import {getRolesById} from 'mattermost-redux/selectors/entities/roles'; -import type {GenericAction, ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import {setNavigationBlocked} from 'actions/admin_actions.jsx'; @@ -27,12 +24,6 @@ type Props = { }; } -type Actions = { - editRole(role: Role): Promise; - updateUserRoles(userId: string, roles: string): Promise; - setNavigationBlocked: (blocked: boolean) => void; -} - function mapStateToProps(state: GlobalState, props: Props) { const role = getRolesById(state)[props.match.params.role_id]; const license = getLicense(state); @@ -44,9 +35,9 @@ function mapStateToProps(state: GlobalState, props: Props) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ editRole, updateUserRoles, setNavigationBlocked, diff --git a/webapp/channels/src/components/admin_console/system_roles/system_role/system_role_users/index.tsx b/webapp/channels/src/components/admin_console/system_roles/system_role/system_role_users/index.tsx index 47de118fc4..42d4bda0de 100644 --- a/webapp/channels/src/components/admin_console/system_roles/system_role/system_role_users/index.tsx +++ b/webapp/channels/src/components/admin_console/system_roles/system_role/system_role_users/index.tsx @@ -3,14 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {UserProfile} from '@mattermost/types/users'; import {getFilteredUsersStats, getProfiles, searchProfiles} from 'mattermost-redux/actions/users'; import {getRoles} from 'mattermost-redux/selectors/entities/roles_helpers'; import {getProfiles as selectProfiles, getFilteredUsersStats as selectFilteredUserStats, makeSearchProfilesStartingWithTerm, filterProfiles} from 'mattermost-redux/selectors/entities/users'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import {filterProfilesStartingWithTerm, profileListToMap} from 'mattermost-redux/utils/user_utils'; import {setUserGridSearch} from 'actions/views/search'; @@ -18,7 +17,6 @@ import {setUserGridSearch} from 'actions/views/search'; import type {GlobalState} from 'types/store'; import SystemRoleUsers from './system_role_users'; -import type {Props} from './system_role_users'; type OwnProps = { roleName: string; @@ -57,9 +55,9 @@ function mapStateToProps(state: GlobalState, props: OwnProps) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ getProfiles, getFilteredUsersStats, searchProfiles, diff --git a/webapp/channels/src/components/admin_console/system_roles/system_role/system_role_users/system_role_users.tsx b/webapp/channels/src/components/admin_console/system_roles/system_role/system_role_users/system_role_users.tsx index 71b9809172..7faf5f6503 100644 --- a/webapp/channels/src/components/admin_console/system_roles/system_role/system_role_users/system_role_users.tsx +++ b/webapp/channels/src/components/admin_console/system_roles/system_role/system_role_users/system_role_users.tsx @@ -4,10 +4,11 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; -import type {ServerError} from '@mattermost/types/errors'; import type {Role} from '@mattermost/types/roles'; import type {UserProfile, UsersStats, GetFilteredUsersStatsOpts} from '@mattermost/types/users'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import DataGrid from 'components/admin_console/data_grid/data_grid'; import UserGridName from 'components/admin_console/user_grid/user_grid_name'; import UserGridRemove from 'components/admin_console/user_grid/user_grid_remove'; @@ -30,13 +31,10 @@ export type Props = { onAddCallback: (users: UserProfile[]) => void; onRemoveCallback: (user: UserProfile) => void; actions: { - getFilteredUsersStats: (filters: GetFilteredUsersStatsOpts) => Promise<{ - data?: UsersStats; - error?: ServerError; - }>; - getProfiles: (page?: number | undefined, perPage?: number | undefined, options?: any) => Promise; - searchProfiles: (term: string, options: any) => Promise; - setUserGridSearch: (term: string) => Promise; + getFilteredUsersStats: (filters: GetFilteredUsersStatsOpts) => Promise>; + getProfiles: (page?: number | undefined, perPage?: number | undefined, options?: any) => Promise; + searchProfiles: (term: string, options: any) => Promise; + setUserGridSearch: (term: string) => void; }; readOnly?: boolean; } diff --git a/webapp/channels/src/components/admin_console/system_user_detail/index.ts b/webapp/channels/src/components/admin_console/system_user_detail/index.ts index 18667b477b..ec52a190f6 100644 --- a/webapp/channels/src/components/admin_console/system_user_detail/index.ts +++ b/webapp/channels/src/components/admin_console/system_user_detail/index.ts @@ -3,17 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {ServerError} from '@mattermost/types/errors'; import type {GlobalState} from '@mattermost/types/store'; -import type {TeamMembership} from '@mattermost/types/teams'; import {addUserToTeam} from 'mattermost-redux/actions/teams'; import {updateUserActive} from 'mattermost-redux/actions/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getUser} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; +import type {GenericAction} from 'mattermost-redux/types/actions'; import {setNavigationBlocked} from 'actions/admin_actions.jsx'; @@ -33,14 +31,8 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { }; } -type Actions = { - updateUserActive: (userId: string, active: boolean) => Promise<{error: ServerError}>; - setNavigationBlocked: (blocked: boolean) => void; - addUserToTeam: (teamId: string, userId?: string) => Promise<{data: TeamMembership; error?: any}>; -} - function mapDispatchToProps(dispatch: Dispatch) { - const apiActions = bindActionCreators, Actions>({ + const apiActions = bindActionCreators({ updateUserActive, addUserToTeam, }, dispatch); diff --git a/webapp/channels/src/components/admin_console/system_user_detail/system_user_detail.tsx b/webapp/channels/src/components/admin_console/system_user_detail/system_user_detail.tsx index e6f1e027bd..a518b5e8fa 100644 --- a/webapp/channels/src/components/admin_console/system_user_detail/system_user_detail.tsx +++ b/webapp/channels/src/components/admin_console/system_user_detail/system_user_detail.tsx @@ -11,6 +11,7 @@ import type {ServerError} from '@mattermost/types/errors'; import type {Team, TeamMembership} from '@mattermost/types/teams'; import type {UserProfile} from '@mattermost/types/users'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {isEmail} from 'mattermost-redux/utils/helpers'; import {adminResetMfa, adminResetEmail} from 'actions/admin_actions.jsx'; @@ -42,9 +43,9 @@ export type Props = { mfaEnabled: boolean; isDisabled?: boolean; actions: { - updateUserActive: (userId: string, active: boolean) => Promise<{error: ServerError}>; + updateUserActive: (userId: string, active: boolean) => Promise; setNavigationBlocked: (blocked: boolean) => void; - addUserToTeam: (teamId: string, userId?: string) => Promise<{data: TeamMembership; error?: any}>; + addUserToTeam: (teamId: string, userId: string) => Promise; }; } diff --git a/webapp/channels/src/components/admin_console/system_user_detail/team_list/abstract_list.tsx b/webapp/channels/src/components/admin_console/system_user_detail/team_list/abstract_list.tsx index 129f558670..3d4d809750 100644 --- a/webapp/channels/src/components/admin_console/system_user_detail/team_list/abstract_list.tsx +++ b/webapp/channels/src/components/admin_console/system_user_detail/team_list/abstract_list.tsx @@ -6,6 +6,8 @@ import {FormattedMessage} from 'react-intl'; import type {Team} from '@mattermost/types/teams'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import NextIcon from 'components/widgets/icons/fa_next_icon'; import PreviousIcon from 'components/widgets/icons/fa_previous_icon'; @@ -25,7 +27,7 @@ type Props = { emptyListTextId: string; emptyListTextDefaultMessage: string; actions: { - getTeamsData: (userId: string) => Promise<{data: Team[]}>; + getTeamsData: (userId: string) => Promise>; removeGroup?: () => void; }; } diff --git a/webapp/channels/src/components/admin_console/system_user_detail/team_list/index.ts b/webapp/channels/src/components/admin_console/system_user_detail/team_list/index.ts index 9140aa2335..2a73b52dc3 100644 --- a/webapp/channels/src/components/admin_console/system_user_detail/team_list/index.ts +++ b/webapp/channels/src/components/admin_console/system_user_detail/team_list/index.ts @@ -3,9 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {Team, TeamMembership} from '@mattermost/types/teams'; +import type {Dispatch} from 'redux'; import { getTeamsForUser, @@ -13,7 +11,7 @@ import { removeUserFromTeam, updateTeamMemberSchemeRoles, } from 'mattermost-redux/actions/teams'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; +import type {GenericAction} from 'mattermost-redux/types/actions'; import {getCurrentLocale} from 'selectors/i18n'; @@ -21,13 +19,6 @@ import type {GlobalState} from 'types/store'; import TeamList from './team_list'; -type Actions = { - getTeamsData: (userId: string) => Promise<{data: Team[]}>; - getTeamMembersForUser: (userId: string) => Promise<{data: TeamMembership[]}>; - removeUserFromTeam: (userId: string, teamId: string) => Promise; - updateTeamMemberSchemeRoles: (userId: string, teamId: string, isSchemeUser: boolean, isSchemeAdmin: boolean) => Promise; -} - function mapStateToProps(state: GlobalState) { return { locale: getCurrentLocale(state), @@ -36,7 +27,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getTeamsData: getTeamsForUser, getTeamMembersForUser, removeUserFromTeam, diff --git a/webapp/channels/src/components/admin_console/system_user_detail/team_list/team_list.tsx b/webapp/channels/src/components/admin_console/system_user_detail/team_list/team_list.tsx index 29f0211cf9..0140f6fb32 100644 --- a/webapp/channels/src/components/admin_console/system_user_detail/team_list/team_list.tsx +++ b/webapp/channels/src/components/admin_console/system_user_detail/team_list/team_list.tsx @@ -51,8 +51,8 @@ type Props = { emptyListTextId: string; emptyListTextDefaultMessage: string; actions: { - getTeamsData: (userId: string) => Promise<{data: Team[]}>; - getTeamMembersForUser: (userId: string) => Promise<{data: TeamMembership[]}>; + getTeamsData: (userId: string) => Promise>; + getTeamMembersForUser: (userId: string) => Promise>; removeUserFromTeam: (teamId: string, userId: string) => Promise; updateTeamMemberSchemeRoles: (teamId: string, userId: string, isSchemeUser: boolean, isSchemeAdmin: boolean) => Promise; }; @@ -103,11 +103,11 @@ export default class TeamList extends React.PureComponent { }; // check this out - private mergeTeamsWithMemberships = (data: [{data: Team[]}, {data: TeamMembership[]}]): TeamWithMembership[] => { + private mergeTeamsWithMemberships = (data: [ActionResult, ActionResult]): TeamWithMembership[] => { const teams = data[0].data; const memberships = data[1].data; - let teamsWithMemberships = teams.map((object: Team) => { - const results = memberships.filter((team: TeamMembership) => team.team_id === object.id); + let teamsWithMemberships = teams!.map((object: Team) => { + const results = memberships!.filter((team: TeamMembership) => team.team_id === object.id); const team = {...object, ...results[0]}; return team; }); diff --git a/webapp/channels/src/components/admin_console/system_users/index.ts b/webapp/channels/src/components/admin_console/system_users/index.ts index 3e2cc18b12..35b510f9f8 100644 --- a/webapp/channels/src/components/admin_console/system_users/index.ts +++ b/webapp/channels/src/components/admin_console/system_users/index.ts @@ -3,11 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {StatusOK} from '@mattermost/types/client4'; -import type {ServerError} from '@mattermost/types/errors'; -import type {GetFilteredUsersStatsOpts, UsersStats} from '@mattermost/types/users'; +import type {Dispatch} from 'redux'; import {logError} from 'mattermost-redux/actions/errors'; import {getTeams, getTeamStats} from 'mattermost-redux/actions/teams'; @@ -21,7 +17,6 @@ import { import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getTeamsList} from 'mattermost-redux/selectors/entities/teams'; import {getFilteredUsersStats as selectFilteredUserStats, getUsers} from 'mattermost-redux/selectors/entities/users'; -import type {Action, ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {loadProfilesAndTeamMembers, loadProfilesWithoutTeam} from 'actions/user_actions'; import {setSystemUsersSearch} from 'actions/views/search'; @@ -74,28 +69,9 @@ function mapStateToProps(state: GlobalState) { }; } -type StatusOKFunc = () => Promise; -type PromiseStatusFunc = () => Promise<{status: string}>; -type ActionCreatorTypes = Action | PromiseStatusFunc | StatusOKFunc; - -type Actions = { - getTeams: (startInde: number, endIndex: number) => void; - getTeamStats: (teamId: string) => ActionFunc; - getUser: (id: string) => ActionFunc; - getUserAccessToken: (tokenId: string) => Promise | ActionFunc; - loadProfilesAndTeamMembers: (page: number, maxItemsPerPage: number, teamId: string, options: Record) => void; - loadProfilesWithoutTeam: (page: number, maxItemsPerPage: number, options: Record) => void; - getProfiles: (page: number, maxItemsPerPage: number, options: Record) => void; - setSystemUsersSearch: (searchTerm: string, teamId: string, filter: string) => void; - searchProfiles: (term: string, options?: any) => Promise | ActionFunc; - revokeSessionsForAllUsers: () => any; - logError: (error: {type: string; message: string}) => void; - getFilteredUsersStats: (filters: GetFilteredUsersStatsOpts) => Promise<{ data?: UsersStats | undefined; error?: ServerError | undefined}>; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getTeams, getTeamStats, getUser, diff --git a/webapp/channels/src/components/admin_console/system_users/system_users.tsx b/webapp/channels/src/components/admin_console/system_users/system_users.tsx index 8331254a12..29e7f6e825 100644 --- a/webapp/channels/src/components/admin_console/system_users/system_users.tsx +++ b/webapp/channels/src/components/admin_console/system_users/system_users.tsx @@ -7,10 +7,10 @@ import {FormattedMessage} from 'react-intl'; import type {ServerError} from '@mattermost/types/errors'; import type {Team} from '@mattermost/types/teams'; -import type {GetFilteredUsersStatsOpts, UserProfile, UsersStats} from '@mattermost/types/users'; +import type {GetFilteredUsersStatsOpts, UserAccessToken, UserProfile, UsersStats} from '@mattermost/types/users'; import {debounce} from 'mattermost-redux/actions/helpers'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import AdminHeader from 'components/widgets/admin_console/admin_header'; @@ -68,22 +68,22 @@ type Props = { /** * Function to get statistics for a team */ - getTeamStats: (teamId: string) => ActionFunc; + getTeamStats: (teamId: string) => Promise; /** * Function to get a user */ - getUser: (id: string) => ActionFunc; + getUser: (id: string) => Promise; /** * Function to get a user access token */ - getUserAccessToken: (tokenId: string) => Promise | ActionFunc; + getUserAccessToken: (tokenId: string) => Promise>; loadProfilesAndTeamMembers: (page: number, maxItemsPerPage: number, teamId: string, options: Record) => void; loadProfilesWithoutTeam: (page: number, maxItemsPerPage: number, options: Record) => void; getProfiles: (page: number, maxItemsPerPage: number, options: Record) => void; setSystemUsersSearch: (searchTerm: string, teamId: string, filter: string) => void; - searchProfiles: (term: string, options?: any) => Promise | ActionFunc; + searchProfiles: (term: string, options?: any) => Promise>; /** * Function to log errors @@ -213,7 +213,7 @@ export class SystemUsers extends React.PureComponent { }; const {data: profiles} = await this.props.actions.searchProfiles(term, options); - if (profiles.length === 0 && term.length === USER_ID_LENGTH) { + if (profiles!.length === 0 && term.length === USER_ID_LENGTH) { await this.getUserByTokenOrId(term); } @@ -267,7 +267,7 @@ export class SystemUsers extends React.PureComponent { }; const {data: profiles} = await this.props.actions.searchProfiles(term, options); - if (profiles.length === 0 && term.length === USER_ID_LENGTH) { + if (profiles!.length === 0 && term.length === USER_ID_LENGTH) { await this.getUserByTokenOrId(term); } diff --git a/webapp/channels/src/components/admin_console/system_users/system_users_dropdown/index.ts b/webapp/channels/src/components/admin_console/system_users/system_users_dropdown/index.ts index b30f43632e..b15aa23ac4 100644 --- a/webapp/channels/src/components/admin_console/system_users/system_users_dropdown/index.ts +++ b/webapp/channels/src/components/admin_console/system_users/system_users_dropdown/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {loadBots} from 'mattermost-redux/actions/bots'; import {createGroupTeamsAndChannels} from 'mattermost-redux/actions/groups'; @@ -12,12 +12,10 @@ import * as Selectors from 'mattermost-redux/selectors/entities/admin'; import {getExternalBotAccounts} from 'mattermost-redux/selectors/entities/bots'; import {getLicense} from 'mattermost-redux/selectors/entities/general'; import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import SystemUsersDropdown from './system_users_dropdown'; -import type {Props} from './system_users_dropdown'; function mapStateToProps(state: GlobalState) { const bots = getExternalBotAccounts(state); @@ -32,7 +30,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ updateUserActive, revokeAllSessionsForUser, promoteGuestToUser, diff --git a/webapp/channels/src/components/admin_console/system_users/system_users_dropdown/system_users_dropdown.tsx b/webapp/channels/src/components/admin_console/system_users/system_users_dropdown/system_users_dropdown.tsx index 8d28a35411..f227182083 100644 --- a/webapp/channels/src/components/admin_console/system_users/system_users_dropdown/system_users_dropdown.tsx +++ b/webapp/channels/src/components/admin_console/system_users/system_users_dropdown/system_users_dropdown.tsx @@ -11,6 +11,7 @@ import type {UserProfile} from '@mattermost/types/users'; import type {DeepPartial} from '@mattermost/types/utilities'; import {Permissions} from 'mattermost-redux/constants'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import * as UserUtils from 'mattermost-redux/utils/user_utils'; import {adminResetMfa} from 'actions/admin_actions.jsx'; @@ -43,12 +44,12 @@ export type Props = { bots: Record; isLicensed: boolean; actions: { - updateUserActive: (id: string, active: boolean) => Promise<{error: ServerError}>; - revokeAllSessionsForUser: (id: string) => Promise<{error: ServerError; data: any}>; - promoteGuestToUser: (id: string) => Promise<{error: ServerError}>; - demoteUserToGuest: (id: string) => Promise<{error: ServerError}>; + updateUserActive: (id: string, active: boolean) => Promise; + revokeAllSessionsForUser: (id: string) => Promise>; + promoteGuestToUser: (id: string) => Promise; + demoteUserToGuest: (id: string) => Promise; loadBots: (page?: number, size?: number) => Promise; - createGroupTeamsAndChannels: (userId: string) => Promise<{error: ServerError}>; + createGroupTeamsAndChannels: (userId: string) => Promise; }; doPasswordReset: (user: UserProfile) => void; doEmailReset: (user: UserProfile) => void; @@ -146,7 +147,7 @@ export default class SystemUsersDropdown extends React.PureComponent { + onUpdateActiveResult = ({error}: ActionResult) => { if (error) { this.props.onError({id: error.server_error_id, ...error}); } diff --git a/webapp/channels/src/components/admin_console/system_users/system_users_list/__snapshots__/system_users_list.test.tsx.snap b/webapp/channels/src/components/admin_console/system_users/system_users_list/__snapshots__/system_users_list.test.tsx.snap index 8905b2f523..1b256d51a9 100644 --- a/webapp/channels/src/components/admin_console/system_users/system_users_list/__snapshots__/system_users_list.test.tsx.snap +++ b/webapp/channels/src/components/admin_console/system_users/system_users_list/__snapshots__/system_users_list.test.tsx.snap @@ -63,11 +63,6 @@ exports[`components/admin_console/system_users/list should match default snapsho show={false} /> @@ -266,11 +261,6 @@ exports[`components/admin_console/system_users/list should match default snapsho show={false} /> @@ -494,11 +484,6 @@ exports[`components/admin_console/system_users/list should match default snapsho show={false} /> diff --git a/webapp/channels/src/components/admin_console/system_users/system_users_list/index.ts b/webapp/channels/src/components/admin_console/system_users/system_users_list/index.ts index 44d0711825..a2a7de6f9c 100644 --- a/webapp/channels/src/components/admin_console/system_users/system_users_list/index.ts +++ b/webapp/channels/src/components/admin_console/system_users/system_users_list/index.ts @@ -3,21 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; -import type {UserProfile} from '@mattermost/types/users'; import {getUser} from 'mattermost-redux/actions/users'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import {getNonBotUsers} from './selectors'; import SystemUsersList from './system_users_list'; -type Actions = { - getUser: (id: string) => UserProfile; -}; - type Props = { loading: boolean; teamId: string; @@ -32,9 +26,9 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getUser, }, dispatch), }; diff --git a/webapp/channels/src/components/admin_console/system_users/system_users_list/system_users_list.tsx b/webapp/channels/src/components/admin_console/system_users/system_users_list/system_users_list.tsx index 62c07bd193..fcaea61c60 100644 --- a/webapp/channels/src/components/admin_console/system_users/system_users_list/system_users_list.tsx +++ b/webapp/channels/src/components/admin_console/system_users/system_users_list/system_users_list.tsx @@ -7,8 +7,6 @@ import {FormattedMessage} from 'react-intl'; import type {Team} from '@mattermost/types/teams'; import type {UserProfile} from '@mattermost/types/users'; -import {getUserAccessTokensForUser} from 'mattermost-redux/actions/users'; - import ManageRolesModal from 'components/admin_console/manage_roles_modal'; import ManageTeamsModal from 'components/admin_console/manage_teams_modal'; import ManageTokensModal from 'components/admin_console/manage_tokens_modal'; @@ -53,7 +51,7 @@ type Props = { experimentalEnableAuthenticationTransfer: boolean; actions: { - getUser: (id: string) => UserProfile; + getUser: (id: string) => void; }; }; @@ -364,7 +362,6 @@ export default class SystemUsersList extends React.PureComponent { user={this.state.user} show={this.state.showManageTokensModal} onModalDismissed={this.doManageTokensDismiss} - actions={{getUserAccessTokensForUser}} /> Promise; - linkGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType, patch: SyncablePatch) => ActionResult; - unlinkGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType) => ActionFunc; - membersMinusGroupMembers: (channelID: string, groupIDs: string[], page?: number, perPage?: number) => ActionResult; + linkGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType, patch: SyncablePatch) => Promise; + unlinkGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType) => Promise; + membersMinusGroupMembers: (channelID: string, groupIDs: string[], page?: number, perPage?: number) => Promise; setNavigationBlocked: (blocked: boolean) => {type: 'SET_NAVIGATION_BLOCKED'; blocked: boolean}; - getChannel: (channelId: string) => ActionFunc; + getChannel: (channelId: string) => void; getTeam: (teamId: string) => Promise; getChannelModerations: (channelId: string) => Promise; - patchChannel: (channelId: string, patch: Channel) => ActionFunc; + patchChannel: (channelId: string, patch: Channel) => Promise; updateChannelPrivacy: (channelId: string, privacy: string) => Promise; - patchGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType, patch: Partial) => ActionFunc; - patchChannelModerations: (channelID: string, patch: ChannelModerationPatch[]) => {data: Channel; error: ServerError}; + patchGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType, patch: Partial) => Promise; + patchChannelModerations: (channelID: string, patch: ChannelModerationPatch[]) => Promise; loadScheme: (schemeID: string) => Promise; addChannelMember: (channelId: string, userId: string, postRootId?: string) => Promise; removeChannelMember: (channelId: string, userId: string) => Promise; diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_members/channel_members.tsx b/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_members/channel_members.tsx index 7ad70e6990..6e9eec8256 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_members/channel_members.tsx +++ b/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_members/channel_members.tsx @@ -5,8 +5,7 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; import type {Channel, ChannelMembership} from '@mattermost/types/channels'; -import type {ServerError} from '@mattermost/types/errors'; -import type {UserProfile, UsersStats, GetFilteredUsersStatsOpts} from '@mattermost/types/users'; +import type {UserProfile, GetFilteredUsersStatsOpts} from '@mattermost/types/users'; import GeneralConstants from 'mattermost-redux/constants/general'; import type {ActionResult} from 'mattermost-redux/types/actions'; @@ -45,21 +44,12 @@ type Props = { isDisabled?: boolean; actions: { - getChannelStats: (channelId: string) => Promise<{ - data: boolean; - }>; - loadProfilesAndReloadChannelMembers: (page: number, perPage: number, channelId?: string, sort?: string, options?: {[key: string]: any}) => Promise<{ - data: boolean; - }>; - searchProfilesAndChannelMembers: (term: string, options?: {[key: string]: any}) => Promise<{ - data: boolean; - }>; - getFilteredUsersStats: (filters: GetFilteredUsersStatsOpts) => Promise<{ - data?: UsersStats; - error?: ServerError; - }>; - setUserGridSearch: (term: string) => ActionResult; - setUserGridFilters: (filters: GetFilteredUsersStatsOpts) => ActionResult; + getChannelStats: (channelId: string) => Promise; + loadProfilesAndReloadChannelMembers: (page: number, perPage: number, channelId?: string, sort?: string, options?: {[key: string]: any}) => Promise; + searchProfilesAndChannelMembers: (term: string, options?: {[key: string]: any}) => Promise; + getFilteredUsersStats: (filters: GetFilteredUsersStatsOpts) => Promise; + setUserGridSearch: (term: string) => void; + setUserGridFilters: (filters: GetFilteredUsersStatsOpts) => void; }; } diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_members/index.ts b/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_members/index.ts index 41cdd16c4b..d3491c6b6c 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_members/index.ts +++ b/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/channel_members/index.ts @@ -3,11 +3,10 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {ChannelStats} from '@mattermost/types/channels'; -import type {ServerError} from '@mattermost/types/errors'; -import type {UserProfile, UsersStats, GetFilteredUsersStatsOpts} from '@mattermost/types/users'; +import type {UserProfile, UsersStats} from '@mattermost/types/users'; import {getChannelStats} from 'mattermost-redux/actions/channels'; import {getFilteredUsersStats} from 'mattermost-redux/actions/users'; @@ -15,7 +14,6 @@ import {createSelector} from 'mattermost-redux/selectors/create_selector'; import {getChannelMembersInChannels, getAllChannelStats, getChannel} from 'mattermost-redux/selectors/entities/channels'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {makeGetProfilesInChannel, makeSearchProfilesInChannel, filterProfiles, getFilteredUsersStats as selectFilteredUsersStats} from 'mattermost-redux/selectors/entities/users'; -import type {ActionResult, ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {filterProfilesStartingWithTerm, profileListToMap} from 'mattermost-redux/utils/user_utils'; import {loadProfilesAndReloadChannelMembers, searchProfilesAndChannelMembers} from 'actions/user_actions'; @@ -31,24 +29,6 @@ type Props = { usersToRemove: Record; }; -type Actions = { - getChannelStats: (channelId: string) => Promise<{ - data: boolean; - }>; - loadProfilesAndReloadChannelMembers: (page: number, perPage: number, channelId?: string, sort?: string, options?: {[key: string]: any}) => Promise<{ - data: boolean; - }>; - searchProfilesAndChannelMembers: (term: string, options?: {[key: string]: any}) => Promise<{ - data: boolean; - }>; - getFilteredUsersStats: (filters: GetFilteredUsersStatsOpts) => Promise<{ - data?: UsersStats; - error?: ServerError; - }>; - setUserGridSearch: (term: string) => ActionResult; - setUserGridFilters: (filters: GetFilteredUsersStatsOpts) => ActionResult; -}; - function searchUsersToAdd(users: Record, term: string): Record { const profiles = filterProfilesStartingWithTerm(Object.values(users), term); const filteredProfilesMap = filterProfiles(profileListToMap(profiles), {}); @@ -118,9 +98,9 @@ function makeMapStateToProps() { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getChannelStats, loadProfilesAndReloadChannelMembers, searchProfilesAndChannelMembers, diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/index.ts b/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/index.ts index 60bcd4c140..d75c11f375 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/index.ts +++ b/webapp/channels/src/components/admin_console/team_channel_settings/channel/details/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; @@ -33,14 +33,12 @@ import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general import {getAllGroups, getGroupsAssociatedToChannel} from 'mattermost-redux/selectors/entities/groups'; import {getScheme} from 'mattermost-redux/selectors/entities/schemes'; import {getTeam} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import {setNavigationBlocked} from 'actions/admin_actions'; import {LicenseSkus} from 'utils/constants'; import ChannelDetails from './channel_details'; -import type {ChannelDetailsActions} from './channel_details'; type OwnProps = { match: { @@ -88,7 +86,7 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, ChannelDetailsActions>({ + actions: bindActionCreators({ getGroups: fetchAssociatedGroups, linkGroupSyncable, unlinkGroupSyncable, diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/channel/list/channel_list.tsx b/webapp/channels/src/components/admin_console/team_channel_settings/channel/list/channel_list.tsx index 86049c5fac..3e9ae83927 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/channel/list/channel_list.tsx +++ b/webapp/channels/src/components/admin_console/team_channel_settings/channel/list/channel_list.tsx @@ -8,7 +8,7 @@ import {Link} from 'react-router-dom'; import type {ChannelWithTeamData, ChannelSearchOpts} from '@mattermost/types/channels'; import {debounce} from 'mattermost-redux/actions/helpers'; -import type {ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {trackEvent} from 'actions/telemetry_actions.jsx'; @@ -28,10 +28,10 @@ import {Constants} from 'utils/constants'; import './channel_list.scss'; -interface ChannelListProps { +export interface ChannelListProps { actions: { - searchAllChannels: (term: string, opts: ChannelSearchOpts) => Promise<{ data: any }>; - getData: (page: number, perPage: number, notAssociatedToGroup?: string, excludeDefaultChannels?: boolean, includeDeleted?: boolean) => ActionFunc | ActionResult | Promise; + searchAllChannels: (term: string, opts: ChannelSearchOpts) => Promise; + getData: (page: number, perPage: number, notAssociatedToGroup?: string, excludeDefaultChannels?: boolean, includeDeleted?: boolean) => Promise; }; data: ChannelWithTeamData[]; total: number; diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/channel/list/index.ts b/webapp/channels/src/components/admin_console/team_channel_settings/channel/list/index.ts index eedb8908d0..c3f9e2cbc5 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/channel/list/index.ts +++ b/webapp/channels/src/components/admin_console/team_channel_settings/channel/list/index.ts @@ -3,14 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; -import type {ChannelWithTeamData, ChannelSearchOpts} from '@mattermost/types/channels'; +import type {ChannelWithTeamData} from '@mattermost/types/channels'; import {getAllChannelsWithCount as getData, searchAllChannels} from 'mattermost-redux/actions/channels'; import {createSelector} from 'mattermost-redux/selectors/create_selector'; import {getAllChannels} from 'mattermost-redux/selectors/entities/channels'; -import type {GenericAction, ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import {Constants} from 'utils/constants'; @@ -35,14 +34,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - searchAllChannels: (term: string, opts: ChannelSearchOpts) => Promise<{ data: any }>; - getData: (page: number, perPage: number, notAssociatedToGroup?: string, excludeDefaultChannels?: boolean, includeDeleted?: boolean) => ActionFunc | ActionResult | Promise; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getData, searchAllChannels, }, dispatch), diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/group/group_users/index.ts b/webapp/channels/src/components/admin_console/team_channel_settings/group/group_users/index.ts index 0f6dc8e75f..085e99dfe9 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/group/group_users/index.ts +++ b/webapp/channels/src/components/admin_console/team_channel_settings/group/group_users/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {UserProfile} from '@mattermost/types/users'; @@ -11,7 +11,6 @@ import {getChannelMembersInChannels} from 'mattermost-redux/selectors/entities/c import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getMembersInTeams} from 'mattermost-redux/selectors/entities/teams'; import {filterProfiles} from 'mattermost-redux/selectors/entities/users'; -import type {ActionResult, GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import {memoizeResult} from 'mattermost-redux/utils/helpers'; import {filterProfilesStartingWithTerm, profileListToMap} from 'mattermost-redux/utils/user_utils'; @@ -30,17 +29,6 @@ type Props = { total: number; }; -type Actions = { - loadTeamMembersForProfilesList: (profiles: UserProfile[], id: string, reloadAllMembers?: boolean) => Promise<{ - data: boolean; - }>; - loadChannelMembersForProfilesList: (profiles: UserProfile[], id: string, reloadAllMembers?: boolean) => Promise<{ - data: boolean; - }>; - setModalSearchTerm: (term: string) => ActionResult; - setModalFilters: (filters: Filters) => ActionResult; -}; - function makeMapStateToProps() { const searchUsers = memoizeResult((users: UserProfile[], term: string, filters: Filters, memberships: Memberships) => { let profiles = users; @@ -90,9 +78,9 @@ function makeMapStateToProps() { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ loadChannelMembersForProfilesList, loadTeamMembersForProfilesList, setModalSearchTerm, diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/group/group_users/users_to_remove.tsx b/webapp/channels/src/components/admin_console/team_channel_settings/group/group_users/users_to_remove.tsx index ea8d3596b4..35c6be9447 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/group/group_users/users_to_remove.tsx +++ b/webapp/channels/src/components/admin_console/team_channel_settings/group/group_users/users_to_remove.tsx @@ -32,7 +32,7 @@ export type Filters = { export type Memberships = RelationOneToOne | RelationOneToOne; -interface Props { +export interface Props { members: UserProfile[]; memberships: Memberships; total: number; diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/team/details/index.ts b/webapp/channels/src/components/admin_console/team_channel_settings/team/details/index.ts index 77f7364d59..d15f09403e 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/team/details/index.ts +++ b/webapp/channels/src/components/admin_console/team_channel_settings/team/details/index.ts @@ -4,7 +4,7 @@ import {connect} from 'react-redux'; import type {RouteComponentProps} from 'react-router-dom'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import { getGroupsAssociatedToTeam as fetchAssociatedGroups, @@ -15,14 +15,13 @@ import { import {getTeam as fetchTeam, membersMinusGroupMembers, patchTeam, removeUserFromTeam, updateTeamMemberSchemeRoles, addUserToTeam, deleteTeam, unarchiveTeam} from 'mattermost-redux/actions/teams'; import {getAllGroups, getGroupsAssociatedToTeam} from 'mattermost-redux/selectors/entities/groups'; import {getTeam} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; +import type {GenericAction} from 'mattermost-redux/types/actions'; import {setNavigationBlocked} from 'actions/admin_actions'; import type {GlobalState} from 'types/store'; import TeamDetails from './team_details'; -import type {Props} from './team_details'; type Params = { team_id: string; @@ -49,7 +48,7 @@ function mapStateToProps(state: GlobalState, props: OwnProps) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ getTeam: fetchTeam, getGroups: fetchAssociatedGroups, patchTeam, diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_details.tsx b/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_details.tsx index 649a2a83f3..4e6b7432f4 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_details.tsx +++ b/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_details.tsx @@ -45,7 +45,7 @@ export type Props = { unlinkGroupSyncable: (groupId: string, syncableId: string, syncableType: SyncableType) => Promise; membersMinusGroupMembers: (teamId: string, groupIds: string[], page?: number, perPage?: number) => Promise; getGroups: (teamId: string, q?: string, page?: number, perPage?: number, filterAllowReference?: boolean) => Promise; - patchTeam: (team: Team) => ActionResult; + patchTeam: (team: Team) => Promise; patchGroupSyncable: (groupId: string, syncableId: string, syncableType: SyncableType, patch: Partial) => Promise; addUserToTeam: (teamId: string, userId: string) => Promise; removeUserFromTeam: (teamId: string, userId: string) => Promise; diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_members/index.ts b/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_members/index.ts index 8e7162523c..8a48d25b9a 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_members/index.ts +++ b/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_members/index.ts @@ -3,17 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; -import type {ServerError} from '@mattermost/types/errors'; -import type {UserProfile, UsersStats, GetFilteredUsersStatsOpts} from '@mattermost/types/users'; +import type {UserProfile, UsersStats} from '@mattermost/types/users'; import {getTeamStats as loadTeamStats} from 'mattermost-redux/actions/teams'; import {getFilteredUsersStats} from 'mattermost-redux/actions/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getMembersInTeams, getTeamStats, getTeam} from 'mattermost-redux/selectors/entities/teams'; import {getProfilesInTeam, searchProfilesInTeam, filterProfiles, getFilteredUsersStats as selectFilteredUsersStats} from 'mattermost-redux/selectors/entities/users'; -import type {GenericAction, ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import {filterProfilesStartingWithTerm, profileListToMap} from 'mattermost-redux/utils/user_utils'; import {loadProfilesAndReloadTeamMembers, searchProfilesAndTeamMembers} from 'actions/user_actions'; @@ -29,24 +27,6 @@ type Props = { usersToRemove: Record; }; -type Actions = { - getTeamStats: (teamId: string) => Promise<{ - data: boolean; - }>; - loadProfilesAndReloadTeamMembers: (page: number, perPage: number, teamId?: string, options?: {[key: string]: any}) => Promise<{ - data: boolean; - }>; - searchProfilesAndTeamMembers: (term: string, options?: {[key: string]: any}) => Promise<{ - data: boolean; - }>; - getFilteredUsersStats: (filters: GetFilteredUsersStatsOpts) => Promise<{ - data?: UsersStats; - error?: ServerError; - }>; - setUserGridSearch: (term: string) => ActionResult; - setUserGridFilters: (filters: GetFilteredUsersStatsOpts) => ActionResult; -}; - function searchUsersToAdd(users: Record, term: string): Record { const profiles = filterProfilesStartingWithTerm(Object.keys(users).map((key) => users[key]), term); const filteredProfilesMap = filterProfiles(profileListToMap(profiles), {}); @@ -96,9 +76,9 @@ function mapStateToProps(state: GlobalState, props: Props) { enableGuestAccounts: config.EnableGuestAccounts === 'true', }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getTeamStats: loadTeamStats, loadProfilesAndReloadTeamMembers, searchProfilesAndTeamMembers, diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_members/team_members.tsx b/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_members/team_members.tsx index fa52337c5a..5bffd640ef 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_members/team_members.tsx +++ b/webapp/channels/src/components/admin_console/team_channel_settings/team/details/team_members/team_members.tsx @@ -4,9 +4,8 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; -import type {ServerError} from '@mattermost/types/errors'; import type {TeamMembership, Team} from '@mattermost/types/teams'; -import type {UserProfile, UsersStats, GetFilteredUsersStatsOpts} from '@mattermost/types/users'; +import type {UserProfile, GetFilteredUsersStatsOpts} from '@mattermost/types/users'; import GeneralConstants from 'mattermost-redux/constants/general'; import type {ActionResult} from 'mattermost-redux/types/actions'; @@ -44,21 +43,12 @@ type Props = { updateRole: (userId: string, schemeUser: boolean, schemeAdmin: boolean) => void; actions: { - getTeamStats: (teamId: string) => Promise<{ - data: boolean; - }>; - loadProfilesAndReloadTeamMembers: (page: number, perPage: number, teamId?: string, options?: {[key: string]: any}) => Promise<{ - data: boolean; - }>; - searchProfilesAndTeamMembers: (term: string, options?: {[key: string]: any}) => Promise<{ - data: boolean; - }>; - getFilteredUsersStats: (filters: GetFilteredUsersStatsOpts) => Promise<{ - data?: UsersStats; - error?: ServerError; - }>; - setUserGridSearch: (term: string) => ActionResult; - setUserGridFilters: (filters: GetFilteredUsersStatsOpts) => ActionResult; + getTeamStats: (teamId: string) => Promise; + loadProfilesAndReloadTeamMembers: (page: number, perPage: number, teamId: string, options?: {[key: string]: any}) => Promise; + searchProfilesAndTeamMembers: (term: string, options?: {[key: string]: any}) => Promise; + getFilteredUsersStats: (filters: GetFilteredUsersStatsOpts) => Promise; + setUserGridSearch: (term: string) => void; + setUserGridFilters: (filters: GetFilteredUsersStatsOpts) => void; }; } diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/team/list/index.ts b/webapp/channels/src/components/admin_console/team_channel_settings/team/list/index.ts index 22ef409019..9bb80ab4fe 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/team/list/index.ts +++ b/webapp/channels/src/components/admin_console/team_channel_settings/team/list/index.ts @@ -3,23 +3,16 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {TeamSearchOpts, TeamsWithCount} from '@mattermost/types/teams'; +import type {Dispatch} from 'redux'; import {getTeams as fetchTeams, searchTeams} from 'mattermost-redux/actions/teams'; import {createSelector} from 'mattermost-redux/selectors/create_selector'; import {getTeams} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import TeamList from './team_list'; -type Actions = { - searchTeams(term: string, opts: TeamSearchOpts): Promise<{data: TeamsWithCount}>; - getData(page: number, size: number): void; -} const getSortedListOfTeams = createSelector( 'getSortedListOfTeams', getTeams, @@ -36,7 +29,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getData: (page: number, pageSize: number) => fetchTeams(page, pageSize, true), searchTeams, }, dispatch), diff --git a/webapp/channels/src/components/admin_console/team_channel_settings/team/list/team_list.tsx b/webapp/channels/src/components/admin_console/team_channel_settings/team/list/team_list.tsx index 1ab281094f..69508f3fb8 100644 --- a/webapp/channels/src/components/admin_console/team_channel_settings/team/list/team_list.tsx +++ b/webapp/channels/src/components/admin_console/team_channel_settings/team/list/team_list.tsx @@ -8,6 +8,7 @@ import {Link} from 'react-router-dom'; import type {Team, TeamSearchOpts, TeamsWithCount} from '@mattermost/types/teams'; import {debounce} from 'mattermost-redux/actions/helpers'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import DataGrid from 'components/admin_console/data_grid/data_grid'; import type {Column} from 'components/admin_console/data_grid/data_grid'; @@ -26,7 +27,7 @@ type Props = { data: Team[]; total: number; actions: { - searchTeams(term: string, opts: TeamSearchOpts): Promise<{data: TeamsWithCount}>; + searchTeams(term: string, opts: TeamSearchOpts): Promise>; getData(page: number, size: number): void; }; isLicensedForLDAPGroups?: boolean; diff --git a/webapp/channels/src/components/admin_console/user_autocomplete_setting/index.tsx b/webapp/channels/src/components/admin_console/user_autocomplete_setting/index.tsx index 072c2290af..0de144b3fe 100644 --- a/webapp/channels/src/components/admin_console/user_autocomplete_setting/index.tsx +++ b/webapp/channels/src/components/admin_console/user_autocomplete_setting/index.tsx @@ -3,18 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {Dispatch} from 'redux'; import {autocompleteUsers} from 'actions/user_actions'; import UserAutocompleteSetting from './user_autocomplete_setting'; -import type {Props} from './user_autocomplete_setting'; function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ autocompleteUsers, }, dispatch), }; diff --git a/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.test.tsx b/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.test.tsx index 1e79614ef1..00aeac2050 100644 --- a/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.test.tsx +++ b/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.test.tsx @@ -75,7 +75,7 @@ describe('components/AdvancedCreateComment', () => { maxPostSize: Constants.DEFAULT_CHARACTER_LIMIT, rhsExpanded: false, badConnection: false, - getChannelTimezones: jest.fn(() => Promise.resolve({data: '', error: ''})), + getChannelTimezones: jest.fn(() => Promise.resolve({data: [], error: ''})), selectedPostFocussedAt: 0, canPost: true, canUploadFiles: true, @@ -91,7 +91,7 @@ describe('components/AdvancedCreateComment', () => { }, groupsWithAllowReference: null, channelMemberCountsByGroup: undefined as any, - savePreferences(): ActionResult { + savePreferences(): Promise { throw new Error('Function not implemented.'); }, }; diff --git a/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.tsx b/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.tsx index 0783d8fb32..6bd5a5e3c6 100644 --- a/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.tsx +++ b/webapp/channels/src/components/advanced_create_comment/advanced_create_comment.tsx @@ -116,16 +116,16 @@ export type Props = { onResetHistoryIndex: () => void; // Called when navigating back through comment message history - moveHistoryIndexBack: (index: string) => Promise; + moveHistoryIndexBack: (index: string) => Promise; // Called when navigating forward through comment message history - moveHistoryIndexForward: (index: string) => Promise; + moveHistoryIndexForward: (index: string) => Promise; // Called to initiate editing the user's latest post - onEditLatestPost: () => ActionResult; + onEditLatestPost: () => ActionResult; // Function to get the users timezones in the channel - getChannelTimezones: (channelId: string) => Promise; + getChannelTimezones: (channelId: string) => Promise>; // Reset state of createPost request resetCreatePostRequest: () => void; @@ -152,7 +152,7 @@ export type Props = { selectedPostFocussedAt: number; // Function to set or unset emoji picker for last message - emitShortcutReactToLastPostFrom: (location: string) => void; + emitShortcutReactToLastPostFrom: (location: keyof typeof Constants.Locations) => void; // Determines if the current user can send special channel mentions useChannelMentions: boolean; @@ -176,10 +176,10 @@ export type Props = { focusOnMount?: boolean; isThreadView?: boolean; openModal:

(modalData: ModalData

) => void; - savePreferences: (userId: string, preferences: PreferenceType[]) => ActionResult; + savePreferences: (userId: string, preferences: PreferenceType[]) => Promise; useCustomGroupMentions: boolean; isFormattingBarHidden: boolean; - searchAssociatedGroupsForReference: (prefix: string, teamId: string, channelId: string | undefined) => Promise<{ data: any }>; + searchAssociatedGroupsForReference: (prefix: string, teamId: string, channelId: string | undefined) => Promise; postEditorActions: PluginComponent[]; placeholder?: string; } diff --git a/webapp/channels/src/components/advanced_create_comment/index.ts b/webapp/channels/src/components/advanced_create_comment/index.ts index f4489f8ca5..c511268260 100644 --- a/webapp/channels/src/components/advanced_create_comment/index.ts +++ b/webapp/channels/src/components/advanced_create_comment/index.ts @@ -3,9 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {PreferenceType} from '@mattermost/types/preferences'; +import type {Dispatch} from 'redux'; import {getChannelTimezones, getChannelMemberCountsByGroup} from 'mattermost-redux/actions/channels'; import {moveHistoryIndexBack, moveHistoryIndexForward, resetCreatePostRequest, resetHistoryIndex} from 'mattermost-redux/actions/posts'; @@ -19,7 +17,6 @@ import {makeGetMessageInHistoryItem} from 'mattermost-redux/selectors/entities/p import {getBool, isCustomGroupsEnabled} from 'mattermost-redux/selectors/entities/preferences'; import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc, ActionResult, DispatchFunc} from 'mattermost-redux/types/actions.js'; import {emitShortcutReactToLastPostFrom} from 'actions/post_actions'; import { @@ -39,7 +36,6 @@ import {showPreviewOnCreateComment} from 'selectors/views/textbox'; import {AdvancedTextEditor, Constants, StoragePrefixes} from 'utils/constants'; import {canUploadFiles} from 'utils/file_utils'; -import type {ModalData} from 'types/actions.js'; import type {PostDraft} from 'types/store/draft'; import type {GlobalState} from 'types/store/index.js'; @@ -123,33 +119,11 @@ function makeUpdateCommentDraftWithRootId(channelId: string) { return (rootId: string, draft?: PostDraft, save = false) => updateCommentDraft(rootId, draft ? {...draft, channelId} : draft, save); } -type Actions = { - clearCommentDraftUploads: () => void; - onUpdateCommentDraft: (draft?: PostDraft, save?: boolean) => void; - updateCommentDraftWithRootId: (rootID: string, draft: PostDraft, save?: boolean) => void; - onSubmit: (draft: PostDraft, options: {ignoreSlash: boolean}) => void; - onResetHistoryIndex: () => void; - moveHistoryIndexBack: (index: string) => Promise; - moveHistoryIndexForward: (index: string) => Promise; - onEditLatestPost: () => ActionResult; - resetCreatePostRequest: () => void; - getChannelTimezones: (channelId: string) => Promise; - emitShortcutReactToLastPostFrom: (location: string) => void; - setShowPreview: (showPreview: boolean) => void; - getChannelMemberCountsByGroup: (channelID: string) => void; - openModal:

(modalData: ModalData

) => void; - savePreferences: (userId: string, preferences: PreferenceType[]) => ActionResult; - searchAssociatedGroupsForReference: (prefix: string, teamId: string, channelId: string | undefined) => Promise<{ data: any }>; -}; - function makeMapDispatchToProps() { - let onUpdateCommentDraft: (draft?: PostDraft, save?: boolean) => void; - let updateCommentDraftWithRootId: (rootID: string, draft: PostDraft, save?: boolean) => void; - let onSubmit: ( - draft: PostDraft, - options: {ignoreSlash: boolean}, - ) => (dispatch: DispatchFunc, getState: () => GlobalState) => Promise | ActionResult; - let onEditLatestPost: () => ActionFunc; + let onUpdateCommentDraft: ReturnType; + let updateCommentDraftWithRootId: ReturnType; + let onSubmit: ReturnType; + let onEditLatestPost: ReturnType; function onResetHistoryIndex() { return resetHistoryIndex(Posts.MESSAGE_TYPES.COMMENT); @@ -180,7 +154,7 @@ function makeMapDispatchToProps() { channelId = ownProps.channelId; latestPostId = ownProps.latestPostId; - return bindActionCreators, Actions>( + return bindActionCreators( { clearCommentDraftUploads, onUpdateCommentDraft, diff --git a/webapp/channels/src/components/advanced_create_post/advanced_create_post.test.tsx b/webapp/channels/src/components/advanced_create_post/advanced_create_post.test.tsx index a6f5f41d78..1df6a270f6 100644 --- a/webapp/channels/src/components/advanced_create_post/advanced_create_post.test.tsx +++ b/webapp/channels/src/components/advanced_create_post/advanced_create_post.test.tsx @@ -88,16 +88,16 @@ const baseProp: Props = { setShowPreview: jest.fn(), savePreferences: jest.fn(), executeCommand: () => { - return {data: true}; + return Promise.resolve({data: true}); }, getChannelTimezones: jest.fn(() => { - return {data: '', error: ''}; + return Promise.resolve({data: [], error: ''}); }), runMessageWillBePostedHooks: (post: Post) => { - return {data: post}; + return Promise.resolve({data: post}); }, runSlashCommandWillBePostedHooks: (message: string, args: CommandArgs) => { - return {data: {message, args}}; + return Promise.resolve({data: {message, args}}); }, scrollPostListToBottom: jest.fn(), getChannelMemberCountsByGroup: jest.fn(), @@ -389,7 +389,7 @@ describe('components/advanced_create_post', () => { advancedCreatePost({ actions: { ...baseProp.actions, - getChannelTimezones: jest.fn(() => result), + getChannelTimezones: jest.fn(() => Promise.resolve(result)), }, currentChannelMembersCount: 9, }), @@ -426,7 +426,7 @@ describe('components/advanced_create_post', () => { advancedCreatePost({ actions: { ...baseProp.actions, - getChannelTimezones: jest.fn(() => result), + getChannelTimezones: jest.fn(() => Promise.resolve(result)), }, currentChannelMembersCount: 9, }), @@ -1014,7 +1014,7 @@ describe('components/advanced_create_post', () => { const result: ActionResult = { error, }; - const executeCommand = jest.fn(() => result); + const executeCommand = jest.fn(() => Promise.resolve(result)); const onSubmitPost = jest.fn(); const wrapper = shallow( diff --git a/webapp/channels/src/components/advanced_create_post/advanced_create_post.tsx b/webapp/channels/src/components/advanced_create_post/advanced_create_post.tsx index 47a820e429..8ac9271fb6 100644 --- a/webapp/channels/src/components/advanced_create_post/advanced_create_post.tsx +++ b/webapp/channels/src/components/advanced_create_post/advanced_create_post.tsx @@ -169,10 +169,10 @@ export type Props = { addMessageIntoHistory: (message: string) => void; // func called for navigation through messages by Up arrow - moveHistoryIndexBack: (index: string) => Promise; + moveHistoryIndexBack: (index: string) => Promise; // func called for navigation through messages by Down arrow - moveHistoryIndexForward: (index: string) => Promise; + moveHistoryIndexForward: (index: string) => Promise; submitReaction: (postId: string, action: string, emojiName: string) => void; @@ -189,10 +189,10 @@ export type Props = { clearDraftUploads: () => void; //hooks called before a message is sent to the server - runMessageWillBePostedHooks: (originalPost: Post) => ActionResult; + runMessageWillBePostedHooks: (originalPost: Post) => Promise>; //hooks called before a slash command is sent to the server - runSlashCommandWillBePostedHooks: (originalMessage: string, originalArgs: CommandArgs) => ActionResult; + runSlashCommandWillBePostedHooks: (originalMessage: string, originalArgs: CommandArgs) => Promise; // func called for setting drafts setDraft: (name: string, value: PostDraft | null, draftChannelId: string, save?: boolean) => void; @@ -206,19 +206,19 @@ export type Props = { //Function to open a modal openModal:

(modalData: ModalData

) => void; - executeCommand: (message: string, args: CommandArgs) => ActionResult; + executeCommand: (message: string, args: CommandArgs) => Promise; //Function to get the users timezones in the channel - getChannelTimezones: (channelId: string) => ActionResult; + getChannelTimezones: (channelId: string) => Promise>; scrollPostListToBottom: () => void; //Function to set or unset emoji picker for last message - emitShortcutReactToLastPostFrom: (emittedFrom: string) => void; + emitShortcutReactToLastPostFrom: (emittedFrom: 'CENTER' | 'RHS_ROOT' | 'NO_WHERE') => void; getChannelMemberCountsByGroup: (channelId: string) => void; //Function used to advance the tutorial forward - savePreferences: (userId: string, preferences: PreferenceType[]) => ActionResult; + savePreferences: (userId: string, preferences: PreferenceType[]) => Promise; searchAssociatedGroupsForReference: (prefix: string, teamId: string, channelId: string | undefined) => Promise<{ data: any }>; }; @@ -735,7 +735,7 @@ class AdvancedCreatePost extends React.PureComponent { await this.doSubmit(e); }; - sendMessage = async (originalPost: Post) => { + sendMessage = async (originalPost: Post): Promise => { const { actions, currentChannel, @@ -783,7 +783,7 @@ class AdvancedCreatePost extends React.PureComponent { return hookResult; } - post = hookResult.data; + post = hookResult.data!; actions.onSubmitPost(post, draft.fileInfos); actions.scrollPostListToBottom(); diff --git a/webapp/channels/src/components/advanced_create_post/index.ts b/webapp/channels/src/components/advanced_create_post/index.ts index a070b53e39..e3ecd82a7e 100644 --- a/webapp/channels/src/components/advanced_create_post/index.ts +++ b/webapp/channels/src/components/advanced_create_post/index.ts @@ -3,12 +3,10 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {FileInfo} from '@mattermost/types/files'; -import type {CommandArgs} from '@mattermost/types/integrations'; import type {Post} from '@mattermost/types/posts'; -import type {PreferenceType} from '@mattermost/types/preferences'; import {getChannelTimezones, getChannelMemberCountsByGroup} from 'mattermost-redux/actions/channels'; import { @@ -32,7 +30,7 @@ import {get, getInt, getBool, isCustomGroupsEnabled} from 'mattermost-redux/sele import {haveICurrentChannelPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId, getStatusForUserId, getUser, isCurrentUserGuestUser} from 'mattermost-redux/selectors/entities/users'; -import type {ActionResult, GetStateFunc, DispatchFunc} from 'mattermost-redux/types/actions.js'; +import type {GetStateFunc, DispatchFunc} from 'mattermost-redux/types/actions.js'; import {executeCommand} from 'actions/command'; import {runMessageWillBePostedHooks, runSlashCommandWillBePostedHooks} from 'actions/hooks'; @@ -55,7 +53,6 @@ import {OnboardingTourSteps, TutorialTourName, OnboardingTourStepsForGuestUsers} import {AdvancedTextEditor, Constants, Preferences, StoragePrefixes, UserStatuses} from 'utils/constants'; import {canUploadFiles} from 'utils/file_utils'; -import type {ModalData} from 'types/actions.js'; import type {PostDraft} from 'types/store/draft'; import type {GlobalState} from 'types/store/index.js'; @@ -145,33 +142,7 @@ function onSubmitPost(post: Post, fileInfos: FileInfo[]) { }; } -type Actions = { - setShowPreview: (showPreview: boolean) => void; - addMessageIntoHistory: (message: string) => void; - moveHistoryIndexBack: (index: string) => Promise; - moveHistoryIndexForward: (index: string) => Promise; - addReaction: (postId: string, emojiName: string) => void; - onSubmitPost: (post: Post, fileInfos: FileInfo[]) => void; - removeReaction: (postId: string, emojiName: string) => void; - submitReaction: (postId: string, action: string, emojiName: string) => void; - clearDraftUploads: () => void; - runMessageWillBePostedHooks: (originalPost: Post) => ActionResult; - runSlashCommandWillBePostedHooks: (originalMessage: string, originalArgs: CommandArgs) => ActionResult; - setDraft: (name: string, value: PostDraft | null) => void; - setEditingPost: (postId?: string, refocusId?: string, title?: string, isRHS?: boolean) => void; - selectPostFromRightHandSideSearchByPostId: (postId: string) => void; - openModal:

(modalData: ModalData

) => void; - closeModal: (modalId: string) => void; - executeCommand: (message: string, args: CommandArgs) => ActionResult; - getChannelTimezones: (channelId: string) => ActionResult; - scrollPostListToBottom: () => void; - emitShortcutReactToLastPostFrom: (emittedFrom: string) => void; - getChannelMemberCountsByGroup: (channelId: string) => void; - savePreferences: (userId: string, preferences: PreferenceType[]) => ActionResult; - searchAssociatedGroupsForReference: (prefix: string, teamId: string, channelId: string | undefined) => Promise<{ data: any }>; -} - -function setDraft(key: string, value: PostDraft, draftChannelId: string, save = false) { +function setDraft(key: string, value: PostDraft | null, draftChannelId: string, save = false) { return (dispatch: DispatchFunc, getState: GetStateFunc) => { const channelId = draftChannelId || getCurrentChannelId(getState()); let updatedValue = null; @@ -198,7 +169,7 @@ function clearDraftUploads() { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ addMessageIntoHistory, onSubmitPost, moveHistoryIndexBack, diff --git a/webapp/channels/src/components/analytics/team_analytics/index.ts b/webapp/channels/src/components/analytics/team_analytics/index.ts index f8ca225cbd..1ea66ea62d 100644 --- a/webapp/channels/src/components/analytics/team_analytics/index.ts +++ b/webapp/channels/src/components/analytics/team_analytics/index.ts @@ -3,12 +3,11 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getTeams} from 'mattermost-redux/actions/teams'; import {getProfilesInTeam} from 'mattermost-redux/actions/users'; import {getTeamsList} from 'mattermost-redux/selectors/entities/teams'; -import type {Action, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {setGlobalItem} from 'actions/storage'; import {getCurrentLocale} from 'selectors/i18n'; @@ -33,15 +32,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - getTeams: (page?: number, perPage?: number, includeTotalCount?: boolean, excludePolicyConstrained?: boolean) => void; - getProfilesInTeam: (teamId: string, page: number, perPage?: number, sort?: string, options?: undefined) => Promise; - setGlobalItem: (name: string, value: string) => void; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getTeams, getProfilesInTeam, setGlobalItem, diff --git a/webapp/channels/src/components/announcement_bar/configuration_bar/configuration_bar.tsx b/webapp/channels/src/components/announcement_bar/configuration_bar/configuration_bar.tsx index aa77ff1100..4126b018d6 100644 --- a/webapp/channels/src/components/announcement_bar/configuration_bar/configuration_bar.tsx +++ b/webapp/channels/src/components/announcement_bar/configuration_bar/configuration_bar.tsx @@ -10,8 +10,6 @@ import {Link} from 'react-router-dom'; import type {ClientConfig, WarnMetricStatus} from '@mattermost/types/config'; import type {PreferenceType} from '@mattermost/types/preferences'; -import type {DispatchFunc} from 'mattermost-redux/types/actions'; - import {trackEvent} from 'actions/telemetry_actions'; import PurchaseLink from 'components/announcement_bar/purchase_link/purchase_link'; @@ -47,7 +45,7 @@ type Props = { warnMetricsStatus?: Record; actions: { dismissNotice: (notice: string) => void; - savePreferences: (userId: string, preferences: PreferenceType[]) => (dispatch: DispatchFunc) => Promise<{ + savePreferences: (userId: string, preferences: PreferenceType[]) => Promise<{ data: boolean; }>; }; diff --git a/webapp/channels/src/components/apps_form/apps_form_field/apps_form_field.tsx b/webapp/channels/src/components/apps_form/apps_form_field/apps_form_field.tsx index 8f0bfe9c61..c4b9165933 100644 --- a/webapp/channels/src/components/apps_form/apps_form_field/apps_form_field.tsx +++ b/webapp/channels/src/components/apps_form/apps_form_field/apps_form_field.tsx @@ -8,6 +8,7 @@ import type {UserAutocomplete} from '@mattermost/types/autocomplete'; import type {Channel} from '@mattermost/types/channels'; import {AppFieldTypes} from 'mattermost-redux/constants/apps'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import type AutocompleteSelector from 'components/autocomplete_selector'; import Markdown from 'components/markdown'; @@ -33,7 +34,7 @@ export interface Props { listComponent?: React.ComponentProps['listComponent']; performLookup: (name: string, userInput: string) => Promise; actions: { - autocompleteChannels: (term: string, success: (channels: Channel[]) => void, error: () => void) => (dispatch: any, getState: any) => Promise; + autocompleteChannels: (term: string, success: (channels: Channel[]) => void, error: () => void) => Promise; autocompleteUsers: (search: string) => Promise; }; } diff --git a/webapp/channels/src/components/apps_form/apps_form_field/apps_form_select_field.tsx b/webapp/channels/src/components/apps_form/apps_form_field/apps_form_select_field.tsx index 111b735c98..998bc9931c 100644 --- a/webapp/channels/src/components/apps_form/apps_form_field/apps_form_select_field.tsx +++ b/webapp/channels/src/components/apps_form/apps_form_field/apps_form_select_field.tsx @@ -10,6 +10,7 @@ import type {UserAutocomplete} from '@mattermost/types/autocomplete'; import type {Channel} from '@mattermost/types/channels'; import {AppFieldTypes} from 'mattermost-redux/constants/apps'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {displayUsername} from 'mattermost-redux/utils/user_utils'; import {imageURLForUser} from 'utils/utils'; @@ -26,7 +27,7 @@ export type Props = { performLookup: (name: string, userInput: string) => Promise; teammateNameDisplay?: string; actions: { - autocompleteChannels: (term: string, success: (channels: Channel[]) => void, error: () => void) => (dispatch: any, getState: any) => Promise; + autocompleteChannels: (term: string, success: (channels: Channel[]) => void, error: () => void) => Promise; autocompleteUsers: (search: string) => Promise; }; }; diff --git a/webapp/channels/src/components/apps_form/apps_form_field/index.ts b/webapp/channels/src/components/apps_form/apps_form_field/index.ts index 96059c7dca..77752515b1 100644 --- a/webapp/channels/src/components/apps_form/apps_form_field/index.ts +++ b/webapp/channels/src/components/apps_form/apps_form_field/index.ts @@ -3,18 +3,16 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import {getTeammateNameDisplaySetting} from 'mattermost-redux/selectors/entities/preferences'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {autocompleteChannels} from 'actions/channel_actions'; import {autocompleteUsers} from 'actions/user_actions'; import AppsFormField from './apps_form_field'; -import type {Props} from './apps_form_field'; function mapStateToProps(state: GlobalState) { return { @@ -22,9 +20,9 @@ function mapStateToProps(state: GlobalState) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ autocompleteChannels, autocompleteUsers, }, dispatch), diff --git a/webapp/channels/src/components/apps_form/index.ts b/webapp/channels/src/components/apps_form/index.ts index 13ac2ca645..9e89a90d95 100644 --- a/webapp/channels/src/components/apps_form/index.ts +++ b/webapp/channels/src/components/apps_form/index.ts @@ -3,26 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; +import type {Dispatch} from 'redux'; import {doAppSubmit, doAppFetchForm, doAppLookup, postEphemeralCallResponseForContext} from 'actions/apps'; -import type {DoAppSubmit, DoAppFetchForm, DoAppLookup, PostEphemeralCallResponseForContext} from 'types/apps'; - import AppsFormContainer from './apps_form_container'; -type Actions = { - doAppSubmit: DoAppSubmit; - doAppFetchForm: DoAppFetchForm; - doAppLookup: DoAppLookup; - postEphemeralCallResponseForContext: PostEphemeralCallResponseForContext; -}; - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ doAppSubmit, doAppFetchForm, doAppLookup, diff --git a/webapp/channels/src/components/audit_table/audit_table.tsx b/webapp/channels/src/components/audit_table/audit_table.tsx index fa44a5f624..e69cc03bd7 100644 --- a/webapp/channels/src/components/audit_table/audit_table.tsx +++ b/webapp/channels/src/components/audit_table/audit_table.tsx @@ -8,8 +8,6 @@ import type {IntlShape} from 'react-intl'; import type {Audit} from '@mattermost/types/audits'; import type {UserProfile} from '@mattermost/types/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; - import FormatAudit from './format_audit'; type Props = { @@ -20,7 +18,7 @@ type Props = { showSession?: boolean; currentUser: UserProfile; actions: { - getMissingProfilesByIds: (userIds: string[]) => ActionFunc; + getMissingProfilesByIds: (userIds: string[]) => void; }; }; diff --git a/webapp/channels/src/components/authorize/authorize.tsx b/webapp/channels/src/components/authorize/authorize.tsx index f13f600b65..a94d45e2d4 100644 --- a/webapp/channels/src/components/authorize/authorize.tsx +++ b/webapp/channels/src/components/authorize/authorize.tsx @@ -7,6 +7,8 @@ import {FormattedMessage} from 'react-intl'; import type {OAuthApp} from '@mattermost/types/integrations'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import FormError from 'components/form_error'; import FormattedMarkdownMessage from 'components/formatted_markdown_message'; @@ -26,8 +28,8 @@ type Props = { search: string; }; actions: { - getOAuthAppInfo: (clientId: string | null) => Promise<{data: OAuthApp; error?: Error}>; - allowOAuth2: (params: Params) => Promise<{data?: any; error?: Error}>; + getOAuthAppInfo: (clientId: string | null) => Promise>; + allowOAuth2: (params: Params) => Promise>; }; } diff --git a/webapp/channels/src/components/authorize/index.ts b/webapp/channels/src/components/authorize/index.ts index a76f2dd572..ddaee9e066 100644 --- a/webapp/channels/src/components/authorize/index.ts +++ b/webapp/channels/src/components/authorize/index.ts @@ -3,25 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {OAuthApp} from '@mattermost/types/integrations'; - -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; +import type {Dispatch} from 'redux'; import {allowOAuth2, getOAuthAppInfo} from 'actions/admin_actions.jsx'; import Authorize from './authorize'; -import type {Params} from './authorize'; -type Actions = { - getOAuthAppInfo: (clientId: string | null) => Promise<{data: OAuthApp; error?: Error}>; - allowOAuth2: (params: Params) => Promise<{data?: any; error?: Error}>; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getOAuthAppInfo, allowOAuth2, }, dispatch), diff --git a/webapp/channels/src/components/browse_channels/browse_channels.tsx b/webapp/channels/src/components/browse_channels/browse_channels.tsx index 4d447767e8..fa484dd3d1 100644 --- a/webapp/channels/src/components/browse_channels/browse_channels.tsx +++ b/webapp/channels/src/components/browse_channels/browse_channels.tsx @@ -6,7 +6,7 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; import {GenericModal} from '@mattermost/components'; -import type {Channel, ChannelMembership, ChannelSearchOpts} from '@mattermost/types/channels'; +import type {Channel, ChannelMembership, ChannelSearchOpts, ChannelsWithTotalCount} from '@mattermost/types/channels'; import type {RelationOneToOne} from '@mattermost/types/utilities'; import Permissions from 'mattermost-redux/constants/permissions'; @@ -40,10 +40,10 @@ export enum Filter { export type FilterType = keyof typeof Filter; type Actions = { - getChannels: (teamId: string, page: number, perPage: number) => Promise>; - getArchivedChannels: (teamId: string, page: number, channelsPerPage: number) => Promise>; + getChannels: (teamId: string, page: number, perPage: number) => Promise>; + getArchivedChannels: (teamId: string, page: number, channelsPerPage: number) => Promise>; joinChannel: (currentUserId: string, teamId: string, channelId: string) => Promise; - searchAllChannels: (term: string, opts?: ChannelSearchOpts) => Promise>; + searchAllChannels: (term: string, opts?: ChannelSearchOpts) => Promise>; openModal:

(modalData: ModalData

) => void; closeModal: (modalId: string) => void; @@ -201,7 +201,7 @@ export default class BrowseChannels extends React.PureComponent { const searchTimeoutId = window.setTimeout( async () => { try { - const {data} = await this.props.actions.searchAllChannels(term, {team_ids: [this.props.teamId], nonAdminSearch: true, include_deleted: true}); + const {data} = await this.props.actions.searchAllChannels(term, {team_ids: [this.props.teamId], nonAdminSearch: true, include_deleted: true}) as ActionResult; // HARRISONTODO if (searchTimeoutId !== this.searchTimeoutId) { return; } diff --git a/webapp/channels/src/components/browse_channels/index.ts b/webapp/channels/src/components/browse_channels/index.ts index 45111c2b38..ec7ca1fe11 100644 --- a/webapp/channels/src/components/browse_channels/index.ts +++ b/webapp/channels/src/components/browse_channels/index.ts @@ -3,9 +3,9 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {Channel, ChannelSearchOpts} from '@mattermost/types/channels'; +import type {Channel} from '@mattermost/types/channels'; import {getChannels, getArchivedChannels, joinChannel, getChannelsMemberCount, searchAllChannels} from 'mattermost-redux/actions/channels'; import {RequestStatus} from 'mattermost-redux/constants'; @@ -14,7 +14,6 @@ import {getChannelsInCurrentTeam, getMyChannelMemberships, getChannelsMemberCoun import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {Action, ActionResult} from 'mattermost-redux/types/actions'; import {setGlobalItem} from 'actions/storage'; import {openModal, closeModal} from 'actions/views/modals'; @@ -24,7 +23,6 @@ import {makeGetGlobalItem} from 'selectors/storage'; import Constants, {StoragePrefixes} from 'utils/constants'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import BrowseChannels from './browse_channels'; @@ -68,22 +66,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - getChannels: (teamId: string, page: number, perPage: number) => Promise>; - getArchivedChannels: (teamId: string, page: number, channelsPerPage: number) => Promise>; - getPrivateChannels: (teamId: string, page: number, channelsPerPage: number) => Promise>; - joinChannel: (currentUserId: string, teamId: string, channelId: string) => Promise; - searchAllChannels: (term: string, opts?: ChannelSearchOpts) => Promise>; - openModal:

(modalData: ModalData

) => void; - closeModal: (modalId: string) => void; - setGlobalItem: (name: string, value: string) => void; - closeRightHandSide: () => void; - getChannelsMemberCount: (channelIds: string[]) => Promise; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getChannels, getArchivedChannels, joinChannel, diff --git a/webapp/channels/src/components/channel_groups_manage_modal/channel_groups_manage_modal.tsx b/webapp/channels/src/components/channel_groups_manage_modal/channel_groups_manage_modal.tsx index 149f45ff61..69eacc0203 100644 --- a/webapp/channels/src/components/channel_groups_manage_modal/channel_groups_manage_modal.tsx +++ b/webapp/channels/src/components/channel_groups_manage_modal/channel_groups_manage_modal.tsx @@ -9,6 +9,8 @@ import type {Channel} from '@mattermost/types/channels'; import {SyncableType} from '@mattermost/types/groups'; import type {Group} from '@mattermost/types/groups'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import AddGroupsToChannelModal from 'components/add_groups_to_channel_modal'; import ListModal, {DEFAULT_NUM_PER_PAGE} from 'components/list_modal'; import DropdownIcon from 'components/widgets/icons/fa_dropdown_icon'; @@ -25,10 +27,10 @@ type Props = { channel: Channel; intl: IntlShape; actions: { - getGroupsAssociatedToChannel: (channelId: string, searchTerm: string, pageNumber: number, perPage: number) => any; - unlinkGroupSyncable: (itemId: string, channelId: string, groupsSyncableTypeChannel: string) => any; - patchGroupSyncable: (itemId: string, channelId: string, groupsSyncableTypeChannel: string, params: {scheme_admin: boolean}) => any; - getMyChannelMember: (channelId: string) => any; + getGroupsAssociatedToChannel: (channelId: string, searchTerm: string, pageNumber: number, perPage: number) => Promise; + unlinkGroupSyncable: (itemId: string, channelId: string, groupsSyncableTypeChannel: SyncableType) => Promise; + patchGroupSyncable: (itemId: string, channelId: string, groupsSyncableTypeChannel: SyncableType, params: {scheme_admin: boolean}) => Promise; + getMyChannelMember: (channelId: string) => void; closeModal: (modalId: string) => void; openModal:

(modalData: ModalData

) => void; }; diff --git a/webapp/channels/src/components/channel_groups_manage_modal/index.ts b/webapp/channels/src/components/channel_groups_manage_modal/index.ts index 42b01e5848..f53c1aaafa 100644 --- a/webapp/channels/src/components/channel_groups_manage_modal/index.ts +++ b/webapp/channels/src/components/channel_groups_manage_modal/index.ts @@ -3,18 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import {getMyChannelMember} from 'mattermost-redux/actions/channels'; import {getGroupsAssociatedToChannel, unlinkGroupSyncable, patchGroupSyncable} from 'mattermost-redux/actions/groups'; -import type {Action} from 'mattermost-redux/types/actions'; import {closeModal, openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; - import ChannelGroupsManageModal from './channel_groups_manage_modal'; const mapStateToProps = (state: GlobalState, ownProps: any) => { @@ -23,25 +20,8 @@ const mapStateToProps = (state: GlobalState, ownProps: any) => { }; }; -type Actions = { - getGroupsAssociatedToChannel: (channelId: string, searchTerm: string, pageNumber: number, DEFAULT_NUM_PER_PAGE: number) => Promise<{ - data: boolean; - }>; - unlinkGroupSyncable: (itemId: string, channelId: string, type: string) => Promise<{ - data: boolean; - }>; - patchGroupSyncable: (itemId: string, channelId: string, groupsSyncableTypeChannel: string, params: {scheme_admin: boolean}) => Promise<{ - data: boolean; - }>; - getMyChannelMember: (channelId: string) => Promise<{ - data: boolean; - }>; - closeModal: (modalId: string) => void; - openModal:

(modalData: ModalData

) => void; -}; - const mapDispatchToProps = (dispatch: Dispatch) => ({ - actions: bindActionCreators, Actions>( + actions: bindActionCreators( { getGroupsAssociatedToChannel, closeModal, diff --git a/webapp/channels/src/components/channel_header/channel_header.test.tsx b/webapp/channels/src/components/channel_header/channel_header.test.tsx index 1b1315d5b0..8827d7ad75 100644 --- a/webapp/channels/src/components/channel_header/channel_header.test.tsx +++ b/webapp/channels/src/components/channel_header/channel_header.test.tsx @@ -22,7 +22,6 @@ describe('components/ChannelHeader', () => { showChannelFiles: jest.fn(), closeRightHandSide: jest.fn(), openModal: jest.fn(), - closeModal: jest.fn(), getCustomEmojisInText: jest.fn(), updateChannelNotifyProps: jest.fn(), goToLastViewedChannel: jest.fn(), diff --git a/webapp/channels/src/components/channel_header/channel_header.tsx b/webapp/channels/src/components/channel_header/channel_header.tsx index 75cd38f4e7..e600f86447 100644 --- a/webapp/channels/src/components/channel_header/channel_header.tsx +++ b/webapp/channels/src/components/channel_header/channel_header.tsx @@ -71,7 +71,6 @@ export type Props = { updateChannelNotifyProps: (userId: string, channelId: string, props: Partial) => void; goToLastViewedChannel: () => void; openModal:

(modalData: ModalData

) => void; - closeModal: () => void; showChannelMembers: (channelId: string, inEditingMode?: boolean) => void; }; currentRelativeTeamUrl: string; diff --git a/webapp/channels/src/components/channel_header/index.ts b/webapp/channels/src/components/channel_header/index.ts index 9ab64e4fb5..35bceda339 100644 --- a/webapp/channels/src/components/channel_header/index.ts +++ b/webapp/channels/src/components/channel_header/index.ts @@ -4,7 +4,7 @@ import {connect} from 'react-redux'; import {withRouter} from 'react-router-dom'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import { updateChannelNotifyProps, @@ -27,7 +27,6 @@ import { getUser, makeGetProfilesInChannel, } from 'mattermost-redux/selectors/entities/users'; -import type {Action} from 'mattermost-redux/types/actions'; import {getUserIdFromChannelName} from 'mattermost-redux/utils/channel_utils'; import {goToLastViewedChannel} from 'actions/views/channel'; @@ -49,7 +48,6 @@ import {isFileAttachmentsEnabled} from 'utils/file_utils'; import type {GlobalState} from 'types/store'; import ChannelHeader from './channel_header'; -import type {Props} from './channel_header'; const EMPTY_CHANNEL = {}; const EMPTY_CHANNEL_STATS = {member_count: 0, guest_count: 0, pinnedpost_count: 0, files_count: 0}; @@ -118,7 +116,7 @@ function makeMapStateToProps() { } const mapDispatchToProps = (dispatch: Dispatch) => ({ - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ showPinnedPosts, showChannelFiles, closeRightHandSide, diff --git a/webapp/channels/src/components/channel_header_dropdown/menu_items/toggle_mute_channel/index.ts b/webapp/channels/src/components/channel_header_dropdown/menu_items/toggle_mute_channel/index.ts index 403683a1dc..3a1d1031b3 100644 --- a/webapp/channels/src/components/channel_header_dropdown/menu_items/toggle_mute_channel/index.ts +++ b/webapp/channels/src/components/channel_header_dropdown/menu_items/toggle_mute_channel/index.ts @@ -3,16 +3,14 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {updateChannelNotifyProps} from 'mattermost-redux/actions/channels'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import MenuItemToggleMuteChannel from './toggle_mute_channel'; -import type {Actions} from './toggle_mute_channel'; const mapDispatchToProps = (dispatch: Dispatch) => ({ - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ updateChannelNotifyProps, }, dispatch), }); diff --git a/webapp/channels/src/components/channel_header_dropdown/menu_items/toggle_mute_channel/toggle_mute_channel.tsx b/webapp/channels/src/components/channel_header_dropdown/menu_items/toggle_mute_channel/toggle_mute_channel.tsx index 2fd75c1b79..68dab79191 100644 --- a/webapp/channels/src/components/channel_header_dropdown/menu_items/toggle_mute_channel/toggle_mute_channel.tsx +++ b/webapp/channels/src/components/channel_header_dropdown/menu_items/toggle_mute_channel/toggle_mute_channel.tsx @@ -6,15 +6,13 @@ import React from 'react'; import type {Channel, ChannelNotifyProps} from '@mattermost/types/channels'; import type {UserProfile} from '@mattermost/types/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; - import Menu from 'components/widgets/menu/menu'; import {Constants, NotificationLevels} from 'utils/constants'; import {localizeMessage} from 'utils/utils'; export type Actions = { - updateChannelNotifyProps(userId: string, channelId: string, props: Partial): ActionFunc; + updateChannelNotifyProps(userId: string, channelId: string, props: Partial): void; }; type Props = { diff --git a/webapp/channels/src/components/channel_header_dropdown/menu_items/view_pinned_posts/view_pinned_posts.tsx b/webapp/channels/src/components/channel_header_dropdown/menu_items/view_pinned_posts/view_pinned_posts.tsx index 316234ba02..89a57cdaac 100644 --- a/webapp/channels/src/components/channel_header_dropdown/menu_items/view_pinned_posts/view_pinned_posts.tsx +++ b/webapp/channels/src/components/channel_header_dropdown/menu_items/view_pinned_posts/view_pinned_posts.tsx @@ -5,8 +5,6 @@ import React, {useCallback, memo} from 'react'; import type {MouseEvent} from 'react'; import {useIntl} from 'react-intl'; -import type {GetStateFunc, DispatchFunc} from 'mattermost-redux/types/actions'; - import Menu from 'components/widgets/menu/menu'; type Props = { @@ -14,7 +12,7 @@ type Props = { channel: any; hasPinnedPosts: boolean; actions: { - closeRightHandSide: () => (dispatch: DispatchFunc, getState: GetStateFunc) => void; + closeRightHandSide: () => void; showPinnedPosts: (id: any) => void; }; } diff --git a/webapp/channels/src/components/channel_invite_modal/channel_invite_modal.tsx b/webapp/channels/src/components/channel_invite_modal/channel_invite_modal.tsx index 86cdad98c1..523a6daab3 100644 --- a/webapp/channels/src/components/channel_invite_modal/channel_invite_modal.tsx +++ b/webapp/channels/src/components/channel_invite_modal/channel_invite_modal.tsx @@ -67,7 +67,7 @@ export type Props = { groups: Group[]; isGroupsEnabled: boolean; actions: { - addUsersToChannel: (channelId: string, userIds: string[]) => Promise; + addUsersToChannel: (channelId: string, userIds: string[]) => Promise; getProfilesNotInChannel: (teamId: string, channelId: string, groupConstrained: boolean, page: number, perPage?: number) => Promise; getProfilesInChannel: (channelId: string, page: number, perPage: number, sort: string, options: {active?: boolean}) => Promise; getTeamStats: (teamId: string) => void; diff --git a/webapp/channels/src/components/channel_invite_modal/index.ts b/webapp/channels/src/components/channel_invite_modal/index.ts index f25403cb6e..f808818a05 100644 --- a/webapp/channels/src/components/channel_invite_modal/index.ts +++ b/webapp/channels/src/components/channel_invite_modal/index.ts @@ -3,9 +3,8 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {GroupSearchParams} from '@mattermost/types/groups'; import type {TeamMembership} from '@mattermost/types/teams'; import type {UserProfile} from '@mattermost/types/users'; import type {RelationOneToOne} from '@mattermost/types/utilities'; @@ -20,7 +19,6 @@ import {getTeammateNameDisplaySetting, isCustomGroupsEnabled} from 'mattermost-r import {haveICurrentTeamPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeam, getMembersInCurrentTeam, getMembersInTeam, getTeam} from 'mattermost-redux/selectors/entities/teams'; import {getProfilesNotInCurrentChannel, getProfilesInCurrentChannel, getProfilesNotInCurrentTeam, getProfilesNotInTeam, getUserStatuses, makeGetProfilesNotInChannel, makeGetProfilesInChannel} from 'mattermost-redux/selectors/entities/users'; -import type {Action, ActionResult} from 'mattermost-redux/types/actions'; import {addUsersToChannel} from 'actions/channel_actions'; import {loadStatusesForProfilesList} from 'actions/status_actions'; @@ -101,21 +99,9 @@ function makeMapStateToProps(initialState: GlobalState, initialProps: OwnProps) }; } -type Actions = { - addUsersToChannel: (channelId: string, userIds: string[]) => Promise; - getProfilesNotInChannel: (teamId: string, channelId: string, groupConstrained: boolean, page: number, perPage?: number) => Promise; - getTeamStats: (teamId: string) => void; - loadStatusesForProfilesList: (users: UserProfile[]) => void; - searchProfiles: (term: string, options: any) => Promise; - closeModal: (modalId: string) => void; - getProfilesInChannel: (channelId: string, page: number, perPage: number, sort: string, options: {active?: boolean}) => Promise; - searchAssociatedGroupsForReference: (prefix: string, teamId: string, channelId: string | undefined, opts: GroupSearchParams) => Promise; - getTeamMembersByIds: (teamId: string, userIds: string[]) => Promise; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ addUsersToChannel, getProfilesNotInChannel, getProfilesInChannel, diff --git a/webapp/channels/src/components/channel_layout/center_channel/center_channel.test.tsx b/webapp/channels/src/components/channel_layout/center_channel/center_channel.test.tsx index 9b4104457f..969a1f82fd 100644 --- a/webapp/channels/src/components/channel_layout/center_channel/center_channel.test.tsx +++ b/webapp/channels/src/components/channel_layout/center_channel/center_channel.test.tsx @@ -25,7 +25,7 @@ describe('components/channel_layout/CenterChannel', () => { currentUserId: 'testUserId', isMobileView: false, actions: { - getProfiles: jest.fn, + getProfiles: jest.fn(), }, }; test('should call update returnTo on props change', () => { diff --git a/webapp/channels/src/components/channel_layout/center_channel/index.ts b/webapp/channels/src/components/channel_layout/center_channel/index.ts index 33c8ee1e1c..59bf14ec0a 100644 --- a/webapp/channels/src/components/channel_layout/center_channel/index.ts +++ b/webapp/channels/src/components/channel_layout/center_channel/index.ts @@ -6,14 +6,13 @@ import type {ConnectedProps} from 'react-redux'; import {withRouter} from 'react-router-dom'; import type {RouteComponentProps} from 'react-router-dom'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getProfiles} from 'mattermost-redux/actions/users'; import {getRedirectChannelNameForTeam} from 'mattermost-redux/selectors/entities/channels'; import {isCollapsedThreadsEnabled} from 'mattermost-redux/selectors/entities/preferences'; import {getTeamByName} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {getIsLhsOpen} from 'selectors/lhs'; import {getLastViewedChannelNameByTeamName, getLastViewedTypeByTeamName, getPreviousTeamId, getPreviousTeamLastViewedType} from 'selectors/local_storage'; @@ -67,13 +66,9 @@ const mapStateToProps = (state: GlobalState, ownProps: OwnProps) => { }; }; -type Actions = { - getProfiles: (page?: number, perPage?: number, options?: Record) => ActionFunc; -}; - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ getProfiles, }, dispatch), }; diff --git a/webapp/channels/src/components/channel_members_dropdown/channel_members_dropdown.tsx b/webapp/channels/src/components/channel_members_dropdown/channel_members_dropdown.tsx index 993f0a5eb7..a5ff31c4a0 100644 --- a/webapp/channels/src/components/channel_members_dropdown/channel_members_dropdown.tsx +++ b/webapp/channels/src/components/channel_members_dropdown/channel_members_dropdown.tsx @@ -25,7 +25,7 @@ import type {ModalData} from 'types/actions'; const ROWS_FROM_BOTTOM_TO_OPEN_UP = 2; -interface Props { +export interface Props { channel: Channel; user: UserProfile; currentUserId: string; diff --git a/webapp/channels/src/components/channel_members_dropdown/index.ts b/webapp/channels/src/components/channel_members_dropdown/index.ts index d582b9aadd..ddb1cd5a69 100644 --- a/webapp/channels/src/components/channel_members_dropdown/index.ts +++ b/webapp/channels/src/components/channel_members_dropdown/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, AnyAction, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {Channel} from '@mattermost/types/channels'; @@ -11,7 +11,6 @@ import {getChannelStats, updateChannelMemberSchemeRoles, removeChannelMember, ge import {Permissions} from 'mattermost-redux/constants'; import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {Action} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; @@ -42,9 +41,9 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, any>({ + actions: bindActionCreators({ getChannelMember, getChannelStats, updateChannelMemberSchemeRoles, diff --git a/webapp/channels/src/components/channel_members_modal/index.ts b/webapp/channels/src/components/channel_members_modal/index.ts index 6554c72ce9..d8d4ae83bb 100644 --- a/webapp/channels/src/components/channel_members_modal/index.ts +++ b/webapp/channels/src/components/channel_members_modal/index.ts @@ -3,14 +3,12 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {canManageChannelMembers} from 'mattermost-redux/selectors/entities/channels'; -import type {Action} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import ChannelMembersModal from './channel_members_modal'; @@ -19,12 +17,8 @@ const mapStateToProps = (state: GlobalState) => ({ canManageChannelMembers: canManageChannelMembers(state), }); -type Actions = { - openModal:

(modalData: ModalData

) => void; -} - const mapDispatchToProps = (dispatch: Dispatch) => ({ - actions: bindActionCreators, Actions>({openModal}, dispatch), + actions: bindActionCreators({openModal}, dispatch), }); export default connect(mapStateToProps, mapDispatchToProps)(ChannelMembersModal); diff --git a/webapp/channels/src/components/channel_notifications_modal/index.ts b/webapp/channels/src/components/channel_notifications_modal/index.ts index 7e3779523b..3022e415b0 100644 --- a/webapp/channels/src/components/channel_notifications_modal/index.ts +++ b/webapp/channels/src/components/channel_notifications_modal/index.ts @@ -4,9 +4,7 @@ import {connect} from 'react-redux'; import type {ConnectedProps} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {ChannelNotifyProps} from '@mattermost/types/channels'; +import type {Dispatch} from 'redux'; import {updateChannelNotifyProps} from 'mattermost-redux/actions/channels'; import {getMyCurrentChannelMembership} from 'mattermost-redux/selectors/entities/channels'; @@ -14,7 +12,6 @@ import {getConfig} from 'mattermost-redux/selectors/entities/general'; import { isCollapsedThreadsEnabled, } from 'mattermost-redux/selectors/entities/preferences'; -import type {ActionResult} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store/index'; @@ -26,12 +23,8 @@ const mapStateToProps = (state: GlobalState) => ({ sendPushNotifications: getConfig(state).SendPushNotifications === 'true', }); -type Actions = { - updateChannelNotifyProps: (userId: string, channelId: string, props: Partial) => Promise; -}; - const mapDispatchToProps = (dispatch: Dispatch) => ({ - actions: bindActionCreators({ + actions: bindActionCreators({ updateChannelNotifyProps, }, dispatch), }); diff --git a/webapp/channels/src/components/channel_selector_modal/channel_selector_modal.tsx b/webapp/channels/src/components/channel_selector_modal/channel_selector_modal.tsx index d937ba390d..06d2ba9083 100644 --- a/webapp/channels/src/components/channel_selector_modal/channel_selector_modal.tsx +++ b/webapp/channels/src/components/channel_selector_modal/channel_selector_modal.tsx @@ -26,9 +26,9 @@ type Props = { intl: IntlShape; groupID: string; actions: { - loadChannels: (page?: number, perPage?: number, notAssociatedToGroup?: string, excludeDefaultChannels?: boolean, excludePolicyConstrained?: boolean) => Promise<{data: ChannelWithTeamData[]}>; - setModalSearchTerm: (term: string) => ActionResult; - searchAllChannels: (term: string, opts?: ChannelSearchOpts) => Promise<{data: ChannelWithTeamData[]}>; + loadChannels: (page?: number, perPage?: number, notAssociatedToGroup?: string, excludeDefaultChannels?: boolean, excludePolicyConstrained?: boolean) => Promise>; + setModalSearchTerm: (term: string) => void; + searchAllChannels: (term: string, opts?: ChannelSearchOpts) => Promise>; }; alreadySelected?: string[]; excludePolicyConstrained?: boolean; @@ -59,7 +59,7 @@ export class ChannelSelectorModal extends React.PureComponent { componentDidMount() { this.props.actions.loadChannels(0, CHANNELS_PER_PAGE + 1, this.props.groupID, false, this.props.excludePolicyConstrained).then((response) => { - this.setState({channels: response.data.sort(compareChannels)}); + this.setState({channels: response.data!.sort(compareChannels)}); this.setChannelsLoadingState(false); }); } @@ -71,7 +71,7 @@ export class ChannelSelectorModal extends React.PureComponent { const searchTerm = this.props.searchTerm; if (searchTerm === '') { this.props.actions.loadChannels(0, CHANNELS_PER_PAGE + 1, this.props.groupID, false, this.props.excludePolicyConstrained).then((response) => { - this.setState({channels: response.data.sort(compareChannels)}); + this.setState({channels: response.data!.sort(compareChannels)}); this.setChannelsLoadingState(false); }); } else { @@ -79,7 +79,7 @@ export class ChannelSelectorModal extends React.PureComponent { async () => { this.setChannelsLoadingState(true); const response = await this.props.actions.searchAllChannels(searchTerm, {not_associated_to_group: this.props.groupID}); - this.setState({channels: response.data}); + this.setState({channels: response.data!}); this.setChannelsLoadingState(false); }, Constants.SEARCH_TIMEOUT_MILLISECONDS, @@ -135,7 +135,7 @@ export class ChannelSelectorModal extends React.PureComponent { this.props.actions.loadChannels(page, CHANNELS_PER_PAGE + 1, this.props.groupID, false, this.props.excludePolicyConstrained).then((response) => { const newState = [...this.state.channels]; const stateChannelIDs = this.state.channels.map((stateChannel) => stateChannel.id); - response.data.forEach((serverChannel) => { + response.data!.forEach((serverChannel) => { if (!stateChannelIDs.includes(serverChannel.id)) { newState.push(serverChannel); } diff --git a/webapp/channels/src/components/channel_selector_modal/index.ts b/webapp/channels/src/components/channel_selector_modal/index.ts index 90cc9425bc..818fc1075b 100644 --- a/webapp/channels/src/components/channel_selector_modal/index.ts +++ b/webapp/channels/src/components/channel_selector_modal/index.ts @@ -3,12 +3,9 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {ChannelWithTeamData, ChannelSearchOpts} from '@mattermost/types/channels'; +import type {Dispatch} from 'redux'; import {getAllChannels as loadChannels, searchAllChannels} from 'mattermost-redux/actions/channels'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {setModalSearchTerm} from 'actions/views/search'; @@ -16,21 +13,15 @@ import type {GlobalState} from 'types/store'; import ChannelSelectorModal from './channel_selector_modal'; -type Actions = { - loadChannels: (page?: number, perPage?: number, notAssociatedToGroup?: string, excludeDefaultChannels?: boolean) => Promise<{data: ChannelWithTeamData[]}>; - setModalSearchTerm: (term: string) => ActionResult; - searchAllChannels: (term: string, opts?: ChannelSearchOpts) => Promise<{data: ChannelWithTeamData[]}>; -} - function mapStateToProps(state: GlobalState) { return { searchTerm: state.views.search.modalSearch, }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ loadChannels, setModalSearchTerm, searchAllChannels, diff --git a/webapp/channels/src/components/claim/claim_controller.tsx b/webapp/channels/src/components/claim/claim_controller.tsx index 9f3e87fc46..daf96e2a00 100644 --- a/webapp/channels/src/components/claim/claim_controller.tsx +++ b/webapp/channels/src/components/claim/claim_controller.tsx @@ -6,6 +6,8 @@ import {Route, Switch} from 'react-router-dom'; import type {AuthChangeResponse} from '@mattermost/types/users'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import EmailToLDAP from 'components/claim/components/email_to_ldap'; import EmailToOAuth from 'components/claim/components/email_to_oauth'; import LDAPToEmail from 'components/claim/components/ldap_to_email'; @@ -35,7 +37,7 @@ export type Props = { url: string; }; actions: { - switchLdapToEmail: (ldapPassword: string, email: string, emailPassword: string, mfaCode?: string) => Promise<{data: AuthChangeResponse; error: {server_error_id: string; message: string}}>; + switchLdapToEmail: (ldapPassword: string, email: string, emailPassword: string, mfaCode?: string) => Promise>; }; } diff --git a/webapp/channels/src/components/claim/components/ldap_to_email.tsx b/webapp/channels/src/components/claim/components/ldap_to_email.tsx index 7f4e46f5ad..7402cf1d88 100644 --- a/webapp/channels/src/components/claim/components/ldap_to_email.tsx +++ b/webapp/channels/src/components/claim/components/ldap_to_email.tsx @@ -7,6 +7,8 @@ import {FormattedMessage, useIntl} from 'react-intl'; import type {AuthChangeResponse} from '@mattermost/types/users'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import LoginMfa from 'components/login/login_mfa'; import {ClaimErrors} from 'utils/constants'; @@ -19,7 +21,7 @@ import type {PasswordConfig} from '../claim_controller'; type Props = { email: string | null; - switchLdapToEmail: (ldapPassword: string, email: string, password: string, token: string) => Promise<{data?: AuthChangeResponse; error?: {server_error_id: string; message: string}}>; + switchLdapToEmail: (ldapPassword: string, email: string, password: string, token: string) => Promise>; passwordConfig?: PasswordConfig; } diff --git a/webapp/channels/src/components/claim/index.ts b/webapp/channels/src/components/claim/index.ts index 6cd4d1be90..b692da6087 100644 --- a/webapp/channels/src/components/claim/index.ts +++ b/webapp/channels/src/components/claim/index.ts @@ -3,18 +3,16 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import {switchLdapToEmail} from 'mattermost-redux/actions/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {getPasswordConfig} from 'utils/utils'; import ClaimController from './claim_controller'; -import type {Props} from './claim_controller'; function mapStateToProps(state: GlobalState) { const config = getConfig(state); @@ -28,9 +26,9 @@ function mapStateToProps(state: GlobalState) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ switchLdapToEmail, }, dispatch), }; diff --git a/webapp/channels/src/components/convert_gm_to_channel_modal/index.ts b/webapp/channels/src/components/convert_gm_to_channel_modal/index.ts index ad77ce52f1..d71da3cb24 100644 --- a/webapp/channels/src/components/convert_gm_to_channel_modal/index.ts +++ b/webapp/channels/src/components/convert_gm_to_channel_modal/index.ts @@ -2,7 +2,7 @@ // See LICENSE.txt for license information. import {connect} from 'react-redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {bindActionCreators} from 'redux'; import {convertGroupMessageToPrivateChannel} from 'mattermost-redux/actions/channels'; @@ -11,7 +11,7 @@ import { getCurrentUserId, makeGetProfilesInChannel, } from 'mattermost-redux/selectors/entities/users'; -import type {Action, ActionResult} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {moveChannelsInSidebar} from 'actions/views/channel_sidebar'; import {closeModal} from 'actions/views/modals'; @@ -45,7 +45,7 @@ export type Actions = { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ closeModal, convertGroupMessageToPrivateChannel, moveChannelsInSidebar, diff --git a/webapp/channels/src/components/create_team/components/team_url/index.ts b/webapp/channels/src/components/create_team/components/team_url/index.ts index 6217f04650..2aa2285674 100644 --- a/webapp/channels/src/components/create_team/components/team_url/index.ts +++ b/webapp/channels/src/components/create_team/components/team_url/index.ts @@ -3,24 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {ServerError} from '@mattermost/types/errors'; -import type {Team} from '@mattermost/types/teams'; +import type {Dispatch} from 'redux'; import {checkIfTeamExists, createTeam} from 'mattermost-redux/actions/teams'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import TeamUrl from './team_url'; -type Actions = { - checkIfTeamExists: (teamName: string) => Promise<{data: boolean}>; - createTeam: (team: Team) => Promise<{data: Team; error: ServerError}>; -}; - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ checkIfTeamExists, createTeam, }, dispatch), diff --git a/webapp/channels/src/components/create_team/components/team_url/team_url.tsx b/webapp/channels/src/components/create_team/components/team_url/team_url.tsx index 1b692438fd..bc63db74a0 100644 --- a/webapp/channels/src/components/create_team/components/team_url/team_url.tsx +++ b/webapp/channels/src/components/create_team/components/team_url/team_url.tsx @@ -5,9 +5,10 @@ import React from 'react'; import {Button} from 'react-bootstrap'; import {FormattedMessage} from 'react-intl'; -import type {ServerError} from '@mattermost/types/errors'; import type {Team} from '@mattermost/types/teams'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import {trackEvent} from 'actions/telemetry_actions.jsx'; import ExternalLink from 'components/external_link'; @@ -44,12 +45,12 @@ type Props = { /* * Action creator to check if a team already exists */ - checkIfTeamExists: (teamName: string) => Promise<{data: boolean}>; + checkIfTeamExists: (teamName: string) => Promise>; /* * Action creator to create a new team */ - createTeam: (team: Team) => Promise<{data: Team; error: ServerError}>; + createTeam: (team: Team) => Promise>; }; history: { push(path: string): void; @@ -151,7 +152,7 @@ export default class TeamUrl extends React.PureComponent { teamSignup.team.type = 'O'; teamSignup.team.name = name; - const checkIfTeamExistsData: { data: boolean } = await checkIfTeamExists(name); + const checkIfTeamExistsData = await checkIfTeamExists(name); const exists = checkIfTeamExistsData.data; if (exists) { @@ -165,7 +166,7 @@ export default class TeamUrl extends React.PureComponent { return; } - const createTeamData: { data: Team; error: any } = await createTeam(teamSignup.team); + const createTeamData = await createTeam(teamSignup.team); const data = createTeamData.data; const error = createTeamData.error; diff --git a/webapp/channels/src/components/create_user_groups_modal/index.ts b/webapp/channels/src/components/create_user_groups_modal/index.ts index f1b2a9c413..5787f76956 100644 --- a/webapp/channels/src/components/create_user_groups_modal/index.ts +++ b/webapp/channels/src/components/create_user_groups_modal/index.ts @@ -3,27 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {GroupCreateWithUserIds} from '@mattermost/types/groups'; +import type {Dispatch} from 'redux'; import {createGroupWithUserIds} from 'mattermost-redux/actions/groups'; -import type {Action, ActionResult} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; - import CreateUserGroupsModal from './create_user_groups_modal'; -type Actions = { - createGroupWithUserIds: (group: GroupCreateWithUserIds) => Promise; - openModal:

(modalData: ModalData

) => void; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ createGroupWithUserIds, openModal, }, dispatch), diff --git a/webapp/channels/src/components/data_prefetch/data_prefetch.tsx b/webapp/channels/src/components/data_prefetch/data_prefetch.tsx index d09959d1e0..b929ff7816 100644 --- a/webapp/channels/src/components/data_prefetch/data_prefetch.tsx +++ b/webapp/channels/src/components/data_prefetch/data_prefetch.tsx @@ -6,6 +6,8 @@ import React from 'react'; import type {Channel} from '@mattermost/types/channels'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import {loadProfilesForSidebar} from 'actions/user_actions'; import {Constants} from 'utils/constants'; @@ -23,7 +25,7 @@ type Props = { unreadChannels: Channel[]; actions: { - prefetchChannelPosts: (channelId: string, delay?: number) => Promise; + prefetchChannelPosts: (channelId: string, delay?: number) => Promise; trackPreloadedChannels: (prefetchQueueObj: Record) => void; }; } diff --git a/webapp/channels/src/components/data_prefetch/index.ts b/webapp/channels/src/components/data_prefetch/index.ts index fa5bac9aca..1056d3043c 100644 --- a/webapp/channels/src/components/data_prefetch/index.ts +++ b/webapp/channels/src/components/data_prefetch/index.ts @@ -3,9 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {PostList} from '@mattermost/types/posts'; +import type {Dispatch} from 'redux'; import {getCurrentChannelId, getUnreadChannels} from 'mattermost-redux/selectors/entities/channels'; import {getMyChannelMemberships} from 'mattermost-redux/selectors/entities/common'; @@ -19,11 +17,6 @@ import type {GlobalState} from 'types/store'; import {prefetchQueue, trackPreloadedChannels} from './actions'; import DataPrefetch from './data_prefetch'; -type Actions = { - prefetchChannelPosts: (channelId: string, delay?: number) => Promise<{data: PostList}>; - trackPreloadedChannels: (prefetchQueueObj: Record) => void; -}; - function isSidebarLoaded(state: GlobalState) { return getCategoriesForCurrentTeam(state).length > 0; } @@ -46,7 +39,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ prefetchChannelPosts, trackPreloadedChannels, }, dispatch), diff --git a/webapp/channels/src/components/delete_channel_modal/delete_channel_modal.tsx b/webapp/channels/src/components/delete_channel_modal/delete_channel_modal.tsx index 3bf6a0b73e..b00552bf09 100644 --- a/webapp/channels/src/components/delete_channel_modal/delete_channel_modal.tsx +++ b/webapp/channels/src/components/delete_channel_modal/delete_channel_modal.tsx @@ -19,7 +19,7 @@ export type Props = { canViewArchivedChannels?: boolean; penultimateViewedChannelName: string; actions: { - deleteChannel: (channelId: string) => {data: boolean}; + deleteChannel: (channelId: string) => void; }; } diff --git a/webapp/channels/src/components/delete_channel_modal/index.ts b/webapp/channels/src/components/delete_channel_modal/index.ts index d1ea0290dd..85cd0068f4 100644 --- a/webapp/channels/src/components/delete_channel_modal/index.ts +++ b/webapp/channels/src/components/delete_channel_modal/index.ts @@ -3,13 +3,12 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import {deleteChannel} from 'actions/views/channel'; @@ -24,13 +23,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - deleteChannel: (channelId: string) => {data: true}; -}; - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>( + actions: bindActionCreators( { deleteChannel, }, diff --git a/webapp/channels/src/components/delete_post_modal/delete_post_modal.tsx b/webapp/channels/src/components/delete_post_modal/delete_post_modal.tsx index db95a849bd..f5aec456f9 100644 --- a/webapp/channels/src/components/delete_post_modal/delete_post_modal.tsx +++ b/webapp/channels/src/components/delete_post_modal/delete_post_modal.tsx @@ -8,6 +8,8 @@ import {matchPath} from 'react-router-dom'; import type {Post} from '@mattermost/types/posts'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import {getHistory} from 'utils/browser_history'; import * as UserAgent from 'utils/user_agent'; @@ -22,7 +24,7 @@ type Props = { isRHS: boolean; onExited: () => void; actions: { - deleteAndRemovePost: (post: Post) => Promise<{data: boolean}>; + deleteAndRemovePost: (post: Post) => Promise>; }; location: { pathname: string; diff --git a/webapp/channels/src/components/delete_post_modal/index.ts b/webapp/channels/src/components/delete_post_modal/index.ts index 0b14d3f3b8..5211c0ca4c 100644 --- a/webapp/channels/src/components/delete_post_modal/index.ts +++ b/webapp/channels/src/components/delete_post_modal/index.ts @@ -4,12 +4,11 @@ import {connect} from 'react-redux'; import {withRouter} from 'react-router-dom'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {Post} from '@mattermost/types/posts'; import {makeGetCommentCountForPost} from 'mattermost-redux/selectors/entities/posts'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import {deleteAndRemovePost} from 'actions/post_actions'; @@ -17,10 +16,6 @@ import type {GlobalState} from 'types/store'; import DeletePostModal from './delete_post_modal'; -type Actions = { - deleteAndRemovePost: (post: Post) => Promise<{data: boolean}>; -}; - type Props = { channelName?: string; teamName?: string; @@ -50,7 +45,7 @@ function makeMapStateToProps() { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ deleteAndRemovePost, }, dispatch), }; diff --git a/webapp/channels/src/components/dnd_custom_time_picker_modal/dnd_custom_time_picker_modal.tsx b/webapp/channels/src/components/dnd_custom_time_picker_modal/dnd_custom_time_picker_modal.tsx index ad8252c74b..6fa7f2c05c 100644 --- a/webapp/channels/src/components/dnd_custom_time_picker_modal/dnd_custom_time_picker_modal.tsx +++ b/webapp/channels/src/components/dnd_custom_time_picker_modal/dnd_custom_time_picker_modal.tsx @@ -12,7 +12,6 @@ import {GenericModal} from '@mattermost/components'; import type {UserStatus} from '@mattermost/types/users'; import type {Theme} from 'mattermost-redux/selectors/entities/preferences'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import CompassThemeProvider from 'components/compass_theme_provider/compass_theme_provider'; import DatePicker from 'components/date_picker'; @@ -36,7 +35,7 @@ type Props = { theme: Theme; actions: { - setStatus: (status: UserStatus) => ActionFunc; + setStatus: (status: UserStatus) => void; }; }; diff --git a/webapp/channels/src/components/dot_menu/dot_menu.tsx b/webapp/channels/src/components/dot_menu/dot_menu.tsx index 14181f7b2e..36581e23d6 100644 --- a/webapp/channels/src/components/dot_menu/dot_menu.tsx +++ b/webapp/channels/src/components/dot_menu/dot_menu.tsx @@ -63,7 +63,7 @@ type Props = { intl: IntlShape; post: Post; teamId: string; - location?: 'CENTER' | 'RHS_ROOT' | 'RHS_COMMENT' | 'SEARCH' | string; + location?: keyof typeof Constants.Locations; isFlagged?: boolean; handleCommentClick?: React.EventHandler; handleDropdownOpened: (open: boolean) => void; @@ -115,7 +115,7 @@ type Props = { /** * Function to set the unread mark at given post */ - markPostAsUnread: (post: Post, location?: 'CENTER' | 'RHS_ROOT' | 'RHS_COMMENT' | string) => void; + markPostAsUnread: (post: Post, location?: string) => void; /** * Function to set the thread as followed/unfollowed diff --git a/webapp/channels/src/components/dot_menu/index.ts b/webapp/channels/src/components/dot_menu/index.ts index 2aa6956fe1..8b226f29c2 100644 --- a/webapp/channels/src/components/dot_menu/index.ts +++ b/webapp/channels/src/components/dot_menu/index.ts @@ -4,7 +4,7 @@ import type {ComponentProps} from 'react'; import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {Post} from '@mattermost/types/posts'; @@ -17,7 +17,6 @@ import {getCurrentTeamId, getCurrentTeam, getTeam} from 'mattermost-redux/select import {makeGetThreadOrSynthetic} from 'mattermost-redux/selectors/entities/threads'; import {getCurrentTimezone} from 'mattermost-redux/selectors/entities/timezone'; import {getCurrentUserId, getCurrentUserMentionKeys} from 'mattermost-redux/selectors/entities/users'; -import type {GenericAction} from 'mattermost-redux/types/actions'; import {isSystemMessage} from 'mattermost-redux/utils/post_utils'; import { @@ -39,7 +38,6 @@ import {matchUserMentionTriggersWithMessageMentions} from 'utils/post_utils'; import {allAtMentions} from 'utils/text_formatting'; import {getSiteURL} from 'utils/url'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import DotMenu from './dot_menu'; @@ -130,20 +128,9 @@ function makeMapStateToProps() { }; } -type Actions = { - flagPost: (postId: string) => void; - unflagPost: (postId: string) => void; - setEditingPost: (postId?: string, refocusId?: string, title?: string, isRHS?: boolean) => void; - pinPost: (postId: string) => void; - unpinPost: (postId: string) => void; - openModal:

(modalData: ModalData

) => void; - markPostAsUnread: (post: Post) => void; - setThreadFollow: (userId: string, teamId: string, threadId: string, newState: boolean) => void; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ flagPost, unflagPost, setEditingPost, diff --git a/webapp/channels/src/components/edit_category_modal/edit_category_modal.tsx b/webapp/channels/src/components/edit_category_modal/edit_category_modal.tsx index a10ecc778c..42c657afc8 100644 --- a/webapp/channels/src/components/edit_category_modal/edit_category_modal.tsx +++ b/webapp/channels/src/components/edit_category_modal/edit_category_modal.tsx @@ -5,7 +5,6 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; import {GenericModal} from '@mattermost/components'; -import type {ChannelCategory} from '@mattermost/types/channel_categories'; import {trackEvent} from 'actions/telemetry_actions'; @@ -25,7 +24,7 @@ type Props = { initialCategoryName?: string; channelIdsToAdd?: string[]; actions: { - createCategory: (teamId: string, displayName: string, channelIds?: string[] | undefined) => {data: ChannelCategory}; + createCategory: (teamId: string, displayName: string, channelIds?: string[] | undefined) => void; renameCategory: (categoryId: string, newName: string) => void; }; }; diff --git a/webapp/channels/src/components/edit_category_modal/index.ts b/webapp/channels/src/components/edit_category_modal/index.ts index 6d8b88a2e5..a57bd5eb0a 100644 --- a/webapp/channels/src/components/edit_category_modal/index.ts +++ b/webapp/channels/src/components/edit_category_modal/index.ts @@ -3,13 +3,10 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {ChannelCategory} from '@mattermost/types/channel_categories'; +import type {Dispatch} from 'redux'; import {renameCategory} from 'mattermost-redux/actions/channel_categories'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import {createCategory} from 'actions/views/channel_sidebar'; @@ -25,14 +22,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - createCategory: (teamId: string, displayName: string, channelIds?: string[] | undefined) => {data: ChannelCategory}; - renameCategory: (categoryId: string, displayName: string) => void; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ createCategory, renameCategory, }, dispatch), diff --git a/webapp/channels/src/components/edit_channel_header_modal/index.ts b/webapp/channels/src/components/edit_channel_header_modal/index.ts index 468c1def0f..d4a8d476d5 100644 --- a/webapp/channels/src/components/edit_channel_header_modal/index.ts +++ b/webapp/channels/src/components/edit_channel_header_modal/index.ts @@ -3,14 +3,11 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {Channel} from '@mattermost/types/channels'; +import type {Dispatch} from 'redux'; import {patchChannel} from 'mattermost-redux/actions/channels'; import {Preferences} from 'mattermost-redux/constants'; import {getBool} from 'mattermost-redux/selectors/entities/preferences'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {setShowPreviewOnEditChannelHeaderModal} from 'actions/views/textbox'; import {showPreviewOnEditChannelHeaderModal} from 'selectors/views/textbox'; @@ -30,14 +27,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - patchChannel: (channelId: string, patch: Partial) => Promise; - setShowPreview: (showPreview: boolean) => void; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ patchChannel, setShowPreview: setShowPreviewOnEditChannelHeaderModal, }, dispatch), diff --git a/webapp/channels/src/components/edit_channel_purpose_modal/index.tsx b/webapp/channels/src/components/edit_channel_purpose_modal/index.tsx index 2be9cca033..f405f12ff6 100644 --- a/webapp/channels/src/components/edit_channel_purpose_modal/index.tsx +++ b/webapp/channels/src/components/edit_channel_purpose_modal/index.tsx @@ -3,13 +3,10 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {Channel} from '@mattermost/types/channels'; +import type {Dispatch} from 'redux'; import {patchChannel} from 'mattermost-redux/actions/channels'; import {getBool} from 'mattermost-redux/selectors/entities/preferences'; -import type {ActionFunc, GenericAction, ActionResult} from 'mattermost-redux/types/actions'; import Constants from 'utils/constants'; @@ -23,13 +20,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - patchChannel: (channelId: string, patch: Partial) => Promise; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ patchChannel, }, dispatch), }; diff --git a/webapp/channels/src/components/edit_post/index.ts b/webapp/channels/src/components/edit_post/index.ts index ebb8dffbf6..5092128d5c 100644 --- a/webapp/channels/src/components/edit_post/index.ts +++ b/webapp/channels/src/components/edit_post/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {addMessageIntoHistory} from 'mattermost-redux/actions/posts'; import {Preferences, Permissions} from 'mattermost-redux/constants'; @@ -28,7 +28,6 @@ import Constants, {RHSStates, StoragePrefixes} from 'utils/constants'; import type {GlobalState} from 'types/store'; import EditPost from './edit_post'; -import type {Actions} from './edit_post'; function mapStateToProps(state: GlobalState) { const config = getConfig(state); @@ -65,7 +64,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ scrollPostListToBottom, addMessageIntoHistory, editPost, diff --git a/webapp/channels/src/components/emoji/add_emoji/index.ts b/webapp/channels/src/components/emoji/add_emoji/index.ts index cc8e90adc9..5c8542669a 100644 --- a/webapp/channels/src/components/emoji/add_emoji/index.ts +++ b/webapp/channels/src/components/emoji/add_emoji/index.ts @@ -3,12 +3,9 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {CustomEmoji} from '@mattermost/types/emojis'; +import type {Dispatch} from 'redux'; import {createCustomEmoji} from 'mattermost-redux/actions/emojis'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {getEmojiMap} from 'selectors/emojis'; @@ -16,19 +13,15 @@ import type {GlobalState} from 'types/store'; import AddEmoji from './add_emoji'; -type Actions = { - createCustomEmoji: (emoji: CustomEmoji, imageData: File) => Promise; -}; - function mapStateToProps(state: GlobalState) { return { emojiMap: getEmojiMap(state), }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ createCustomEmoji, }, dispatch), }; diff --git a/webapp/channels/src/components/emoji/emoji_list/emoji_list.tsx b/webapp/channels/src/components/emoji/emoji_list/emoji_list.tsx index 3bc90fa49d..8ea569711c 100644 --- a/webapp/channels/src/components/emoji/emoji_list/emoji_list.tsx +++ b/webapp/channels/src/components/emoji/emoji_list/emoji_list.tsx @@ -6,10 +6,10 @@ import type {ChangeEvent, ChangeEventHandler} from 'react'; import {FormattedMessage, injectIntl, type IntlShape} from 'react-intl'; import type {CustomEmoji} from '@mattermost/types/emojis'; -import type {ServerError} from '@mattermost/types/errors'; import {deleteCustomEmoji} from 'mattermost-redux/actions/emojis'; import {Emoji} from 'mattermost-redux/constants'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import EmojiListItem from 'components/emoji/emoji_list_item'; import LoadingScreen from 'components/loading_screen'; @@ -21,7 +21,7 @@ import SearchIcon from 'components/widgets/icons/fa_search_icon'; const EMOJI_PER_PAGE = 50; const EMOJI_SEARCH_DELAY_MILLISECONDS = 200; -interface Props { +export interface Props { /** * Custom emojis on the system. @@ -38,12 +38,12 @@ interface Props { /** * Get pages of custom emojis. */ - getCustomEmojis: (page?: number, perPage?: number, sort?: string, loadUsers?: boolean) => Promise<{ data: CustomEmoji[]; error: ServerError }>; + getCustomEmojis: (page?: number, perPage?: number, sort?: string, loadUsers?: boolean) => Promise>; /** * Search custom emojis. */ - searchCustomEmojis: (term: string, options: any, loadUsers: boolean) => Promise<{ data: CustomEmoji[]; error: ServerError }>; + searchCustomEmojis: (term: string, options: any, loadUsers: boolean) => Promise>; }; } @@ -73,7 +73,7 @@ class EmojiList extends React.PureComponent { async componentDidMount(): Promise { this.props.actions.getCustomEmojis(0, EMOJI_PER_PAGE + 1, Emoji.SORT_BY_NAME, true). - then(({data}: { data: CustomEmoji[] }) => { + then(({data}: ActionResult) => { this.setState({loading: false}); if (data && data.length < EMOJI_PER_PAGE) { this.setState({missingPages: false}); @@ -89,7 +89,7 @@ class EmojiList extends React.PureComponent { const next = this.state.page + 1; this.setState({nextLoading: true}); this.props.actions.getCustomEmojis(next, EMOJI_PER_PAGE, Emoji.SORT_BY_NAME, true). - then(({data}: { data: CustomEmoji[] }) => { + then(({data}: ActionResult) => { this.setState({page: next, nextLoading: false}); if (data && data.length < EMOJI_PER_PAGE) { this.setState({missingPages: false}); @@ -129,7 +129,7 @@ class EmojiList extends React.PureComponent { this.setState({loading: true}); - const {data}: { data: CustomEmoji[] } = await this.props.actions.searchCustomEmojis( + const {data} = await this.props.actions.searchCustomEmojis( term, {}, true, diff --git a/webapp/channels/src/components/emoji/emoji_list/index.ts b/webapp/channels/src/components/emoji/emoji_list/index.ts index d65b6cfaa3..43218897f1 100644 --- a/webapp/channels/src/components/emoji/emoji_list/index.ts +++ b/webapp/channels/src/components/emoji/emoji_list/index.ts @@ -3,32 +3,24 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {CustomEmoji} from '@mattermost/types/emojis'; -import type {ServerError} from '@mattermost/types/errors'; import type {GlobalState} from '@mattermost/types/store'; import {getCustomEmojis, searchCustomEmojis} from 'mattermost-redux/actions/emojis'; import {getCustomEmojiIdsSortedByName} from 'mattermost-redux/selectors/entities/emojis'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import EmojiList from './emoji_list'; -type Actions = { - getCustomEmojis: (page?: number, perPage?: number, sort?: string, loadUsers?: boolean) => Promise<{ data: CustomEmoji[]; error: ServerError }>; - searchCustomEmojis: (term: string, options: any, loadUsers: boolean) => Promise<{ data: CustomEmoji[]; error: ServerError }>; -} - function mapStateToProps(state: GlobalState) { return { emojiIds: getCustomEmojiIdsSortedByName(state) || [], }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getCustomEmojis, searchCustomEmojis, }, dispatch), diff --git a/webapp/channels/src/components/emoji/emoji_list_item/emoji_list_item.tsx b/webapp/channels/src/components/emoji/emoji_list_item/emoji_list_item.tsx index eb3e70d69e..17439ba6c0 100644 --- a/webapp/channels/src/components/emoji/emoji_list_item/emoji_list_item.tsx +++ b/webapp/channels/src/components/emoji/emoji_list_item/emoji_list_item.tsx @@ -7,7 +7,6 @@ import type {CustomEmoji} from '@mattermost/types/emojis'; import {Client4} from 'mattermost-redux/client'; import Permissions from 'mattermost-redux/constants/permissions'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import AnyTeamPermissionGate from 'components/permissions_gates/any_team_permission_gate'; @@ -21,7 +20,7 @@ export type Props = { creatorUsername?: string; onDelete?: (emojiId: string) => void; actions: { - deleteCustomEmoji: (emojiId: string) => ActionFunc; + deleteCustomEmoji: (emojiId: string) => void; }; } diff --git a/webapp/channels/src/components/emoji_picker/components/emoji_picker_current_results.tsx b/webapp/channels/src/components/emoji_picker/components/emoji_picker_current_results.tsx index 9ee56752d1..5d31768785 100644 --- a/webapp/channels/src/components/emoji_picker/components/emoji_picker_current_results.tsx +++ b/webapp/channels/src/components/emoji_picker/components/emoji_picker_current_results.tsx @@ -9,7 +9,8 @@ import type {ListItemKeySelector, ListOnScrollProps} from 'react-window'; import InfiniteLoader from 'react-window-infinite-loader'; import type {Emoji, EmojiCategory, CustomEmoji, SystemEmoji} from '@mattermost/types/emojis'; -import type {ServerError} from '@mattermost/types/errors'; + +import type {ActionResult} from 'mattermost-redux/types/actions'; import EmojiPickerCategoryOrEmojiRow from 'components/emoji_picker/components/emoji_picker_category_or_emoji_row'; import {ITEM_HEIGHT, EMOJI_ROWS_OVERSCAN_COUNT, EMOJI_CONTAINER_HEIGHT, CUSTOM_EMOJIS_PER_PAGE, EMOJI_SCROLL_THROTTLE_DELAY} from 'components/emoji_picker/constants'; @@ -28,7 +29,7 @@ interface Props { onEmojiClick: (emoji: Emoji) => void; onEmojiMouseOver: (cursor: EmojiCursor) => void; incrementEmojiPickerPage: () => void; - getCustomEmojis: (page?: number, perPage?: number, sort?: string, loadUsers?: boolean) => Promise<{ data: CustomEmoji[]; error: ServerError }>; + getCustomEmojis: (page?: number, perPage?: number, sort?: string, loadUsers?: boolean) => Promise>; } const EmojiPickerCurrentResults = forwardRef(({categoryOrEmojisRows, isFiltering, activeCategory, cursorRowIndex, cursorEmojiId, customEmojisEnabled, customEmojiPage, setActiveCategory, onEmojiClick, onEmojiMouseOver, getCustomEmojis, incrementEmojiPickerPage}: Props, ref) => { diff --git a/webapp/channels/src/components/emoji_picker/emoji_picker.tsx b/webapp/channels/src/components/emoji_picker/emoji_picker.tsx index 2be2745749..6585787f09 100644 --- a/webapp/channels/src/components/emoji_picker/emoji_picker.tsx +++ b/webapp/channels/src/components/emoji_picker/emoji_picker.tsx @@ -34,7 +34,7 @@ import {NoResultsVariant} from 'components/no_results_indicator/types'; import type {PropsFromRedux} from './index'; -interface Props extends PropsFromRedux { +export interface Props extends PropsFromRedux { filter: string; onEmojiClick: (emoji: Emoji) => void; handleFilterChange: (filter: string) => void; diff --git a/webapp/channels/src/components/emoji_picker/index.ts b/webapp/channels/src/components/emoji_picker/index.ts index db3ccc65e6..f3e6be2813 100644 --- a/webapp/channels/src/components/emoji_picker/index.ts +++ b/webapp/channels/src/components/emoji_picker/index.ts @@ -4,15 +4,11 @@ import {connect} from 'react-redux'; import type {ConnectedProps} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {CustomEmoji} from '@mattermost/types/emojis'; -import type {ServerError} from '@mattermost/types/errors'; +import type {Dispatch} from 'redux'; import {getCustomEmojis, searchCustomEmojis} from 'mattermost-redux/actions/emojis'; import {getCustomEmojisEnabled} from 'mattermost-redux/selectors/entities/emojis'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {incrementEmojiPickerPage, setUserSkinTone} from 'actions/emoji_actions'; import {getEmojiMap, getRecentEmojisNames, getUserSkinTone} from 'selectors/emojis'; @@ -32,16 +28,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - getCustomEmojis: (page?: number, perPage?: number, sort?: string, loadUsers?: boolean) => Promise<{ data: CustomEmoji[]; error: ServerError }>; - searchCustomEmojis: (term: string, options?: any, loadUsers?: boolean) => ActionFunc; - incrementEmojiPickerPage: () => void; - setUserSkinTone: (skin: string) => void; -}; - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ getCustomEmojis, searchCustomEmojis, incrementEmojiPickerPage, diff --git a/webapp/channels/src/components/file_upload/index.ts b/webapp/channels/src/components/file_upload/index.ts index fff6bd07c6..4ea30b6721 100644 --- a/webapp/channels/src/components/file_upload/index.ts +++ b/webapp/channels/src/components/file_upload/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; @@ -16,7 +16,6 @@ import type {GlobalState} from 'types/store'; import type {FilesWillUploadHook} from 'types/store/plugins'; import FileUpload from './file_upload'; -import type {Props} from './file_upload'; function mapStateToProps(state: GlobalState) { const config = getConfig(state); @@ -33,7 +32,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ uploadFile, }, dispatch), }; diff --git a/webapp/channels/src/components/forward_post_modal/forward_post_modal.tsx b/webapp/channels/src/components/forward_post_modal/forward_post_modal.tsx index c1a8ed65d6..5dede7a63c 100644 --- a/webapp/channels/src/components/forward_post_modal/forward_post_modal.tsx +++ b/webapp/channels/src/components/forward_post_modal/forward_post_modal.tsx @@ -14,6 +14,7 @@ import {General, Permissions} from 'mattermost-redux/constants'; import {makeGetChannel} from 'mattermost-redux/selectors/entities/channels'; import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {getPermalinkURL} from 'selectors/urls'; @@ -190,7 +191,7 @@ const ForwardPostModal = ({onExited, post, actions}: Props) => { if (type === Constants.DM_CHANNEL && userId) { return actions.openDirectChannelToUserId(userId); } - return {data: false}; + return {data: false} as ActionResult; }).then(({data}) => { if (data) { channelToForward.details.id = data.id; diff --git a/webapp/channels/src/components/forward_post_modal/index.ts b/webapp/channels/src/components/forward_post_modal/index.ts index 4213712c1e..a254309398 100644 --- a/webapp/channels/src/components/forward_post_modal/index.ts +++ b/webapp/channels/src/components/forward_post_modal/index.ts @@ -4,7 +4,7 @@ import {connect} from 'react-redux'; import type {ConnectedProps} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {Channel} from '@mattermost/types/channels'; import type {Post} from '@mattermost/types/posts'; @@ -28,7 +28,7 @@ export type ActionProps = { switchToChannel: (channel: Channel) => Promise; // switch to the selected channel - openDirectChannelToUserId: (userId: string) => Promise; + openDirectChannelToUserId: (userId: string) => Promise>; // action called to forward the post with an optional comment forwardPost: (post: Post, channelId: Channel, message?: string) => Promise; @@ -45,7 +45,7 @@ export type OwnProps = { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, ActionProps>({ + actions: bindActionCreators({ joinChannelById, switchToChannel, forwardPost, diff --git a/webapp/channels/src/components/global_header/left_controls/product_menu/product_menu_list/index.ts b/webapp/channels/src/components/global_header/left_controls/product_menu/product_menu_list/index.ts index 138a976f62..99d93b4ace 100644 --- a/webapp/channels/src/components/global_header/left_controls/product_menu/product_menu_list/index.ts +++ b/webapp/channels/src/components/global_header/left_controls/product_menu/product_menu_list/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getPrevTrialLicense} from 'mattermost-redux/actions/admin'; import {Permissions} from 'mattermost-redux/constants'; @@ -21,7 +21,6 @@ import { import {haveICurrentTeamPermission, haveISystemPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; -import type {Action} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; import {getIsMobileView} from 'selectors/views/browser'; @@ -31,16 +30,10 @@ import {OnboardingTaskCategory, OnboardingTasksName, TaskNameMapToSteps} from 'c import {CloudProducts} from 'utils/constants'; import {isCloudLicense} from 'utils/license_utils'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import ProductMenuList from './product_menu_list'; -type Actions = { - openModal:

(modalData: ModalData

) => void; - getPrevTrialLicense: () => void; -} - function mapStateToProps(state: GlobalState) { const config = getConfig(state); const currentTeam = getCurrentTeam(state) || {}; @@ -101,7 +94,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ openModal, getPrevTrialLicense, }, dispatch), diff --git a/webapp/channels/src/components/integrations/add_command/add_command.tsx b/webapp/channels/src/components/integrations/add_command/add_command.tsx index 5d282a67f7..c268b4c695 100644 --- a/webapp/channels/src/components/integrations/add_command/add_command.tsx +++ b/webapp/channels/src/components/integrations/add_command/add_command.tsx @@ -25,7 +25,7 @@ export type Props = { /** * The function to call to add new command */ - addCommand: (command: Command) => Promise; + addCommand: (command: Command) => Promise>; }; }; diff --git a/webapp/channels/src/components/integrations/add_command/index.ts b/webapp/channels/src/components/integrations/add_command/index.ts index 168508fb92..e91834e817 100644 --- a/webapp/channels/src/components/integrations/add_command/index.ts +++ b/webapp/channels/src/components/integrations/add_command/index.ts @@ -3,17 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {addCommand} from 'mattermost-redux/actions/integrations'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import AddCommand from './add_command'; -import type {Props} from './add_command'; function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ addCommand, }, dispatch), }; diff --git a/webapp/channels/src/components/integrations/add_incoming_webhook/add_incoming_webhook.tsx b/webapp/channels/src/components/integrations/add_incoming_webhook/add_incoming_webhook.tsx index 09ac5f4cf5..d27a9b4f76 100644 --- a/webapp/channels/src/components/integrations/add_incoming_webhook/add_incoming_webhook.tsx +++ b/webapp/channels/src/components/integrations/add_incoming_webhook/add_incoming_webhook.tsx @@ -6,6 +6,8 @@ import React from 'react'; import type {IncomingWebhook} from '@mattermost/types/integrations'; import type {Team} from '@mattermost/types/teams'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import AbstractIncomingWebhook from 'components/integrations/abstract_incoming_webhook'; import {getHistory} from 'utils/browser_history'; @@ -37,7 +39,7 @@ type Props = { /** * The function to call to add a new incoming webhook */ - createIncomingHook: (hook: IncomingWebhook) => Promise<{ data?: IncomingWebhook; error?: Error }>; + createIncomingHook: (hook: IncomingWebhook) => Promise>; }; }; diff --git a/webapp/channels/src/components/integrations/add_incoming_webhook/index.ts b/webapp/channels/src/components/integrations/add_incoming_webhook/index.ts index d5552ad02e..3196e8e052 100644 --- a/webapp/channels/src/components/integrations/add_incoming_webhook/index.ts +++ b/webapp/channels/src/components/integrations/add_incoming_webhook/index.ts @@ -3,14 +3,12 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {IncomingWebhook} from '@mattermost/types/integrations'; import type {GlobalState} from '@mattermost/types/store'; import {createIncomingHook} from 'mattermost-redux/actions/integrations'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; -import type {Action, GenericAction} from 'mattermost-redux/types/actions'; import AddIncomingWebhook from './add_incoming_webhook'; @@ -25,13 +23,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - createIncomingHook: (hook: IncomingWebhook) => Promise<{ data?: IncomingWebhook; error?: Error }>; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ createIncomingHook, }, dispatch), }; diff --git a/webapp/channels/src/components/integrations/add_oauth_app/add_oauth_app.tsx b/webapp/channels/src/components/integrations/add_oauth_app/add_oauth_app.tsx index d44ecb0c8b..2b2ca16784 100644 --- a/webapp/channels/src/components/integrations/add_oauth_app/add_oauth_app.tsx +++ b/webapp/channels/src/components/integrations/add_oauth_app/add_oauth_app.tsx @@ -29,7 +29,7 @@ export type Props = { /** * The function to call to add new OAuthApp */ - addOAuthApp: (app: OAuthApp) => Promise; + addOAuthApp: (app: OAuthApp) => Promise>; }; }; diff --git a/webapp/channels/src/components/integrations/add_oauth_app/index.ts b/webapp/channels/src/components/integrations/add_oauth_app/index.ts index 1442f6de10..e6afb6451c 100644 --- a/webapp/channels/src/components/integrations/add_oauth_app/index.ts +++ b/webapp/channels/src/components/integrations/add_oauth_app/index.ts @@ -3,17 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {addOAuthApp} from 'mattermost-redux/actions/integrations'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import AddOAuthApp from './add_oauth_app'; -import type {Props} from './add_oauth_app'; function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ addOAuthApp, }, dispatch), }; diff --git a/webapp/channels/src/components/integrations/add_outgoing_webhook/add_outgoing_webhook.tsx b/webapp/channels/src/components/integrations/add_outgoing_webhook/add_outgoing_webhook.tsx index 681e5fb5f0..fb3f8b852b 100644 --- a/webapp/channels/src/components/integrations/add_outgoing_webhook/add_outgoing_webhook.tsx +++ b/webapp/channels/src/components/integrations/add_outgoing_webhook/add_outgoing_webhook.tsx @@ -29,7 +29,7 @@ export type Props = { /** * The function to call to add a new outgoing webhook */ - createOutgoingHook: (hook: OutgoingWebhook) => Promise; + createOutgoingHook: (hook: OutgoingWebhook) => Promise>; }; /** diff --git a/webapp/channels/src/components/integrations/add_outgoing_webhook/index.ts b/webapp/channels/src/components/integrations/add_outgoing_webhook/index.ts index 7c431749eb..d5662c6f9c 100644 --- a/webapp/channels/src/components/integrations/add_outgoing_webhook/index.ts +++ b/webapp/channels/src/components/integrations/add_outgoing_webhook/index.ts @@ -3,16 +3,14 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {createOutgoingHook} from 'mattermost-redux/actions/integrations'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import AddOutgoingWebhook from './add_outgoing_webhook'; -import type {Props} from './add_outgoing_webhook'; function mapStateToProps(state: GlobalState) { const config = getConfig(state); @@ -26,7 +24,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ createOutgoingHook, }, dispatch), }; diff --git a/webapp/channels/src/components/integrations/bots/add_bot/add_bot.tsx b/webapp/channels/src/components/integrations/bots/add_bot/add_bot.tsx index 32b603ab3d..766fd9e3f7 100644 --- a/webapp/channels/src/components/integrations/bots/add_bot/add_bot.tsx +++ b/webapp/channels/src/components/integrations/bots/add_bot/add_bot.tsx @@ -8,7 +8,7 @@ import {Link} from 'react-router-dom'; import type {Bot, BotPatch} from '@mattermost/types/bots'; import type {Team} from '@mattermost/types/teams'; -import type {UserProfile} from '@mattermost/types/users'; +import type {UserAccessToken, UserProfile} from '@mattermost/types/users'; import {General} from 'mattermost-redux/constants'; import type {ActionResult} from 'mattermost-redux/types/actions'; @@ -70,32 +70,32 @@ export type Props = { /** * Creates a new bot account. */ - createBot: (bot: Partial) => ActionResult; + createBot: (bot: Partial) => Promise>; /** * Patches an existing bot account. */ - patchBot: (botUserId: string, botPatch: Partial) => ActionResult; + patchBot: (botUserId: string, botPatch: Partial) => Promise>; /** * Uploads a user profile image */ - uploadProfileImage: (userId: string, image: File | string) => ActionResult; + uploadProfileImage: (userId: string, image: File | string) => Promise; /** * Set profile image to default */ - setDefaultProfileImage: (userId: string) => ActionResult; + setDefaultProfileImage: (userId: string) => Promise; /** * For creating default access token */ - createUserAccessToken: (userId: string, description: string) => ActionResult; + createUserAccessToken: (userId: string, description: string) => Promise>; /** * For creating setting bot to system admin or special posting permissions */ - updateUserRoles: (userId: string, roles: string) => ActionResult; + updateUserRoles: (userId: string, roles: string) => Promise; }; }; @@ -355,7 +355,7 @@ export default class AddBot extends React.PureComponent { return; } - token = tokenResult.data.token; + token = tokenResult.data!.token!; } if (!error && data) { diff --git a/webapp/channels/src/components/integrations/bots/add_bot/index.ts b/webapp/channels/src/components/integrations/bots/add_bot/index.ts index 386670dc3c..35cb3ed99e 100644 --- a/webapp/channels/src/components/integrations/bots/add_bot/index.ts +++ b/webapp/channels/src/components/integrations/bots/add_bot/index.ts @@ -4,7 +4,7 @@ import {connect} from 'react-redux'; import type {RouteComponentProps} from 'react-router-dom'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {createBot, patchBot} from 'mattermost-redux/actions/bots'; import {updateUserRoles, uploadProfileImage, setDefaultProfileImage, createUserAccessToken} from 'mattermost-redux/actions/users'; @@ -13,12 +13,10 @@ import {getBotAccounts} from 'mattermost-redux/selectors/entities/bots'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {haveISystemPermission} from 'mattermost-redux/selectors/entities/roles'; import {getUser} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import AddBot from './add_bot'; -import type {Props} from './add_bot'; type OwnProps = { @@ -46,7 +44,7 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ createBot, patchBot, uploadProfileImage, diff --git a/webapp/channels/src/components/integrations/bots/bot.tsx b/webapp/channels/src/components/integrations/bots/bot.tsx index b8c5aef28f..37ec5c420b 100644 --- a/webapp/channels/src/components/integrations/bots/bot.tsx +++ b/webapp/channels/src/components/integrations/bots/bot.tsx @@ -84,14 +84,11 @@ type Props = { /** * Access token managment */ - createUserAccessToken: (userId: string, description: string) => Promise<{ - data: {token: string; description: string; id: string; is_active: boolean} | null; - error?: Error; - }>; + createUserAccessToken: (userId: string, description: string) => Promise>; - revokeUserAccessToken: (tokenId: string) => Promise<{data: string; error?: Error}>; - enableUserAccessToken: (tokenId: string) => Promise<{data: string; error?: Error}>; - disableUserAccessToken: (tokenId: string) => Promise<{data: string; error?: Error}>; + revokeUserAccessToken: (tokenId: string) => Promise; + enableUserAccessToken: (tokenId: string) => Promise; + disableUserAccessToken: (tokenId: string) => Promise; }; /** diff --git a/webapp/channels/src/components/integrations/bots/bots.tsx b/webapp/channels/src/components/integrations/bots/bots.tsx index 05806f4a16..2375e61e49 100644 --- a/webapp/channels/src/components/integrations/bots/bots.tsx +++ b/webapp/channels/src/components/integrations/bots/bots.tsx @@ -59,7 +59,7 @@ type Props = { /** * Ensure we have bot accounts */ - loadBots: (page?: number, perPage?: number) => Promise<{data: BotType[]; error?: Error}>; + loadBots: (page?: number, perPage?: number) => Promise>; /** * Load access tokens for bot accounts @@ -69,14 +69,11 @@ type Props = { /** * Access token managment */ - createUserAccessToken: (userId: string, description: string) => Promise<{ - data: {token: string; description: string; id: string; is_active: boolean} | null; - error?: Error; - }>; + createUserAccessToken: (userId: string, description: string) => Promise>; - revokeUserAccessToken: (tokenId: string) => Promise<{data: string; error?: Error}>; - enableUserAccessToken: (tokenId: string) => Promise<{data: string; error?: Error}>; - disableUserAccessToken: (tokenId: string) => Promise<{data: string; error?: Error}>; + revokeUserAccessToken: (tokenId: string) => Promise; + enableUserAccessToken: (tokenId: string) => Promise; + disableUserAccessToken: (tokenId: string) => Promise; /** * Load owner of bot account diff --git a/webapp/channels/src/components/integrations/bots/index.ts b/webapp/channels/src/components/integrations/bots/index.ts index d68637f7f4..cb11355e2e 100644 --- a/webapp/channels/src/components/integrations/bots/index.ts +++ b/webapp/channels/src/components/integrations/bots/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {Bot as BotType} from '@mattermost/types/bots'; import type {GlobalState} from '@mattermost/types/store'; @@ -17,7 +17,7 @@ import {getExternalBotAccounts} from 'mattermost-redux/selectors/entities/bots'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getAppsBotIDs} from 'mattermost-redux/selectors/entities/integrations'; import * as UserSelectors from 'mattermost-redux/selectors/entities/users'; -import type {GenericAction, ActionResult, ActionFunc} from 'mattermost-redux/types/actions'; +import type {GenericAction} from 'mattermost-redux/types/actions'; import Bots from './bots'; @@ -48,25 +48,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - fetchAppsBotIDs: () => Promise<{data: string[]}>; - loadBots: (page?: number, perPage?: number) => Promise<{data: BotType[]; error?: Error}>; - getUserAccessTokensForUser: (userId: string, page?: number, perPage?: number) => void; - createUserAccessToken: (userId: string, description: string) => Promise<{ - data: {token: string; description: string; id: string; is_active: boolean} | null; - error?: Error; - }>; - revokeUserAccessToken: (tokenId: string) => Promise<{data: string; error?: Error}>; - enableUserAccessToken: (tokenId: string) => Promise<{data: string; error?: Error}>; - disableUserAccessToken: (tokenId: string) => Promise<{data: string; error?: Error}>; - getUser: (userId: string) => void; - disableBot: (userId: string) => Promise; - enableBot: (userId: string) => Promise; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ fetchAppsBotIDs, loadBots, getUserAccessTokensForUser, diff --git a/webapp/channels/src/components/integrations/edit_command/edit_command.test.tsx b/webapp/channels/src/components/integrations/edit_command/edit_command.test.tsx index 6b33816552..7b3716efb5 100644 --- a/webapp/channels/src/components/integrations/edit_command/edit_command.test.tsx +++ b/webapp/channels/src/components/integrations/edit_command/edit_command.test.tsx @@ -7,6 +7,8 @@ import React from 'react'; import type {Command} from '@mattermost/types/integrations'; import type {Team} from '@mattermost/types/teams'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import EditCommand from 'components/integrations/edit_command/edit_command'; import {TestHelper} from 'utils/test_helper'; @@ -14,8 +16,8 @@ import {TestHelper} from 'utils/test_helper'; describe('components/integrations/EditCommand', () => { const getCustomTeamCommands = jest.fn( () => { - return new Promise((resolve) => { - process.nextTick(() => resolve([])); + return new Promise>((resolve) => { + process.nextTick(() => resolve({data: []})); }); }, ); diff --git a/webapp/channels/src/components/integrations/edit_command/edit_command.tsx b/webapp/channels/src/components/integrations/edit_command/edit_command.tsx index 9953aefbf9..32fc775bcc 100644 --- a/webapp/channels/src/components/integrations/edit_command/edit_command.tsx +++ b/webapp/channels/src/components/integrations/edit_command/edit_command.tsx @@ -8,6 +8,8 @@ import type {Command} from '@mattermost/types/integrations'; import type {Team} from '@mattermost/types/teams'; import type {RelationOneToOne} from '@mattermost/types/utilities'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import ConfirmModal from 'components/confirm_modal'; import LoadingScreen from 'components/loading_screen'; @@ -41,12 +43,12 @@ type Props = { /** * The function to call to fetch team commands */ - getCustomTeamCommands: (teamId: string) => Promise; + getCustomTeamCommands: (teamId: string) => Promise; /** * The function to call to edit command */ - editCommand: (command?: Command) => Promise<{data?: Command; error?: Error}>; + editCommand: (command: Command) => Promise; }; /** @@ -59,7 +61,6 @@ type State = { originalCommand: Command | null; showConfirmModal: boolean; serverError: string; - } export default class EditCommand extends React.PureComponent { @@ -115,7 +116,7 @@ export default class EditCommand extends React.PureComponent { public submitCommand = async (): Promise => { this.setState({serverError: ''}); - const {data, error} = await this.props.actions.editCommand(this.newCommand); + const {data, error} = await this.props.actions.editCommand(this.newCommand!); if (data) { getHistory().push(`/${this.props.team.name}/integrations/commands`); diff --git a/webapp/channels/src/components/integrations/edit_command/index.ts b/webapp/channels/src/components/integrations/edit_command/index.ts index cfc4ab1afc..948dcdcf18 100644 --- a/webapp/channels/src/components/integrations/edit_command/index.ts +++ b/webapp/channels/src/components/integrations/edit_command/index.ts @@ -3,15 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; -import type {Command} from '@mattermost/types/integrations'; import type {GlobalState} from '@mattermost/types/store'; import {editCommand, getCustomTeamCommands} from 'mattermost-redux/actions/integrations'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getCommands} from 'mattermost-redux/selectors/entities/integrations'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import EditCommand from './edit_command'; @@ -19,11 +17,6 @@ type Props = { location: Location; } -type Actions = { - getCustomTeamCommands: (teamId: string) => Promise; - editCommand: (command?: Command) => Promise<{data?: Command; error?: Error}>; -} - function mapStateToProps(state: GlobalState, ownProps: Props) { const config = getConfig(state); const commandId = (new URLSearchParams(ownProps.location.search)).get('id'); @@ -36,9 +29,9 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getCustomTeamCommands, editCommand, }, dispatch), diff --git a/webapp/channels/src/components/integrations/edit_incoming_webhook/index.ts b/webapp/channels/src/components/integrations/edit_incoming_webhook/index.ts index ec8e1f3323..8328dcfeed 100644 --- a/webapp/channels/src/components/integrations/edit_incoming_webhook/index.ts +++ b/webapp/channels/src/components/integrations/edit_incoming_webhook/index.ts @@ -3,14 +3,12 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {IncomingWebhook} from '@mattermost/types/integrations'; import type {GlobalState} from '@mattermost/types/store'; import {getIncomingHook, updateIncomingHook} from 'mattermost-redux/actions/integrations'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import EditIncomingWebhook from './edit_incoming_webhook'; @@ -18,11 +16,6 @@ type Props = { location: Location; } -type Actions = { - updateIncomingHook: (hook: IncomingWebhook) => Promise; - getIncomingHook: (hookId: string) => Promise; -} - function mapStateToProps(state: GlobalState, ownProps: Props) { const config = getConfig(state); const enableIncomingWebhooks = config.EnableIncomingWebhooks === 'true'; @@ -39,9 +32,9 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ updateIncomingHook, getIncomingHook, }, dispatch), diff --git a/webapp/channels/src/components/integrations/edit_oauth_app/edit_oauth_app.tsx b/webapp/channels/src/components/integrations/edit_oauth_app/edit_oauth_app.tsx index ba491a76a7..83cfa20eab 100644 --- a/webapp/channels/src/components/integrations/edit_oauth_app/edit_oauth_app.tsx +++ b/webapp/channels/src/components/integrations/edit_oauth_app/edit_oauth_app.tsx @@ -21,7 +21,7 @@ const FOOTER = {id: 'update_incoming_webhook.update', defaultMessage: 'Update'}; const LOADING = {id: 'update_incoming_webhook.updating', defaultMessage: 'Updating...'}; type Actions = { - getOAuthApp: (id: string) => OAuthApp; + getOAuthApp: (id: string) => void; editOAuthApp: (app: OAuthApp) => Promise; }; diff --git a/webapp/channels/src/components/integrations/edit_oauth_app/index.ts b/webapp/channels/src/components/integrations/edit_oauth_app/index.ts index df536c0160..3964c917a6 100644 --- a/webapp/channels/src/components/integrations/edit_oauth_app/index.ts +++ b/webapp/channels/src/components/integrations/edit_oauth_app/index.ts @@ -6,22 +6,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; -import type {OAuthApp} from '@mattermost/types/integrations'; import type {GlobalState} from '@mattermost/types/store'; import {getOAuthApp, editOAuthApp} from 'mattermost-redux/actions/integrations'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; -import type {ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import EditOAuthApp from './edit_oauth_app'; -type Actions = { - getOAuthApp: (id: string) => OAuthApp; - editOAuthApp: (app: OAuthApp) => Promise; -}; - type Props = { location: Location; }; @@ -40,7 +33,7 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getOAuthApp, editOAuthApp, }, dispatch), diff --git a/webapp/channels/src/components/integrations/edit_outgoing_webhook/edit_outgoing_webhook.tsx b/webapp/channels/src/components/integrations/edit_outgoing_webhook/edit_outgoing_webhook.tsx index 7be864c857..18c0df19fb 100644 --- a/webapp/channels/src/components/integrations/edit_outgoing_webhook/edit_outgoing_webhook.tsx +++ b/webapp/channels/src/components/integrations/edit_outgoing_webhook/edit_outgoing_webhook.tsx @@ -4,10 +4,11 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; -import type {ServerError} from '@mattermost/types/errors'; import type {OutgoingWebhook} from '@mattermost/types/integrations'; import type {Team} from '@mattermost/types/teams'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import ConfirmModal from 'components/confirm_modal'; import AbstractOutgoingWebhook from 'components/integrations/abstract_outgoing_webhook'; import LoadingScreen from 'components/loading_screen'; @@ -18,7 +19,7 @@ const HEADER = {id: 'integrations.edit', defaultMessage: 'Edit'}; const FOOTER = {id: 'update_outgoing_webhook.update', defaultMessage: 'Update'}; const LOADING = {id: 'update_outgoing_webhook.updating', defaultMessage: 'Updating...'}; -interface Props { +export interface Props { /** * The current team @@ -39,12 +40,12 @@ interface Props { /** * The function to call to update an outgoing webhook */ - updateOutgoingHook: (hook: OutgoingWebhook) => Promise<{ data: OutgoingWebhook; error: ServerError }>; + updateOutgoingHook: (hook: OutgoingWebhook) => Promise>; /** * The function to call to get an outgoing webhook */ - getOutgoingHook: (hookId: string) => Promise<{ data: OutgoingWebhook; error: ServerError }>; + getOutgoingHook: (hookId: string) => Promise>; }; /** @@ -121,7 +122,7 @@ export default class EditOutgoingWebhook extends React.PureComponent => { this.setState({serverError: ''}); - const {data, error}: {data: OutgoingWebhook; error: ServerError} = await this.props.actions.updateOutgoingHook(this.newHook!); + const {data, error} = await this.props.actions.updateOutgoingHook(this.newHook!); if (data) { getHistory().push(`/${this.props.team.name}/integrations/outgoing_webhooks`); diff --git a/webapp/channels/src/components/integrations/edit_outgoing_webhook/index.ts b/webapp/channels/src/components/integrations/edit_outgoing_webhook/index.ts index bc94df635d..92eae8c172 100644 --- a/webapp/channels/src/components/integrations/edit_outgoing_webhook/index.ts +++ b/webapp/channels/src/components/integrations/edit_outgoing_webhook/index.ts @@ -3,15 +3,12 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {ServerError} from '@mattermost/types/errors'; -import type {OutgoingWebhook} from '@mattermost/types/integrations'; import type {GlobalState} from '@mattermost/types/store'; import {getOutgoingHook, updateOutgoingHook} from 'mattermost-redux/actions/integrations'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import EditOutgoingWebhook from './edit_outgoing_webhook'; @@ -21,11 +18,6 @@ type OwnProps = { }; } -type Actions = { - updateOutgoingHook: (hook: OutgoingWebhook) => Promise<{ data: OutgoingWebhook; error: ServerError }>; - getOutgoingHook: (hookId: string) => Promise<{ data: OutgoingWebhook; error: ServerError }>; -} - function mapStateToProps(state: GlobalState, ownProps: OwnProps) { const config = getConfig(state); const hookId = (new URLSearchParams(ownProps.location.search)).get('id'); @@ -42,9 +34,9 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ updateOutgoingHook, getOutgoingHook, }, dispatch), diff --git a/webapp/channels/src/components/integrations/installed_commands/index.ts b/webapp/channels/src/components/integrations/installed_commands/index.ts index bee8b2b1f2..fa116746c9 100644 --- a/webapp/channels/src/components/integrations/installed_commands/index.ts +++ b/webapp/channels/src/components/integrations/installed_commands/index.ts @@ -3,14 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import {deleteCommand, regenCommandToken} from 'mattermost-redux/actions/integrations'; import {Permissions} from 'mattermost-redux/constants'; import {haveITeamPermission} from 'mattermost-redux/selectors/entities/roles'; -import type {GenericAction, ActionResult, ActionFunc} from 'mattermost-redux/types/actions'; import InstalledCommands from './installed_commands'; @@ -20,11 +19,6 @@ type Props = { }; } -type Actions = { - regenCommandToken: (id: string) => Promise; - deleteCommand: (id: string) => Promise; -} - function mapStateToProps(state: GlobalState, ownProps: Props) { const canManageOthersSlashCommands = haveITeamPermission(state, ownProps.team.id, Permissions.MANAGE_OTHERS_SLASH_COMMANDS); @@ -33,9 +27,9 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ regenCommandToken, deleteCommand, }, dispatch), diff --git a/webapp/channels/src/components/integrations/installed_incoming_webhooks/index.ts b/webapp/channels/src/components/integrations/installed_incoming_webhooks/index.ts index 3123e5a27f..9bf7832eb8 100644 --- a/webapp/channels/src/components/integrations/installed_incoming_webhooks/index.ts +++ b/webapp/channels/src/components/integrations/installed_incoming_webhooks/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; @@ -15,17 +15,11 @@ import {getIncomingHooks} from 'mattermost-redux/selectors/entities/integrations import {haveITeamPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getUsers} from 'mattermost-redux/selectors/entities/users'; -import type {ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {loadIncomingHooksAndProfilesForTeam} from 'actions/integration_actions'; import InstalledIncomingWebhooks from './installed_incoming_webhooks'; -type Actions = { - removeIncomingHook: (hookId: string) => Promise; - loadIncomingHooksAndProfilesForTeam: (teamId: string, startPageNumber: number, pageSize: string) => Promise; -} - function mapStateToProps(state: GlobalState) { const config = getConfig(state); const teamId = getCurrentTeamId(state); @@ -45,9 +39,9 @@ function mapStateToProps(state: GlobalState) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ loadIncomingHooksAndProfilesForTeam, removeIncomingHook, }, dispatch), diff --git a/webapp/channels/src/components/integrations/installed_incoming_webhooks/installed_incoming_webhooks.tsx b/webapp/channels/src/components/integrations/installed_incoming_webhooks/installed_incoming_webhooks.tsx index 732246c1fa..68f1b06383 100644 --- a/webapp/channels/src/components/integrations/installed_incoming_webhooks/installed_incoming_webhooks.tsx +++ b/webapp/channels/src/components/integrations/installed_incoming_webhooks/installed_incoming_webhooks.tsx @@ -31,7 +31,7 @@ type Props = { actions: { removeIncomingHook: (hookId: string) => Promise; loadIncomingHooksAndProfilesForTeam: (teamId: string, startPageNumber: number, - pageSize: string) => Promise; + pageSize: number) => Promise; }; } @@ -53,7 +53,7 @@ export default class InstalledIncomingWebhooks extends React.PureComponent this.setState({loading: false}), ); diff --git a/webapp/channels/src/components/integrations/installed_oauth_apps/index.ts b/webapp/channels/src/components/integrations/installed_oauth_apps/index.ts index f06c93419d..be47ee11c0 100644 --- a/webapp/channels/src/components/integrations/installed_oauth_apps/index.ts +++ b/webapp/channels/src/components/integrations/installed_oauth_apps/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; @@ -13,7 +13,6 @@ import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getAppsOAuthAppIDs, getOAuthApps} from 'mattermost-redux/selectors/entities/integrations'; import {haveISystemPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; -import type {GenericAction} from 'mattermost-redux/types/actions'; import {loadOAuthAppsAndProfiles} from 'actions/integration_actions'; @@ -32,15 +31,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - loadOAuthAppsAndProfiles: (page?: number, perPage?: number) => Promise; - regenOAuthAppSecret: (appId: string) => Promise<{ error?: Error }>; - deleteOAuthApp: (appId: string) => Promise; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ loadOAuthAppsAndProfiles, regenOAuthAppSecret, deleteOAuthApp, diff --git a/webapp/channels/src/components/integrations/installed_oauth_apps/installed_oauth_apps.tsx b/webapp/channels/src/components/integrations/installed_oauth_apps/installed_oauth_apps.tsx index 1dc75021c5..62e8babfef 100644 --- a/webapp/channels/src/components/integrations/installed_oauth_apps/installed_oauth_apps.tsx +++ b/webapp/channels/src/components/integrations/installed_oauth_apps/installed_oauth_apps.tsx @@ -6,6 +6,8 @@ import {FormattedMessage} from 'react-intl'; import type {OAuthApp} from '@mattermost/types/integrations'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import BackstageList from 'components/backstage/components/backstage_list'; import ExternalLink from 'components/external_link'; import FormattedMarkdownMessage from 'components/formatted_markdown_message'; @@ -50,17 +52,17 @@ type Props = { /** * The function to call to fetch OAuth apps */ - loadOAuthAppsAndProfiles: (page?: number, perPage?: number) => Promise; + loadOAuthAppsAndProfiles: (page?: number, perPage?: number) => Promise; /** * The function to call when Regenerate Secret link is clicked */ - regenOAuthAppSecret: (appId: string) => Promise<{ error?: Error }>; + regenOAuthAppSecret: (appId: string) => Promise; /** * The function to call when Delete link is clicked */ - deleteOAuthApp: (appId: string) => Promise; + deleteOAuthApp: (appId: string) => Promise; }); }; diff --git a/webapp/channels/src/components/integrations/installed_outgoing_webhooks/index.ts b/webapp/channels/src/components/integrations/installed_outgoing_webhooks/index.ts index aeb37041f4..ed96468efd 100644 --- a/webapp/channels/src/components/integrations/installed_outgoing_webhooks/index.ts +++ b/webapp/channels/src/components/integrations/installed_outgoing_webhooks/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import * as Actions from 'mattermost-redux/actions/integrations'; import {Permissions} from 'mattermost-redux/constants'; @@ -19,7 +19,6 @@ import {loadOutgoingHooksAndProfilesForTeam} from 'actions/integration_actions'; import type {GlobalState} from 'types/store'; import InstalledOutgoingWebhook from './installed_outgoing_webhooks'; -import type {Props} from './installed_outgoing_webhooks'; function mapStateToProps(state: GlobalState) { const config = getConfig(state); @@ -43,7 +42,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ loadOutgoingHooksAndProfilesForTeam, removeOutgoingHook: Actions.removeOutgoingHook, regenOutgoingHookToken: Actions.regenOutgoingHookToken, diff --git a/webapp/channels/src/components/integrations/installed_outgoing_webhooks/installed_outgoing_webhooks.tsx b/webapp/channels/src/components/integrations/installed_outgoing_webhooks/installed_outgoing_webhooks.tsx index 883b94ce89..221a26ded4 100644 --- a/webapp/channels/src/components/integrations/installed_outgoing_webhooks/installed_outgoing_webhooks.tsx +++ b/webapp/channels/src/components/integrations/installed_outgoing_webhooks/installed_outgoing_webhooks.tsx @@ -10,6 +10,8 @@ import type {Team} from '@mattermost/types/teams'; import type {UserProfile} from '@mattermost/types/users'; import type {IDMappedObjects} from '@mattermost/types/utilities'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import BackstageList from 'components/backstage/components/backstage_list'; import ExternalLink from 'components/external_link'; import FormattedMarkdownMessage from 'components/formatted_markdown_message'; @@ -60,17 +62,17 @@ export type Props = { /** * The function to call for removing outgoingWebhook */ - removeOutgoingHook: (hookId: string) => Promise; + removeOutgoingHook: (hookId: string) => Promise; /** * The function to call for outgoingWebhook List and for the status of api */ - loadOutgoingHooksAndProfilesForTeam: (teamId: string, page: number, perPage: number) => Promise; + loadOutgoingHooksAndProfilesForTeam: (teamId: string, page: number, perPage: number) => Promise; /** * The function to call for regeneration of webhook token */ - regenOutgoingHookToken: (hookId: string) => Promise; + regenOutgoingHookToken: (hookId: string) => Promise; }; /** diff --git a/webapp/channels/src/components/interactive_dialog/dialog_element/index.ts b/webapp/channels/src/components/interactive_dialog/dialog_element/index.ts index 1f9ef93fce..c640c0df43 100644 --- a/webapp/channels/src/components/interactive_dialog/dialog_element/index.ts +++ b/webapp/channels/src/components/interactive_dialog/dialog_element/index.ts @@ -3,19 +3,16 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; +import type {Dispatch} from 'redux'; import {autocompleteChannels} from 'actions/channel_actions'; import {autocompleteUsers} from 'actions/user_actions'; import DialogElement from './dialog_element'; -import type {Props} from './dialog_element'; -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ autocompleteChannels, autocompleteUsers, }, dispatch), diff --git a/webapp/channels/src/components/intl_provider/intl_provider.tsx b/webapp/channels/src/components/intl_provider/intl_provider.tsx index 90f3324539..9f8ec2b3c2 100644 --- a/webapp/channels/src/components/intl_provider/intl_provider.tsx +++ b/webapp/channels/src/components/intl_provider/intl_provider.tsx @@ -7,7 +7,6 @@ import {IntlProvider as BaseIntlProvider} from 'react-intl'; import type {IntlConfig} from 'react-intl'; import {Client4} from 'mattermost-redux/client'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import {setLocalizeFunction} from 'mattermost-redux/utils/i18n_utils'; import * as I18n from 'i18n/i18n'; @@ -18,7 +17,7 @@ type Props = { locale: IntlConfig['locale']; translations?: IntlConfig['messages']; actions: { - loadTranslations: ((locale: string, url: string) => ActionFunc) | (() => void); + loadTranslations: (locale: string, url: string) => void; }; }; diff --git a/webapp/channels/src/components/invitation_modal/index.tsx b/webapp/channels/src/components/invitation_modal/index.tsx index 66b3323921..25dc6164c2 100644 --- a/webapp/channels/src/components/invitation_modal/index.tsx +++ b/webapp/channels/src/components/invitation_modal/index.tsx @@ -4,10 +4,9 @@ import React from 'react'; import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {Channel} from '@mattermost/types/channels'; -import type {UserProfile} from '@mattermost/types/users'; import {searchChannels as reduxSearchChannels} from 'mattermost-redux/actions/channels'; import {regenerateTeamInviteId} from 'mattermost-redux/actions/teams'; @@ -18,7 +17,6 @@ import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general import {haveIChannelPermission, haveICurrentTeamPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeam, getCurrentTeamId, getTeam} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {isAdmin} from 'mattermost-redux/utils/user_utils'; import { @@ -26,7 +24,6 @@ import { sendGuestsInvites, sendMembersInvitesToChannels, } from 'actions/invite_actions'; -import type {CloseModalType} from 'actions/views/modals'; import {makeAsyncComponent} from 'components/async_load'; @@ -34,8 +31,6 @@ import {Constants} from 'utils/constants'; import type {GlobalState} from 'types/store'; -import type {InviteResults} from './result_view'; - const InvitationModal = makeAsyncComponent('InvitationModal', React.lazy(() => import('./invitation_modal'))); const searchProfiles = (term: string, options = {}) => { @@ -94,18 +89,9 @@ export function mapStateToProps(state: GlobalState, props: OwnProps) { }; } -type Actions = { - sendGuestsInvites: (teamId: string, channels: Channel[], users: UserProfile[], emails: string[], message: string) => Promise<{data: InviteResults}>; - sendMembersInvites: (teamId: string, users: UserProfile[], emails: string[]) => Promise<{data: InviteResults}>; - sendMembersInvitesToChannels: (teamId: string, channels: Channel[], users: UserProfile[], emails: string[], message: string) => Promise<{data: InviteResults}>; - regenerateTeamInviteId: (teamId: string) => void; - searchProfiles: (term: string, options?: Record) => Promise<{data: UserProfile[]}>; - searchChannels: (teamId: string, term: string) => ActionFunc; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ sendGuestsInvites, sendMembersInvites, sendMembersInvitesToChannels, diff --git a/webapp/channels/src/components/invitation_modal/invitation_modal.tsx b/webapp/channels/src/components/invitation_modal/invitation_modal.tsx index fe5701125e..7b316a5500 100644 --- a/webapp/channels/src/components/invitation_modal/invitation_modal.tsx +++ b/webapp/channels/src/components/invitation_modal/invitation_modal.tsx @@ -11,7 +11,7 @@ import type {Team} from '@mattermost/types/teams'; import type {UserProfile} from '@mattermost/types/users'; import {debounce} from 'mattermost-redux/actions/helpers'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import deepFreeze from 'mattermost-redux/utils/deep_freeze'; import {isEmail} from 'mattermost-redux/utils/helpers'; @@ -35,29 +35,29 @@ type Backdrop = 'static' | boolean export type Props = { actions: { - searchChannels: (teamId: string, term: string) => ActionFunc; + searchChannels: (teamId: string, term: string) => Promise>; regenerateTeamInviteId: (teamId: string) => void; - searchProfiles: (term: string, options?: Record) => Promise<{data: UserProfile[]}>; + searchProfiles: (term: string, options?: Record) => Promise>; sendGuestsInvites: ( currentTeamId: string, channels: Channel[], users: UserProfile[], emails: string[], message: string, - ) => Promise<{data: InviteResults}>; + ) => Promise>; sendMembersInvites: ( teamId: string, users: UserProfile[], emails: string[] - ) => Promise<{data: InviteResults}>; + ) => Promise>; sendMembersInvitesToChannels: ( teamId: string, channels: Channel[], users: UserProfile[], emails: string[], message: string, - ) => Promise<{data: InviteResults}>; + ) => Promise>; }; currentTeam: Team; currentChannel: Channel; @@ -186,10 +186,10 @@ export class InvitationModal extends React.PureComponent { emails, this.state.invite.customMessage.open ? this.state.invite.customMessage.message : '', ); - invites = result.data; + invites = result.data!; } else { const result = await this.props.actions.sendMembersInvites(this.props.currentTeam.id, users, emails); - invites = result.data; + invites = result.data!; } } else if (inviteAs === InviteType.GUEST) { const result = await this.props.actions.sendGuestsInvites( @@ -199,7 +199,7 @@ export class InvitationModal extends React.PureComponent { emails, this.state.invite.customMessage.open ? this.state.invite.customMessage.message : '', ); - invites = result.data; + invites = result.data!; } if (this.state.invite.usersEmailsSearch !== '') { @@ -287,9 +287,9 @@ export class InvitationModal extends React.PureComponent { debouncedSearchProfiles = debounce((term: string, callback: (users: UserProfile[]) => void) => { this.props.actions.searchProfiles(term). - then(({data}: {data: UserProfile[]}) => { - callback(data); - if (data.length === 0) { + then(({data}: ActionResult) => { + callback(data!); + if (data!.length === 0) { this.setState({termWithoutResults: term}); } else { this.setState({termWithoutResults: null}); diff --git a/webapp/channels/src/components/leave_team_modal/leave_team_modal.tsx b/webapp/channels/src/components/leave_team_modal/leave_team_modal.tsx index f745e27649..1d22dda50f 100644 --- a/webapp/channels/src/components/leave_team_modal/leave_team_modal.tsx +++ b/webapp/channels/src/components/leave_team_modal/leave_team_modal.tsx @@ -7,7 +7,6 @@ import {FormattedMessage} from 'react-intl'; import type {UserProfile} from '@mattermost/types/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import * as UserUtils from 'mattermost-redux/utils/user_utils'; import FormattedMarkdownMessage from 'components/formatted_markdown_message'; @@ -23,7 +22,7 @@ type Props = { numOfPrivateChannels: number; onExited: () => void; actions: { - leaveTeam: (teamId: string, userId: string) => ActionFunc; + leaveTeam: (teamId: string, userId: string) => void; toggleSideBarRightMenu: () => void; }; }; diff --git a/webapp/channels/src/components/markdown_image/index.ts b/webapp/channels/src/components/markdown_image/index.ts index 1f59c1553a..ad10648efc 100644 --- a/webapp/channels/src/components/markdown_image/index.ts +++ b/webapp/channels/src/components/markdown_image/index.ts @@ -3,18 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {Action, GenericAction} from 'mattermost-redux/types/actions'; +import type {Dispatch} from 'redux'; import {openModal} from 'actions/views/modals'; import MarkdownImage from './markdown_image'; -import type {Props} from './markdown_image'; -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ openModal, }, dispatch), }; diff --git a/webapp/channels/src/components/member_list_channel/index.ts b/webapp/channels/src/components/member_list_channel/index.ts index 554c49c31f..9d726bcb63 100644 --- a/webapp/channels/src/components/member_list_channel/index.ts +++ b/webapp/channels/src/components/member_list_channel/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {Channel, ChannelMembership} from '@mattermost/types/channels'; import type {UserProfile} from '@mattermost/types/users'; @@ -14,7 +14,6 @@ import {createSelector} from 'mattermost-redux/selectors/create_selector'; import {getMembersInCurrentChannel, getCurrentChannelStats, getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'; import {getMembersInCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; import {searchProfilesInCurrentChannel, getProfilesInCurrentChannel} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {sortByUsername} from 'mattermost-redux/utils/user_utils'; import {loadStatusesForProfilesList} from 'actions/status_actions'; @@ -27,7 +26,6 @@ import {setModalSearchTerm} from 'actions/views/search'; import type {GlobalState} from 'types/store'; import MemberListChannel from './member_list_channel'; -import type {Props} from './member_list_channel'; const getUsersAndActionsToDisplay = createSelector( 'getUsersAndActionsToDisplay', @@ -89,7 +87,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ getChannelMembers, searchProfiles, getChannelStats, diff --git a/webapp/channels/src/components/member_list_channel/member_list_channel.tsx b/webapp/channels/src/components/member_list_channel/member_list_channel.tsx index 0a5364fe27..1daed70466 100644 --- a/webapp/channels/src/components/member_list_channel/member_list_channel.tsx +++ b/webapp/channels/src/components/member_list_channel/member_list_channel.tsx @@ -6,6 +6,8 @@ import React from 'react'; import type {Channel, ChannelStats, ChannelMembership} from '@mattermost/types/channels'; import type {UserProfile} from '@mattermost/types/users'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import ChannelMembersDropdown from 'components/channel_members_dropdown'; import LoadingScreen from 'components/loading_screen'; import SearchableUserList from 'components/searchable_user_list/searchable_user_list_container'; @@ -30,27 +32,23 @@ export type Props = { totalChannelMembers: number; channel: Channel; actions: { - searchProfiles: (term: string, options?: Record) => Promise<{data: UserProfile[]}>; - getChannelMembers: (channelId: string) => Promise<{data: ChannelMembership[]}>; - getChannelStats: (channelId: string) => Promise<{data: ChannelStats}>; - setModalSearchTerm: (term: string) => Promise<{data: boolean}>; + searchProfiles: (term: string, options?: Record) => Promise>; + getChannelMembers: (channelId: string) => Promise>; + getChannelStats: (channelId: string) => Promise>; + setModalSearchTerm: (term: string) => void; loadProfilesAndTeamMembersAndChannelMembers: ( page: number, perPage: number, - teamId?: string, - channelId?: string, + teamId: string, + channelId: string, options?: any - ) => Promise<{ - data: boolean; - }>; - loadStatusesForProfilesList: (users: UserProfile[]) => Promise<{data: boolean}>; + ) => Promise; + loadStatusesForProfilesList: (users: UserProfile[]) => void; loadTeamMembersAndChannelMembersForProfilesList: ( - profiles: any, + profiles: UserProfile[], teamId: string, channelId: string - ) => Promise<{ - data: boolean; - }>; + ) => Promise; }; } @@ -109,8 +107,8 @@ export default class MemberListChannel extends React.PureComponent return; } - this.props.actions.loadStatusesForProfilesList(data); - this.props.actions.loadTeamMembersAndChannelMembersForProfilesList(data, this.props.currentTeamId, this.props.currentChannelId).then(({data: membersLoaded}) => { + this.props.actions.loadStatusesForProfilesList(data!); + this.props.actions.loadTeamMembersAndChannelMembersForProfilesList(data!, this.props.currentTeamId, this.props.currentChannelId).then(({data: membersLoaded}) => { if (membersLoaded) { this.loadComplete(); } @@ -128,7 +126,7 @@ export default class MemberListChannel extends React.PureComponent }; nextPage = (page: number) => { - this.props.actions.loadProfilesAndTeamMembersAndChannelMembers(page + 1, USERS_PER_PAGE, undefined, undefined, {active: true}); + this.props.actions.loadProfilesAndTeamMembersAndChannelMembers(page + 1, USERS_PER_PAGE, '', '', {active: true}); }; handleSearch = (term: string) => { diff --git a/webapp/channels/src/components/member_list_team/index.ts b/webapp/channels/src/components/member_list_team/index.ts index a8b80ba6dd..796cfb5c41 100644 --- a/webapp/channels/src/components/member_list_team/index.ts +++ b/webapp/channels/src/components/member_list_team/index.ts @@ -3,10 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {GetTeamMembersOpts, TeamStats, TeamMembership} from '@mattermost/types/teams'; -import type {UserProfile} from '@mattermost/types/users'; +import type {Dispatch} from 'redux'; import {getTeamStats, getTeamMembers} from 'mattermost-redux/actions/teams'; import {searchProfiles} from 'mattermost-redux/actions/users'; @@ -14,7 +11,6 @@ import {Permissions} from 'mattermost-redux/constants'; import {haveITeamPermission} from 'mattermost-redux/selectors/entities/roles'; import {getMembersInCurrentTeam, getCurrentTeamStats} from 'mattermost-redux/selectors/entities/teams'; import {getProfilesInCurrentTeam, searchProfilesInCurrentTeam} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction, ActionResult} from 'mattermost-redux/types/actions'; import {loadStatusesForProfilesList} from 'actions/status_actions'; import {loadProfilesAndTeamMembers, loadTeamMembersForProfilesList} from 'actions/user_actions'; @@ -28,22 +24,6 @@ type Props = { teamId: string; } -type Actions = { - getTeamMembers: (teamId: string, page?: number, perPage?: number, options?: GetTeamMembersOpts) => Promise<{data: TeamMembership}>; - searchProfiles: (term: string, options?: {[key: string]: any}) => Promise<{data: UserProfile[]}>; - getTeamStats: (teamId: string) => Promise<{data: TeamStats}>; - loadProfilesAndTeamMembers: (page: number, perPage: number, teamId?: string, options?: {[key: string]: any}) => Promise<{ - data: boolean; - }>; - loadStatusesForProfilesList: (users: UserProfile[]) => Promise<{ - data: boolean; - }>; - loadTeamMembersForProfilesList: (profiles: any, teamId: string, reloadAllMembers: boolean) => Promise<{ - data: boolean; - }>; - setModalSearchTerm: (term: string) => ActionResult; -} - function mapStateToProps(state: GlobalState, ownProps: Props) { const canManageTeamMembers = haveITeamPermission(state, ownProps.teamId, Permissions.MANAGE_TEAM_ROLES); @@ -70,7 +50,7 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ searchProfiles, getTeamStats, getTeamMembers, diff --git a/webapp/channels/src/components/member_list_team/member_list_team.tsx b/webapp/channels/src/components/member_list_team/member_list_team.tsx index 820856fc5b..08f413393f 100644 --- a/webapp/channels/src/components/member_list_team/member_list_team.tsx +++ b/webapp/channels/src/components/member_list_team/member_list_team.tsx @@ -27,18 +27,12 @@ type Props = { totalTeamMembers: number; canManageTeamMembers?: boolean; actions: { - getTeamMembers: (teamId: string, page?: number, perPage?: number, options?: GetTeamMembersOpts) => Promise<{data: TeamMembership}>; - searchProfiles: (term: string, options?: {[key: string]: any}) => Promise<{data: UserProfile[]}>; - getTeamStats: (teamId: string) => Promise<{data: TeamStats}>; - loadProfilesAndTeamMembers: (page: number, perPage: number, teamId?: string, options?: {[key: string]: any}) => Promise<{ - data: boolean; - }>; - loadStatusesForProfilesList: (users: UserProfile[]) => Promise<{ - data: boolean; - }>; - loadTeamMembersForProfilesList: (profiles: any, teamId: string, reloadAllMembers: boolean) => Promise<{ - data: boolean; - }>; + getTeamMembers: (teamId: string, page?: number, perPage?: number, options?: GetTeamMembersOpts) => Promise>; + searchProfiles: (term: string, options?: {[key: string]: any}) => Promise>; + getTeamStats: (teamId: string) => Promise>; + loadProfilesAndTeamMembers: (page: number, perPage: number, teamId: string, options?: {[key: string]: any}) => Promise; + loadStatusesForProfilesList: (users: UserProfile[]) => void; + loadTeamMembersForProfilesList: (profiles: any, teamId: string, reloadAllMembers: boolean) => Promise; setModalSearchTerm: (term: string) => ActionResult; }; } @@ -67,7 +61,7 @@ export default class MemberListTeam extends React.PureComponent { { sort: Teams.SORT_USERNAME_OPTION, exclude_deleted_users: true, - } as GetTeamMembersOpts, + }, ), this.props.actions.getTeamStats(this.props.currentTeamId), ]); @@ -104,7 +98,7 @@ export default class MemberListTeam extends React.PureComponent { this.setState({loading: true}); - loadStatusesForProfilesList(data); + loadStatusesForProfilesList(data!); loadTeamMembersForProfilesList(data, this.props.currentTeamId, true).then(({data: membersLoaded}) => { if (membersLoaded) { this.loadComplete(); diff --git a/webapp/channels/src/components/mfa/setup/index.ts b/webapp/channels/src/components/mfa/setup/index.ts index f526170549..c25286a6bd 100644 --- a/webapp/channels/src/components/mfa/setup/index.ts +++ b/webapp/channels/src/components/mfa/setup/index.ts @@ -3,13 +3,12 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import {activateMfa, generateMfaSecret} from 'actions/views/mfa'; @@ -28,14 +27,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - activateMfa: (code: string) => Promise<{ error?: { server_error_id: string; message: string } }>; - generateMfaSecret: () => Promise<{data: { secret: string; qr_code: string }; error?: { message: string }}>; -}; - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ activateMfa, generateMfaSecret, }, dispatch), diff --git a/webapp/channels/src/components/modal_controller/index.ts b/webapp/channels/src/components/modal_controller/index.ts index e6c75d403c..c192ed798b 100644 --- a/webapp/channels/src/components/modal_controller/index.ts +++ b/webapp/channels/src/components/modal_controller/index.ts @@ -3,9 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {Action, GenericAction} from 'mattermost-redux/types/actions.js'; +import type {Dispatch} from 'redux'; import {closeModal} from 'actions/views/modals'; @@ -19,13 +17,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - closeModal: (modalId: string) => void; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ closeModal, }, dispatch), }; diff --git a/webapp/channels/src/components/more_direct_channels/index.ts b/webapp/channels/src/components/more_direct_channels/index.ts index fa95aff87a..f8d35ac2fc 100644 --- a/webapp/channels/src/components/more_direct_channels/index.ts +++ b/webapp/channels/src/components/more_direct_channels/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {UserProfile} from '@mattermost/types/users'; @@ -25,7 +25,6 @@ import { searchProfilesInCurrentTeam, getTotalUsersStats as getTotalUsersStatsSelector, } from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {openDirectChannelToUserId, openGroupChannelToUserIds} from 'actions/channel_actions'; import {loadStatusesForProfilesList, loadProfilesMissingStatus} from 'actions/status_actions'; @@ -84,25 +83,9 @@ const makeMapStateToProps = () => { }; }; -type Actions = { - getProfiles: (page?: number | undefined, perPage?: number | undefined, options?: any) => Promise; - getProfilesInTeam: (teamId: string, page: number, perPage?: number | undefined, sort?: string | undefined, options?: any) => Promise; - loadProfilesMissingStatus: (users: UserProfile[]) => ActionFunc; - getTotalUsersStats: () => ActionFunc; - loadStatusesForProfilesList: (users: any) => { - data: boolean; - }; - loadProfilesForGroupChannels: (groupChannels: any) => Promise; - openDirectChannelToUserId: (userId: any) => Promise; - openGroupChannelToUserIds: (userIds: any) => Promise; - searchProfiles: (term: string, options?: any) => Promise; - searchGroupChannels: (term: string) => Promise; - setModalSearchTerm: (term: any) => GenericAction; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getProfiles, getProfilesInTeam, loadProfilesMissingStatus, diff --git a/webapp/channels/src/components/more_direct_channels/more_direct_channels.test.tsx b/webapp/channels/src/components/more_direct_channels/more_direct_channels.test.tsx index 5621b33e04..13abb78651 100644 --- a/webapp/channels/src/components/more_direct_channels/more_direct_channels.test.tsx +++ b/webapp/channels/src/components/more_direct_channels/more_direct_channels.test.tsx @@ -54,8 +54,8 @@ describe('components/MoreDirectChannels', () => { onExited: jest.fn(), actions: { getProfiles: jest.fn(() => { - return new Promise((resolve) => { - process.nextTick(() => resolve()); + return new Promise((resolve) => { + process.nextTick(() => resolve({data: true})); }); }), getProfilesInTeam: jest.fn().mockResolvedValue({data: true}), diff --git a/webapp/channels/src/components/more_direct_channels/more_direct_channels.tsx b/webapp/channels/src/components/more_direct_channels/more_direct_channels.tsx index 06b93290fb..8c4e5c9d55 100644 --- a/webapp/channels/src/components/more_direct_channels/more_direct_channels.tsx +++ b/webapp/channels/src/components/more_direct_channels/more_direct_channels.tsx @@ -6,9 +6,10 @@ import React from 'react'; import {Modal} from 'react-bootstrap'; import {FormattedMessage} from 'react-intl'; +import type {Channel} from '@mattermost/types/channels'; import type {UserProfile} from '@mattermost/types/users'; -import type {GenericAction} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import type MultiSelect from 'components/multiselect/multiselect'; @@ -49,19 +50,17 @@ export type Props = { onModalDismissed?: () => void; onExited?: () => void; actions: { - getProfiles: (page?: number | undefined, perPage?: number | undefined, options?: any) => Promise; - getProfilesInTeam: (teamId: string, page: number, perPage?: number | undefined, sort?: string | undefined, options?: any) => Promise; + getProfiles: (page?: number | undefined, perPage?: number | undefined, options?: any) => Promise; + getProfilesInTeam: (teamId: string, page: number, perPage?: number | undefined, sort?: string | undefined, options?: any) => Promise; loadProfilesMissingStatus: (users: UserProfile[]) => void; getTotalUsersStats: () => void; - loadStatusesForProfilesList: (users: any) => { - data: boolean; - }; - loadProfilesForGroupChannels: (groupChannels: any) => void; - openDirectChannelToUserId: (userId: any) => Promise; - openGroupChannelToUserIds: (userIds: any) => Promise; - searchProfiles: (term: string, options?: any) => Promise; - searchGroupChannels: (term: string) => Promise; - setModalSearchTerm: (term: any) => GenericAction; + loadStatusesForProfilesList: (users: UserProfile[]) => void; + loadProfilesForGroupChannels: (groupChannels: Channel[]) => void; + openDirectChannelToUserId: (userId: string) => Promise; + openGroupChannelToUserIds: (userIds: string[]) => Promise; + searchProfiles: (term: string, options: any) => Promise>; + searchGroupChannels: (term: string) => Promise>; + setModalSearchTerm: (term: string) => void; }; } diff --git a/webapp/channels/src/components/move_thread_modal/index.ts b/webapp/channels/src/components/move_thread_modal/index.ts index e0bea32e62..0a4fd2c23f 100644 --- a/webapp/channels/src/components/move_thread_modal/index.ts +++ b/webapp/channels/src/components/move_thread_modal/index.ts @@ -3,21 +3,20 @@ import type {ConnectedProps} from 'react-redux'; import {connect} from 'react-redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {bindActionCreators} from 'redux'; import {moveThread} from 'mattermost-redux/actions/posts'; import {joinChannelById, switchToChannel} from 'actions/views/channel'; -import type {ActionProps} from './move_thread_modal'; import MoveThreadModal from './move_thread_modal'; export type PropsFromRedux = ConnectedProps; function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, ActionProps>({ + actions: bindActionCreators({ joinChannelById, switchToChannel, moveThread, diff --git a/webapp/channels/src/components/password_reset_form/index.ts b/webapp/channels/src/components/password_reset_form/index.ts index 36815b7ad8..f2e29e3aa1 100644 --- a/webapp/channels/src/components/password_reset_form/index.ts +++ b/webapp/channels/src/components/password_reset_form/index.ts @@ -3,28 +3,21 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {ServerError} from '@mattermost/types/errors'; +import type {Dispatch} from 'redux'; import {resetUserPassword} from 'mattermost-redux/actions/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import PasswordResetForm from './password_reset_form'; -type Actions = { - resetUserPassword: (token: string, newPassword: string) => Promise<{data: any; error: ServerError}>; -} - function mapStateToProps(state: GlobalState) { return {siteName: getConfig(state).SiteName}; } -const mapDispatchToProps = (dispatch: Dispatch) => ({ - actions: bindActionCreators, Actions>({ +const mapDispatchToProps = (dispatch: Dispatch) => ({ + actions: bindActionCreators({ resetUserPassword, }, dispatch), }); diff --git a/webapp/channels/src/components/password_reset_form/password_reset_form.tsx b/webapp/channels/src/components/password_reset_form/password_reset_form.tsx index ee9d6c94f6..42d6a35963 100644 --- a/webapp/channels/src/components/password_reset_form/password_reset_form.tsx +++ b/webapp/channels/src/components/password_reset_form/password_reset_form.tsx @@ -6,14 +6,14 @@ import React, {useState, useRef, memo} from 'react'; import {FormattedMessage, useIntl} from 'react-intl'; import {useHistory} from 'react-router-dom'; -import type {ServerError} from '@mattermost/types/errors'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import Constants from 'utils/constants'; -interface Props { +export interface Props { location: {search: string}; actions: { - resetUserPassword: (token: string, newPassword: string) => Promise<{data: any; error: ServerError}>; + resetUserPassword: (token: string, newPassword: string) => Promise; }; siteName?: string; } diff --git a/webapp/channels/src/components/password_reset_send_link/index.ts b/webapp/channels/src/components/password_reset_send_link/index.ts index 40bdfef111..c09f2c1c3e 100644 --- a/webapp/channels/src/components/password_reset_send_link/index.ts +++ b/webapp/channels/src/components/password_reset_send_link/index.ts @@ -3,21 +3,14 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; - -import type {ServerError} from '@mattermost/types/errors'; +import type {Dispatch} from 'redux'; import {sendPasswordResetEmail} from 'mattermost-redux/actions/users'; -import type {GenericAction, ActionFunc} from 'mattermost-redux/types/actions'; import PasswordResetSendLink from './password_reset_send_link'; -type Actions = { - sendPasswordResetEmail: (emal: string) => Promise<{data: any; error: ServerError}>; -} - -const mapDispatchToProps = (dispatch: Dispatch) => ({ - actions: bindActionCreators, Actions>({ +const mapDispatchToProps = (dispatch: Dispatch) => ({ + actions: bindActionCreators({ sendPasswordResetEmail, }, dispatch), }); diff --git a/webapp/channels/src/components/password_reset_send_link/password_reset_send_link.tsx b/webapp/channels/src/components/password_reset_send_link/password_reset_send_link.tsx index f6379e47de..ef557132ae 100644 --- a/webapp/channels/src/components/password_reset_send_link/password_reset_send_link.tsx +++ b/webapp/channels/src/components/password_reset_send_link/password_reset_send_link.tsx @@ -4,15 +4,14 @@ import React from 'react'; import {FormattedMessage, injectIntl, type IntlShape} from 'react-intl'; -import type {ServerError} from '@mattermost/types/errors'; - +import type {ActionResult} from 'mattermost-redux/types/actions'; import {isEmail} from 'mattermost-redux/utils/helpers'; import BackButton from 'components/common/back_button'; -interface Props { +export interface Props { actions: { - sendPasswordResetEmail: (email: string) => Promise<{data: any; error: ServerError}>; + sendPasswordResetEmail: (email: string) => Promise; }; intl: IntlShape; } diff --git a/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_app/index.ts b/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_app/index.ts index 837f8f996d..3b9e764200 100644 --- a/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_app/index.ts +++ b/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_app/index.ts @@ -3,9 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {GenericAction} from 'mattermost-redux/types/actions'; +import type {Dispatch} from 'redux'; import {installApp} from 'actions/marketplace'; import {trackEvent} from 'actions/telemetry_actions.jsx'; @@ -17,7 +15,6 @@ import {ModalIdentifiers} from 'utils/constants'; import type {GlobalState} from 'types/store'; import MarketplaceItemApp from './marketplace_item_app'; -import type {MarketplaceItemAppProps} from './marketplace_item_app'; type Props = { id: string; @@ -34,9 +31,9 @@ function mapStateToProps(state: GlobalState, props: Props) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ installApp, closeMarketplaceModal: () => closeModal(ModalIdentifiers.PLUGIN_MARKETPLACE), }, dispatch), diff --git a/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_plugin/index.ts b/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_plugin/index.ts index 87ed7e7f52..6838bdac7d 100644 --- a/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_plugin/index.ts +++ b/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_plugin/index.ts @@ -3,11 +3,10 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getPluginStatus} from 'mattermost-redux/selectors/entities/admin'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; -import type {GenericAction} from 'mattermost-redux/types/actions'; import {installPlugin} from 'actions/marketplace'; import {trackEvent} from 'actions/telemetry_actions.jsx'; @@ -19,7 +18,6 @@ import {ModalIdentifiers} from 'utils/constants'; import type {GlobalState} from 'types/store'; import MarketplaceItemPlugin from './marketplace_item_plugin'; -import type {MarketplaceItemPluginProps} from './marketplace_item_plugin'; type Props = { id: string; @@ -41,9 +39,9 @@ function mapStateToProps(state: GlobalState, props: Props) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ installPlugin, closeMarketplaceModal: () => closeModal(ModalIdentifiers.PLUGIN_MARKETPLACE), }, dispatch), diff --git a/webapp/channels/src/components/post_edit_history/edited_post_item/index.ts b/webapp/channels/src/components/post_edit_history/edited_post_item/index.ts index 866bcd1daa..e89aa0635f 100644 --- a/webapp/channels/src/components/post_edit_history/edited_post_item/index.ts +++ b/webapp/channels/src/components/post_edit_history/edited_post_item/index.ts @@ -4,9 +4,7 @@ import {connect} from 'react-redux'; import type {ConnectedProps} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {Post} from '@mattermost/types/posts'; +import type {Dispatch} from 'redux'; import {getPost} from 'mattermost-redux/selectors/entities/posts'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; @@ -16,7 +14,6 @@ import {editPost} from 'actions/views/posts'; import {closeRightHandSide} from 'actions/views/rhs'; import {getSelectedPostId} from 'selectors/rhs'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import EditedPostItem from './edited_post_item'; @@ -31,15 +28,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - editPost: (post: Post) => Promise<{data: Post}>; - closeRightHandSide: () => void; - openModal:

(modalData: ModalData

) => void; -}; - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ editPost, closeRightHandSide, openModal, diff --git a/webapp/channels/src/components/post_view/combined_system_message/combined_system_message.tsx b/webapp/channels/src/components/post_view/combined_system_message/combined_system_message.tsx index 8030766568..744679049d 100644 --- a/webapp/channels/src/components/post_view/combined_system_message/combined_system_message.tsx +++ b/webapp/channels/src/components/post_view/combined_system_message/combined_system_message.tsx @@ -8,7 +8,6 @@ import type {IntlShape, MessageDescriptor} from 'react-intl'; import type {UserProfile} from '@mattermost/types/users'; import {Posts} from 'mattermost-redux/constants'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import Markdown from 'components/markdown'; @@ -200,8 +199,8 @@ export type Props = { showJoinLeave: boolean; userProfiles: UserProfile[]; actions: { - getMissingProfilesByIds: (userIds: string[]) => ActionFunc ; - getMissingProfilesByUsernames: (usernames: string[]) => ActionFunc; + getMissingProfilesByIds: (userIds: string[]) => void; + getMissingProfilesByUsernames: (usernames: string[]) => void; }; } diff --git a/webapp/channels/src/components/post_view/embedded_bindings/button_binding/index.ts b/webapp/channels/src/components/post_view/embedded_bindings/button_binding/index.ts index 8921a188ed..9d03eae7c2 100644 --- a/webapp/channels/src/components/post_view/embedded_bindings/button_binding/index.ts +++ b/webapp/channels/src/components/post_view/embedded_bindings/button_binding/index.ts @@ -3,27 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getChannel} from 'mattermost-redux/actions/channels'; -import type {ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {postEphemeralCallResponseForPost, handleBindingClick, openAppsModal} from 'actions/apps'; -import type {PostEphemeralCallResponseForPost, HandleBindingClick, OpenAppsModal} from 'types/apps'; - import ButtonBinding from './button_binding'; -type Actions = { - handleBindingClick: HandleBindingClick; - getChannel: (channelId: string) => Promise; - postEphemeralCallResponseForPost: PostEphemeralCallResponseForPost; - openAppsModal: OpenAppsModal; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ handleBindingClick, getChannel, postEphemeralCallResponseForPost, diff --git a/webapp/channels/src/components/post_view/embedded_bindings/select_binding/index.ts b/webapp/channels/src/components/post_view/embedded_bindings/select_binding/index.ts index d348c4e60e..46d0ccb404 100644 --- a/webapp/channels/src/components/post_view/embedded_bindings/select_binding/index.ts +++ b/webapp/channels/src/components/post_view/embedded_bindings/select_binding/index.ts @@ -3,27 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getChannel} from 'mattermost-redux/actions/channels'; -import type {ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {postEphemeralCallResponseForPost, handleBindingClick, openAppsModal} from 'actions/apps'; -import type {PostEphemeralCallResponseForPost, HandleBindingClick, OpenAppsModal} from 'types/apps'; - import SelectBinding from './select_binding'; -type Actions = { - handleBindingClick: HandleBindingClick; - getChannel: (channelId: string) => Promise; - postEphemeralCallResponseForPost: PostEphemeralCallResponseForPost; - openAppsModal: OpenAppsModal; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ handleBindingClick, getChannel, postEphemeralCallResponseForPost, diff --git a/webapp/channels/src/components/post_view/failed_post_options/failed_post_options.tsx b/webapp/channels/src/components/post_view/failed_post_options/failed_post_options.tsx index fe23951e04..4bcc7828ec 100644 --- a/webapp/channels/src/components/post_view/failed_post_options/failed_post_options.tsx +++ b/webapp/channels/src/components/post_view/failed_post_options/failed_post_options.tsx @@ -9,18 +9,12 @@ import type {FileInfo} from '@mattermost/types/files'; import type {Post} from '@mattermost/types/posts'; import type {ExtendedPost} from 'mattermost-redux/actions/posts'; -import type {DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; - -type CreatePostAction = - (post: Post, files: FileInfo[]) => (dispatch: DispatchFunc) => Promise<{data?: boolean}>; -type RemovePostAction = - (post: ExtendedPost) => (dispatch: DispatchFunc, getState: GetStateFunc) => void; type Props = { post: Post; actions: { - createPost: CreatePostAction; - removePost: RemovePostAction; + createPost: (post: Post, files: FileInfo[]) => void; + removePost: (post: ExtendedPost) => void; }; }; diff --git a/webapp/channels/src/components/post_view/message_attachments/message_attachment/index.ts b/webapp/channels/src/components/post_view/message_attachments/message_attachment/index.ts index 13ec898970..0807c186e4 100644 --- a/webapp/channels/src/components/post_view/message_attachments/message_attachment/index.ts +++ b/webapp/channels/src/components/post_view/message_attachments/message_attachment/index.ts @@ -3,18 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import {doPostActionWithCookie} from 'mattermost-redux/actions/posts'; import {getCurrentRelativeTeamUrl} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; - import MessageAttachment from './message_attachment'; function mapStateToProps(state: GlobalState) { @@ -23,14 +20,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - doPostActionWithCookie: (postId: string, actionId: string, actionCookie: string, selectedOption?: string | undefined) => Promise; - openModal:

(modalData: ModalData

) => void; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ doPostActionWithCookie, openModal, }, dispatch), }; diff --git a/webapp/channels/src/components/post_view/post_flag_icon/index.ts b/webapp/channels/src/components/post_view/post_flag_icon/index.ts index db1c9464c7..95922d28bc 100644 --- a/webapp/channels/src/components/post_view/post_flag_icon/index.ts +++ b/webapp/channels/src/components/post_view/post_flag_icon/index.ts @@ -3,18 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {Action} from 'mattermost-redux/types/actions'; +import type {Dispatch} from 'redux'; import {flagPost, unflagPost} from 'actions/post_actions'; import PostFlagIcon from './post_flag_icon'; -import type {Actions} from './post_flag_icon'; function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ flagPost, unflagPost, }, dispatch), diff --git a/webapp/channels/src/components/post_view/post_flag_icon/post_flag_icon.tsx b/webapp/channels/src/components/post_view/post_flag_icon/post_flag_icon.tsx index 29503557b6..8da6fa28b9 100644 --- a/webapp/channels/src/components/post_view/post_flag_icon/post_flag_icon.tsx +++ b/webapp/channels/src/components/post_view/post_flag_icon/post_flag_icon.tsx @@ -5,8 +5,6 @@ import classNames from 'classnames'; import React, {useCallback, useEffect, useRef, useState} from 'react'; import {FormattedMessage} from 'react-intl'; -import type {flagPost, unflagPost} from 'actions/post_actions'; - import OverlayTrigger from 'components/overlay_trigger'; import Tooltip from 'components/tooltip'; import FlagIcon from 'components/widgets/icons/flag_icon'; @@ -17,8 +15,8 @@ import {t} from 'utils/i18n'; import {localizeMessage} from 'utils/utils'; export type Actions = { - flagPost: typeof flagPost; - unflagPost: typeof unflagPost; + flagPost: (postId: string) => void; + unflagPost: (postId: string) => void; } type Props = { diff --git a/webapp/channels/src/components/post_view/post_list/index.tsx b/webapp/channels/src/components/post_view/post_list/index.tsx index 3bd4771f38..617850c3df 100644 --- a/webapp/channels/src/components/post_view/post_list/index.tsx +++ b/webapp/channels/src/components/post_view/post_list/index.tsx @@ -3,12 +3,11 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {markChannelAsRead} from 'mattermost-redux/actions/channels'; import {RequestStatus} from 'mattermost-redux/constants'; import {getRecentPostsChunkInChannel, makeGetPostsChunkAroundPost, getUnreadPostsChunk, getPost, isPostsChunkIncludingUnreadsPosts, getLimitedViews} from 'mattermost-redux/selectors/entities/posts'; -import type {Action} from 'mattermost-redux/types/actions'; import {memoizeResult} from 'mattermost-redux/utils/helpers'; import {makePreparePostIdsForPostList} from 'mattermost-redux/utils/post_list'; @@ -27,7 +26,6 @@ import {getLatestPostId} from 'utils/post_utils'; import type {GlobalState} from 'types/store'; import PostList from './post_list'; -import type {Props as PostListProps} from './post_list'; const isFirstLoad = (state: GlobalState, channelId: string) => !state.entities.posts.postsInChannel[channelId]; const memoizedGetLatestPostId = memoizeResult((postIds: string[]) => getLatestPostId(postIds)); @@ -109,7 +107,7 @@ function makeMapStateToProps() { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, PostListProps['actions']>({ + actions: bindActionCreators({ loadUnreads, loadPosts, loadLatestPosts, diff --git a/webapp/channels/src/components/post_view/post_list/post_list.tsx b/webapp/channels/src/components/post_view/post_list/post_list.tsx index b77963f2c2..65392acb75 100644 --- a/webapp/channels/src/components/post_view/post_list/post_list.tsx +++ b/webapp/channels/src/components/post_view/post_list/post_list.tsx @@ -3,6 +3,8 @@ import React from 'react'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import type {updateNewMessagesAtInChannel} from 'actions/global_actions'; import {clearMarks, mark, measure, trackEvent} from 'actions/telemetry_actions.jsx'; import type {LoadPostsParameters, LoadPostsReturnValue, CanLoadMorePosts} from 'actions/views/channel'; @@ -113,12 +115,12 @@ export interface Props { /* * Used for getting permalink view posts */ - loadPostsAround: (channelId: string, focusedPostId: string) => Promise; + loadPostsAround: (channelId: string, focusedPostId: string) => Promise; /* * Used for geting unreads posts */ - loadUnreads: (channelId: string) => Promise; + loadUnreads: (channelId: string) => Promise; /* * Used for getting posts using BEFORE_ID and AFTER_ID @@ -128,13 +130,13 @@ export interface Props { /* * Used to loading posts since a timestamp to sync the posts */ - syncPostsInChannel: (channelId: string, since: number, prefetch: boolean) => Promise; + syncPostsInChannel: (channelId: string, since: number, prefetch: boolean) => Promise; /* * Used to loading posts if it not first visit, permalink or there exists any postListIds * This happens when previous channel visit has a chunk which is not the latest set of posts */ - loadLatestPosts: (channelId: string) => Promise; + loadLatestPosts: (channelId: string) => Promise; markChannelAsRead: (channelId: string) => void; updateNewMessagesAtInChannel: typeof updateNewMessagesAtInChannel; diff --git a/webapp/channels/src/components/post_view/post_reaction/index.ts b/webapp/channels/src/components/post_view/post_reaction/index.ts index 30837b3866..99b5954ea3 100644 --- a/webapp/channels/src/components/post_view/post_reaction/index.ts +++ b/webapp/channels/src/components/post_view/post_reaction/index.ts @@ -3,18 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {Action} from 'mattermost-redux/types/actions'; +import type {Dispatch} from 'redux'; import {toggleReaction} from 'actions/post_actions'; import PostReaction from './post_reaction'; -import type {Props} from './post_reaction'; function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ toggleReaction, }, dispatch), }; diff --git a/webapp/channels/src/components/post_view/post_reaction/post_reaction.tsx b/webapp/channels/src/components/post_view/post_reaction/post_reaction.tsx index 0bb3389e78..068f5a00a3 100644 --- a/webapp/channels/src/components/post_view/post_reaction/post_reaction.tsx +++ b/webapp/channels/src/components/post_view/post_reaction/post_reaction.tsx @@ -4,7 +4,6 @@ import classNames from 'classnames'; import React from 'react'; import {FormattedMessage} from 'react-intl'; -import type {Dispatch} from 'redux'; import type {Emoji} from '@mattermost/types/emojis'; @@ -30,7 +29,7 @@ export type Props = { showEmojiPicker: boolean; toggleEmojiPicker: (e?: React.MouseEvent) => void; actions: { - toggleReaction: (postId: string, emojiName: string) => (dispatch: Dispatch) => {data: boolean}; + toggleReaction: (postId: string, emojiName: string) => void; }; } diff --git a/webapp/channels/src/components/preparing_workspace/index.tsx b/webapp/channels/src/components/preparing_workspace/index.tsx index 088bce19b9..8abf34d476 100644 --- a/webapp/channels/src/components/preparing_workspace/index.tsx +++ b/webapp/channels/src/components/preparing_workspace/index.tsx @@ -3,18 +3,16 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {checkIfTeamExists, createTeam, updateTeam} from 'mattermost-redux/actions/teams'; import {getProfiles} from 'mattermost-redux/actions/users'; -import type {Action} from 'mattermost-redux/types/actions'; import PreparingWorkspace from './preparing_workspace'; -import type {Actions} from './preparing_workspace'; function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ updateTeam, createTeam, getProfiles, diff --git a/webapp/channels/src/components/preparing_workspace/organization.tsx b/webapp/channels/src/components/preparing_workspace/organization.tsx index c932933fc0..8b7b0e86f4 100644 --- a/webapp/channels/src/components/preparing_workspace/organization.tsx +++ b/webapp/channels/src/components/preparing_workspace/organization.tsx @@ -35,7 +35,7 @@ type Props = PreparingWorkspacePageProps & { organization: Form['organization']; setOrganization: (organization: Form['organization']) => void; className?: string; - createTeam: (OrganizationName: string) => Promise<{error: string | null; newTeam: Team | null}>; + createTeam: (OrganizationName: string) => Promise<{error: string | null; newTeam: Team | null | undefined}>; updateTeam: (teamToUpdate: Team) => Promise<{error: string | null; updatedTeam: Team | null}>; setInviteId: (inviteId: string) => void; } @@ -90,7 +90,7 @@ const Organization = (props: Props) => { if (name) { const {error, newTeam} = await props.createTeam(name); - if (error !== null || newTeam === null) { + if (error !== null || newTeam == null) { props.setInviteId(''); setApiCallError(); return; diff --git a/webapp/channels/src/components/preparing_workspace/preparing_workspace.tsx b/webapp/channels/src/components/preparing_workspace/preparing_workspace.tsx index f4887b8a3e..e2ecc7c8da 100644 --- a/webapp/channels/src/components/preparing_workspace/preparing_workspace.tsx +++ b/webapp/channels/src/components/preparing_workspace/preparing_workspace.tsx @@ -65,10 +65,10 @@ type SubmissionState = typeof SubmissionStates[keyof typeof SubmissionStates]; const WAIT_FOR_REDIRECT_TIME = 2000 - START_TRANSITIONING_OUT; export type Actions = { - createTeam: (team: Team) => ActionResult; - updateTeam: (team: Team) => ActionResult; - checkIfTeamExists: (teamName: string) => ActionResult; - getProfiles: (page: number, perPage: number, options: Record) => ActionResult; + createTeam: (team: Team) => Promise; + updateTeam: (team: Team) => Promise; + checkIfTeamExists: (teamName: string) => Promise>; + getProfiles: (page: number, perPage: number, options: Record) => Promise; } type Props = RouterProps & { @@ -213,7 +213,7 @@ const PreparingWorkspace = ({ trackSubmitFail[redirectTo](); }, []); - const createTeam = async (OrganizationName: string): Promise<{error: string | null; newTeam: Team | null}> => { + const createTeam = async (OrganizationName: string): Promise<{error: string | null; newTeam: Team | undefined | null}> => { const data = await actions.createTeam(makeNewTeam(OrganizationName, teamNameToUrl(OrganizationName || '').url)); if (data.error) { return {error: genericSubmitError, newTeam: null}; diff --git a/webapp/channels/src/components/product_notices_modal/index.tsx b/webapp/channels/src/components/product_notices_modal/index.tsx index 8ed1656013..445cd6d70c 100644 --- a/webapp/channels/src/components/product_notices_modal/index.tsx +++ b/webapp/channels/src/components/product_notices_modal/index.tsx @@ -4,15 +4,13 @@ import {connect} from 'react-redux'; import type {ConnectedProps} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {ClientConfig} from '@mattermost/types/config'; -import type {ProductNotices} from '@mattermost/types/product_notices'; import {getInProductNotices, updateNoticesAsViewed} from 'mattermost-redux/actions/teams'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import {getSocketStatus} from 'selectors/views/websocket'; @@ -20,13 +18,6 @@ import type {GlobalState} from 'types/store'; import ProductNoticesModal from './product_notices_modal'; -type Actions = { - getInProductNotices: (teamId: string, client: string, clientVersion: string) => Promise<{ - data: ProductNotices; - }>; - updateNoticesAsViewed: (noticeIds: string[]) => Promise>; -} - function mapStateToProps(state: GlobalState) { const config: Partial = getConfig(state); const version: string = config.Version || ''; //this should always exist but TS throws error @@ -41,7 +32,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getInProductNotices, updateNoticesAsViewed, }, dispatch), diff --git a/webapp/channels/src/components/profile_popover/index.ts b/webapp/channels/src/components/profile_popover/index.ts index a2c30790c9..a0ebb296d5 100644 --- a/webapp/channels/src/components/profile_popover/index.ts +++ b/webapp/channels/src/components/profile_popover/index.ts @@ -3,9 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {ServerError} from '@mattermost/types/errors'; +import type {Dispatch} from 'redux'; import { canManageAnyChannelMembersInCurrentTeam, @@ -22,7 +20,6 @@ import { } from 'mattermost-redux/selectors/entities/teams'; import {getCurrentTimezone} from 'mattermost-redux/selectors/entities/timezone'; import {displayLastActiveLabel, getCurrentUserId, getLastActiveTimestampUnits, getLastActivityForUserId, getStatusForUserId, getUser} from 'mattermost-redux/selectors/entities/users'; -import type {GenericAction} from 'mattermost-redux/types/actions'; import {openDirectChannelToUserId} from 'actions/channel_actions'; import {closeModal, openModal} from 'actions/views/modals'; @@ -35,7 +32,6 @@ import {isAnyModalOpen} from 'selectors/views/modals'; import {getDirectChannelName} from 'utils/utils'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import ProfilePopover from './profile_popover'; @@ -122,16 +118,9 @@ function makeMapStateToProps() { }; } -type Actions = { - openModal:

(modalData: ModalData

) => void; - closeModal: (modalId: string) => void; - openDirectChannelToUserId: (userId?: string) => Promise<{error: ServerError}>; - getMembershipForEntities: (teamId: string, userId: string, channelId?: string) => Promise; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ closeModal, openDirectChannelToUserId, openModal, diff --git a/webapp/channels/src/components/profile_popover/profile_popover.tsx b/webapp/channels/src/components/profile_popover/profile_popover.tsx index 85021990d2..bbf251db2a 100644 --- a/webapp/channels/src/components/profile_popover/profile_popover.tsx +++ b/webapp/channels/src/components/profile_popover/profile_popover.tsx @@ -8,11 +8,11 @@ import type {IntlShape} from 'react-intl'; import {AccountOutlineIcon, AccountPlusOutlineIcon, CloseIcon, EmoticonHappyOutlineIcon, PhoneInTalkIcon, SendIcon} from '@mattermost/compass-icons/components'; import type {Channel} from '@mattermost/types/channels'; -import type {ServerError} from '@mattermost/types/errors'; import type {UserCustomStatus, UserProfile} from '@mattermost/types/users'; import {CustomStatusDuration} from '@mattermost/types/users'; import {Client4} from 'mattermost-redux/client'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {displayUsername, isGuest, isSystemAdmin} from 'mattermost-redux/utils/user_utils'; import * as GlobalActions from 'actions/global_actions'; @@ -167,8 +167,8 @@ export interface ProfilePopoverProps extends Omit(modalData: ModalData

) => void; closeModal: (modalId: string) => void; - openDirectChannelToUserId: (userId?: string) => Promise<{error: ServerError}>; - getMembershipForEntities: (teamId: string, userId: string, channelId?: string) => Promise; + openDirectChannelToUserId: (userId: string) => Promise; + getMembershipForEntities: (teamId: string, userId: string, channelId?: string) => void; }; intl: IntlShape; lastActivityTimestamp: number; @@ -282,7 +282,7 @@ class ProfilePopover extends React.PureComponent { + actions.openDirectChannelToUserId(user.id).then((result: ActionResult) => { if (!result.error) { if (this.props.isMobileView) { GlobalActions.emitCloseRightHandSide(); diff --git a/webapp/channels/src/components/purchase_modal/index.ts b/webapp/channels/src/components/purchase_modal/index.ts index 651576e0ed..6c31e36f2c 100644 --- a/webapp/channels/src/components/purchase_modal/index.ts +++ b/webapp/channels/src/components/purchase_modal/index.ts @@ -1,18 +1,16 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import type {Stripe} from '@stripe/stripe-js'; import React from 'react'; import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {getCloudProducts, getCloudSubscription, getInvoices} from 'mattermost-redux/actions/cloud'; import {getClientConfig} from 'mattermost-redux/actions/general'; import {getAdminAnalytics} from 'mattermost-redux/selectors/entities/admin'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; -import type {Action} from 'mattermost-redux/types/actions'; import {completeStripeAddPaymentMethod, subscribeCloudSubscription} from 'actions/cloud'; import {closeModal, openModal} from 'actions/views/modals'; @@ -27,8 +25,6 @@ import {ModalIdentifiers} from 'utils/constants'; import {getCloudContactSalesLink, getCloudSupportLink} from 'utils/contact_support_sales'; import {findOnlyYearlyProducts} from 'utils/products'; -import type {ModalData} from 'types/actions'; -import type {BillingDetails} from 'types/cloud/sku'; import type {GlobalState} from 'types/store'; const PurchaseModal = makeAsyncComponent('PurchaseModal', React.lazy(() => import('./purchase_modal'))); @@ -69,20 +65,10 @@ function mapStateToProps(state: GlobalState) { stripePublicKey, }; } -type Actions = { - closeModal: () => void; - openModal:

(modalData: ModalData

) => void; - getCloudProducts: () => void; - completeStripeAddPaymentMethod: (stripe: Stripe, billingDetails: BillingDetails, cwsMockMode: boolean) => Promise; - subscribeCloudSubscription: typeof subscribeCloudSubscription; - getClientConfig: () => void; - getCloudSubscription: () => void; - getInvoices: () => void; -} function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>( + actions: bindActionCreators( { closeModal: () => closeModal(ModalIdentifiers.CLOUD_PURCHASE), openModal, diff --git a/webapp/channels/src/components/quick_switch_modal/__snapshots__/quick_switch_modal.test.tsx.snap b/webapp/channels/src/components/quick_switch_modal/__snapshots__/quick_switch_modal.test.tsx.snap index 15ba8aa4e6..8c289738df 100644 --- a/webapp/channels/src/components/quick_switch_modal/__snapshots__/quick_switch_modal.test.tsx.snap +++ b/webapp/channels/src/components/quick_switch_modal/__snapshots__/quick_switch_modal.test.tsx.snap @@ -92,6 +92,13 @@ exports[`components/QuickSwitchModal should match snapshot 1`] = ` "latestComplete": true, "latestPrefix": "", "requestStarted": false, + "store": Object { + "@@observable": [Function], + "dispatch": [Function], + "getState": [Function], + "replaceReducer": [Function], + "subscribe": [Function], + }, }, ] } diff --git a/webapp/channels/src/components/quick_switch_modal/index.tsx b/webapp/channels/src/components/quick_switch_modal/index.tsx index 72799a8dcb..2721b618ba 100644 --- a/webapp/channels/src/components/quick_switch_modal/index.tsx +++ b/webapp/channels/src/components/quick_switch_modal/index.tsx @@ -3,9 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {Dispatch} from 'redux'; import {joinChannelById, switchToChannel} from 'actions/views/channel'; import {closeRightHandSide} from 'actions/views/rhs'; @@ -15,7 +13,6 @@ import {getIsMobileView} from 'selectors/views/browser'; import type {GlobalState} from 'types/store'; import QuickSwitchModal from './quick_switch_modal'; -import type {Props} from './quick_switch_modal'; function mapStateToProps(state: GlobalState) { return { @@ -27,7 +24,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ joinChannelById, switchToChannel, closeRightHandSide, diff --git a/webapp/channels/src/components/rename_channel_modal/index.ts b/webapp/channels/src/components/rename_channel_modal/index.ts index 000f998a77..8bb91d8456 100644 --- a/webapp/channels/src/components/rename_channel_modal/index.ts +++ b/webapp/channels/src/components/rename_channel_modal/index.ts @@ -3,24 +3,18 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {Channel} from '@mattermost/types/channels'; import type {GlobalState} from '@mattermost/types/store'; import {patchChannel} from 'mattermost-redux/actions/channels'; import {createSelector} from 'mattermost-redux/selectors/create_selector'; import {getTeam} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {getSiteURL} from 'utils/url'; import RenameChannelModal from './rename_channel_modal'; -type Actions = { - patchChannel(channelId: string, patch: Channel): Promise<{ data: Channel; error: Error }>; -}; - const mapStateToPropsRenameChannel = createSelector( 'mapStateToPropsRenameChannel', (state: GlobalState) => { @@ -35,9 +29,9 @@ const mapStateToPropsRenameChannel = createSelector( (teamInfo) => ({...teamInfo}), ); -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ patchChannel, }, dispatch), }; diff --git a/webapp/channels/src/components/rename_channel_modal/rename_channel_modal.tsx b/webapp/channels/src/components/rename_channel_modal/rename_channel_modal.tsx index fb08d96ee4..f5916e63f4 100644 --- a/webapp/channels/src/components/rename_channel_modal/rename_channel_modal.tsx +++ b/webapp/channels/src/components/rename_channel_modal/rename_channel_modal.tsx @@ -11,6 +11,8 @@ import type {Channel} from '@mattermost/types/channels'; import type {ServerError} from '@mattermost/types/errors'; import type {Team} from '@mattermost/types/teams'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import OverlayTrigger from 'components/overlay_trigger'; import Tooltip from 'components/tooltip'; @@ -69,7 +71,7 @@ type Props = { /* * Action creator to patch current channel */ - patchChannel: (channelId: string, patch: Channel) => Promise<{ data: Channel; error: Error }>; + patchChannel: (channelId: string, patch: Channel) => Promise; }; } diff --git a/webapp/channels/src/components/reset_status_modal/index.ts b/webapp/channels/src/components/reset_status_modal/index.ts index c49ee04f71..128c29e3d5 100644 --- a/webapp/channels/src/components/reset_status_modal/index.ts +++ b/webapp/channels/src/components/reset_status_modal/index.ts @@ -3,17 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {PreferenceType} from '@mattermost/types/preferences'; -import type {UserStatus} from '@mattermost/types/users'; +import type {Dispatch} from 'redux'; import {savePreferences} from 'mattermost-redux/actions/preferences'; import {setStatus} from 'mattermost-redux/actions/users'; import {Preferences} from 'mattermost-redux/constants'; import {get} from 'mattermost-redux/selectors/entities/preferences'; import {getStatusForUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions.js'; import {autoResetStatus} from 'actions/user_actions'; @@ -29,15 +25,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - autoResetStatus: () => Promise<{data: UserStatus}>; - setStatus: (status: UserStatus) => void; - savePreferences: (userId: string, preferences: PreferenceType[]) => void; -}; - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ autoResetStatus, setStatus, savePreferences, diff --git a/webapp/channels/src/components/root/index.ts b/webapp/channels/src/components/root/index.ts index 3a457772c2..27acf5c303 100644 --- a/webapp/channels/src/components/root/index.ts +++ b/webapp/channels/src/components/root/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getFirstAdminSetupComplete} from 'mattermost-redux/actions/general'; import {getProfiles} from 'mattermost-redux/actions/users'; @@ -12,7 +12,6 @@ import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; import {getTeam} from 'mattermost-redux/selectors/entities/teams'; import {shouldShowTermsOfService, getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {Action} from 'mattermost-redux/types/actions'; import {migrateRecentEmojis} from 'actions/emoji_actions'; import {loadConfigAndMe, registerCustomPostRenderer} from 'actions/views/root'; @@ -30,7 +29,6 @@ import {initializeProducts} from 'plugins/products'; import type {GlobalState} from 'types/store/index'; import Root from './root'; -import type {Actions} from './root'; function mapStateToProps(state: GlobalState) { const config = getConfig(state); @@ -62,7 +60,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ loadConfigAndMe, getFirstAdminSetupComplete, getProfiles, diff --git a/webapp/channels/src/components/root/root.tsx b/webapp/channels/src/components/root/root.tsx index 63bed46f8d..cd74be3188 100644 --- a/webapp/channels/src/components/root/root.tsx +++ b/webapp/channels/src/components/root/root.tsx @@ -139,9 +139,9 @@ export type Actions = { getFirstAdminSetupComplete: () => Promise; getProfiles: (page?: number, pageSize?: number, options?: Record) => Promise; migrateRecentEmojis: () => void; - loadConfigAndMe: () => Promise<{data: boolean}>; + loadConfigAndMe: () => Promise; registerCustomPostRenderer: (type: string, component: any, id: string) => Promise; - initializeProducts: () => Promise; + initializeProducts: () => Promise; } type Props = { @@ -292,7 +292,7 @@ export default class Root extends React.PureComponent { }); this.props.actions.migrateRecentEmojis(); - loadRecentlyUsedCustomEmojis()(store.dispatch, store.getState); + store.dispatch(loadRecentlyUsedCustomEmojis()); const iosDownloadLink = getConfig(store.getState()).IosAppDownloadLink; const androidDownloadLink = getConfig(store.getState()).AndroidAppDownloadLink; diff --git a/webapp/channels/src/components/root/root_redirect/index.ts b/webapp/channels/src/components/root/root_redirect/index.ts index 314fbe54f8..d361a82c98 100644 --- a/webapp/channels/src/components/root/root_redirect/index.ts +++ b/webapp/channels/src/components/root/root_redirect/index.ts @@ -3,17 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getFirstAdminSetupComplete} from 'mattermost-redux/actions/general'; import {getIsOnboardingFlowEnabled} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentUserId, isCurrentUserSystemAdmin, isFirstAdmin} from 'mattermost-redux/selectors/entities/users'; -import type {GenericAction} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import RootRedirect from './root_redirect'; -import type {Props} from './root_redirect'; function mapStateToProps(state: GlobalState) { const onboardingFlowEnabled = getIsOnboardingFlowEnabled(state); @@ -28,9 +26,9 @@ function mapStateToProps(state: GlobalState) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ getFirstAdminSetupComplete, }, dispatch), }; diff --git a/webapp/channels/src/components/root/root_redirect/root_redirect.tsx b/webapp/channels/src/components/root/root_redirect/root_redirect.tsx index 50c2f7c65e..c528a91c3a 100644 --- a/webapp/channels/src/components/root/root_redirect/root_redirect.tsx +++ b/webapp/channels/src/components/root/root_redirect/root_redirect.tsx @@ -4,6 +4,8 @@ import React, {useEffect} from 'react'; import {Redirect, useHistory} from 'react-router-dom'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import * as GlobalActions from 'actions/global_actions'; export type Props = { @@ -12,7 +14,7 @@ export type Props = { location?: Location; isFirstAdmin: boolean; actions: { - getFirstAdminSetupComplete: () => Promise<{data: boolean; error: any}>; + getFirstAdminSetupComplete: () => Promise; }; } diff --git a/webapp/channels/src/components/search/index.tsx b/webapp/channels/src/components/search/index.tsx index baaf821a5b..39ebceb086 100644 --- a/webapp/channels/src/components/search/index.tsx +++ b/webapp/channels/src/components/search/index.tsx @@ -3,11 +3,10 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getMorePostsForSearch, getMoreFilesForSearch} from 'mattermost-redux/actions/search'; import {getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'; -import type {Action} from 'mattermost-redux/types/actions'; import {autocompleteChannelsForSearch} from 'actions/channel_actions'; import {autocompleteUsersInTeam} from 'actions/user_actions'; @@ -33,7 +32,6 @@ import {RHSStates} from 'utils/constants'; import type {GlobalState} from 'types/store'; import Search from './search'; -import type {StateProps, DispatchProps, OwnProps} from './types'; function mapStateToProps(state: GlobalState) { const rhsState = getRhsState(state); @@ -65,7 +63,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, DispatchProps['actions']>({ + actions: bindActionCreators({ updateSearchTerms, updateSearchTermsForShortcut, updateSearchType, @@ -85,4 +83,4 @@ function mapDispatchToProps(dispatch: Dispatch) { }, dispatch), }; } -export default connect(mapStateToProps, mapDispatchToProps)(Search); +export default connect(mapStateToProps, mapDispatchToProps)(Search); diff --git a/webapp/channels/src/components/search/types.ts b/webapp/channels/src/components/search/types.ts index 90806f26cc..2ce015d5ab 100644 --- a/webapp/channels/src/components/search/types.ts +++ b/webapp/channels/src/components/search/types.ts @@ -8,8 +8,6 @@ import type {UserAutocomplete} from '@mattermost/types/autocomplete'; import type {Channel} from '@mattermost/types/channels'; import type {ServerError} from '@mattermost/types/errors'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; - import type {SearchType} from 'types/store/rhs'; export type SearchFilterType = 'all' | 'documents' | 'spreadsheets' | 'presentations' | 'code' | 'images' | 'audio' | 'video'; @@ -51,12 +49,12 @@ export type DispatchProps = { showFlaggedPosts: () => void; setRhsExpanded: (expanded: boolean) => Action; closeRightHandSide: () => void; - autocompleteChannelsForSearch: (term: string, success: (channels: Channel[]) => void, error: (err: ServerError) => void) => ActionFunc; + autocompleteChannelsForSearch: (term: string, success?: (channels: Channel[]) => void, error?: (err: ServerError) => void) => void; autocompleteUsersInTeam: (username: string) => Promise; updateRhsState: (rhsState: string) => void; - getMorePostsForSearch: () => ActionFunc; + getMorePostsForSearch: () => void; openRHSSearch: () => void; - getMoreFilesForSearch: () => ActionFunc; + getMoreFilesForSearch: () => void; filterFilesSearchByExt: (extensions: string[]) => void; }; } diff --git a/webapp/channels/src/components/sidebar/channel_navigator/index.ts b/webapp/channels/src/components/sidebar/channel_navigator/index.ts index 6531b296c6..f5c07e0cc3 100644 --- a/webapp/channels/src/components/sidebar/channel_navigator/index.ts +++ b/webapp/channels/src/components/sidebar/channel_navigator/index.ts @@ -3,17 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {shouldShowUnreadsCategory} from 'mattermost-redux/selectors/entities/preferences'; -import type {Action} from 'mattermost-redux/types/actions'; import {openModal, closeModal} from 'actions/views/modals'; import {isModalOpen} from 'selectors/views/modals'; import {ModalIdentifiers} from 'utils/constants'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import ChannelNavigator from './channel_navigator'; @@ -25,14 +23,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - openModal:

(modalData: ModalData

) => void; - closeModal: (modalId: string) => void; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ openModal, closeModal, }, dispatch), diff --git a/webapp/channels/src/components/sidebar/index.ts b/webapp/channels/src/components/sidebar/index.ts index b25807c4cc..fe67d9ebb2 100644 --- a/webapp/channels/src/components/sidebar/index.ts +++ b/webapp/channels/src/components/sidebar/index.ts @@ -3,14 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {fetchMyCategories} from 'mattermost-redux/actions/channel_categories'; import Permissions from 'mattermost-redux/constants/permissions'; import {isCustomGroupsEnabled} from 'mattermost-redux/selectors/entities/preferences'; import {haveICurrentChannelPermission, haveISystemPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; -import type {GenericAction} from 'mattermost-redux/types/actions'; import {clearChannelSelection} from 'actions/views/channel_sidebar'; import {closeModal, openModal} from 'actions/views/modals'; @@ -23,7 +22,6 @@ import {isModalOpen} from 'selectors/views/modals'; import {ModalIdentifiers} from 'utils/constants'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import Sidebar from './sidebar'; @@ -61,17 +59,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - fetchMyCategories: (teamId: string) => {data: boolean}; - openModal:

(modalData: ModalData

) => void; - clearChannelSelection: () => void; - closeModal: (modalId: string) => void; - closeRightHandSide: () => void; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ clearChannelSelection, fetchMyCategories, openModal, diff --git a/webapp/channels/src/components/sidebar/sidebar.tsx b/webapp/channels/src/components/sidebar/sidebar.tsx index 5ad4a18d78..0400d0836e 100644 --- a/webapp/channels/src/components/sidebar/sidebar.tsx +++ b/webapp/channels/src/components/sidebar/sidebar.tsx @@ -37,7 +37,7 @@ type Props = { canJoinPublicChannel: boolean; isOpen: boolean; actions: { - fetchMyCategories: (teamId: string) => {data: boolean}; + fetchMyCategories: (teamId: string) => void; openModal:

(modalData: ModalData

) => void; closeModal: (modalId: string) => void; clearChannelSelection: () => void; diff --git a/webapp/channels/src/components/sidebar/sidebar_category/sidebar_category_menu/index.test.tsx b/webapp/channels/src/components/sidebar/sidebar_category/sidebar_category_menu/index.test.tsx index 44d01f85cd..99e742fb4f 100644 --- a/webapp/channels/src/components/sidebar/sidebar_category/sidebar_category_menu/index.test.tsx +++ b/webapp/channels/src/components/sidebar/sidebar_category/sidebar_category_menu/index.test.tsx @@ -43,7 +43,7 @@ const initialState = { }; jest.spyOn(redux, 'useSelector').mockImplementation((cb) => cb(initialState)); -jest.spyOn(redux, 'useDispatch').mockReturnValue((t) => t); +jest.spyOn(redux, 'useDispatch').mockReturnValue((t: unknown) => t); describe('components/sidebar/sidebar_category/sidebar_category_menu', () => { const categoryId = 'test_category_id'; diff --git a/webapp/channels/src/components/sidebar/sidebar_category/sidebar_category_sorting_menu.test.tsx b/webapp/channels/src/components/sidebar/sidebar_category/sidebar_category_sorting_menu.test.tsx index d0b82fc607..78ada2f352 100644 --- a/webapp/channels/src/components/sidebar/sidebar_category/sidebar_category_sorting_menu.test.tsx +++ b/webapp/channels/src/components/sidebar/sidebar_category/sidebar_category_sorting_menu.test.tsx @@ -25,7 +25,7 @@ const initialState = { }; jest.spyOn(redux, 'useSelector').mockImplementation((cb) => cb(initialState)); -jest.spyOn(redux, 'useDispatch').mockReturnValue((t) => t); +jest.spyOn(redux, 'useDispatch').mockReturnValue((t: unknown) => t); describe('components/sidebar/sidebar_category/sidebar_category_sorting_menu', () => { const baseProps = { diff --git a/webapp/channels/src/components/sidebar/sidebar_channel/sidebar_direct_channel/index.ts b/webapp/channels/src/components/sidebar/sidebar_channel/sidebar_direct_channel/index.ts index 92d2877bc6..850d0e87f2 100644 --- a/webapp/channels/src/components/sidebar/sidebar_channel/sidebar_direct_channel/index.ts +++ b/webapp/channels/src/components/sidebar/sidebar_channel/sidebar_direct_channel/index.ts @@ -3,17 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {Channel} from '@mattermost/types/channels'; -import type {PreferenceType} from '@mattermost/types/preferences'; import type {GlobalState} from '@mattermost/types/store'; import {savePreferences} from 'mattermost-redux/actions/preferences'; import {getCurrentChannelId, getRedirectChannelNameForTeam} from 'mattermost-redux/selectors/entities/channels'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUser, getUser} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import {leaveDirectChannel} from 'actions/views/channel'; @@ -40,16 +38,9 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { }; } -type Actions = { - savePreferences: (userId: string, preferences: PreferenceType[]) => Promise<{ - data: boolean; - }>; - leaveDirectChannel: (channelId: string) => Promise<{data: boolean}>; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ savePreferences, leaveDirectChannel, }, dispatch), diff --git a/webapp/channels/src/components/sidebar/sidebar_channel/sidebar_group_channel/index.ts b/webapp/channels/src/components/sidebar/sidebar_channel/sidebar_group_channel/index.ts index 446979cedb..18502617c1 100644 --- a/webapp/channels/src/components/sidebar/sidebar_channel/sidebar_group_channel/index.ts +++ b/webapp/channels/src/components/sidebar/sidebar_channel/sidebar_group_channel/index.ts @@ -3,17 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {Channel} from '@mattermost/types/channels'; -import type {PreferenceType} from '@mattermost/types/preferences'; import type {GlobalState} from '@mattermost/types/store'; import {savePreferences} from 'mattermost-redux/actions/preferences'; import {getCurrentChannelId, getRedirectChannelNameForTeam, makeGetGmChannelMemberCount} from 'mattermost-redux/selectors/entities/channels'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import SidebarGroupChannel from './sidebar_group_channel'; @@ -41,15 +39,9 @@ function makeMapStateToProps() { }; } -type Actions = { - savePreferences: (userId: string, preferences: PreferenceType[]) => Promise<{ - data: boolean; - }>; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ savePreferences, }, dispatch), }; diff --git a/webapp/channels/src/components/single_image_view/single_image_view.tsx b/webapp/channels/src/components/single_image_view/single_image_view.tsx index 8ee64d9787..e75a146c1e 100644 --- a/webapp/channels/src/components/single_image_view/single_image_view.tsx +++ b/webapp/channels/src/components/single_image_view/single_image_view.tsx @@ -22,7 +22,7 @@ import type {PropsFromRedux} from './index'; const PREVIEW_IMAGE_MIN_DIMENSION = 50; const DISPROPORTIONATE_HEIGHT_RATIO = 20; -interface Props extends PropsFromRedux { +export interface Props extends PropsFromRedux { postId: string; fileInfo: FileInfo; isRhsOpen: boolean; diff --git a/webapp/channels/src/components/size_aware_image.tsx b/webapp/channels/src/components/size_aware_image.tsx index 99ea7415c4..36e46ab62c 100644 --- a/webapp/channels/src/components/size_aware_image.tsx +++ b/webapp/channels/src/components/size_aware_image.tsx @@ -12,7 +12,7 @@ import {DownloadOutlineIcon, LinkVariantIcon, CheckIcon} from '@mattermost/compa import type {FileInfo} from '@mattermost/types/files'; import type {PostImage} from '@mattermost/types/posts'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {getFileMiniPreviewUrl} from 'mattermost-redux/utils/file_utils'; import LoadingImagePreview from 'components/loading_image_preview'; @@ -87,7 +87,7 @@ export type Props = { /** * Action to fetch public link of an image from server. */ - getFilePublicLink?: () => ActionFunc; + getFilePublicLink?: () => Promise>; /* * Prevents display of utility buttons when image in a location that makes them inappropriate diff --git a/webapp/channels/src/components/status_dropdown/status_dropdown.tsx b/webapp/channels/src/components/status_dropdown/status_dropdown.tsx index bf97e105d9..d526155306 100644 --- a/webapp/channels/src/components/status_dropdown/status_dropdown.tsx +++ b/webapp/channels/src/components/status_dropdown/status_dropdown.tsx @@ -16,8 +16,6 @@ import type {PreferenceType} from '@mattermost/types/preferences'; import {CustomStatusDuration} from '@mattermost/types/users'; import type {UserCustomStatus, UserProfile, UserStatus} from '@mattermost/types/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; - import * as GlobalActions from 'actions/global_actions'; import CustomStatusEmoji from 'components/custom_status/custom_status_emoji'; @@ -53,8 +51,8 @@ type Props = { autoResetPref?: string; actions: { openModal:

(modalData: ModalData

) => void; - setStatus: (status: UserStatus) => ActionFunc; - unsetCustomStatus: () => ActionFunc; + setStatus: (status: UserStatus) => void; + unsetCustomStatus: () => void; savePreferences: (userId: string, preferences: PreferenceType[]) => void; setStatusDropdown: (open: boolean) => void; }; diff --git a/webapp/channels/src/components/suggestion/search_channel_provider.tsx b/webapp/channels/src/components/suggestion/search_channel_provider.tsx index a4e0c16551..355d05d97f 100644 --- a/webapp/channels/src/components/suggestion/search_channel_provider.tsx +++ b/webapp/channels/src/components/suggestion/search_channel_provider.tsx @@ -3,7 +3,6 @@ import type {ServerError} from '@mattermost/types/errors'; -import type {ActionFunc} from 'mattermost-redux/types/actions.js'; import {isDirectChannel, isGroupChannel, sortChannelsByTypeListAndDisplayName} from 'mattermost-redux/utils/channel_utils'; import {getCurrentLocale} from 'selectors/i18n'; @@ -32,9 +31,12 @@ function itemToTerm(isAtSearch: boolean, item: { type: string; display_name: str return item.name; } +type SearchChannelAutocomplete = (term: string, success?: (channels: Channel[]) => void, error?: (err: ServerError) => void) => void; + export default class SearchChannelProvider extends Provider { - autocompleteChannelsForSearch: any; - constructor(channelSearchFunc: (term: string, success: (channels: Channel[]) => void, error: (err: ServerError) => void) => ActionFunc) { + autocompleteChannelsForSearch: SearchChannelAutocomplete; + + constructor(channelSearchFunc: SearchChannelAutocomplete) { super(); this.autocompleteChannelsForSearch = channelSearchFunc; } diff --git a/webapp/channels/src/components/suggestion/switch_channel_provider.test.tsx b/webapp/channels/src/components/suggestion/switch_channel_provider.test.tsx index 0dcebe5c15..f5fae47b87 100644 --- a/webapp/channels/src/components/suggestion/switch_channel_provider.test.tsx +++ b/webapp/channels/src/components/suggestion/switch_channel_provider.test.tsx @@ -5,15 +5,11 @@ import type {UserProfile} from '@mattermost/types/users'; import {Preferences} from 'mattermost-redux/constants'; -import Store from 'stores/redux_store'; - import mockStore from 'tests/test_store'; import {TestHelper} from 'utils/test_helper'; import SwitchChannelProvider from './switch_channel_provider'; -const getState = Store.getState; - const latestPost = TestHelper.getPostMock({ id: 'latest_post_id', user_id: 'current_user_id', @@ -22,11 +18,6 @@ const latestPost = TestHelper.getPostMock({ create_at: Date.now(), }); -jest.mock('stores/redux_store', () => ({ - dispatch: jest.fn(), - getState: jest.fn(), -})); - jest.mock('mattermost-redux/client', () => { const original = jest.requireActual('mattermost-redux/client'); @@ -81,6 +72,7 @@ describe('components/SwitchChannelProvider', () => { id: 'direct_other_user', name: 'current_user_id__other_user', }, + myMembers: {}, }, messageCounts: { direct_other_user: { @@ -147,8 +139,7 @@ describe('components/SwitchChannelProvider', () => { it('should change name on wrapper to be unique with same name user channel and public channel', () => { const switchProvider = new SwitchChannelProvider(); const store = mockStore(defaultState); - - getState.mockImplementation(store.getState); + switchProvider.store = store; const users = [ TestHelper.getUserMock({ @@ -192,8 +183,7 @@ describe('components/SwitchChannelProvider', () => { it('should change name on wrapper to be unique with same name user in channel and public channel', () => { const switchProvider = new SwitchChannelProvider(); const store = mockStore(defaultState); - - getState.mockImplementation(store.getState); + switchProvider.store = store; const users = [ TestHelper.getUserMock({ @@ -229,8 +219,7 @@ describe('components/SwitchChannelProvider', () => { it('should not fail if nothing matches', () => { const switchProvider = new SwitchChannelProvider(); const store = mockStore(defaultState); - - getState.mockImplementation(store.getState); + switchProvider.store = store; const users: UserProfile[] = []; const channels = [{ @@ -273,8 +262,6 @@ describe('components/SwitchChannelProvider', () => { let res = switchProvider.userWrappedChannel(user, channel); expect(res.channel.display_name).toEqual('fn ln'); - getState.mockClear(); - const store = mockStore({ entities: { general: { @@ -312,7 +299,7 @@ describe('components/SwitchChannelProvider', () => { }, }, }); - getState.mockImplementation(store.getState); + switchProvider.store = store; res = switchProvider.userWrappedChannel(user, channel); expect(res.channel.display_name).toEqual('fn ln'); @@ -356,6 +343,12 @@ describe('components/SwitchChannelProvider', () => { ...defaultState.entities, channels: { ...defaultState.entities.channels, + channels: { + ...defaultState.entities.channels.channels, + [channels[0].id]: channels[0], + [channels[1].id]: channels[1], + [channels[2].id]: channels[2], + }, myMembers: { current_channel_id: { channel_id: 'current_channel_id', @@ -369,13 +362,20 @@ describe('components/SwitchChannelProvider', () => { direct_other_user2: {}, }, }, + users: { + ...defaultState.entities.users, + profiles: { + ...defaultState.entities.users.profiles, + [users[0].id]: users[0], + [users[1].id]: users[1], + }, + }, }, }; const switchProvider = new SwitchChannelProvider(); const store = mockStore(modifiedState); - - getState.mockImplementation(store.getState); + switchProvider.store = store; const searchText = 'other'; @@ -392,42 +392,6 @@ describe('components/SwitchChannelProvider', () => { }); it('should sort results based on last_viewed_at order followed by alphabetical andomit users not in members', () => { - const modifiedState = { - ...defaultState, - entities: { - ...defaultState.entities, - channels: { - ...defaultState.entities.channels, - myMembers: { - current_channel_id: { - channel_id: 'current_channel_id', - user_id: 'current_user_id', - roles: 'channel_role', - mention_count: 1, - msg_count: 9, - last_viewed_at: 1, - }, - direct_other_user1: { - channel_id: 'direct_other_user1', - msg_count: 1, - last_viewed_at: 2, - }, - direct_other_user4: { - channel_id: 'direct_other_user4', - msg_count: 1, - last_viewed_at: 3, - }, - channel_other_user: {}, - }, - }, - }, - }; - - const switchProvider = new SwitchChannelProvider(); - const store = mockStore(modifiedState); - - getState.mockImplementation(store.getState); - const users = [ TestHelper.getUserMock({ id: 'other_user1', @@ -473,6 +437,58 @@ describe('components/SwitchChannelProvider', () => { delete_at: 0, }]; + const modifiedState = { + ...defaultState, + entities: { + ...defaultState.entities, + channels: { + ...defaultState.entities.channels, + channels: { + ...defaultState.entities.channels.channels, + [channels[0].id]: channels[0], + [channels[1].id]: channels[1], + [channels[2].id]: channels[2], + [channels[3].id]: channels[3], + }, + myMembers: { + current_channel_id: { + channel_id: 'current_channel_id', + user_id: 'current_user_id', + roles: 'channel_role', + mention_count: 1, + msg_count: 9, + last_viewed_at: 1, + }, + direct_other_user1: { + channel_id: 'direct_other_user1', + msg_count: 1, + last_viewed_at: 2, + }, + direct_other_user4: { + channel_id: 'direct_other_user4', + msg_count: 1, + last_viewed_at: 3, + }, + channel_other_user: {}, + }, + }, + users: { + ...defaultState.entities.users, + profiles: { + ...defaultState.entities.users.profiles, + [users[0].id]: users[0], + [users[1].id]: users[1], + [users[2].id]: users[2], + [users[3].id]: users[3], + }, + }, + }, + }; + + const switchProvider = new SwitchChannelProvider(); + const store = mockStore(modifiedState); + switchProvider.store = store; + const searchText = 'other'; switchProvider.startNewRequest(''); @@ -538,12 +554,10 @@ describe('components/SwitchChannelProvider', () => { }, }; - getState.mockClear(); - const switchProvider = new SwitchChannelProvider(); const store = mockStore(modifiedState); + switchProvider.store = store; - getState.mockImplementation(store.getState); const searchText = 'other'; const resultsCallback = jest.fn(); @@ -627,12 +641,9 @@ describe('components/SwitchChannelProvider', () => { }, }; - getState.mockClear(); - const switchProvider = new SwitchChannelProvider(); const store = mockStore(modifiedState); - - getState.mockImplementation(store.getState); + switchProvider.store = store; const searchText = 'other.'; const resultsCallback = jest.fn(); @@ -718,12 +729,10 @@ describe('components/SwitchChannelProvider', () => { }, }, }; - getState.mockClear(); const switchProvider = new SwitchChannelProvider(); const store = mockStore(modifiedState); - - getState.mockImplementation(store.getState); + switchProvider.store = store; const searchText = 'other'; const resultsCallback = jest.fn(); @@ -808,8 +817,7 @@ describe('components/SwitchChannelProvider', () => { const switchProvider = new SwitchChannelProvider(); const store = mockStore(modifiedState); - - getState.mockImplementation(store.getState); + switchProvider.store = store; const users = [ TestHelper.getUserMock({ @@ -873,12 +881,9 @@ describe('components/SwitchChannelProvider', () => { }, }; - getState.mockClear(); - const switchProvider = new SwitchChannelProvider(); const store = mockStore(modifiedState); - - getState.mockImplementation(store.getState); + switchProvider.store = store; const searchText = 'chan'; const resultsCallback = jest.fn(); @@ -963,12 +968,9 @@ describe('components/SwitchChannelProvider', () => { }, }; - getState.mockClear(); - const switchProvider = new SwitchChannelProvider(); const store = mockStore(modifiedState); - - getState.mockImplementation(store.getState); + switchProvider.store = store; const searchText = 'thread'; const resultsCallback = jest.fn(); diff --git a/webapp/channels/src/components/suggestion/switch_channel_provider.tsx b/webapp/channels/src/components/suggestion/switch_channel_provider.tsx index 4c9ed28328..5ca9355716 100644 --- a/webapp/channels/src/components/suggestion/switch_channel_provider.tsx +++ b/webapp/channels/src/components/suggestion/switch_channel_provider.tsx @@ -3,7 +3,7 @@ import classNames from 'classnames'; import React from 'react'; -import {connect} from 'react-redux'; +import {connect, useSelector} from 'react-redux'; import type {Channel, ChannelMembership, ChannelType} from '@mattermost/types/channels'; import type {PreferenceType} from '@mattermost/types/preferences'; @@ -49,7 +49,7 @@ import {getPreferenceKey} from 'mattermost-redux/utils/preference_utils'; import {isGuest} from 'mattermost-redux/utils/user_utils'; import {getPostDraft} from 'selectors/rhs'; -import store from 'stores/redux_store'; +import globalStore from 'stores/redux_store'; import CustomStatusEmoji from 'components/custom_status/custom_status_emoji'; import ProfilePicture from 'components/profile_picture'; @@ -67,7 +67,6 @@ import type {ResultsCallback} from './provider'; import {SuggestionContainer} from './suggestion'; import type {SuggestionProps} from './suggestion'; -const getState = store.getState; const searchProfilesMatchingWithTerm = makeSearchProfilesMatchingWithTerm(); const ThreadsChannel: FakeChannel = { @@ -125,6 +124,8 @@ const SwitchChannelSuggestion = React.forwardRef((props, const channel = item.channel; const channelIsArchived = channel.delete_at && channel.delete_at !== 0; + const currentUserId = useSelector(getCurrentUserId); + const member = props.channelMember; const teammate = props.dmChannelTeammate; let badge = null; @@ -224,7 +225,6 @@ const SwitchChannelSuggestion = React.forwardRef((props, description = '@' + teammate.username + deactivated; } else { name = teammate.username; - const currentUserId = getCurrentUserId(getState()); if (teammate.id === currentUserId) { name += (' ' + Utils.localizeMessage('suggestion.user.isCurrent', '(you)')); } @@ -382,10 +382,9 @@ export function quickSwitchSorter(wrappedA: WrappedChannel, wrappedB: WrappedCha return sortChannelsByRecencyAndTypeAndDisplayName(wrappedA, wrappedB); } -function makeChannelSearchFilter(channelPrefix: string) { +function makeChannelSearchFilter(curState: GlobalState, channelPrefix: string) { const channelPrefixLower = channelPrefix.toLowerCase(); const splitPrefixBySpace = channelPrefixLower.trim().split(/[ ,]+/); - const curState = getState(); const usersInChannels = getUserIdsInChannels(curState); const userSearchStrings: RelationOneToOne = {}; const SEPARATOR = ';|;'; @@ -432,6 +431,8 @@ function makeChannelSearchFilter(channelPrefix: string) { } export default class SwitchChannelProvider extends Provider { + store = globalStore; + /** * whenever this gets adjusted/refactored to not call the callback twice we need to adjust the behavior in * the ForwardPostChannelSelect component as well. @@ -447,9 +448,9 @@ export default class SwitchChannelProvider extends Provider { } // Dispatch suggestions for local data (filter out deleted and archived channels from local store data) - let channels = getChannelsInAllTeams(getState()).concat(getDirectAndGroupChannels(getState())).filter((c) => c.delete_at === 0); + let channels = getChannelsInAllTeams(this.store.getState()).concat(getDirectAndGroupChannels(this.store.getState())).filter((c) => c.delete_at === 0); channels = this.removeChannelsFromArchivedTeams(channels); - const users = searchProfilesMatchingWithTerm(getState(), channelPrefix, false); + const users = searchProfilesMatchingWithTerm(this.store.getState(), channelPrefix, false); const formattedData = this.formatList(channelPrefix, [ThreadsChannel, ...channels], users, true, true); if (formattedData) { resultsCallback(formattedData); @@ -465,7 +466,7 @@ export default class SwitchChannelProvider extends Provider { } async fetchUsersAndChannels(channelPrefix: string, resultsCallback: ResultsCallback) { - const state = getState(); + const state = this.store.getState(); const teamId = getCurrentTeamId(state); if (!teamId) { @@ -480,7 +481,7 @@ export default class SwitchChannelProvider extends Provider { usersAsync = Client4.autocompleteUsers(channelPrefix, '', ''); } - const channelsAsync = searchAllChannels(channelPrefix, {nonAdminSearch: true})(store.dispatch, store.getState); + const channelsAsync = this.store.dispatch(searchAllChannels(channelPrefix, {nonAdminSearch: true})); let usersFromServer; let channelsFromServer; @@ -490,7 +491,7 @@ export default class SwitchChannelProvider extends Provider { const channelsResponse = await channelsAsync; channelsFromServer = (channelsResponse as ActionResult).data; } catch (err) { - store.dispatch(logError(err)); + this.store.dispatch(logError(err)); return; } @@ -511,7 +512,7 @@ export default class SwitchChannelProvider extends Provider { const remoteUserData = usersFromServer.users || []; const remoteFormattedData = this.formatList(channelPrefix, remoteChannelData, remoteUserData, false); - store.dispatch({ + this.store.dispatch({ type: UserTypes.RECEIVED_PROFILES_LIST, data: [...localUserData.filter((user) => user.id !== currentUserId), ...remoteUserData.filter((user) => user.id !== currentUserId)], }); @@ -527,7 +528,7 @@ export default class SwitchChannelProvider extends Provider { userWrappedChannel(user: UserProfile, channel?: ChannelItem): WrappedChannel { let displayName = ''; - const currentUserId = getCurrentUserId(getState()); + const currentUserId = getCurrentUserId(this.store.getState()); // The naming format is fullname (nickname) // username is shown seperately @@ -565,13 +566,13 @@ export default class SwitchChannelProvider extends Provider { formatList(channelPrefix: string, allChannels: ChannelItem[], users: UserProfile[], skipNotMember = true, localData = false) { const channels = []; - const members = getMyChannelMemberships(getState()); + const members = getMyChannelMemberships(this.store.getState()); const completedChannels: RelationOneToOne = {}; - const channelFilter = makeChannelSearchFilter(channelPrefix); + const channelFilter = makeChannelSearchFilter(this.store.getState(), channelPrefix); - const state = getState(); + const state = this.store.getState(); const config = getConfig(state); const viewArchivedChannels = config.ExperimentalViewArchivedChannels === 'true'; const allUnreadChannelIds = getAllTeamsUnreadChannelIds(state); @@ -700,7 +701,7 @@ export default class SwitchChannelProvider extends Provider { } removeChannelsFromArchivedTeams(channels: Channel[]) { - const state = getState(); + const state = this.store.getState(); const activeTeams = getActiveTeamsList(state).map((team: Team) => team.id); const newChannels = channels.filter((channel: Channel) => { if (!channel.team_id) { @@ -712,7 +713,7 @@ export default class SwitchChannelProvider extends Provider { } fetchAndFormatRecentlyViewedChannels(resultsCallback: ResultsCallback) { - const state = getState(); + const state = this.store.getState(); let recentChannels = getChannelsInAllTeams(state).concat(getDirectAndGroupChannels(state)); recentChannels = this.removeChannelsFromArchivedTeams(recentChannels); const wrappedRecentChannels = this.wrapChannels(recentChannels, Constants.MENTION_RECENT_CHANNELS); @@ -746,7 +747,7 @@ export default class SwitchChannelProvider extends Provider { } getThreadsItem(countType = 'total', itemType?: string) { - const state = getState(); + const state = this.store.getState(); const counts = getThreadCountsInCurrentTeam(state); const collapsedThreads = isCollapsedThreadsEnabled(state); @@ -787,7 +788,7 @@ export default class SwitchChannelProvider extends Provider { } wrapChannels(channels: Channel[], channelType: string) { - const state = getState(); + const state = this.store.getState(); const currentChannel = getCurrentChannel(state); const myMembers = getMyChannelMemberships(state); const myPreferences = getMyPreferences(state); @@ -808,7 +809,7 @@ export default class SwitchChannelProvider extends Provider { if (channel.type === Constants.GM_CHANNEL) { wrappedChannel.name = channel.display_name; } else if (channel.type === Constants.DM_CHANNEL) { - const user = getUser(getState(), Utils.getUserIdFromChannelId(channel.name)); + const user = getUser(this.store.getState(), Utils.getUserIdFromChannelId(channel.name)); if (!user) { continue; @@ -831,19 +832,19 @@ export default class SwitchChannelProvider extends Provider { } async fetchChannels(resultsCallback: ResultsCallback) { - const state = getState(); + const state = this.store.getState(); const teamId = getCurrentTeamId(state); if (!teamId) { return; } - const channelsAsync = store.dispatch(fetchAllMyTeamsChannelsAndChannelMembersREST()); + const channelsAsync = this.store.dispatch(fetchAllMyTeamsChannelsAndChannelMembersREST()); let channels; try { const {data} = await channelsAsync; channels = data.channels as Channel[]; } catch (err) { - store.dispatch(logError(err)); + this.store.dispatch(logError(err)); return; } diff --git a/webapp/channels/src/components/team_general_tab/index.ts b/webapp/channels/src/components/team_general_tab/index.ts index e4ef15d607..f3f3c8af50 100644 --- a/webapp/channels/src/components/team_general_tab/index.ts +++ b/webapp/channels/src/components/team_general_tab/index.ts @@ -4,7 +4,7 @@ import {connect} from 'react-redux'; import type {ConnectedProps} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {Team} from '@mattermost/types/teams'; @@ -12,7 +12,6 @@ import {getTeam, patchTeam, removeTeamIcon, setTeamIcon, regenerateTeamInviteId} import {Permissions} from 'mattermost-redux/constants'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {haveITeamPermission} from 'mattermost-redux/selectors/entities/roles'; -import type {ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {getIsMobileView} from 'selectors/views/browser'; @@ -22,7 +21,7 @@ import TeamGeneralTab from './team_general_tab'; export type OwnProps = { updateSection: (section: string) => void; - team?: Team & { last_team_icon_update?: number }; + team: Team & { last_team_icon_update?: number }; activeSection: string; closeModal: () => void; collapseModal: () => void; @@ -41,17 +40,9 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { }; } -type Actions = { - getTeam: (teamId: string) => Promise; - patchTeam: (team: Partial) => Promise; - regenerateTeamInviteId: (teamId: string) => Promise; - removeTeamIcon: (teamId: string) => Promise; - setTeamIcon: (teamId: string, teamIconFile: File) => Promise; -}; - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ getTeam, patchTeam, regenerateTeamInviteId, diff --git a/webapp/channels/src/components/team_general_tab/open_invite.tsx b/webapp/channels/src/components/team_general_tab/open_invite.tsx index 199ae5827d..8ed09d0296 100644 --- a/webapp/channels/src/components/team_general_tab/open_invite.tsx +++ b/webapp/channels/src/components/team_general_tab/open_invite.tsx @@ -13,12 +13,12 @@ import SettingItemMax from 'components/setting_item_max'; import SettingItemMin from 'components/setting_item_min'; type Props = { - teamId?: string; + teamId: string; isActive: boolean; isGroupConstrained?: boolean; allowOpenInvite?: boolean; onToggle: (active: boolean) => void; - patchTeam: (patch: Partial) => Promise; + patchTeam: (patch: Partial & {id: string}) => Promise; }; const OpenInvite = (props: Props) => { diff --git a/webapp/channels/src/components/team_groups_manage_modal/index.ts b/webapp/channels/src/components/team_groups_manage_modal/index.ts index 598e691bcf..310f59d4e1 100644 --- a/webapp/channels/src/components/team_groups_manage_modal/index.ts +++ b/webapp/channels/src/components/team_groups_manage_modal/index.ts @@ -3,20 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; -import type {Group, SyncablePatch, SyncableType} from '@mattermost/types/groups'; import type {GlobalState} from '@mattermost/types/store'; -import type {TeamMembership} from '@mattermost/types/teams'; import {getGroupsAssociatedToTeam, unlinkGroupSyncable, patchGroupSyncable} from 'mattermost-redux/actions/groups'; import {getMyTeamMembers} from 'mattermost-redux/actions/teams'; -import type {Action} from 'mattermost-redux/types/actions'; import {closeModal, openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; - import TeamGroupsManageModal from './team_groups_manage_modal'; type OwnProps = { @@ -29,29 +24,8 @@ const mapStateToProps = (state: GlobalState, ownProps: OwnProps) => { }; }; -type Actions = { - getGroupsAssociatedToTeam: (teamID: string, q: string, page: number, perPage: number, filterAllowReference: boolean) => Promise<{ - data: { - groups: Group[]; - totalGroupCount: number; - teamID: string; - }; - }>; - closeModal: (modalId: string) => void; - openModal:

(modalData: ModalData

) => void; - unlinkGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType) => Promise<{ - data: boolean; - }>; - patchGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType, patch: Partial) => Promise<{ - data: boolean; - }>; - getMyTeamMembers: () => Promise<{ - data: TeamMembership[]; - }>; -} - const mapDispatchToProps = (dispatch: Dispatch) => ({ - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getGroupsAssociatedToTeam, closeModal, openModal, diff --git a/webapp/channels/src/components/team_groups_manage_modal/team_groups_manage_modal.tsx b/webapp/channels/src/components/team_groups_manage_modal/team_groups_manage_modal.tsx index ee1852a0aa..414c75219d 100644 --- a/webapp/channels/src/components/team_groups_manage_modal/team_groups_manage_modal.tsx +++ b/webapp/channels/src/components/team_groups_manage_modal/team_groups_manage_modal.tsx @@ -7,7 +7,9 @@ import type {IntlShape} from 'react-intl'; import {SyncableType} from '@mattermost/types/groups'; import type {Group, SyncablePatch} from '@mattermost/types/groups'; -import type {Team, TeamMembership} from '@mattermost/types/teams'; +import type {Team} from '@mattermost/types/teams'; + +import type {ActionResult} from 'mattermost-redux/types/actions'; import AddGroupsToTeamModal from 'components/add_groups_to_team_modal'; import ConfirmModal from 'components/confirm_modal'; @@ -26,24 +28,12 @@ type Props = { intl: IntlShape; team: Team; actions: { - getGroupsAssociatedToTeam: (teamID: string, q: string, page: number, perPage: number, filterAllowReference: boolean) => Promise<{ - data: { - groups: Group[]; - totalGroupCount: number; - teamID: string; - }; - }>; + getGroupsAssociatedToTeam: (teamID: string, q: string, page: number, perPage: number, filterAllowReference: boolean) => Promise>; closeModal: (modalId: string) => void; openModal:

(modalData: ModalData

) => void; - unlinkGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType) => Promise<{ - data: boolean; - }>; - patchGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType, patch: Partial) => Promise<{ - data: boolean; - }>; - getMyTeamMembers: () => Promise<{ - data: TeamMembership[]; - }>; + unlinkGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType) => Promise; + patchGroupSyncable: (groupID: string, syncableID: string, syncableType: SyncableType, patch: Partial) => Promise; + getMyTeamMembers: () => void; }; }; @@ -65,8 +55,8 @@ class TeamGroupsManageModal extends React.PureComponent { const {data} = await this.props.actions.getGroupsAssociatedToTeam(this.props.team.id, searchTerm, pageNumber, DEFAULT_NUM_PER_PAGE, true); return { - items: data.groups, - totalCount: data.totalGroupCount, + items: data!.groups, + totalCount: data!.totalGroupCount, }; }; diff --git a/webapp/channels/src/components/team_members_dropdown/team_members_dropdown.tsx b/webapp/channels/src/components/team_members_dropdown/team_members_dropdown.tsx index 36c1f39da7..3a495a0b73 100644 --- a/webapp/channels/src/components/team_members_dropdown/team_members_dropdown.tsx +++ b/webapp/channels/src/components/team_members_dropdown/team_members_dropdown.tsx @@ -8,7 +8,7 @@ import type {Team, TeamMembership} from '@mattermost/types/teams'; import type {UserProfile} from '@mattermost/types/users'; import type {isCollapsedThreadsEnabled} from 'mattermost-redux/selectors/entities/preferences'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {isGuest, isAdmin, isSystemAdmin} from 'mattermost-redux/utils/user_utils'; import ConfirmModal from 'components/confirm_modal'; @@ -35,11 +35,11 @@ type Props = { getMyTeamUnreads: (collapsedThreads: boolean) => void; getUser: (id: string) => void; getTeamMember: (teamId: string, userId: string) => void; - getTeamStats: (teamId: string) => ActionFunc; + getTeamStats: (teamId: string) => void; getChannelStats: (channelId: string) => void; - updateTeamMemberSchemeRoles: (teamId: string, userId: string, b1: boolean, b2: boolean) => ActionFunc & Partial<{error: Error}>; - updateUserActive: (userId: string, active: boolean) => ActionFunc; - removeUserFromTeamAndGetStats: (teamId: string, userId: string) => ActionFunc & Partial<{error: Error}>; + updateTeamMemberSchemeRoles: (teamId: string, userId: string, b1: boolean, b2: boolean) => Promise; + updateUserActive: (userId: string, active: boolean) => Promise; + removeUserFromTeamAndGetStats: (teamId: string, userId: string) => Promise; }; }; diff --git a/webapp/channels/src/components/team_members_modal/index.ts b/webapp/channels/src/components/team_members_modal/index.ts index 58eac94464..0e3a440b6c 100644 --- a/webapp/channels/src/components/team_members_modal/index.ts +++ b/webapp/channels/src/components/team_members_modal/index.ts @@ -3,25 +3,19 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams'; -import type {Action} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; import {isModalOpen} from 'selectors/views/modals'; import {ModalIdentifiers} from 'utils/constants'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import TeamMembersModal from './team_members_modal'; -type Actions = { - openModal:

(modalData: ModalData

) => void; -} - function mapStateToProps(state: GlobalState) { const modalId = ModalIdentifiers.TEAM_MEMBERS; return { @@ -32,7 +26,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ openModal, }, dispatch), }; diff --git a/webapp/channels/src/components/team_selector_modal/index.ts b/webapp/channels/src/components/team_selector_modal/index.ts index 7e7665f5d7..5065b16042 100644 --- a/webapp/channels/src/components/team_selector_modal/index.ts +++ b/webapp/channels/src/components/team_selector_modal/index.ts @@ -3,11 +3,10 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, AnyAction, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {getTeams as loadTeams, searchTeams} from 'mattermost-redux/actions/teams'; import {getTeams} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {setModalSearchTerm} from 'actions/views/search'; @@ -29,15 +28,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - loadTeams: (page?: number, perPage?: number, includeTotalCount?: boolean) => Promise; - searchTeams: (searchTerm: string) => void; - setModalSearchTerm: (searchTerm: string) => GenericAction; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ loadTeams, setModalSearchTerm, searchTeams, diff --git a/webapp/channels/src/components/team_sidebar/index.ts b/webapp/channels/src/components/team_sidebar/index.ts index b5fee7b3d6..d97695f147 100644 --- a/webapp/channels/src/components/team_sidebar/index.ts +++ b/webapp/channels/src/components/team_sidebar/index.ts @@ -5,10 +5,9 @@ import {connect} from 'react-redux'; import type {ConnectedProps} from 'react-redux'; import {withRouter} from 'react-router-dom'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {ClientConfig} from '@mattermost/types/config'; -import type {Team} from '@mattermost/types/teams'; import {getTeams} from 'mattermost-redux/actions/teams'; import {getTeamsUnreadStatuses} from 'mattermost-redux/selectors/entities/channels'; @@ -19,7 +18,6 @@ import { getJoinableTeamIds, getMyTeams, } from 'mattermost-redux/selectors/entities/teams'; -import type {GenericAction, GetStateFunc} from 'mattermost-redux/types/actions'; import {switchTeam, updateTeamsOrderForUser} from 'actions/team_actions'; import {getCurrentLocale} from 'selectors/i18n'; @@ -56,15 +54,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - getTeams: (page?: number, perPage?: number, includeTotalCount?: boolean) => void; - switchTeam: (url: string, team?: Team) => (dispatch: Dispatch, getState: GetStateFunc) => void; - updateTeamsOrderForUser: (teamIds: string[]) => (dispatch: Dispatch, getState: GetStateFunc) => Promise; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators({ + actions: bindActionCreators({ getTeams, switchTeam, updateTeamsOrderForUser, diff --git a/webapp/channels/src/components/terms_of_service/index.ts b/webapp/channels/src/components/terms_of_service/index.ts index 2cf3000c35..ce19d6dcb5 100644 --- a/webapp/channels/src/components/terms_of_service/index.ts +++ b/webapp/channels/src/components/terms_of_service/index.ts @@ -3,28 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; -import type {TermsOfService as ReduxTermsOfService} from '@mattermost/types/terms_of_service'; import {getTermsOfService, updateMyTermsOfServiceStatus} from 'mattermost-redux/actions/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getIsOnboardingFlowEnabled} from 'mattermost-redux/selectors/entities/preferences'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {getEmojiMap} from 'selectors/emojis'; import TermsOfService from './terms_of_service'; -import type {UpdateMyTermsOfServiceStatusResponse} from './terms_of_service'; - -type Actions = { - getTermsOfService: () => Promise<{data: ReduxTermsOfService}>; - updateMyTermsOfServiceStatus: ( - termsOfServiceId: string, - accepted: boolean - ) => {data: UpdateMyTermsOfServiceStatusResponse}; -}; function mapStateToProps(state: GlobalState) { const config = getConfig(state); @@ -36,9 +25,9 @@ function mapStateToProps(state: GlobalState) { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getTermsOfService, updateMyTermsOfServiceStatus, }, dispatch), diff --git a/webapp/channels/src/components/terms_of_service/terms_of_service.tsx b/webapp/channels/src/components/terms_of_service/terms_of_service.tsx index f9fedc7568..28c70c765c 100644 --- a/webapp/channels/src/components/terms_of_service/terms_of_service.tsx +++ b/webapp/channels/src/components/terms_of_service/terms_of_service.tsx @@ -8,6 +8,7 @@ import type {RouteComponentProps} from 'react-router'; import type {TermsOfService as ReduxTermsOfService} from '@mattermost/types/terms_of_service'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {memoizeResult} from 'mattermost-redux/utils/helpers'; import * as GlobalActions from 'actions/global_actions'; @@ -33,11 +34,11 @@ export interface UpdateMyTermsOfServiceStatusResponse { export interface TermsOfServiceProps extends RouteComponentProps { termsEnabled: boolean; actions: { - getTermsOfService: () => Promise<{ data: ReduxTermsOfService }>; + getTermsOfService: () => Promise>; updateMyTermsOfServiceStatus: ( termsOfServiceId: string, accepted: boolean - ) => {data: UpdateMyTermsOfServiceStatusResponse}; + ) => Promise; }; emojiMap: EmojiMap; onboardingFlowEnabled: boolean; diff --git a/webapp/channels/src/components/textbox/index.ts b/webapp/channels/src/components/textbox/index.ts index 71c8d48c76..dcf7ee074a 100644 --- a/webapp/channels/src/components/textbox/index.ts +++ b/webapp/channels/src/components/textbox/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; @@ -14,14 +14,12 @@ import {makeGetProfilesForThread} from 'mattermost-redux/selectors/entities/post import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {Action} from 'mattermost-redux/types/actions'; import {autocompleteChannels} from 'actions/channel_actions'; import {autocompleteUsersInChannel} from 'actions/views/channel'; import {searchAssociatedGroupsForReference} from 'actions/views/group'; import Textbox from './textbox'; -import type {Props as TextboxProps} from './textbox'; import TextboxLinks from './textbox_links'; type Props = { @@ -54,7 +52,7 @@ const makeMapStateToProps = () => { }; const mapDispatchToProps = (dispatch: Dispatch) => ({ - actions: bindActionCreators, TextboxProps['actions']>({ + actions: bindActionCreators({ autocompleteUsersInChannel, autocompleteChannels, searchAssociatedGroupsForReference, diff --git a/webapp/channels/src/components/unarchive_channel_modal/index.ts b/webapp/channels/src/components/unarchive_channel_modal/index.ts index aea1d063d3..0b6de58fd7 100644 --- a/webapp/channels/src/components/unarchive_channel_modal/index.ts +++ b/webapp/channels/src/components/unarchive_channel_modal/index.ts @@ -3,17 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {unarchiveChannel} from 'mattermost-redux/actions/channels'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import UnarchiveChannelModal from './unarchive_channel_modal'; -import type {ChannelDetailsActions} from './unarchive_channel_modal'; -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, ChannelDetailsActions>({ + actions: bindActionCreators({ unarchiveChannel, }, dispatch), }; diff --git a/webapp/channels/src/components/update_user_group_modal/index.ts b/webapp/channels/src/components/update_user_group_modal/index.ts index 760eab9ade..70edada046 100644 --- a/webapp/channels/src/components/update_user_group_modal/index.ts +++ b/webapp/channels/src/components/update_user_group_modal/index.ts @@ -3,17 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {CustomGroupPatch} from '@mattermost/types/groups'; +import type {Dispatch} from 'redux'; import {patchGroup} from 'mattermost-redux/actions/groups'; import {getGroup} from 'mattermost-redux/selectors/entities/groups'; -import type {Action, ActionResult} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import UpdateUserGroupModal from './update_user_group_modal'; @@ -30,14 +26,9 @@ function makeMapStateToProps(state: GlobalState, props: OwnProps) { }; } -type Actions = { - patchGroup: (groupId: string, group: CustomGroupPatch) => Promise; - openModal:

(modalData: ModalData

) => void; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ patchGroup, openModal, }, dispatch), diff --git a/webapp/channels/src/components/user_group_popover/group_member_list/group_member_list.tsx b/webapp/channels/src/components/user_group_popover/group_member_list/group_member_list.tsx index aaa44fce3a..67aa163e8c 100644 --- a/webapp/channels/src/components/user_group_popover/group_member_list/group_member_list.tsx +++ b/webapp/channels/src/components/user_group_popover/group_member_list/group_member_list.tsx @@ -10,10 +10,11 @@ import type {ListChildComponentProps} from 'react-window'; import InfiniteLoader from 'react-window-infinite-loader'; import styled, {css} from 'styled-components'; -import type {ServerError} from '@mattermost/types/errors'; import type {Group} from '@mattermost/types/groups'; import type {UserProfile} from '@mattermost/types/users'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import NoResultsIndicator from 'components/no_results_indicator'; import {NoResultsVariant} from 'components/no_results_indicator/types'; import LoadingSpinner from 'components/widgets/loading/loading_spinner'; @@ -72,8 +73,8 @@ export type Props = { searchTerm: string; actions: { - getUsersInGroup: (groupId: string, page: number, perPage: number, sort: string) => Promise<{ data: UserProfile[] }>; - openDirectChannelToUserId: (userId?: string) => Promise<{ error: ServerError }>; + getUsersInGroup: (groupId: string, page: number, perPage: number, sort: string) => Promise>; + openDirectChannelToUserId: (userId: string) => Promise; closeRightHandSide: () => void; }; } @@ -130,7 +131,7 @@ const GroupMemberList = (props: Props) => { return; } setCurrentDMLoading(user.id); - actions.openDirectChannelToUserId(user.id).then((result: { error: ServerError }) => { + actions.openDirectChannelToUserId(user.id).then((result: ActionResult) => { if (!result.error) { actions.closeRightHandSide(); setCurrentDMLoading(undefined); diff --git a/webapp/channels/src/components/user_group_popover/group_member_list/index.ts b/webapp/channels/src/components/user_group_popover/group_member_list/index.ts index 42fca57ac4..623f51d0f4 100644 --- a/webapp/channels/src/components/user_group_popover/group_member_list/index.ts +++ b/webapp/channels/src/components/user_group_popover/group_member_list/index.ts @@ -3,9 +3,8 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; -import type {ServerError} from '@mattermost/types/errors'; import type {Group} from '@mattermost/types/groups'; import type {UserProfile} from '@mattermost/types/users'; @@ -14,7 +13,6 @@ import {createSelector} from 'mattermost-redux/selectors/create_selector'; import {getTeammateNameDisplaySetting} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentRelativeTeamUrl} from 'mattermost-redux/selectors/entities/teams'; import {getProfilesInGroupWithoutSorting, searchProfilesInGroupWithoutSorting} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {displayUsername} from 'mattermost-redux/utils/user_utils'; import {openDirectChannelToUserId} from 'actions/channel_actions'; @@ -25,12 +23,6 @@ import type {GlobalState} from 'types/store'; import GroupMemberList from './group_member_list'; import type {GroupMember} from './group_member_list'; -type Actions = { - getUsersInGroup: (groupId: string, page: number, perPage: number) => Promise<{data: UserProfile[]}>; - openDirectChannelToUserId: (userId?: string) => Promise<{error: ServerError}>; - closeRightHandSide: () => void; -}; - type OwnProps = { group: Group; }; @@ -87,7 +79,7 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getUsersInGroup, openDirectChannelToUserId, closeRightHandSide, diff --git a/webapp/channels/src/components/user_group_popover/index.ts b/webapp/channels/src/components/user_group_popover/index.ts index c7ea328292..54d08c041a 100644 --- a/webapp/channels/src/components/user_group_popover/index.ts +++ b/webapp/channels/src/components/user_group_popover/index.ts @@ -3,26 +3,18 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {searchProfiles} from 'mattermost-redux/actions/users'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; import {setPopoverSearchTerm} from 'actions/views/search'; import {getIsMobileView} from 'selectors/views/browser'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import UserGroupPopover from './user_group_popover'; -type Actions = { - setPopoverSearchTerm: (term: string) => void; - openModal:

(modalData: ModalData

) => void; - searchProfiles: (term: string, options: any) => Promise; -}; - function mapStateToProps(state: GlobalState) { return { searchTerm: state.views.search.popoverSearch, @@ -32,7 +24,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ setPopoverSearchTerm, openModal, searchProfiles, diff --git a/webapp/channels/src/components/user_groups_modal/index.ts b/webapp/channels/src/components/user_groups_modal/index.ts index 5c861400a9..6934ea0d22 100644 --- a/webapp/channels/src/components/user_groups_modal/index.ts +++ b/webapp/channels/src/components/user_groups_modal/index.ts @@ -3,14 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; -import type {GetGroupsForUserParams, GetGroupsParams, Group, GroupSearchParams} from '@mattermost/types/groups'; +import type {Group} from '@mattermost/types/groups'; import {getGroups, getGroupsByUserIdPaginated, searchGroups} from 'mattermost-redux/actions/groups'; import {makeGetAllAssociatedGroupsForReference, makeGetMyAllowReferencedGroups, searchAllowReferencedGroups, searchMyAllowReferencedGroups, searchArchivedGroups, getArchivedGroups} from 'mattermost-redux/selectors/entities/groups'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {setModalSearchTerm} from 'actions/views/search'; import {isModalOpen} from 'selectors/views/modals'; @@ -21,19 +20,6 @@ import type {GlobalState} from 'types/store'; import UserGroupsModal from './user_groups_modal'; -type Actions = { - getGroups: ( - groupsParams: GetGroupsParams, - ) => Promise<{data: Group[]}>; - setModalSearchTerm: (term: string) => void; - getGroupsByUserIdPaginated: ( - opts: GetGroupsForUserParams, - ) => Promise<{data: Group[]}>; - searchGroups: ( - params: GroupSearchParams, - ) => Promise<{data: Group[]}>; -}; - function makeMapStateToProps() { const getAllAssociatedGroupsForReference = makeGetAllAssociatedGroupsForReference(); const getMyAllowReferencedGroups = makeGetMyAllowReferencedGroups(); @@ -67,7 +53,7 @@ function makeMapStateToProps() { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getGroups, setModalSearchTerm, getGroupsByUserIdPaginated, diff --git a/webapp/channels/src/components/user_groups_modal/user_groups_list/index.ts b/webapp/channels/src/components/user_groups_modal/user_groups_list/index.ts index 229f960178..ff2e0c85ba 100644 --- a/webapp/channels/src/components/user_groups_modal/user_groups_list/index.ts +++ b/webapp/channels/src/components/user_groups_modal/user_groups_list/index.ts @@ -3,25 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {archiveGroup, restoreGroup} from 'mattermost-redux/actions/groups'; import {getGroupListPermissions} from 'mattermost-redux/selectors/entities/roles'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import UserGroupsList from './user_groups_list'; -type Actions = { - openModal:

(modalData: ModalData

) => void; - archiveGroup: (groupId: string) => Promise; - restoreGroup: (groupId: string) => Promise; -}; - function mapStateToProps(state: GlobalState) { const groupPermissionsMap = getGroupListPermissions(state); return { @@ -31,7 +23,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ openModal, archiveGroup, restoreGroup, diff --git a/webapp/channels/src/components/user_groups_modal/user_groups_modal.tsx b/webapp/channels/src/components/user_groups_modal/user_groups_modal.tsx index ccaf405838..66b2e5957f 100644 --- a/webapp/channels/src/components/user_groups_modal/user_groups_modal.tsx +++ b/webapp/channels/src/components/user_groups_modal/user_groups_modal.tsx @@ -7,6 +7,8 @@ import {Modal} from 'react-bootstrap'; import type {GetGroupsForUserParams, GetGroupsParams, Group, GroupSearchParams} from '@mattermost/types/groups'; import './user_groups_modal.scss'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import NoResultsIndicator from 'components/no_results_indicator'; import {NoResultsVariant} from 'components/no_results_indicator/types'; import Input from 'components/widgets/inputs/input/input'; @@ -33,14 +35,14 @@ export type Props = { actions: { getGroups: ( opts: GetGroupsParams, - ) => Promise<{data: Group[]}>; + ) => Promise>; setModalSearchTerm: (term: string) => void; getGroupsByUserIdPaginated: ( opts: GetGroupsForUserParams, - ) => Promise<{data: Group[]}>; + ) => Promise>; searchGroups: ( params: GroupSearchParams, - ) => Promise<{data: Group[]}>; + ) => Promise; }; } @@ -79,7 +81,7 @@ const UserGroupsModal = (props: Props) => { per_page: GROUPS_PER_PAGE, include_member_count: true, }; - let data: {data: Group[]} = {data: []}; + let data: ActionResult = {data: []}; if (groupType === 'all') { groupsParams.include_archived = true; @@ -96,7 +98,7 @@ const UserGroupsModal = (props: Props) => { data = await actions.getGroups(groupsParams); } - if (data && data.data.length === 0) { + if (data && data.data!.length === 0) { setGroupsFull(true); } else { setGroupsFull(false); diff --git a/webapp/channels/src/components/user_groups_modal/user_groups_modal_header/index.ts b/webapp/channels/src/components/user_groups_modal/user_groups_modal_header/index.ts index 4edbef6da2..5dae4f429e 100644 --- a/webapp/channels/src/components/user_groups_modal/user_groups_modal_header/index.ts +++ b/webapp/channels/src/components/user_groups_modal/user_groups_modal_header/index.ts @@ -3,23 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {Permissions} from 'mattermost-redux/constants'; import {haveISystemPermission} from 'mattermost-redux/selectors/entities/roles'; -import type {ActionFunc, GenericAction} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import UserGroupsModalHeader from './user_groups_modal_header'; -type Actions = { - openModal:

(modalData: ModalData

) => void; -}; - function mapStateToProps(state: GlobalState) { const canCreateCustomGroups = haveISystemPermission(state, {permission: Permissions.CREATE_CUSTOM_GROUP}); @@ -30,7 +24,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ openModal, }, dispatch), }; diff --git a/webapp/channels/src/components/user_settings/advanced/index.ts b/webapp/channels/src/components/user_settings/advanced/index.ts index 4ea3a91b8d..abd584fb23 100644 --- a/webapp/channels/src/components/user_settings/advanced/index.ts +++ b/webapp/channels/src/components/user_settings/advanced/index.ts @@ -3,21 +3,19 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {savePreferences} from 'mattermost-redux/actions/preferences'; import {updateUserActive, revokeAllSessionsForUser} from 'mattermost-redux/actions/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {get, getUnreadScrollPositionPreference, makeGetCategory, syncedDraftsAreAllowed} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import {Preferences} from 'utils/constants'; import type {GlobalState} from 'types/store'; import AdvancedSettingsDisplay from './user_settings_advanced'; -import type {Props} from './user_settings_advanced'; function makeMapStateToProps() { const getAdvancedSettingsCategory = makeGetCategory(); @@ -47,7 +45,7 @@ function makeMapStateToProps() { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ savePreferences, updateUserActive, revokeAllSessionsForUser, diff --git a/webapp/channels/src/components/user_settings/display/index.ts b/webapp/channels/src/components/user_settings/display/index.ts index 4e8a5cd4ba..faba3e9fc3 100644 --- a/webapp/channels/src/components/user_settings/display/index.ts +++ b/webapp/channels/src/components/user_settings/display/index.ts @@ -3,12 +3,10 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import timezones from 'timezones.json'; import {CollapsedThreads} from '@mattermost/types/config'; -import type {PreferenceType} from '@mattermost/types/preferences'; -import type {UserProfile} from '@mattermost/types/users'; import {savePreferences} from 'mattermost-redux/actions/preferences'; import {autoUpdateTimezone} from 'mattermost-redux/actions/timezone'; @@ -17,7 +15,6 @@ import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general import {get, isCollapsedThreadsAllowed, getCollapsedThreadsPreference} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentTimezoneFull, getCurrentTimezoneLabel} from 'mattermost-redux/selectors/entities/timezone'; import {getCurrentUserId, getUser} from 'mattermost-redux/selectors/entities/users'; -import type {GenericAction, ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import {getUserCurrentTimezone} from 'mattermost-redux/utils/timezone_utils'; import {Preferences} from 'utils/constants'; @@ -26,12 +23,6 @@ import type {GlobalState} from 'types/store'; import UserSettingsDisplay from './user_settings_display'; -type Actions = { - autoUpdateTimezone: (deviceTimezone: string) => void; - savePreferences: (userId: string, preferences: PreferenceType[]) => void; - updateMe: (user: UserProfile) => Promise; -} - export function makeMapStateToProps() { return (state: GlobalState) => { const config = getConfig(state); @@ -85,9 +76,9 @@ export function makeMapStateToProps() { }; } -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ autoUpdateTimezone, savePreferences, updateMe, diff --git a/webapp/channels/src/components/user_settings/display/manage_languages/index.ts b/webapp/channels/src/components/user_settings/display/manage_languages/index.ts index 92ca8dc818..1b7ccd1cb8 100644 --- a/webapp/channels/src/components/user_settings/display/manage_languages/index.ts +++ b/webapp/channels/src/components/user_settings/display/manage_languages/index.ts @@ -3,24 +3,18 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {UserProfile} from '@mattermost/types/users'; +import type {Dispatch} from 'redux'; import {updateMe} from 'mattermost-redux/actions/users'; -import type {ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import ManageLanguages from './manage_languages'; -type Actions = { - updateMe: (user: UserProfile) => Promise; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ updateMe, - }, dispatch)}; + }, dispatch), + }; } export default connect(null, mapDispatchToProps)(ManageLanguages); diff --git a/webapp/channels/src/components/user_settings/display/manage_timezones/index.ts b/webapp/channels/src/components/user_settings/display/manage_timezones/index.ts index 920f7147f1..262c7c74ad 100644 --- a/webapp/channels/src/components/user_settings/display/manage_timezones/index.ts +++ b/webapp/channels/src/components/user_settings/display/manage_timezones/index.ts @@ -3,27 +3,22 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import timezones from 'timezones.json'; import type {GlobalState} from '@mattermost/types/store'; -import type {UserProfile} from '@mattermost/types/users'; import {updateMe} from 'mattermost-redux/actions/users'; import {getCurrentTimezoneLabel} from 'mattermost-redux/selectors/entities/timezone'; -import type {ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import ManageTimezones from './manage_timezones'; -type Actions = { - updateMe: (user: UserProfile) => Promise; -} - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ updateMe, - }, dispatch)}; + }, dispatch), + }; } function mapStateToProps(state: GlobalState) { const timezoneLabel = getCurrentTimezoneLabel(state); diff --git a/webapp/channels/src/components/user_settings/general/index.ts b/webapp/channels/src/components/user_settings/general/index.ts index edb1a31548..459d138cfa 100644 --- a/webapp/channels/src/components/user_settings/general/index.ts +++ b/webapp/channels/src/components/user_settings/general/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {clearErrors, logError} from 'mattermost-redux/actions/errors'; import { @@ -13,14 +13,12 @@ import { uploadProfileImage, } from 'mattermost-redux/actions/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import {getIsMobileView} from 'selectors/views/browser'; import type {GlobalState} from 'types/store'; import UserSettingsGeneralTab from './user_settings_general'; -import type {Props} from './user_settings_general'; function mapStateToProps(state: GlobalState) { const config = getConfig(state); @@ -55,7 +53,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ logError, clearErrors, updateMe, diff --git a/webapp/channels/src/components/user_settings/general/user_settings_general.tsx b/webapp/channels/src/components/user_settings/general/user_settings_general.tsx index be6ed14726..bbb13236d3 100644 --- a/webapp/channels/src/components/user_settings/general/user_settings_general.tsx +++ b/webapp/channels/src/components/user_settings/general/user_settings_general.tsx @@ -9,6 +9,7 @@ import type {IntlShape} from 'react-intl'; import type {UserProfile} from '@mattermost/types/users'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import {isEmail} from 'mattermost-redux/utils/helpers'; import {trackEvent} from 'actions/telemetry_actions.jsx'; @@ -105,26 +106,10 @@ export type Props = { actions: { logError: ({message, type}: {message: any; type: string}, status: boolean) => void; clearErrors: () => void; - updateMe: (user: UserProfile) => Promise<{ - data: boolean; - error?: { - server_error_id: string; - message: string; - }; - }>; - sendVerificationEmail: (email: string) => Promise<{ - data: boolean; - error?: { - err: string; - }; - }>; + updateMe: (user: UserProfile) => Promise; + sendVerificationEmail: (email: string) => Promise; setDefaultProfileImage: (id: string) => void; - uploadProfileImage: (id: string, file: File) => Promise<{ - data: boolean; - error?: { - message: string; - }; - }>; + uploadProfileImage: (id: string, file: File) => Promise; }; requireEmailVerification?: boolean; ldapFirstNameAttributeSet?: boolean; diff --git a/webapp/channels/src/components/user_settings/modal/index.ts b/webapp/channels/src/components/user_settings/modal/index.ts index 6238bef4ec..687ef6e424 100644 --- a/webapp/channels/src/components/user_settings/modal/index.ts +++ b/webapp/channels/src/components/user_settings/modal/index.ts @@ -3,19 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {sendVerificationEmail} from 'mattermost-redux/actions/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; -import type {Action} from 'mattermost-redux/types/actions'; import {getPluginUserSettings} from 'selectors/plugins'; import type {GlobalState} from 'types/store'; import UserSettingsModal from './user_settings_modal'; -import type {Props} from './user_settings_modal'; function mapStateToProps(state: GlobalState) { const config = getConfig(state); @@ -33,7 +31,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Props['actions']>({ + actions: bindActionCreators({ sendVerificationEmail, }, dispatch), }; diff --git a/webapp/channels/src/components/user_settings/modal/user_settings_modal.tsx b/webapp/channels/src/components/user_settings/modal/user_settings_modal.tsx index 475a44dd8b..eb2105dfac 100644 --- a/webapp/channels/src/components/user_settings/modal/user_settings_modal.tsx +++ b/webapp/channels/src/components/user_settings/modal/user_settings_modal.tsx @@ -12,9 +12,10 @@ import type { IntlShape} from 'react-intl'; import {Provider} from 'react-redux'; -import type {StatusOK} from '@mattermost/types/client4'; import type {UserProfile} from '@mattermost/types/users'; +import type {ActionResult} from 'mattermost-redux/types/actions'; + import store from 'stores/redux_store'; import ConfirmModal from 'components/confirm_modal'; @@ -78,12 +79,7 @@ export type Props = { intl: IntlShape; isContentProductSettings: boolean; actions: { - sendVerificationEmail: (email: string) => Promise<{ - data: StatusOK; - error: { - err: string; - }; - }>; + sendVerificationEmail: (email: string) => Promise; }; pluginSettings: {[pluginId: string]: PluginConfiguration}; } diff --git a/webapp/channels/src/components/user_settings/notifications/email_notification_setting/index.ts b/webapp/channels/src/components/user_settings/notifications/email_notification_setting/index.ts index 7a5cffe667..8f0fd371d0 100644 --- a/webapp/channels/src/components/user_settings/notifications/email_notification_setting/index.ts +++ b/webapp/channels/src/components/user_settings/notifications/email_notification_setting/index.ts @@ -3,9 +3,8 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; -import type {PreferenceType} from '@mattermost/types/preferences'; import type {GlobalState} from '@mattermost/types/store'; import {savePreferences} from 'mattermost-redux/actions/preferences'; @@ -13,15 +12,9 @@ import {Preferences} from 'mattermost-redux/constants'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/common'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {get as getPreference} from 'mattermost-redux/selectors/entities/preferences'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import EmailNotificationSetting from './email_notification_setting'; -type Actions = { - savePreferences: (currentUserId: string, emailIntervalPreference: PreferenceType[]) => - Promise<{data: boolean}>; -} - function mapStateToProps(state: GlobalState) { const config = getConfig(state); const emailInterval = parseInt(getPreference( @@ -41,7 +34,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ savePreferences, }, dispatch), }; diff --git a/webapp/channels/src/components/user_settings/security/index.ts b/webapp/channels/src/components/user_settings/security/index.ts index 123076f3e3..60c910c08d 100644 --- a/webapp/channels/src/components/user_settings/security/index.ts +++ b/webapp/channels/src/components/user_settings/security/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import type {UserProfile} from '@mattermost/types/users'; @@ -12,7 +12,6 @@ import {getAuthorizedOAuthApps, deauthorizeOAuthApp} from 'mattermost-redux/acti import {getMe, updateUserPassword} from 'mattermost-redux/actions/users'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getBool} from 'mattermost-redux/selectors/entities/preferences'; -import type {ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; import * as UserUtils from 'mattermost-redux/utils/user_utils'; import {Preferences} from 'utils/constants'; @@ -20,13 +19,6 @@ import {getPasswordConfig} from 'utils/utils'; import SecurityTab from './user_settings_security'; -type Actions = { - getMe: () => void; - updateUserPassword: (userId: string, currentPassword: string, newPassword: string) => Promise; - getAuthorizedOAuthApps: () => Promise; - deauthorizeOAuthApp: (clientId: string) => Promise; -}; - type Props = { user: UserProfile; activeSection?: string; @@ -70,7 +62,7 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getMe, updateUserPassword, getAuthorizedOAuthApps, diff --git a/webapp/channels/src/components/user_settings/security/mfa_section/index.ts b/webapp/channels/src/components/user_settings/security/mfa_section/index.ts index cf988e8ff8..4dbe38cee1 100644 --- a/webapp/channels/src/components/user_settings/security/mfa_section/index.ts +++ b/webapp/channels/src/components/user_settings/security/mfa_section/index.ts @@ -3,14 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; import type {UserProfile} from '@mattermost/types/users'; import {getConfig, getLicense} from 'mattermost-redux/selectors/entities/general'; import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import {deactivateMfa} from 'actions/views/mfa'; @@ -18,10 +17,6 @@ import Constants from 'utils/constants'; import MfaSection from './mfa_section'; -type Actions = { - deactivateMfa: () => Promise<{error?: {message: string}}>; -} - function mapStateToProps(state: GlobalState) { const license = getLicense(state); const config = getConfig(state); @@ -44,7 +39,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ deactivateMfa, }, dispatch), }; diff --git a/webapp/channels/src/components/user_settings/security/user_access_token_section/index.ts b/webapp/channels/src/components/user_settings/security/user_access_token_section/index.ts index 3ea1f1f853..c7751bc0a5 100644 --- a/webapp/channels/src/components/user_settings/security/user_access_token_section/index.ts +++ b/webapp/channels/src/components/user_settings/security/user_access_token_section/index.ts @@ -3,7 +3,7 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import type {GlobalState} from '@mattermost/types/store'; @@ -15,39 +15,9 @@ import { enableUserAccessToken, disableUserAccessToken, } from 'mattermost-redux/actions/users'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; import UserAccessTokenSection from './user_access_token_section'; -type Actions = { - getUserAccessTokensForUser: (userId: string, page: number, perPage: number) => void; - createUserAccessToken: (userId: string, description: string) => Promise<{ - data: {token: string; description: string; id: string; is_active: boolean} | null; - error?: { - message: string; - }; - }>; - revokeUserAccessToken: (tokenId: string) => Promise<{ - data: string; - error?: { - message: string; - }; - }>; - enableUserAccessToken: (tokenId: string) => Promise<{ - data: string; - error?: { - message: string; - }; - }>; - disableUserAccessToken: (tokenId: string) => Promise<{ - data: string; - error?: { - message: string; - }; - }>; - clearUserAccessTokens: () => void; -} - function mapStateToProps(state: GlobalState) { return { userAccessTokens: state.entities.users.myUserAccessTokens, @@ -56,7 +26,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getUserAccessTokensForUser, createUserAccessToken, revokeUserAccessToken, diff --git a/webapp/channels/src/components/user_settings/security/user_access_token_section/user_access_token_section.tsx b/webapp/channels/src/components/user_settings/security/user_access_token_section/user_access_token_section.tsx index e879c47ba6..7d8a9b33c6 100644 --- a/webapp/channels/src/components/user_settings/security/user_access_token_section/user_access_token_section.tsx +++ b/webapp/channels/src/components/user_settings/security/user_access_token_section/user_access_token_section.tsx @@ -4,8 +4,9 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; -import type {UserProfile} from '@mattermost/types/users'; +import type {UserAccessToken, UserProfile} from '@mattermost/types/users'; +import type {ActionResult} from 'mattermost-redux/types/actions'; import * as UserUtils from 'mattermost-redux/utils/user_utils'; import {trackEvent} from 'actions/telemetry_actions.jsx'; @@ -38,30 +39,10 @@ type Props = { setRequireConfirm: (isRequiredConfirm: boolean, confirmCopyToken: (confirmAction: () => void) => void) => void; actions: { getUserAccessTokensForUser: (userId: string, page: number, perPage: number) => void; - createUserAccessToken: (userId: string, description: string) => Promise<{ - data: {token: string; description: string; id: string; is_active: boolean} | null; - error?: { - message: string; - }; - }>; - revokeUserAccessToken: (tokenId: string) => Promise<{ - data: string; - error?: { - message: string; - }; - }>; - enableUserAccessToken: (tokenId: string) => Promise<{ - data: string; - error?: { - message: string; - }; - }>; - disableUserAccessToken: (tokenId: string) => Promise<{ - data: string; - error?: { - message: string; - }; - }>; + createUserAccessToken: (userId: string, description: string) => Promise>; + revokeUserAccessToken: (tokenId: string) => Promise; + enableUserAccessToken: (tokenId: string) => Promise; + disableUserAccessToken: (tokenId: string) => Promise; clearUserAccessTokens: () => void; }; } @@ -69,7 +50,7 @@ type Props = { type State = { active?: boolean; showConfirmModal: boolean; - newToken?: {token: string; description: string; id: string; is_active: boolean} | null; + newToken?: UserAccessToken | null; tokenCreationState?: string; tokenError?: string; serverError?: string|null; diff --git a/webapp/channels/src/components/view_user_group_modal/index.ts b/webapp/channels/src/components/view_user_group_modal/index.ts index 20d43fd008..f7cd33b71a 100644 --- a/webapp/channels/src/components/view_user_group_modal/index.ts +++ b/webapp/channels/src/components/view_user_group_modal/index.ts @@ -3,33 +3,22 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; -import type {Group} from '@mattermost/types/groups'; import type {UserProfile} from '@mattermost/types/users'; import {getGroup} from 'mattermost-redux/actions/groups'; import {getProfilesInGroup as getUsersInGroup, searchProfiles} from 'mattermost-redux/actions/users'; import {getGroup as getGroupById} from 'mattermost-redux/selectors/entities/groups'; import {getProfilesInGroup, searchProfilesInGroup} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; import {setModalSearchTerm} from 'actions/views/search'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import ViewUserGroupModal from './view_user_group_modal'; -type Actions = { - getGroup: (groupId: string, includeMemberCount: boolean) => Promise<{data: Group}>; - getUsersInGroup: (groupId: string, page: number, perPage: number) => Promise<{data: UserProfile[]}>; - setModalSearchTerm: (term: string) => void; - openModal:

(modalData: ModalData

) => void; - searchProfiles: (term: string, options: any) => Promise; -}; - type OwnProps = { groupId: string; }; @@ -55,7 +44,7 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ getGroup, getUsersInGroup, setModalSearchTerm, diff --git a/webapp/channels/src/components/view_user_group_modal/view_user_group_header_sub_menu/index.ts b/webapp/channels/src/components/view_user_group_modal/view_user_group_header_sub_menu/index.ts index 4f757413bf..15210df3a8 100644 --- a/webapp/channels/src/components/view_user_group_modal/view_user_group_header_sub_menu/index.ts +++ b/webapp/channels/src/components/view_user_group_modal/view_user_group_header_sub_menu/index.ts @@ -3,26 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {addUsersToGroup, archiveGroup, removeUsersFromGroup} from 'mattermost-redux/actions/groups'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import ViewUserGroupHeaderSubMenu from './view_user_group_header_sub_menu'; -type Actions = { - openModal:

(modalData: ModalData

) => void; - removeUsersFromGroup: (groupId: string, userIds: string[]) => Promise; - addUsersToGroup: (groupId: string, userIds: string[]) => Promise; - archiveGroup: (groupId: string) => Promise; -}; - function mapStateToProps(state: GlobalState) { return { currentUserId: getCurrentUserId(state), @@ -31,7 +22,7 @@ function mapStateToProps(state: GlobalState) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ openModal, removeUsersFromGroup, addUsersToGroup, diff --git a/webapp/channels/src/components/view_user_group_modal/view_user_group_list_item/index.ts b/webapp/channels/src/components/view_user_group_modal/view_user_group_list_item/index.ts index e865c63416..09c3c8a618 100644 --- a/webapp/channels/src/components/view_user_group_modal/view_user_group_list_item/index.ts +++ b/webapp/channels/src/components/view_user_group_modal/view_user_group_list_item/index.ts @@ -3,22 +3,17 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {removeUsersFromGroup} from 'mattermost-redux/actions/groups'; import {Permissions} from 'mattermost-redux/constants'; import {getGroup as getGroupById} from 'mattermost-redux/selectors/entities/groups'; import {haveIGroupPermission} from 'mattermost-redux/selectors/entities/roles'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import type {GlobalState} from 'types/store'; import ViewUserGroupListItem from './view_user_group_list_item'; -type Actions = { - removeUsersFromGroup: (groupId: string, userIds: string[]) => Promise; -}; - type OwnProps = { groupId: string; }; @@ -35,7 +30,7 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ removeUsersFromGroup, }, dispatch), }; diff --git a/webapp/channels/src/components/view_user_group_modal/view_user_group_modal.tsx b/webapp/channels/src/components/view_user_group_modal/view_user_group_modal.tsx index ecee6c5e0e..68d3e0c38b 100644 --- a/webapp/channels/src/components/view_user_group_modal/view_user_group_modal.tsx +++ b/webapp/channels/src/components/view_user_group_modal/view_user_group_modal.tsx @@ -37,8 +37,8 @@ export type Props = { backButtonCallback: () => void; backButtonAction: () => void; actions: { - getGroup: (groupId: string, includeMemberCount: boolean) => Promise<{data: Group}>; - getUsersInGroup: (groupId: string, page: number, perPage: number) => Promise<{data: UserProfile[]}>; + getGroup: (groupId: string, includeMemberCount: boolean) => Promise>; + getUsersInGroup: (groupId: string, page: number, perPage: number) => Promise>; setModalSearchTerm: (term: string) => void; searchProfiles: (term: string, options: any) => Promise; }; diff --git a/webapp/channels/src/components/view_user_group_modal/view_user_group_modal_header/index.ts b/webapp/channels/src/components/view_user_group_modal/view_user_group_modal_header/index.ts index eed0c1c4e7..8c6bcc7be4 100644 --- a/webapp/channels/src/components/view_user_group_modal/view_user_group_modal_header/index.ts +++ b/webapp/channels/src/components/view_user_group_modal/view_user_group_modal_header/index.ts @@ -3,29 +3,19 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {Dispatch, ActionCreatorsMapObject} from 'redux'; +import type {Dispatch} from 'redux'; import {addUsersToGroup, archiveGroup, removeUsersFromGroup, restoreGroup} from 'mattermost-redux/actions/groups'; import {Permissions} from 'mattermost-redux/constants'; import {getGroup as getGroupById, isMyGroup} from 'mattermost-redux/selectors/entities/groups'; import {haveIGroupPermission} from 'mattermost-redux/selectors/entities/roles'; -import type {ActionFunc, ActionResult, GenericAction} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; -import type {ModalData} from 'types/actions'; import type {GlobalState} from 'types/store'; import ViewUserGroupModalHeader from './view_user_group_modal_header'; -type Actions = { - openModal:

(modalData: ModalData

) => void; - removeUsersFromGroup: (groupId: string, userIds: string[]) => Promise; - addUsersToGroup: (groupId: string, userIds: string[]) => Promise; - archiveGroup: (groupId: string) => Promise; - restoreGroup: (groupId: string) => Promise; -}; - type OwnProps = { groupId: string; }; @@ -53,7 +43,7 @@ function mapStateToProps(state: GlobalState, ownProps: OwnProps) { function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ openModal, removeUsersFromGroup, addUsersToGroup, diff --git a/webapp/channels/src/components/warn_metric_ack_modal/index.ts b/webapp/channels/src/components/warn_metric_ack_modal/index.ts index 2a650406c8..7f2ebba680 100644 --- a/webapp/channels/src/components/warn_metric_ack_modal/index.ts +++ b/webapp/channels/src/components/warn_metric_ack_modal/index.ts @@ -3,17 +3,13 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; - -import type {ServerError} from '@mattermost/types/errors'; -import type {GetFilteredUsersStatsOpts, UsersStats} from '@mattermost/types/users'; +import type {Dispatch} from 'redux'; import {sendWarnMetricAck} from 'mattermost-redux/actions/admin'; import {getFilteredUsersStats} from 'mattermost-redux/actions/users'; import {getCurrentUser} from 'mattermost-redux/selectors/entities/common'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getFilteredUsersStats as selectFilteredUserStats} from 'mattermost-redux/selectors/entities/users'; -import type {Action, ActionResult} from 'mattermost-redux/types/actions'; import {closeModal} from 'actions/views/modals'; import {isModalOpen} from 'selectors/views/modals'; @@ -40,15 +36,9 @@ function mapStateToProps(state: GlobalState, ownProps: Props) { }; } -type Actions = { - closeModal: (modalId: string) => void; - sendWarnMetricAck: (warnMetricId: string, forceAck: boolean) => Promise; - getFilteredUsersStats: (filters: GetFilteredUsersStatsOpts) => Promise<{ data?: UsersStats | undefined; error?: ServerError | undefined}>; -}; - function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>( + actions: bindActionCreators( { closeModal, sendWarnMetricAck, diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/admin.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/admin.test.ts index 22d7298c6e..70bbb1aca8 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/admin.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/admin.test.ts @@ -9,7 +9,6 @@ import type {CreateDataRetentionCustomPolicy} from '@mattermost/types/data_reten import * as Actions from 'mattermost-redux/actions/admin'; import {Client4} from 'mattermost-redux/client'; -import type {ActionResult} from 'mattermost-redux/types/actions'; import TestHelper from '../../test/test_helper'; import configureStore from '../../test/test_store'; @@ -49,7 +48,7 @@ describe('Actions.Admin', () => { '[2017/04/04 15:01:48 EDT] [INFO] Closing SqlStore', ]); - await Actions.getPlainLogs()(store.dispatch, store.getState); + await store.dispatch(Actions.getPlainLogs()); const state = store.getState(); @@ -75,7 +74,7 @@ describe('Actions.Admin', () => { }, ]); - await Actions.getAudits()(store.dispatch, store.getState); + await store.dispatch(Actions.getAudits()); const state = store.getState(); @@ -102,7 +101,7 @@ describe('Actions.Admin', () => { user_id: '1', }); - await Actions.getConfig()(store.dispatch, store.getState); + await store.dispatch(Actions.getConfig()); const state = store.getState(); @@ -121,7 +120,7 @@ describe('Actions.Admin', () => { }, }); - const {data} = await Actions.getConfig()(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.getConfig()); const updated = JSON.parse(JSON.stringify(data)); const oldSiteName = updated.TeamSettings.SiteName; const testSiteName = 'MattermostReduxTest'; @@ -131,7 +130,7 @@ describe('Actions.Admin', () => { put('/config'). reply(200, updated); - await Actions.updateConfig(updated)(store.dispatch, store.getState); + await store.dispatch(Actions.updateConfig(updated)); let state = store.getState(); @@ -146,7 +145,7 @@ describe('Actions.Admin', () => { put('/config'). reply(200, updated); - await Actions.updateConfig(updated)(store.dispatch, store.getState); + await store.dispatch(Actions.updateConfig(updated)); state = store.getState(); @@ -161,7 +160,7 @@ describe('Actions.Admin', () => { post('/config/reload'). reply(200, OK_RESPONSE); - await Actions.reloadConfig()(store.dispatch, store.getState); + await store.dispatch(Actions.reloadConfig()); expect(nock.isDone()).toBe(true); }); @@ -195,13 +194,13 @@ describe('Actions.Admin', () => { get('/config'). reply(200, {}); - const {data: config} = await Actions.getConfig()(store.dispatch, store.getState) as ActionResult; + const {data: config} = await store.dispatch(Actions.getConfig()); nock(Client4.getBaseRoute()). post('/email/test'). reply(200, OK_RESPONSE); - await Actions.testEmail(config)(store.dispatch, store.getState); + await store.dispatch(Actions.testEmail(config)); expect(nock.isDone()).toBe(true); }); @@ -211,7 +210,7 @@ describe('Actions.Admin', () => { post('/site_url/test'). reply(200, OK_RESPONSE); - await Actions.testSiteURL('http://lo.cal')(store.dispatch, store.getState); + await store.dispatch(Actions.testSiteURL('http://lo.cal')); expect(nock.isDone()).toBe(true); }); @@ -221,13 +220,13 @@ describe('Actions.Admin', () => { get('/config'). reply(200, {}); - const {data: config} = await Actions.getConfig()(store.dispatch, store.getState) as ActionResult; + const {data: config} = await store.dispatch(Actions.getConfig()); nock(Client4.getBaseRoute()). post('/file/s3_test'). reply(200, OK_RESPONSE); - await Actions.testS3Connection(config)(store.dispatch, store.getState); + await store.dispatch(Actions.testS3Connection(config)); expect(nock.isDone()).toBe(true); }); @@ -237,7 +236,7 @@ describe('Actions.Admin', () => { post('/caches/invalidate'). reply(200, OK_RESPONSE); - await Actions.invalidateCaches()(store.dispatch, store.getState); + await store.dispatch(Actions.invalidateCaches()); expect(nock.isDone()).toBe(true); }); @@ -247,7 +246,7 @@ describe('Actions.Admin', () => { post('/database/recycle'). reply(200, OK_RESPONSE); - await Actions.recycleDatabase()(store.dispatch, store.getState); + await store.dispatch(Actions.recycleDatabase()); expect(nock.isDone()).toBe(true); }); @@ -277,7 +276,7 @@ describe('Actions.Admin', () => { emails: 'joram@example.com', }); - const {data: created} = await Actions.createComplianceReport(job)(store.dispatch, store.getState) as ActionResult; + const {data: created} = await store.dispatch(Actions.createComplianceReport(job)); const state = store.getState(); const request = state.requests.admin.createCompliance; @@ -315,13 +314,13 @@ describe('Actions.Admin', () => { emails: 'joram@example.com', }); - const {data: report} = await Actions.createComplianceReport(job)(store.dispatch, store.getState) as ActionResult; + const {data: report} = await store.dispatch(Actions.createComplianceReport(job)); nock(Client4.getBaseRoute()). get(`/compliance/reports/${report.id}`). reply(200, report); - await Actions.getComplianceReport(report.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getComplianceReport(report.id)); const state = store.getState(); @@ -355,14 +354,14 @@ describe('Actions.Admin', () => { emails: 'joram@example.com', }); - const {data: report} = await Actions.createComplianceReport(job)(store.dispatch, store.getState) as ActionResult; + const {data: report} = await store.dispatch(Actions.createComplianceReport(job)); nock(Client4.getBaseRoute()). get('/compliance/reports'). query(true). reply(200, [report]); - await Actions.getComplianceReports()(store.dispatch, store.getState); + await store.dispatch(Actions.getComplianceReports()); const state = store.getState(); @@ -378,7 +377,7 @@ describe('Actions.Admin', () => { post('/brand/image'). reply(200, OK_RESPONSE); - await Actions.uploadBrandImage(testImageData as any)(store.dispatch, store.getState); + await store.dispatch(Actions.uploadBrandImage(testImageData as any)); expect(nock.isDone()).toBe(true); }); @@ -388,7 +387,7 @@ describe('Actions.Admin', () => { delete('/brand/image'). reply(200, OK_RESPONSE); - await Actions.deleteBrandImage()(store.dispatch, store.getState); + await store.dispatch(Actions.deleteBrandImage()); expect(nock.isDone()).toBe(true); }); @@ -403,7 +402,7 @@ describe('Actions.Admin', () => { }, ]); - await Actions.getClusterStatus()(store.dispatch, store.getState); + await store.dispatch(Actions.getClusterStatus()); const state = store.getState(); @@ -418,7 +417,7 @@ describe('Actions.Admin', () => { post('/ldap/test'). reply(200, OK_RESPONSE); - await Actions.testLdap()(store.dispatch, store.getState); + await store.dispatch(Actions.testLdap()); expect(nock.isDone()).toBe(true); }); @@ -428,7 +427,7 @@ describe('Actions.Admin', () => { post('/ldap/sync'). reply(200, OK_RESPONSE); - await Actions.syncLdap()(store.dispatch, store.getState); + await store.dispatch(Actions.syncLdap()); expect(nock.isDone()).toBe(true); }); @@ -442,7 +441,7 @@ describe('Actions.Admin', () => { idp_certificate_file: true, }); - await Actions.getSamlCertificateStatus()(store.dispatch, store.getState); + await store.dispatch(Actions.getSamlCertificateStatus()); const state = store.getState(); @@ -460,7 +459,7 @@ describe('Actions.Admin', () => { post('/saml/certificate/public'). reply(200, OK_RESPONSE); - await Actions.uploadPublicSamlCertificate(testFileData as any)(store.dispatch, store.getState); + await store.dispatch(Actions.uploadPublicSamlCertificate(testFileData as any)); expect(nock.isDone()).toBe(true); }); @@ -472,7 +471,7 @@ describe('Actions.Admin', () => { post('/saml/certificate/private'). reply(200, OK_RESPONSE); - await Actions.uploadPrivateSamlCertificate(testFileData as any)(store.dispatch, store.getState); + await store.dispatch(Actions.uploadPrivateSamlCertificate(testFileData as any)); expect(nock.isDone()).toBe(true); }); @@ -484,7 +483,7 @@ describe('Actions.Admin', () => { post('/saml/certificate/idp'). reply(200, OK_RESPONSE); - await Actions.uploadIdpSamlCertificate(testFileData as any)(store.dispatch, store.getState); + await store.dispatch(Actions.uploadIdpSamlCertificate(testFileData as any)); expect(nock.isDone()).toBe(true); }); @@ -494,7 +493,7 @@ describe('Actions.Admin', () => { delete('/saml/certificate/public'). reply(200, OK_RESPONSE); - await Actions.removePublicSamlCertificate()(store.dispatch, store.getState); + await store.dispatch(Actions.removePublicSamlCertificate()); expect(nock.isDone()).toBe(true); }); @@ -504,7 +503,7 @@ describe('Actions.Admin', () => { delete('/saml/certificate/private'). reply(200, OK_RESPONSE); - await Actions.removePrivateSamlCertificate()(store.dispatch, store.getState); + await store.dispatch(Actions.removePrivateSamlCertificate()); expect(nock.isDone()).toBe(true); }); @@ -514,7 +513,7 @@ describe('Actions.Admin', () => { delete('/saml/certificate/idp'). reply(200, OK_RESPONSE); - await Actions.removeIdpSamlCertificate()(store.dispatch, store.getState); + await store.dispatch(Actions.removeIdpSamlCertificate()); expect(nock.isDone()).toBe(true); }); @@ -526,7 +525,7 @@ describe('Actions.Admin', () => { post('/ldap/certificate/public'). reply(200, OK_RESPONSE); - await Actions.uploadPublicLdapCertificate(testFileData as any)(store.dispatch, store.getState); + await store.dispatch(Actions.uploadPublicLdapCertificate(testFileData as any)); expect(nock.isDone()).toBe(true); }); @@ -538,7 +537,7 @@ describe('Actions.Admin', () => { post('/ldap/certificate/private'). reply(200, OK_RESPONSE); - await Actions.uploadPrivateLdapCertificate(testFileData as any)(store.dispatch, store.getState); + await store.dispatch(Actions.uploadPrivateLdapCertificate(testFileData as any)); expect(nock.isDone()).toBe(true); }); @@ -548,7 +547,7 @@ describe('Actions.Admin', () => { delete('/ldap/certificate/public'). reply(200, OK_RESPONSE); - await Actions.removePublicLdapCertificate()(store.dispatch, store.getState); + await store.dispatch(Actions.removePublicLdapCertificate()); expect(nock.isDone()).toBe(true); }); @@ -558,7 +557,7 @@ describe('Actions.Admin', () => { delete('/ldap/certificate/private'). reply(200, OK_RESPONSE); - await Actions.removePrivateLdapCertificate()(store.dispatch, store.getState); + await store.dispatch(Actions.removePrivateLdapCertificate()); expect(nock.isDone()).toBe(true); }); @@ -568,7 +567,7 @@ describe('Actions.Admin', () => { post('/elasticsearch/test'). reply(200, OK_RESPONSE); - await Actions.testElasticsearch({})(store.dispatch, store.getState); + await store.dispatch(Actions.testElasticsearch({})); expect(nock.isDone()).toBe(true); }); @@ -578,7 +577,7 @@ describe('Actions.Admin', () => { post('/elasticsearch/purge_indexes'). reply(200, OK_RESPONSE); - await Actions.purgeElasticsearchIndexes()(store.dispatch, store.getState); + await store.dispatch(Actions.purgeElasticsearchIndexes()); expect(nock.isDone()).toBe(true); }); @@ -590,7 +589,7 @@ describe('Actions.Admin', () => { post('/license'). reply(200, OK_RESPONSE); - await Actions.uploadLicense(testFileData as any)(store.dispatch, store.getState); + await store.dispatch(Actions.uploadLicense(testFileData as any)); expect(nock.isDone()).toBe(true); }); @@ -600,7 +599,7 @@ describe('Actions.Admin', () => { delete('/license'). reply(200, OK_RESPONSE); - await Actions.removeLicense()(store.dispatch, store.getState); + await store.dispatch(Actions.removeLicense()); expect(nock.isDone()).toBe(true); }); @@ -612,8 +611,8 @@ describe('Actions.Admin', () => { times(2). reply(200, [{name: 'channel_open_count', value: 495}, {name: 'channel_private_count', value: 19}, {name: 'post_count', value: 2763}, {name: 'unique_user_count', value: 316}, {name: 'team_count', value: 159}, {name: 'total_websocket_connections', value: 1}, {name: 'total_master_db_connections', value: 8}, {name: 'total_read_db_connections', value: 0}, {name: 'daily_active_users', value: 22}, {name: 'monthly_active_users', value: 114}, {name: 'registered_users', value: 500}]); - await Actions.getStandardAnalytics()(store.dispatch, store.getState); - await Actions.getStandardAnalytics(TestHelper.basicTeam!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getStandardAnalytics()); + await store.dispatch(Actions.getStandardAnalytics(TestHelper.basicTeam!.id)); const state = store.getState(); @@ -634,8 +633,8 @@ describe('Actions.Admin', () => { times(2). reply(200, [{name: 'file_post_count', value: 24}, {name: 'hashtag_post_count', value: 876}, {name: 'incoming_webhook_count', value: 16}, {name: 'outgoing_webhook_count', value: 18}, {name: 'command_count', value: 14}, {name: 'session_count', value: 149}]); - await Actions.getAdvancedAnalytics()(store.dispatch, store.getState); - await Actions.getAdvancedAnalytics(TestHelper.basicTeam!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getAdvancedAnalytics()); + await store.dispatch(Actions.getAdvancedAnalytics(TestHelper.basicTeam!.id)); const state = store.getState(); @@ -656,8 +655,8 @@ describe('Actions.Admin', () => { times(2). reply(200, [{name: '2017-06-18', value: 16}, {name: '2017-06-16', value: 209}, {name: '2017-06-12', value: 35}, {name: '2017-06-08', value: 227}, {name: '2017-06-07', value: 27}, {name: '2017-06-06', value: 136}, {name: '2017-06-05', value: 127}, {name: '2017-06-04', value: 39}, {name: '2017-06-02', value: 3}, {name: '2017-05-31', value: 52}, {name: '2017-05-30', value: 52}, {name: '2017-05-29', value: 9}, {name: '2017-05-26', value: 198}, {name: '2017-05-25', value: 144}, {name: '2017-05-24', value: 1130}, {name: '2017-05-23', value: 146}]); - await Actions.getPostsPerDayAnalytics()(store.dispatch, store.getState); - await Actions.getPostsPerDayAnalytics(TestHelper.basicTeam!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getPostsPerDayAnalytics()); + await store.dispatch(Actions.getPostsPerDayAnalytics(TestHelper.basicTeam!.id)); const state = store.getState(); @@ -678,8 +677,8 @@ describe('Actions.Admin', () => { times(2). reply(200, [{name: '2017-06-18', value: 2}, {name: '2017-06-16', value: 47}, {name: '2017-06-12', value: 4}, {name: '2017-06-08', value: 55}, {name: '2017-06-07', value: 2}, {name: '2017-06-06', value: 1}, {name: '2017-06-05', value: 2}, {name: '2017-06-04', value: 13}, {name: '2017-06-02', value: 1}, {name: '2017-05-31', value: 3}, {name: '2017-05-30', value: 4}, {name: '2017-05-29', value: 3}, {name: '2017-05-26', value: 40}, {name: '2017-05-25', value: 26}, {name: '2017-05-24', value: 43}, {name: '2017-05-23', value: 3}]); - await Actions.getUsersPerDayAnalytics()(store.dispatch, store.getState); - await Actions.getUsersPerDayAnalytics(TestHelper.basicTeam!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getUsersPerDayAnalytics()); + await store.dispatch(Actions.getUsersPerDayAnalytics(TestHelper.basicTeam!.id)); const state = store.getState(); @@ -700,7 +699,7 @@ describe('Actions.Admin', () => { nock(Client4.getBaseRoute()). post('/plugins'). reply(200, testPlugin); - await Actions.uploadPlugin(testFileData as any, false)(store.dispatch, store.getState); + await store.dispatch(Actions.uploadPlugin(testFileData as any, false)); expect(nock.isDone()).toBe(true); }); @@ -713,7 +712,7 @@ describe('Actions.Admin', () => { let scope = nock(Client4.getBaseRoute()). post(urlMatch). reply(200, testPlugin); - await Actions.installPluginFromUrl(downloadUrl, false)(store.dispatch, store.getState); + await store.dispatch(Actions.installPluginFromUrl(downloadUrl, false)); expect(scope.isDone()).toBe(true); @@ -721,7 +720,7 @@ describe('Actions.Admin', () => { scope = nock(Client4.getBaseRoute()). post(urlMatch). reply(200, testPlugin); - await Actions.installPluginFromUrl(downloadUrl, true)(store.dispatch, store.getState); + await store.dispatch(Actions.installPluginFromUrl(downloadUrl, true)); expect(scope.isDone()).toBe(true); }); @@ -734,7 +733,7 @@ describe('Actions.Admin', () => { nock(Client4.getBaseRoute()). post(urlMatch). reply(200, testPlugin); - await Actions.installPluginFromUrl(downloadUrl, false)(store.dispatch, store.getState); + await store.dispatch(Actions.installPluginFromUrl(downloadUrl, false)); expect(nock.isDone()).toBe(true); }); @@ -747,7 +746,7 @@ describe('Actions.Admin', () => { get('/plugins'). reply(200, {active: [testPlugin], inactive: [testPlugin2]}); - await Actions.getPlugins()(store.dispatch, store.getState); + await store.dispatch(Actions.getPlugins()); const state = store.getState(); @@ -773,7 +772,7 @@ describe('Actions.Admin', () => { get('/plugins/statuses'). reply(200, [testPluginStatus, testPluginStatus2]); - await Actions.getPluginStatuses()(store.dispatch, store.getState); + await store.dispatch(Actions.getPluginStatuses()); const state = store.getState(); @@ -792,7 +791,7 @@ describe('Actions.Admin', () => { get('/plugins'). reply(200, {active: [], inactive: [testPlugin]}); - await Actions.getPlugins()(store.dispatch, store.getState); + await store.dispatch(Actions.getPlugins()); let state = store.getState(); let plugins = state.entities.admin.plugins; @@ -803,7 +802,7 @@ describe('Actions.Admin', () => { delete(`/plugins/${testPlugin.id}`). reply(200, OK_RESPONSE); - await Actions.removePlugin(testPlugin.id)(store.dispatch, store.getState); + await store.dispatch(Actions.removePlugin(testPlugin.id)); state = store.getState(); plugins = state.entities.admin.plugins; @@ -818,7 +817,7 @@ describe('Actions.Admin', () => { get('/plugins'). reply(200, {active: [], inactive: [testPlugin]}); - await Actions.getPlugins()(store.dispatch, store.getState); + await store.dispatch(Actions.getPlugins()); let state = store.getState(); let plugins = state.entities.admin.plugins; @@ -830,7 +829,7 @@ describe('Actions.Admin', () => { post(`/plugins/${testPlugin.id}/enable`). reply(200, OK_RESPONSE); - await Actions.enablePlugin(testPlugin.id)(store.dispatch, store.getState); + await store.dispatch(Actions.enablePlugin(testPlugin.id)); state = store.getState(); plugins = state.entities.admin.plugins; @@ -846,7 +845,7 @@ describe('Actions.Admin', () => { get('/plugins'). reply(200, {active: [testPlugin], inactive: []}); - await Actions.getPlugins()(store.dispatch, store.getState); + await store.dispatch(Actions.getPlugins()); let state = store.getState(); let plugins = state.entities.admin.plugins; @@ -858,7 +857,7 @@ describe('Actions.Admin', () => { post(`/plugins/${testPlugin.id}/disable`). reply(200, OK_RESPONSE); - await Actions.disablePlugin(testPlugin.id)(store.dispatch, store.getState); + await store.dispatch(Actions.disablePlugin(testPlugin.id)); state = store.getState(); plugins = state.entities.admin.plugins; @@ -880,7 +879,7 @@ describe('Actions.Admin', () => { get('/ldap/groups?page=0&per_page=100'). reply(200, ldapGroups); - await Actions.getLdapGroups(0, 100, null as any)(store.dispatch, store.getState); + await store.dispatch(Actions.getLdapGroups(0, 100, null as any)); const state = store.getState(); @@ -895,7 +894,7 @@ describe('Actions.Admin', () => { get('/ldap/groups?page=0&per_page=100&q=&is_linked=true'). reply(200, NO_GROUPS_RESPONSE); - await Actions.getLdapGroups(0, 100, {q: '', is_linked: true})(store.dispatch, store.getState); + await store.dispatch(Actions.getLdapGroups(0, 100, {q: '', is_linked: true})); expect(scope.isDone()).toBe(true); @@ -903,7 +902,7 @@ describe('Actions.Admin', () => { get('/ldap/groups?page=0&per_page=100&q=&is_linked=false'). reply(200, NO_GROUPS_RESPONSE); - await Actions.getLdapGroups(0, 100, {q: '', is_linked: false})(store.dispatch, store.getState); + await store.dispatch(Actions.getLdapGroups(0, 100, {q: '', is_linked: false})); expect(scope.isDone()).toBe(true); }); @@ -913,7 +912,7 @@ describe('Actions.Admin', () => { get('/ldap/groups?page=0&per_page=100&q=&is_configured=true'). reply(200, NO_GROUPS_RESPONSE); - await Actions.getLdapGroups(0, 100, {q: '', is_configured: true})(store.dispatch, store.getState); + await store.dispatch(Actions.getLdapGroups(0, 100, {q: '', is_configured: true})); expect(scope.isDone()).toBe(true); @@ -921,7 +920,7 @@ describe('Actions.Admin', () => { get('/ldap/groups?page=0&per_page=100&q=&is_configured=false'). reply(200, NO_GROUPS_RESPONSE); - await Actions.getLdapGroups(0, 100, {q: '', is_configured: false})(store.dispatch, store.getState); + await store.dispatch(Actions.getLdapGroups(0, 100, {q: '', is_configured: false})); expect(scope.isDone()).toBe(true); }); @@ -931,7 +930,7 @@ describe('Actions.Admin', () => { get('/ldap/groups?page=0&per_page=100&q=est'). reply(200, NO_GROUPS_RESPONSE); - await Actions.getLdapGroups(0, 100, {q: 'est'})(store.dispatch, store.getState); + await store.dispatch(Actions.getLdapGroups(0, 100, {q: 'est'})); expect(scope.isDone()).toBe(true); @@ -939,7 +938,7 @@ describe('Actions.Admin', () => { get('/ldap/groups?page=0&per_page=100&q=esta'). reply(200, NO_GROUPS_RESPONSE); - await Actions.getLdapGroups(0, 100, {q: 'esta'})(store.dispatch, store.getState); + await store.dispatch(Actions.getLdapGroups(0, 100, {q: 'esta'})); expect(scope.isDone()).toBe(true); }); @@ -957,7 +956,7 @@ describe('Actions.Admin', () => { get('/ldap/groups?page=0&per_page=100'). reply(200, ldapGroups); - await Actions.getLdapGroups(0, 100, null as any)(store.dispatch, store.getState); + await store.dispatch(Actions.getLdapGroups(0, 100, null as any)); const key = 'test1'; @@ -965,7 +964,7 @@ describe('Actions.Admin', () => { post(`/ldap/groups/${key}/link`). reply(200, {display_name: 'test1', id: 'new-mattermost-id'}); - await Actions.linkLdapGroup(key)(store.dispatch, store.getState); + await store.dispatch(Actions.linkLdapGroup(key)); const state = store.getState(); const groups = state.entities.admin.ldapGroups; @@ -987,7 +986,7 @@ describe('Actions.Admin', () => { get('/ldap/groups?page=0&per_page=100'). reply(200, ldapGroups); - await Actions.getLdapGroups(0, 100, null as any)(store.dispatch, store.getState); + await store.dispatch(Actions.getLdapGroups(0, 100, null as any)); const key = 'test2'; @@ -995,7 +994,7 @@ describe('Actions.Admin', () => { delete(`/ldap/groups/${key}/link`). reply(200, {ok: true}); - await Actions.unlinkLdapGroup(key)(store.dispatch, store.getState); + await store.dispatch(Actions.unlinkLdapGroup(key)); const state = store.getState(); const groups = state.entities.admin.ldapGroups; @@ -1013,7 +1012,7 @@ describe('Actions.Admin', () => { idp_public_certificate: samlIdpPublicCertificateText, }); - await Actions.getSamlMetadataFromIdp('')(store.dispatch, store.getState); + await store.dispatch(Actions.getSamlMetadataFromIdp('')); const state = store.getState(); const metadataResponse = state.entities.admin.samlMetadataResponse; @@ -1028,7 +1027,7 @@ describe('Actions.Admin', () => { post('/saml/certificate/idp'). reply(200, OK_RESPONSE); - await Actions.setSamlIdpCertificateFromMetadata(samlIdpPublicCertificateText)(store.dispatch, store.getState); + await store.dispatch(Actions.setSamlIdpCertificateFromMetadata(samlIdpPublicCertificateText)); expect(nock.isDone()).toBe(true); }); @@ -1041,7 +1040,7 @@ describe('Actions.Admin', () => { post('/warn_metrics/ack/metric1'). reply(200, OK_RESPONSE); - await Actions.sendWarnMetricAck(warnMetricAck.id, false)(store.dispatch); + await store.dispatch(Actions.sendWarnMetricAck(warnMetricAck.id, false)); expect(nock.isDone()).toBe(true); }); @@ -1070,7 +1069,7 @@ describe('Actions.Admin', () => { get('/data_retention/policies?page=0&per_page=10'). reply(200, policies); - await Actions.getDataRetentionCustomPolicies()(store.dispatch, store.getState); + await store.dispatch(Actions.getDataRetentionCustomPolicies()); const state = store.getState(); const policesState = state.entities.admin.dataRetentionCustomPolicies; @@ -1101,7 +1100,7 @@ describe('Actions.Admin', () => { get('/data_retention/policies/id1'). reply(200, policy); - await Actions.getDataRetentionCustomPolicy('id1')(store.dispatch, store.getState); + await store.dispatch(Actions.getDataRetentionCustomPolicy('id1')); const state = store.getState(); const policesState = state.entities.admin.dataRetentionCustomPolicies; @@ -1129,7 +1128,7 @@ describe('Actions.Admin', () => { total_count: 1, }); - await Actions.getDataRetentionCustomPolicyTeams('id1')(store.dispatch, store.getState); + await store.dispatch(Actions.getDataRetentionCustomPolicyTeams('id1')); const state = store.getState(); const teamsState = state.entities.teams.teams; @@ -1153,7 +1152,7 @@ describe('Actions.Admin', () => { total_count: 1, }); - await Actions.getDataRetentionCustomPolicyChannels('id1')(store.dispatch, store.getState); + await store.dispatch(Actions.getDataRetentionCustomPolicyChannels('id1')); const state = store.getState(); const teamsState = state.entities.channels.channels; @@ -1198,7 +1197,7 @@ describe('Actions.Admin', () => { team_count: 2, channel_count: 1, }); - await Actions.createDataRetentionCustomPolicy(policy)(store.dispatch, store.getState); + await store.dispatch(Actions.createDataRetentionCustomPolicy(policy)); const state = store.getState(); const policesState = state.entities.admin.dataRetentionCustomPolicies; @@ -1221,7 +1220,7 @@ describe('Actions.Admin', () => { team_count: 2, channel_count: 1, }); - await Actions.updateDataRetentionCustomPolicy('id1', {display_name: 'Test123', post_duration: 365} as CreateDataRetentionCustomPolicy)(store.dispatch, store.getState); + await store.dispatch(Actions.updateDataRetentionCustomPolicy('id1', {display_name: 'Test123', post_duration: 365} as CreateDataRetentionCustomPolicy)); const updateState = store.getState(); const policyState = updateState.entities.admin.dataRetentionCustomPolicies; @@ -1250,7 +1249,7 @@ describe('Actions.Admin', () => { team_count: 2, channel_count: 1, }); - await Actions.createDataRetentionCustomPolicy(policy)(store.dispatch, store.getState); + await store.dispatch(Actions.createDataRetentionCustomPolicy(policy)); const state = store.getState(); const policesState = state.entities.admin.dataRetentionCustomPolicies; @@ -1283,13 +1282,13 @@ describe('Actions.Admin', () => { total_count: 2, }); - await Actions.getDataRetentionCustomPolicyTeams('id1')(store.dispatch, store.getState); + await store.dispatch(Actions.getDataRetentionCustomPolicyTeams('id1')); nock(Client4.getBaseRoute()). delete('/data_retention/policies/id1/teams'). reply(200, OK_RESPONSE); - await Actions.removeDataRetentionCustomPolicyTeams('id1', ['teamId2'])(store.dispatch, store.getState); + await store.dispatch(Actions.removeDataRetentionCustomPolicyTeams('id1', ['teamId2'])); const state = store.getState(); const teamsState = state.entities.teams.teams; @@ -1318,13 +1317,13 @@ describe('Actions.Admin', () => { total_count: 1, }); - await Actions.getDataRetentionCustomPolicyChannels('id1')(store.dispatch, store.getState); + await store.dispatch(Actions.getDataRetentionCustomPolicyChannels('id1')); nock(Client4.getBaseRoute()). delete('/data_retention/policies/id1/channels'). reply(200, OK_RESPONSE); - await Actions.removeDataRetentionCustomPolicyChannels('id1', ['channelId2'])(store.dispatch, store.getState); + await store.dispatch(Actions.removeDataRetentionCustomPolicyChannels('id1', ['channelId2'])); const state = store.getState(); const channelsState = state.entities.channels.channels; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/admin.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/admin.ts index 2c874d5373..a6593764dc 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/admin.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/admin.ts @@ -3,32 +3,39 @@ import {batchActions} from 'redux-batched-actions'; -import type {LogFilter} from '@mattermost/types/admin'; +import type {LogFilter, SchemaMigration} from '@mattermost/types/admin'; +import type {Audit} from '@mattermost/types/audits'; import type { + Channel, ChannelSearchOpts, } from '@mattermost/types/channels'; import type {Compliance} from '@mattermost/types/compliance'; -import type {AllowedIPRange} from '@mattermost/types/config'; +import type {AdminConfig, AllowedIPRange, License} from '@mattermost/types/config'; import type { CreateDataRetentionCustomPolicy, + DataRetentionCustomPolicies, + GetDataRetentionCustomPoliciesRequest, + PatchDataRetentionCustomPolicy, } from '@mattermost/types/data_retention'; import type {ServerError} from '@mattermost/types/errors'; -import type {GroupSearchOpts} from '@mattermost/types/groups'; +import type {GroupSearchOpts, MixedUnlinkedGroup} from '@mattermost/types/groups'; +import type {SamlMetadataResponse} from '@mattermost/types/saml'; import type {CompleteOnboardingRequest} from '@mattermost/types/setup'; import type { + Team, TeamSearchOpts, } from '@mattermost/types/teams'; import {AdminTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; -import type {ActionFunc, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {ActionFunc, DispatchFunc, GetStateFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {logError} from './errors'; import {bindClientFunc, forceLogoutIfNecessary} from './helpers'; import {General} from '../constants'; -export function getLogs({serverNames = [], logLevels = [], dateFrom, dateTo}: LogFilter): ActionFunc { +export function getLogs({serverNames = [], logLevels = [], dateFrom, dateTo}: LogFilter): NewActionFuncAsync { const logFilter = { server_names: serverNames, log_levels: logLevels, @@ -41,10 +48,10 @@ export function getLogs({serverNames = [], logLevels = [], dateFrom, dateTo}: Lo params: [ logFilter, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getPlainLogs(page = 0, perPage: number = General.LOGS_PAGE_SIZE_DEFAULT): ActionFunc { +export function getPlainLogs(page = 0, perPage: number = General.LOGS_PAGE_SIZE_DEFAULT): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getPlainLogs, onSuccess: [AdminTypes.RECEIVED_PLAIN_LOGS], @@ -52,10 +59,10 @@ export function getPlainLogs(page = 0, perPage: number = General.LOGS_PAGE_SIZE_ page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getAudits(page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): ActionFunc { +export function getAudits(page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getAudits, onSuccess: [AdminTypes.RECEIVED_AUDITS], @@ -63,7 +70,7 @@ export function getAudits(page = 0, perPage: number = General.PAGE_SIZE_DEFAULT) page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getConfig(): ActionFunc { @@ -73,14 +80,14 @@ export function getConfig(): ActionFunc { }); } -export function updateConfig(config: Record): ActionFunc { +export function updateConfig(config: Record): NewActionFuncAsync> { return bindClientFunc({ clientFunc: Client4.updateConfig, onSuccess: [AdminTypes.RECEIVED_CONFIG], params: [ config, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function reloadConfig(): ActionFunc { @@ -135,7 +142,7 @@ export function recycleDatabase(): ActionFunc { }); } -export function createComplianceReport(job: Partial): ActionFunc { +export function createComplianceReport(job: Partial): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.createComplianceReport, onRequest: AdminTypes.CREATE_COMPLIANCE_REQUEST, @@ -144,7 +151,7 @@ export function createComplianceReport(job: Partial): ActionFunc { params: [ job, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getComplianceReport(reportId: string): ActionFunc { @@ -157,7 +164,7 @@ export function getComplianceReport(reportId: string): ActionFunc { }); } -export function getComplianceReports(page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): ActionFunc { +export function getComplianceReports(page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getComplianceReports, onSuccess: [AdminTypes.RECEIVED_COMPLIANCE_REPORTS], @@ -165,7 +172,7 @@ export function getComplianceReports(page = 0, perPage: number = General.PAGE_SI page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function uploadBrandImage(imageData: File): ActionFunc { @@ -202,7 +209,7 @@ export function syncLdap(): ActionFunc { }); } -export function getLdapGroups(page = 0, perPage: number = General.PAGE_SIZE_MAXIMUM, opts: GroupSearchOpts = {q: ''}): ActionFunc { +export function getLdapGroups(page = 0, perPage: number = General.PAGE_SIZE_MAXIMUM, opts: GroupSearchOpts = {q: ''}): NewActionFuncAsync<{count: number; groups: MixedUnlinkedGroup[]}> { return bindClientFunc({ clientFunc: Client4.getLdapGroups, onSuccess: [AdminTypes.RECEIVED_LDAP_GROUPS], @@ -211,11 +218,11 @@ export function getLdapGroups(page = 0, perPage: number = General.PAGE_SIZE_MAXI perPage, opts, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function linkLdapGroup(key: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function linkLdapGroup(key: string): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.linkLdapGroup(key); @@ -240,8 +247,8 @@ export function linkLdapGroup(key: string): ActionFunc { }; } -export function unlinkLdapGroup(key: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function unlinkLdapGroup(key: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.unlinkLdapGroup(key); } catch (error) { @@ -357,19 +364,19 @@ export function purgeElasticsearchIndexes(): ActionFunc { }); } -export function uploadLicense(fileData: File): ActionFunc { +export function uploadLicense(fileData: File): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.uploadLicense, params: [ fileData, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function removeLicense(): ActionFunc { +export function removeLicense(): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.removeLicense, - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getPrevTrialLicense(): ActionFunc { @@ -472,8 +479,8 @@ export function getPluginStatuses(): ActionFunc { }); } -export function removePlugin(pluginId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function removePlugin(pluginId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.removePlugin(pluginId); } catch (error) { @@ -491,8 +498,8 @@ export function removePlugin(pluginId: string): ActionFunc { }; } -export function enablePlugin(pluginId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function enablePlugin(pluginId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.enablePlugin(pluginId); } catch (error) { @@ -507,8 +514,8 @@ export function enablePlugin(pluginId: string): ActionFunc { }; } -export function disablePlugin(pluginId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function disablePlugin(pluginId: string): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: AdminTypes.DISABLE_PLUGIN_REQUEST, data: pluginId}); try { @@ -525,27 +532,27 @@ export function disablePlugin(pluginId: string): ActionFunc { }; } -export function getSamlMetadataFromIdp(samlMetadataURL: string): ActionFunc { +export function getSamlMetadataFromIdp(samlMetadataURL: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getSamlMetadataFromIdp, onSuccess: AdminTypes.RECEIVED_SAML_METADATA_RESPONSE, params: [ samlMetadataURL, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function setSamlIdpCertificateFromMetadata(certData: string): ActionFunc { +export function setSamlIdpCertificateFromMetadata(certData: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.setSamlIdpCertificateFromMetadata, params: [ certData, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function sendWarnMetricAck(warnMetricId: string, forceAck: boolean) { - return async (dispatch: DispatchFunc) => { +export function sendWarnMetricAck(warnMetricId: string, forceAck: boolean): NewActionFuncAsync { + return async (dispatch) => { try { Client4.trackEvent('api', 'api_request_send_metric_ack', {warnMetricId}); await Client4.sendWarnMetricAck(warnMetricId, forceAck); @@ -557,8 +564,8 @@ export function sendWarnMetricAck(warnMetricId: string, forceAck: boolean) { }; } -export function getDataRetentionCustomPolicies(page = 0, perPage = 10): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getDataRetentionCustomPolicies(page = 0, perPage = 10): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.getDataRetentionCustomPolicies(page, perPage); @@ -581,8 +588,8 @@ export function getDataRetentionCustomPolicies(page = 0, perPage = 10): ActionFu }; } -export function getDataRetentionCustomPolicy(id: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getDataRetentionCustomPolicy(id: string): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.getDataRetentionCustomPolicy(id); @@ -605,8 +612,8 @@ export function getDataRetentionCustomPolicy(id: string): ActionFunc { }; } -export function deleteDataRetentionCustomPolicy(id: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function deleteDataRetentionCustomPolicy(id: string): NewActionFuncAsync<{id: string}> { + return async (dispatch, getState) => { try { await Client4.deleteDataRetentionCustomPolicy(id); } catch (error) { @@ -630,8 +637,8 @@ export function deleteDataRetentionCustomPolicy(id: string): ActionFunc { }; } -export function getDataRetentionCustomPolicyTeams(id: string, page = 0, perPage: number = General.TEAMS_CHUNK_SIZE): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getDataRetentionCustomPolicyTeams(id: string, page = 0, perPage: number = General.TEAMS_CHUNK_SIZE): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.getDataRetentionCustomPolicyTeams(id, page, perPage); @@ -654,8 +661,8 @@ export function getDataRetentionCustomPolicyTeams(id: string, page = 0, perPage: }; } -export function getDataRetentionCustomPolicyChannels(id: string, page = 0, perPage: number = General.TEAMS_CHUNK_SIZE): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getDataRetentionCustomPolicyChannels(id: string, page = 0, perPage: number = General.TEAMS_CHUNK_SIZE): NewActionFuncAsync<{channels: Channel[]; total_count: number}> { + return async (dispatch, getState) => { let data; try { data = await Client4.getDataRetentionCustomPolicyChannels(id, page, perPage); @@ -678,7 +685,7 @@ export function getDataRetentionCustomPolicyChannels(id: string, page = 0, perPa }; } -export function searchDataRetentionCustomPolicyTeams(id: string, term: string, opts: TeamSearchOpts): ActionFunc { +export function searchDataRetentionCustomPolicyTeams(id: string, term: string, opts: TeamSearchOpts): NewActionFuncAsync { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { let data; try { @@ -702,8 +709,8 @@ export function searchDataRetentionCustomPolicyTeams(id: string, term: string, o }; } -export function searchDataRetentionCustomPolicyChannels(id: string, term: string, opts: ChannelSearchOpts): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function searchDataRetentionCustomPolicyChannels(id: string, term: string, opts: ChannelSearchOpts): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.searchDataRetentionCustomPolicyChannels(id, term, opts); @@ -726,8 +733,8 @@ export function searchDataRetentionCustomPolicyChannels(id: string, term: string }; } -export function createDataRetentionCustomPolicy(policy: CreateDataRetentionCustomPolicy): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function createDataRetentionCustomPolicy(policy: CreateDataRetentionCustomPolicy): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.createDataRetentionPolicy(policy); @@ -744,8 +751,8 @@ export function createDataRetentionCustomPolicy(policy: CreateDataRetentionCusto }; } -export function updateDataRetentionCustomPolicy(id: string, policy: CreateDataRetentionCustomPolicy): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function updateDataRetentionCustomPolicy(id: string, policy: PatchDataRetentionCustomPolicy): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.updateDataRetentionPolicy(id, policy); @@ -762,7 +769,7 @@ export function updateDataRetentionCustomPolicy(id: string, policy: CreateDataRe }; } -export function addDataRetentionCustomPolicyTeams(id: string, teams: string[]): ActionFunc { +export function addDataRetentionCustomPolicyTeams(id: string, teams: string[]): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.addDataRetentionPolicyTeams, onSuccess: AdminTypes.ADD_DATA_RETENTION_CUSTOM_POLICY_TEAMS_SUCCESS, @@ -770,11 +777,11 @@ export function addDataRetentionCustomPolicyTeams(id: string, teams: string[]): id, teams, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function removeDataRetentionCustomPolicyTeams(id: string, teams: string[]): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function removeDataRetentionCustomPolicyTeams(id: string, teams: string[]): NewActionFuncAsync<{teams: string[]}> { + return async (dispatch, getState) => { try { await Client4.removeDataRetentionPolicyTeams(id, teams); } catch (error) { @@ -798,7 +805,7 @@ export function removeDataRetentionCustomPolicyTeams(id: string, teams: string[] }; } -export function addDataRetentionCustomPolicyChannels(id: string, channels: string[]): ActionFunc { +export function addDataRetentionCustomPolicyChannels(id: string, channels: string[]): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.addDataRetentionPolicyChannels, onSuccess: AdminTypes.ADD_DATA_RETENTION_CUSTOM_POLICY_CHANNELS_SUCCESS, @@ -806,11 +813,11 @@ export function addDataRetentionCustomPolicyChannels(id: string, channels: strin id, channels, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function removeDataRetentionCustomPolicyChannels(id: string, channels: string[]): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function removeDataRetentionCustomPolicyChannels(id: string, channels: string[]): NewActionFuncAsync<{channels: string[]}> { + return async (dispatch, getState) => { try { await Client4.removeDataRetentionPolicyChannels(id, channels); } catch (error) { @@ -841,10 +848,10 @@ export function completeSetup(completeSetup: CompleteOnboardingRequest): ActionF }); } -export function getAppliedSchemaMigrations(): ActionFunc { +export function getAppliedSchemaMigrations(): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getAppliedSchemaMigrations, - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getIPFilters() { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/bots.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/bots.ts index 925c04cbaf..223b5cd3c7 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/bots.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/bots.ts @@ -5,23 +5,23 @@ import type {Bot, BotPatch} from '@mattermost/types/bots'; import {BotTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {bindClientFunc} from './helpers'; const BOTS_PER_PAGE_DEFAULT = 20; -export function createBot(bot: Bot): ActionFunc { +export function createBot(bot: Partial): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.createBot, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNT, params: [ bot, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function patchBot(botUserId: string, botPatch: BotPatch): ActionFunc { +export function patchBot(botUserId: string, botPatch: Partial): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.patchBot, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNT, @@ -29,7 +29,7 @@ export function patchBot(botUserId: string, botPatch: BotPatch): ActionFunc { botUserId, botPatch, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function loadBot(botUserId: string): ActionFunc { @@ -42,7 +42,7 @@ export function loadBot(botUserId: string): ActionFunc { }); } -export function loadBots(page = 0, perPage = BOTS_PER_PAGE_DEFAULT): ActionFunc { +export function loadBots(page = 0, perPage = BOTS_PER_PAGE_DEFAULT): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getBotsIncludeDeleted, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNTS, @@ -50,27 +50,27 @@ export function loadBots(page = 0, perPage = BOTS_PER_PAGE_DEFAULT): ActionFunc page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function disableBot(botUserId: string): ActionFunc { +export function disableBot(botUserId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.disableBot, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNT, params: [ botUserId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function enableBot(botUserId: string): ActionFunc { +export function enableBot(botUserId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.enableBot, onSuccess: BotTypes.RECEIVED_BOT_ACCOUNT, params: [ botUserId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function assignBot(botUserId: string, newOwnerId: string): ActionFunc { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts index f3e941a6f0..0a9adb9e5b 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/channel_categories.ts @@ -24,6 +24,7 @@ import type { ActionFunc, DispatchFunc, GetStateFunc, + NewActionFuncOldVariantDoNotUse, } from 'mattermost-redux/types/actions'; import {insertMultipleWithoutDuplicates, insertWithoutDuplicates, removeItem} from 'mattermost-redux/utils/array_utils'; @@ -134,8 +135,8 @@ function updateCategory(category: ChannelCategory) { }; } -export function fetchMyCategories(teamId: string, isWebSocket: boolean) { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function fetchMyCategories(teamId: string, isWebSocket?: boolean): NewActionFuncOldVariantDoNotUse { + return async (dispatch, getState) => { const currentUserId = getCurrentUserId(getState()); let data: OrderedChannelCategories; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/channels.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/channels.test.ts index c58030da29..6145dc0d0a 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/channels.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/channels.test.ts @@ -11,7 +11,6 @@ import {createIncomingHook, createOutgoingHook} from 'mattermost-redux/actions/i import {addUserToTeam} from 'mattermost-redux/actions/teams'; import {getProfilesByIds, loadMe} from 'mattermost-redux/actions/users'; import {Client4} from 'mattermost-redux/client'; -import type {ActionResult} from 'mattermost-redux/types/actions'; import {getPreferenceKey} from 'mattermost-redux/utils/preference_utils'; import TestHelper from '../../test/test_helper'; @@ -1985,7 +1984,7 @@ describe('Actions.Channels', () => { put(`/users/${currentUserId}/preferences`). reply(200, OK_RESPONSE); - await Actions.markGroupChannelOpen(channelId)(store.dispatch, store.getState); + await store.dispatch(Actions.markGroupChannelOpen(channelId)); const state = store.getState(); let prefKey = getPreferenceKey(Preferences.CATEGORY_GROUP_CHANNEL_SHOW, channelId); @@ -2000,7 +1999,6 @@ describe('Actions.Channels', () => { }); it('getChannelTimezones', async () => { - const {dispatch, getState} = store; const channelId = TestHelper.basicChannel!.id; const response = { useAutomaticTimezone: 'true', @@ -2013,7 +2011,7 @@ describe('Actions.Channels', () => { query(true). reply(200, response); - const {data} = await Actions.getChannelTimezones(channelId)(dispatch, getState) as ActionResult; + const {data} = await store.dispatch(Actions.getChannelTimezones(channelId)); expect(response).toEqual(data); }); @@ -2028,7 +2026,7 @@ describe('Actions.Channels', () => { `/channels/${channelID}/members_minus_group_members?group_ids=${groupIDs.join(',')}&page=${page}&per_page=${perPage}`). reply(200, {users: [], total_count: 0}); - const {error} = await Actions.membersMinusGroupMembers(channelID, groupIDs, page, perPage)(store.dispatch, store.getState) as ActionResult; + const {error} = await store.dispatch(Actions.membersMinusGroupMembers(channelID, groupIDs, page, perPage)); expect(error).toEqual(undefined); }); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts index 9d51c39780..9547c3a857 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/channels.ts @@ -12,8 +12,12 @@ import type { ChannelsWithTotalCount, ChannelSearchOpts, ServerChannel, + ChannelModeration, + ChannelStats, + ChannelWithTeamData, } from '@mattermost/types/channels'; import type {ServerError} from '@mattermost/types/errors'; +import type {UsersWithGroupsAndCount} from '@mattermost/types/groups'; import type {PreferenceType} from '@mattermost/types/preferences'; import {ChannelTypes, PreferenceTypes, UserTypes} from 'mattermost-redux/action_types'; @@ -30,7 +34,7 @@ import { } from 'mattermost-redux/selectors/entities/channels'; import {getConfig} from 'mattermost-redux/selectors/entities/general'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; -import type {ActionFunc, ActionResult, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {ActionFunc, DispatchFunc, GetStateFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {getChannelByName} from 'mattermost-redux/utils/channel_utils'; import {addChannelToInitialCategory, addChannelToCategory} from './channel_categories'; @@ -130,7 +134,7 @@ export function createDirectChannel(userId: string, otherUserId: string): Action {user_id: userId, category: Preferences.CATEGORY_CHANNEL_OPEN_TIME, name: created.id, value: new Date().getTime().toString()}, ]; - savePreferences(userId, preferences)(dispatch); + dispatch(savePreferences(userId, preferences)); dispatch(batchActions([ { @@ -176,8 +180,8 @@ export function markGroupChannelOpen(channelId: string): ActionFunc { }; } -export function createGroupChannel(userIds: string[]): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function createGroupChannel(userIds: string[]): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: ChannelTypes.CREATE_CHANNEL_REQUEST, data: null}); const {currentUserId} = getState().entities.users; @@ -253,8 +257,8 @@ export function createGroupChannel(userIds: string[]): ActionFunc { }; } -export function patchChannel(channelId: string, patch: Partial): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function patchChannel(channelId: string, patch: Partial): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: ChannelTypes.UPDATE_CHANNEL_REQUEST, data: null}); let updated; @@ -310,8 +314,8 @@ export function updateChannel(channel: Channel): ActionFunc { }; } -export function updateChannelPrivacy(channelId: string, privacy: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function updateChannelPrivacy(channelId: string, privacy: string): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: ChannelTypes.UPDATE_CHANNEL_REQUEST, data: null}); let updatedChannel; @@ -339,8 +343,8 @@ export function updateChannelPrivacy(channelId: string, privacy: string): Action }; } -export function convertGroupMessageToPrivateChannel(channelID: string, teamID: string, displayName: string, name: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function convertGroupMessageToPrivateChannel(channelID: string, teamID: string, displayName: string, name: string): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: ChannelTypes.UPDATE_CHANNEL_REQUEST, data: null}); let updatedChannel; @@ -373,8 +377,8 @@ export function convertGroupMessageToPrivateChannel(channelID: string, teamID: s }; } -export function updateChannelNotifyProps(userId: string, channelId: string, props: Partial): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function updateChannelNotifyProps(userId: string, channelId: string, props: Partial): NewActionFuncAsync { + return async (dispatch, getState) => { const notifyProps = { user_id: userId, channel_id: channelId, @@ -426,8 +430,8 @@ export function getChannelByNameAndTeamName(teamName: string, channelName: strin }; } -export function getChannel(channelId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getChannel(channelId: string): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.getChannel(channelId); @@ -447,8 +451,8 @@ export function getChannel(channelId: string): ActionFunc { }; } -export function getChannelAndMyMember(channelId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getChannelAndMyMember(channelId: string): NewActionFuncAsync<{channel: Channel; member: ChannelMembership}> { + return async (dispatch, getState) => { let channel; let member; try { @@ -480,8 +484,8 @@ export function getChannelAndMyMember(channelId: string): ActionFunc { }; } -export function getChannelTimezones(channelId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getChannelTimezones(channelId: string): NewActionFuncAsync { + return async (dispatch, getState) => { let channelTimezones; try { const channelTimezonesRequest = Client4.getChannelTimezones(channelId); @@ -587,8 +591,8 @@ export function fetchAllMyTeamsChannelsAndChannelMembersREST(): ActionFunc { }; } -export function getChannelMembers(channelId: string, page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getChannelMembers(channelId: string, page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE): NewActionFuncAsync { + return async (dispatch, getState) => { let channelMembers: ChannelMembership[]; try { @@ -602,7 +606,7 @@ export function getChannelMembers(channelId: string, page = 0, perPage: number = } const userIds = channelMembers.map((cm) => cm.user_id); - getMissingProfilesByIds(userIds)(dispatch, getState); + dispatch(getMissingProfilesByIds(userIds)); dispatch({ type: ChannelTypes.RECEIVED_CHANNEL_MEMBERS, @@ -659,8 +663,8 @@ export function leaveChannel(channelId: string): ActionFunc { }; } -export function joinChannel(userId: string, teamId: string, channelId: string, channelName?: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function joinChannel(userId: string, teamId: string, channelId: string, channelName?: string): NewActionFuncAsync<{channel: Channel; member: ChannelMembership} | null> { + return async (dispatch, getState) => { if (!channelId && !channelName) { return {data: null}; } @@ -708,8 +712,8 @@ export function joinChannel(userId: string, teamId: string, channelId: string, c }; } -export function deleteChannel(channelId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function deleteChannel(channelId: string): NewActionFuncAsync { + return async (dispatch, getState) => { let state = getState(); const viewArchivedChannels = state.entities.general.config.ExperimentalViewArchivedChannels === 'true'; @@ -738,8 +742,8 @@ export function deleteChannel(channelId: string): ActionFunc { }; } -export function unarchiveChannel(channelId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function unarchiveChannel(channelId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.unarchiveChannel(channelId); } catch (error) { @@ -769,7 +773,7 @@ export function updateApproximateViewTime(channelId: string): ActionFunc { const preferences = [ {user_id: currentUserId, category: Preferences.CATEGORY_CHANNEL_APPROXIMATE_VIEW_TIME, name: channelId, value: new Date().getTime().toString()}, ]; - savePreferences(currentUserId, preferences)(dispatch); + dispatch(savePreferences(currentUserId, preferences)); } return {data: true}; }; @@ -792,8 +796,8 @@ export function readMultipleChannels(channelIds: string[]): ActionFunc { }; } -export function getChannels(teamId: string, page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getChannels(teamId: string, page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: ChannelTypes.GET_CHANNELS_REQUEST, data: null}); let channels; @@ -821,8 +825,8 @@ export function getChannels(teamId: string, page = 0, perPage: number = General. }; } -export function getArchivedChannels(teamId: string, page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getArchivedChannels(teamId: string, page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE): NewActionFuncAsync { + return async (dispatch, getState) => { let channels; try { channels = await Client4.getArchivedChannels(teamId, page, perPage); @@ -841,13 +845,13 @@ export function getArchivedChannels(teamId: string, page = 0, perPage: number = }; } -export function getAllChannelsWithCount(page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE, notAssociatedToGroup = '', excludeDefaultChannels = false, includeDeleted = false, excludePolicyConstrained = false): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getAllChannelsWithCount(page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE, notAssociatedToGroup = '', excludeDefaultChannels = false, includeDeleted = false, excludePolicyConstrained = false): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: ChannelTypes.GET_ALL_CHANNELS_REQUEST, data: null}); let payload; try { - payload = await Client4.getAllChannels(page, perPage, notAssociatedToGroup, excludeDefaultChannels, true, includeDeleted, excludePolicyConstrained) as ChannelsWithTotalCount; + payload = await Client4.getAllChannels(page, perPage, notAssociatedToGroup, excludeDefaultChannels, true, includeDeleted, excludePolicyConstrained); } catch (error) { forceLogoutIfNecessary(error, dispatch, getState); dispatch({type: ChannelTypes.GET_ALL_CHANNELS_FAILURE, error}); @@ -873,8 +877,8 @@ export function getAllChannelsWithCount(page = 0, perPage: number = General.CHAN }; } -export function getAllChannels(page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE, notAssociatedToGroup = '', excludeDefaultChannels = false, excludePolicyConstrained = false): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getAllChannels(page = 0, perPage: number = General.CHANNELS_CHUNK_SIZE, notAssociatedToGroup = '', excludeDefaultChannels = false, excludePolicyConstrained = false): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: ChannelTypes.GET_ALL_CHANNELS_REQUEST, data: null}); let channels; @@ -901,8 +905,8 @@ export function getAllChannels(page = 0, perPage: number = General.CHANNELS_CHUN }; } -export function autocompleteChannels(teamId: string, term: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function autocompleteChannels(teamId: string, term: string): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: ChannelTypes.GET_CHANNELS_REQUEST, data: null}); let channels; @@ -930,8 +934,8 @@ export function autocompleteChannels(teamId: string, term: string): ActionFunc { }; } -export function autocompleteChannelsForSearch(teamId: string, term: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function autocompleteChannelsForSearch(teamId: string, term: string): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: ChannelTypes.GET_CHANNELS_REQUEST, data: null}); let channels; @@ -959,8 +963,8 @@ export function autocompleteChannelsForSearch(teamId: string, term: string): Act }; } -export function searchChannels(teamId: string, term: string, archived?: boolean): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function searchChannels(teamId: string, term: string, archived?: boolean): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: ChannelTypes.GET_CHANNELS_REQUEST, data: null}); let channels; @@ -992,13 +996,15 @@ export function searchChannels(teamId: string, term: string, archived?: boolean) }; } -export function searchAllChannels(term: string, opts: ChannelSearchOpts = {}): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function searchAllChannels(term: string, opts: {page: number; per_page: number} & ChannelSearchOpts): NewActionFuncAsync; +export function searchAllChannels(term: string, opts: Omit | undefined): NewActionFuncAsync; +export function searchAllChannels(term: string, opts: ChannelSearchOpts = {}): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: ChannelTypes.GET_ALL_CHANNELS_REQUEST, data: null}); let response; try { - response = await Client4.searchAllChannels(term, opts) as ChannelsWithTotalCount; + response = await Client4.searchAllChannels(term, opts); } catch (error) { forceLogoutIfNecessary(error, dispatch, getState); dispatch({type: ChannelTypes.GET_ALL_CHANNELS_FAILURE, error}); @@ -1006,7 +1012,7 @@ export function searchAllChannels(term: string, opts: ChannelSearchOpts = {}): A return {error}; } - const channels = response.channels || response; + const channels = 'channels' in response ? response.channels : response; dispatch(batchActions([ { @@ -1022,15 +1028,15 @@ export function searchAllChannels(term: string, opts: ChannelSearchOpts = {}): A }; } -export function searchGroupChannels(term: string): ActionFunc { +export function searchGroupChannels(term: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.searchGroupChannels, params: [term], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getChannelStats(channelId: string, includeFileCount?: boolean): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getChannelStats(channelId: string, includeFileCount?: boolean): NewActionFuncAsync { + return async (dispatch, getState) => { let stat; try { stat = await Client4.getChannelStats(channelId, includeFileCount); @@ -1049,8 +1055,8 @@ export function getChannelStats(channelId: string, includeFileCount?: boolean): }; } -export function getChannelsMemberCount(channelIds: string[]): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getChannelsMemberCount(channelIds: string[]): NewActionFuncAsync> { + return async (dispatch, getState) => { let channelsMemberCount; try { @@ -1070,8 +1076,8 @@ export function getChannelsMemberCount(channelIds: string[]): ActionFunc { }; } -export function addChannelMember(channelId: string, userId: string, postRootId = ''): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function addChannelMember(channelId: string, userId: string, postRootId = ''): NewActionFuncAsync { + return async (dispatch, getState) => { let member; try { member = await Client4.addToChannel(userId, channelId, postRootId); @@ -1105,8 +1111,8 @@ export function addChannelMember(channelId: string, userId: string, postRootId = }; } -export function removeChannelMember(channelId: string, userId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function removeChannelMember(channelId: string, userId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.removeFromChannel(userId, channelId); } catch (error) { @@ -1353,7 +1359,7 @@ export function getChannelMembersByIds(channelId: string, userIds: string[]) { }); } -export function getChannelMember(channelId: string, userId: string) { +export function getChannelMember(channelId: string, userId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getChannelMember, onSuccess: ChannelTypes.RECEIVED_CHANNEL_MEMBER, @@ -1361,7 +1367,7 @@ export function getChannelMember(channelId: string, userId: string) { channelId, userId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getMyChannelMember(channelId: string) { @@ -1375,8 +1381,8 @@ export function getMyChannelMember(channelId: string) { } export function loadMyChannelMemberAndRole(channelId: string) { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { - const result = await getMyChannelMember(channelId)(dispatch, getState) as ActionResult; + return async (dispatch: DispatchFunc) => { + const result = await dispatch(getMyChannelMember(channelId)); const roles = result.data?.roles.split(' '); if (roles && roles.length > 0) { dispatch(loadRolesIfNeeded(roles)); @@ -1433,17 +1439,17 @@ export function updateChannelScheme(channelId: string, schemeId: string) { }); } -export function updateChannelMemberSchemeRoles(channelId: string, userId: string, isSchemeUser: boolean, isSchemeAdmin: boolean) { +export function updateChannelMemberSchemeRoles(channelId: string, userId: string, isSchemeUser: boolean, isSchemeAdmin: boolean): NewActionFuncAsync { return bindClientFunc({ clientFunc: async () => { await Client4.updateChannelMemberSchemeRoles(channelId, userId, isSchemeUser, isSchemeAdmin); return {channelId, userId, isSchemeUser, isSchemeAdmin}; }, onSuccess: ChannelTypes.UPDATED_CHANNEL_MEMBER_SCHEME_ROLES, - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function membersMinusGroupMembers(channelID: string, groupIDs: string[], page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): ActionFunc { +export function membersMinusGroupMembers(channelID: string, groupIDs: string[], page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.channelMembersMinusGroupMembers, onSuccess: ChannelTypes.RECEIVED_CHANNEL_MEMBERS_MINUS_GROUP_MEMBERS, @@ -1453,10 +1459,10 @@ export function membersMinusGroupMembers(channelID: string, groupIDs: string[], page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getChannelModerations(channelId: string): ActionFunc { +export function getChannelModerations(channelId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: async () => { const moderations = await Client4.getChannelModerations(channelId); @@ -1466,10 +1472,10 @@ export function getChannelModerations(channelId: string): ActionFunc { params: [ channelId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function patchChannelModerations(channelId: string, patch: ChannelModerationPatch[]): ActionFunc { +export function patchChannelModerations(channelId: string, patch: ChannelModerationPatch[]): NewActionFuncAsync { return bindClientFunc({ clientFunc: async () => { const moderations = await Client4.patchChannelModerations(channelId, patch); @@ -1479,7 +1485,7 @@ export function patchChannelModerations(channelId: string, patch: ChannelModerat params: [ channelId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getChannelMemberCountsByGroup(channelId: string): ActionFunc { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/emojis.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/emojis.test.ts index 2e6daffc08..3bff0068a1 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/emojis.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/emojis.test.ts @@ -7,7 +7,6 @@ import nock from 'nock'; import * as Actions from 'mattermost-redux/actions/emojis'; import {Client4} from 'mattermost-redux/client'; -import type {ActionResult} from 'mattermost-redux/types/actions'; import TestHelper from '../../test/test_helper'; import configureStore from '../../test/test_store'; @@ -35,13 +34,13 @@ describe('Actions.Emojis', () => { post('/emoji'). reply(201, {id: TestHelper.generateId(), create_at: 1507918415696, update_at: 1507918415696, delete_at: 0, creator_id: TestHelper.basicUser!.id, name: TestHelper.generateId()}); - const {data: created} = await Actions.createCustomEmoji( + const {data: created} = await store.dispatch(Actions.createCustomEmoji( { name: TestHelper.generateId(), creator_id: TestHelper.basicUser!.id, }, testImageData, - )(store.dispatch, store.getState) as ActionResult; + )); const state = store.getState(); @@ -57,20 +56,20 @@ describe('Actions.Emojis', () => { post('/emoji'). reply(201, {id: TestHelper.generateId(), create_at: 1507918415696, update_at: 1507918415696, delete_at: 0, creator_id: TestHelper.basicUser!.id, name: TestHelper.generateId()}); - const {data: created} = await Actions.createCustomEmoji( + const {data: created} = await store.dispatch(Actions.createCustomEmoji( { name: TestHelper.generateId(), creator_id: TestHelper.basicUser!.id, }, testImageData, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get('/emoji'). query(true). reply(200, [created]); - await Actions.getCustomEmojis()(store.dispatch, store.getState); + await store.dispatch(Actions.getCustomEmojis()); const state = store.getState(); @@ -85,19 +84,19 @@ describe('Actions.Emojis', () => { nock(Client4.getBaseRoute()). post('/emoji'). reply(201, {id: TestHelper.generateId(), create_at: 1507918415696, update_at: 1507918415696, delete_at: 0, creator_id: TestHelper.basicUser!.id, name: TestHelper.generateId()}); - const {data: created} = await Actions.createCustomEmoji( + const {data: created} = await store.dispatch(Actions.createCustomEmoji( { name: TestHelper.generateId(), creator_id: TestHelper.basicUser!.id, }, testImageData, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). delete(`/emoji/${created.id}`). reply(200, OK_RESPONSE); - await Actions.deleteCustomEmoji(created.id)(store.dispatch, store.getState); + await store.dispatch(Actions.deleteCustomEmoji(created.id)); const state = store.getState(); @@ -147,19 +146,19 @@ describe('Actions.Emojis', () => { post('/emoji'). reply(201, {id: TestHelper.generateId(), create_at: 1507918415696, update_at: 1507918415696, delete_at: 0, creator_id: TestHelper.basicUser!.id, name: TestHelper.generateId()}); - const {data: created} = await Actions.createCustomEmoji( + const {data: created} = await store.dispatch(Actions.createCustomEmoji( { name: TestHelper.generateId(), creator_id: TestHelper.basicUser!.id, }, testImageData, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). post('/emoji/search'). reply(200, [created]); - await Actions.searchCustomEmojis(created.name, {prefix_only: true})(store.dispatch, store.getState); + await store.dispatch(Actions.searchCustomEmojis(created.name, {prefix_only: true})); const state = store.getState(); @@ -175,20 +174,20 @@ describe('Actions.Emojis', () => { post('/emoji'). reply(201, {id: TestHelper.generateId(), create_at: 1507918415696, update_at: 1507918415696, delete_at: 0, creator_id: TestHelper.basicUser!.id, name: TestHelper.generateId()}); - const {data: created} = await Actions.createCustomEmoji( + const {data: created} = await store.dispatch(Actions.createCustomEmoji( { name: TestHelper.generateId(), creator_id: TestHelper.basicUser!.id, }, testImageData, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get('/emoji/autocomplete'). query(true). reply(200, [created]); - await Actions.autocompleteCustomEmojis(created.name)(store.dispatch, store.getState); + await store.dispatch(Actions.autocompleteCustomEmojis(created.name)); const state = store.getState(); @@ -204,19 +203,19 @@ describe('Actions.Emojis', () => { post('/emoji'). reply(201, {id: TestHelper.generateId(), create_at: 1507918415696, update_at: 1507918415696, delete_at: 0, creator_id: TestHelper.basicUser!.id, name: TestHelper.generateId()}); - const {data: created} = await Actions.createCustomEmoji( + const {data: created} = await store.dispatch(Actions.createCustomEmoji( { name: TestHelper.generateId(), creator_id: TestHelper.basicUser!.id, }, testImageData, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get(`/emoji/${created.id}`). reply(200, created); - await Actions.getCustomEmoji(created.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getCustomEmoji(created.id)); const state = store.getState(); @@ -232,19 +231,19 @@ describe('Actions.Emojis', () => { post('/emoji'). reply(201, {id: TestHelper.generateId(), create_at: 1507918415696, update_at: 1507918415696, delete_at: 0, creator_id: TestHelper.basicUser!.id, name: TestHelper.generateId()}); - const {data: created} = await Actions.createCustomEmoji( + const {data: created} = await store.dispatch(Actions.createCustomEmoji( { name: TestHelper.generateId(), creator_id: TestHelper.basicUser!.id, }, testImageData, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get(`/emoji/name/${created.name}`). reply(200, created); - await Actions.getCustomEmojiByName(created.name)(store.dispatch, store.getState); + await store.dispatch(Actions.getCustomEmojiByName(created.name)); let state = store.getState(); @@ -258,7 +257,7 @@ describe('Actions.Emojis', () => { get(`/emoji/name/${missingName}`). reply(404, {message: 'Not found', status_code: 404}); - await Actions.getCustomEmojiByName(missingName)(store.dispatch, store.getState); + await store.dispatch(Actions.getCustomEmojiByName(missingName)); state = store.getState(); expect(state.entities.emojis.nonExistentEmoji.has(missingName)).toBeTruthy(); @@ -342,13 +341,13 @@ describe('Actions.Emojis', () => { post('/emoji'). reply(201, {id: TestHelper.generateId(), create_at: 1507918415696, update_at: 1507918415696, delete_at: 0, creator_id: TestHelper.basicUser!.id, name: TestHelper.generateId()}); - const {data: created} = await Actions.createCustomEmoji( + const {data: created} = await store.dispatch(Actions.createCustomEmoji( { name: TestHelper.generateId(), creator_id: TestHelper.basicUser!.id, }, testImageData, - )(store.dispatch, store.getState) as ActionResult; + )); const missingName = TestHelper.generateId(); @@ -356,7 +355,7 @@ describe('Actions.Emojis', () => { post('/emoji/names', [created.name, missingName]). reply(200, [created]); - await Actions.getCustomEmojisInText(`some text :${created.name}: :${missingName}:`)(store.dispatch, store.getState); + await store.dispatch(Actions.getCustomEmojisInText(`some text :${created.name}: :${missingName}:`)); const state = store.getState(); expect(state.entities.emojis.customEmoji[created.id]).toBeTruthy(); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/emojis.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/emojis.ts index 32a1c8b323..b731120094 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/emojis.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/emojis.ts @@ -10,7 +10,7 @@ import type {GlobalState} from '@mattermost/types/store'; import {EmojiTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; import {getCustomEmojisByName as selectCustomEmojisByName} from 'mattermost-redux/selectors/entities/emojis'; -import type {GetStateFunc, DispatchFunc, ActionFunc} from 'mattermost-redux/types/actions'; +import type {GetStateFunc, DispatchFunc, ActionFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {parseEmojiNamesFromText} from 'mattermost-redux/utils/emoji_utils'; import {logError} from './errors'; @@ -24,7 +24,7 @@ export function setSystemEmojis(emojis: Set) { systemEmojis = emojis; } -export function createCustomEmoji(emoji: any, image: any): ActionFunc { +export function createCustomEmoji(emoji: any, image: any): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.createCustomEmoji, onSuccess: EmojiTypes.RECEIVED_CUSTOM_EMOJI, @@ -32,7 +32,7 @@ export function createCustomEmoji(emoji: any, image: any): ActionFunc { emoji, image, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getCustomEmoji(emojiId: string): ActionFunc { @@ -148,8 +148,8 @@ export function getCustomEmojis( perPage: number = General.PAGE_SIZE_DEFAULT, sort: string = Emoji.SORT_BY_NAME, loadUsers = false, -): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.getCustomEmojis(page, perPage, sort); @@ -212,8 +212,8 @@ export function deleteCustomEmoji(emojiId: string): ActionFunc { }; } -export function searchCustomEmojis(term: string, options: any = {}, loadUsers = false): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function searchCustomEmojis(term: string, options: any = {}, loadUsers = false): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.searchCustomEmoji(term, options); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/files.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/files.test.ts index d77daa9007..7529228ff8 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/files.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/files.test.ts @@ -57,7 +57,7 @@ describe('Actions.Files', () => { get(`/posts/${postForFile.id}/files/info`). reply(200, [{id: fileId, user_id: TestHelper.basicUser!.id, create_at: 1507921547541, update_at: 1507921547541, delete_at: 0, name: 'test.png', extension: 'png', size: 258428, mime_type: 'image/png', width: 600, height: 600, has_preview_image: true}]); - await Actions.getFilesForPost(postForFile.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getFilesForPost(postForFile.id)); const {files: allFiles, fileIdsByPostId} = store.getState().entities.files; @@ -80,7 +80,7 @@ describe('Actions.Files', () => { link: 'https://mattermost.com/files/ndans23ry2rtjd1z73g6i5f3fc/public?h=rE1-b2N1VVVMsAQssjwlfNawbVOwUy1TRDuTeGC_tys', }); - await Actions.getFilePublicLink(fileId)(store.dispatch, store.getState); + await store.dispatch(Actions.getFilePublicLink(fileId)); const state = store.getState(); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/files.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/files.ts index 154380d9bb..62d930b812 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/files.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/files.ts @@ -6,7 +6,7 @@ import type {Post} from '@mattermost/types/posts'; import {FileTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; -import type {DispatchFunc, GetStateFunc, ActionFunc} from 'mattermost-redux/types/actions'; +import type {DispatchFunc, GetStateFunc, ActionFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {logError} from './errors'; import {bindClientFunc, forceLogoutIfNecessary} from './helpers'; @@ -63,12 +63,12 @@ export function getFilesForPost(postId: string): ActionFunc { }; } -export function getFilePublicLink(fileId: string): ActionFunc { +export function getFilePublicLink(fileId: string): NewActionFuncAsync<{link: string}> { return bindClientFunc({ clientFunc: Client4.getFilePublicLink, onSuccess: FileTypes.RECEIVED_FILE_PUBLIC_LINK, params: [ fileId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/general.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/general.test.ts index 72a9ed0d79..248b9923fa 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/general.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/general.test.ts @@ -31,7 +31,7 @@ describe('Actions.General', () => { query(true). reply(200, {Version: '4.0.0', BuildNumber: '3', BuildDate: 'Yesterday', BuildHash: '1234'}); - await Actions.getClientConfig()(store.dispatch, store.getState); + await store.dispatch(Actions.getClientConfig()); const clientConfig = store.getState().entities.general.config; @@ -48,7 +48,7 @@ describe('Actions.General', () => { query(true). reply(200, {IsLicensed: 'false'}); - await Actions.getLicenseConfig()(store.dispatch, store.getState); + await store.dispatch(Actions.getLicenseConfig()); const licenseConfig = store.getState().entities.general.license; @@ -58,7 +58,7 @@ describe('Actions.General', () => { it('setServerVersion', async () => { const version = '3.7.0'; - await Actions.setServerVersion(version)(store.dispatch, store.getState); + await store.dispatch(Actions.setServerVersion(version)); await TestHelper.wait(100); const {serverVersion} = store.getState().entities.general; expect(serverVersion).toEqual(version); @@ -77,7 +77,7 @@ describe('Actions.General', () => { query(true). reply(200, responseData); - await Actions.getDataRetentionPolicy()(store.dispatch, store.getState); + await store.dispatch(Actions.getDataRetentionPolicy()); await TestHelper.wait(100); const {dataRetentionPolicy} = store.getState().entities.general; expect(dataRetentionPolicy).toEqual(responseData); @@ -94,7 +94,7 @@ describe('Actions.General', () => { query(true). reply(200, responseData); - await Actions.getWarnMetricsStatus()(store.dispatch, store.getState); + await store.dispatch(Actions.getWarnMetricsStatus()); const {warnMetricsStatus} = store.getState().entities.general; expect(warnMetricsStatus.metric1).toEqual(true); expect(warnMetricsStatus.metric2).toEqual(false); @@ -111,7 +111,7 @@ describe('Actions.General', () => { query(true). reply(200, responseData); - await Actions.getFirstAdminVisitMarketplaceStatus()(store.dispatch, store.getState); + await store.dispatch(Actions.getFirstAdminVisitMarketplaceStatus()); const {firstAdminVisitMarketplaceStatus} = store.getState().entities.general; expect(firstAdminVisitMarketplaceStatus).toEqual(false); }); @@ -121,7 +121,7 @@ describe('Actions.General', () => { post('/marketplace/first_admin_visit'). reply(200, OK_RESPONSE); - await Actions.setFirstAdminVisitMarketplaceStatus()(store.dispatch, store.getState); + await store.dispatch(Actions.setFirstAdminVisitMarketplaceStatus()); const {firstAdminVisitMarketplaceStatus} = store.getState().entities.general; expect(firstAdminVisitMarketplaceStatus).toEqual(true); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts index c4f9e63770..c7aa6a8e6e 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/general.ts @@ -4,10 +4,11 @@ import {batchActions} from 'redux-batched-actions'; import {LogLevel} from '@mattermost/types/client4'; +import type {SystemSetting} from '@mattermost/types/general'; import {GeneralTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; -import type {GetStateFunc, DispatchFunc, ActionFunc} from 'mattermost-redux/types/actions'; +import type {GetStateFunc, DispatchFunc, ActionFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {logError} from './errors'; import {bindClientFunc, forceLogoutIfNecessary} from './helpers'; @@ -134,8 +135,8 @@ export function getFirstAdminVisitMarketplaceStatus(): ActionFunc { } // accompanying "set" happens as part of Client4.completeSetup -export function getFirstAdminSetupComplete(): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getFirstAdminSetupComplete(): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.getFirstAdminSetupComplete(); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/groups.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/groups.test.ts index b18d5d2698..c8f43bcb85 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/groups.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/groups.test.ts @@ -87,8 +87,8 @@ describe('Actions.Groups', () => { get(`/groups/${groupID}/channels`). reply(200, groupChannels); - await Actions.getGroupSyncables(groupID, SyncableType.Team)(store.dispatch, store.getState); - await Actions.getGroupSyncables(groupID, SyncableType.Channel)(store.dispatch, store.getState); + await store.dispatch(Actions.getGroupSyncables(groupID, SyncableType.Team)); + await store.dispatch(Actions.getGroupSyncables(groupID, SyncableType.Channel)); const state = store.getState(); @@ -121,7 +121,7 @@ describe('Actions.Groups', () => { get(`/groups/${groupID}?include_member_count=false`). reply(200, response); - await Actions.getGroup(groupID)(store.dispatch, store.getState); + await store.dispatch(Actions.getGroup(groupID)); const state = store.getState(); @@ -163,8 +163,8 @@ describe('Actions.Groups', () => { post(`/groups/${groupID}/channels/${channelID}/link`). reply(200, groupChannelResponse); - await (Actions.linkGroupSyncable as any)(groupID, teamID, SyncableType.Team)(store.dispatch, store.getState); - await (Actions.linkGroupSyncable as any)(groupID, channelID, SyncableType.Channel)(store.dispatch, store.getState); + await store.dispatch(Actions.linkGroupSyncable(groupID, teamID, SyncableType.Team, {})); + await store.dispatch(Actions.linkGroupSyncable(groupID, channelID, SyncableType.Channel, {})); const state = store.getState(); const syncables = state.entities.groups.syncables; @@ -205,8 +205,8 @@ describe('Actions.Groups', () => { post(`/groups/${groupID}/channels/${channelID}/link`). reply(200, groupChannelResponse); - await (Actions.linkGroupSyncable as any)(groupID, teamID, SyncableType.Team)(store.dispatch, store.getState); - await (Actions.linkGroupSyncable as any)(groupID, channelID, SyncableType.Channel)(store.dispatch, store.getState); + await store.dispatch(Actions.linkGroupSyncable(groupID, teamID, SyncableType.Team, {})); + await store.dispatch(Actions.linkGroupSyncable(groupID, channelID, SyncableType.Channel, {})); let state = store.getState(); let syncables = state.entities.groups.syncables; @@ -226,8 +226,8 @@ describe('Actions.Groups', () => { delete(`/groups/${groupID}/channels/${channelID}/link`). reply(204, {ok: true}); - await Actions.unlinkGroupSyncable(groupID, teamID, SyncableType.Team)(store.dispatch, store.getState); - await Actions.unlinkGroupSyncable(groupID, channelID, SyncableType.Channel)(store.dispatch, store.getState); + await store.dispatch(Actions.unlinkGroupSyncable(groupID, teamID, SyncableType.Team)); + await store.dispatch(Actions.unlinkGroupSyncable(groupID, channelID, SyncableType.Channel)); state = store.getState(); syncables = state.entities.groups.syncables; @@ -281,7 +281,7 @@ describe('Actions.Groups', () => { page: 0, per_page: 0, }; - await Actions.getGroups(groupParams)(store.dispatch, store.getState); + await store.dispatch(Actions.getGroups(groupParams)); const state = store.getState(); @@ -349,7 +349,7 @@ describe('Actions.Groups', () => { get(`/teams/${teamID}/groups?paginate=false&filter_allow_reference=false&include_member_count=true`). reply(200, response); - await Actions.getAllGroupsAssociatedToTeam(teamID, false, true)(store.dispatch, store.getState); + await store.dispatch(Actions.getAllGroupsAssociatedToTeam(teamID, false, true)); const state = store.getState(); @@ -401,7 +401,7 @@ describe('Actions.Groups', () => { get(`/teams/${teamID}/groups?page=100&per_page=60&q=0&include_member_count=true&filter_allow_reference=false`). reply(200, response); - await Actions.getGroupsAssociatedToTeam(teamID, '0', 100)(store.dispatch, store.getState); + await store.dispatch(Actions.getGroupsAssociatedToTeam(teamID, '0', 100)); const state = store.getState(); @@ -450,7 +450,7 @@ describe('Actions.Groups', () => { get(`/groups?not_associated_to_team=${teamID}&page=100&per_page=60&q=0&include_member_count=true`). reply(200, response); - await Actions.getGroupsNotAssociatedToTeam(teamID, '0', 100)(store.dispatch, store.getState); + await store.dispatch(Actions.getGroupsNotAssociatedToTeam(teamID, '0', 100)); const state = store.getState(); const groupIDs = state.entities.teams.groupsAssociatedToTeam[teamID].ids; @@ -513,7 +513,7 @@ describe('Actions.Groups', () => { get(`/channels/${channelID}/groups?paginate=false&filter_allow_reference=false&include_member_count=true`). reply(200, response); - await Actions.getAllGroupsAssociatedToChannel(channelID, false, true)(store.dispatch, store.getState); + await store.dispatch(Actions.getAllGroupsAssociatedToChannel(channelID, false, true)); const state = store.getState(); @@ -613,7 +613,7 @@ describe('Actions.Groups', () => { get(`/teams/${teamID}/groups_by_channels?paginate=false&filter_allow_reference=true`). reply(200, response2); - await Actions.getAllGroupsAssociatedToChannelsInTeam(teamID, false)(store.dispatch, store.getState); + await store.dispatch(Actions.getAllGroupsAssociatedToChannelsInTeam(teamID, false)); let state = store.getState(); @@ -623,7 +623,7 @@ describe('Actions.Groups', () => { expect(response1.groups[channelID1].map((group) => group.id).includes(id)).toBeTruthy(); }); - await Actions.getAllGroupsAssociatedToChannelsInTeam(teamID, true)(store.dispatch, store.getState); + await store.dispatch(Actions.getAllGroupsAssociatedToChannelsInTeam(teamID, true)); state = store.getState(); @@ -675,7 +675,7 @@ describe('Actions.Groups', () => { get(`/channels/${channelID}/groups?page=100&per_page=60&q=0&include_member_count=true&filter_allow_reference=false`). reply(200, response); - await Actions.getGroupsAssociatedToChannel(channelID, '0', 100)(store.dispatch, store.getState); + await store.dispatch(Actions.getGroupsAssociatedToChannel(channelID, '0', 100)); const state = store.getState(); @@ -724,7 +724,7 @@ describe('Actions.Groups', () => { get(`/groups?not_associated_to_channel=${channelID}&page=100&per_page=60&q=0&include_member_count=true`). reply(200, response); - await Actions.getGroupsNotAssociatedToChannel(channelID, '0', 100)(store.dispatch, store.getState); + await store.dispatch(Actions.getGroupsNotAssociatedToChannel(channelID, '0', 100)); const state = store.getState(); @@ -774,8 +774,8 @@ describe('Actions.Groups', () => { put(`/groups/${groupID}/channels/${channelID}/patch`). reply(200, groupChannelResponse); - await Actions.patchGroupSyncable(groupID, teamID, SyncableType.Team, groupSyncablePatch)(store.dispatch, store.getState); - await Actions.patchGroupSyncable(groupID, channelID, SyncableType.Channel, groupSyncablePatch)(store.dispatch, store.getState); + await store.dispatch(Actions.patchGroupSyncable(groupID, teamID, SyncableType.Team, groupSyncablePatch)); + await store.dispatch(Actions.patchGroupSyncable(groupID, channelID, SyncableType.Channel, groupSyncablePatch)); const state = store.getState(); const groupSyncables = state.entities.groups.syncables[groupID]; @@ -813,7 +813,7 @@ describe('Actions.Groups', () => { put(`/groups/${groupID}/patch`). reply(200, response); - await Actions.patchGroup(groupID, groupPatch)(store.dispatch, store.getState); + await store.dispatch(Actions.patchGroup(groupID, groupPatch)); let state = store.getState(); @@ -831,7 +831,7 @@ describe('Actions.Groups', () => { put(`/groups/${groupID}/patch`). reply(200, response); - await Actions.patchGroup(groupID, groupPatch)(store.dispatch, store.getState); + await store.dispatch(Actions.patchGroup(groupID, groupPatch)); state = store.getState(); @@ -849,7 +849,7 @@ describe('Actions.Groups', () => { put(`/groups/${groupID}/patch`). reply(200, response); - await Actions.patchGroup(groupID, groupPatch)(store.dispatch, store.getState); + await store.dispatch(Actions.patchGroup(groupID, groupPatch)); state = store.getState(); @@ -872,7 +872,7 @@ describe('Actions.Groups', () => { get(`/groups/${groupID}/stats`). reply(200, response); - await Actions.getGroupStats(groupID)(store.dispatch, store.getState); + await store.dispatch(Actions.getGroupStats(groupID)); const state = store.getState(); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/groups.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/groups.ts index fde29d0a9f..c1292c27dd 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/groups.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/groups.ts @@ -4,19 +4,20 @@ import type {AnyAction} from 'redux'; import {batchActions} from 'redux-batched-actions'; -import type {GroupPatch, SyncablePatch, GroupCreateWithUserIds, CustomGroupPatch, GroupSearchParams, GetGroupsParams, GetGroupsForUserParams} from '@mattermost/types/groups'; +import type {GroupPatch, SyncablePatch, GroupCreateWithUserIds, CustomGroupPatch, GroupSearchParams, GetGroupsParams, GetGroupsForUserParams, Group, GroupsWithCount, GroupStats} from '@mattermost/types/groups'; import {SyncableType, GroupSource} from '@mattermost/types/groups'; +import type {UserProfile} from '@mattermost/types/users'; import {ChannelTypes, GroupTypes, UserTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; import {General} from 'mattermost-redux/constants'; -import type {ActionFunc, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {ActionFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {logError} from './errors'; import {bindClientFunc, forceLogoutIfNecessary} from './helpers'; -export function linkGroupSyncable(groupID: string, syncableID: string, syncableType: SyncableType, patch: SyncablePatch): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function linkGroupSyncable(groupID: string, syncableID: string, syncableType: SyncableType, patch: Partial): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.linkGroupSyncable(groupID, syncableID, syncableType, patch); @@ -47,8 +48,8 @@ export function linkGroupSyncable(groupID: string, syncableID: string, syncableT }; } -export function unlinkGroupSyncable(groupID: string, syncableID: string, syncableType: SyncableType): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function unlinkGroupSyncable(groupID: string, syncableID: string, syncableType: SyncableType): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.unlinkGroupSyncable(groupID, syncableID, syncableType); } catch (error) { @@ -82,8 +83,8 @@ export function unlinkGroupSyncable(groupID: string, syncableID: string, syncabl }; } -export function getGroupSyncables(groupID: string, syncableType: SyncableType): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getGroupSyncables(groupID: string, syncableType: SyncableType): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.getGroupSyncables(groupID, syncableType); @@ -113,8 +114,8 @@ export function getGroupSyncables(groupID: string, syncableType: SyncableType): }; } -export function patchGroupSyncable(groupID: string, syncableID: string, syncableType: SyncableType, patch: SyncablePatch): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function patchGroupSyncable(groupID: string, syncableID: string, syncableType: SyncableType, patch: Partial): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.patchGroupSyncable(groupID, syncableID, syncableType, patch); @@ -146,7 +147,7 @@ export function patchGroupSyncable(groupID: string, syncableID: string, syncable }; } -export function getGroup(id: string, includeMemberCount = false): ActionFunc { +export function getGroup(id: string, includeMemberCount = false): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getGroup, onSuccess: [GroupTypes.RECEIVED_GROUP], @@ -154,10 +155,10 @@ export function getGroup(id: string, includeMemberCount = false): ActionFunc { id, includeMemberCount, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getGroups(opts: GetGroupsParams): ActionFunc { +export function getGroups(opts: GetGroupsParams): NewActionFuncAsync { return bindClientFunc({ clientFunc: async (opts) => { const result = await Client4.getGroups(opts); @@ -167,10 +168,10 @@ export function getGroups(opts: GetGroupsParams): ActionFunc { params: [ opts, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getGroupsNotAssociatedToTeam(teamID: string, q = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT, source = GroupSource.Ldap): ActionFunc { +export function getGroupsNotAssociatedToTeam(teamID: string, q = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT, source = GroupSource.Ldap): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getGroupsNotAssociatedToTeam, onSuccess: [GroupTypes.RECEIVED_GROUPS], @@ -181,10 +182,10 @@ export function getGroupsNotAssociatedToTeam(teamID: string, q = '', page = 0, p perPage, source, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getGroupsNotAssociatedToChannel(channelID: string, q = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT, filterParentTeamPermitted = false, source = GroupSource.Ldap): ActionFunc { +export function getGroupsNotAssociatedToChannel(channelID: string, q = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT, filterParentTeamPermitted = false, source = GroupSource.Ldap): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getGroupsNotAssociatedToChannel, onSuccess: [GroupTypes.RECEIVED_GROUPS], @@ -196,10 +197,10 @@ export function getGroupsNotAssociatedToChannel(channelID: string, q = '', page filterParentTeamPermitted, source, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getAllGroupsAssociatedToTeam(teamID: string, filterAllowReference = false, includeMemberCount = false): ActionFunc { +export function getAllGroupsAssociatedToTeam(teamID: string, filterAllowReference = false, includeMemberCount = false): NewActionFuncAsync { return bindClientFunc({ clientFunc: async (param1, param2, param3) => { const result = await Client4.getAllGroupsAssociatedToTeam(param1, param2, param3); @@ -212,7 +213,7 @@ export function getAllGroupsAssociatedToTeam(teamID: string, filterAllowReferenc filterAllowReference, includeMemberCount, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getAllGroupsAssociatedToChannelsInTeam(teamID: string, filterAllowReference = false): ActionFunc { @@ -229,7 +230,7 @@ export function getAllGroupsAssociatedToChannelsInTeam(teamID: string, filterAll }); } -export function getAllGroupsAssociatedToChannel(channelID: string, filterAllowReference = false, includeMemberCount = false): ActionFunc { +export function getAllGroupsAssociatedToChannel(channelID: string, filterAllowReference = false, includeMemberCount = false): NewActionFuncAsync { return bindClientFunc({ clientFunc: async (param1, param2, param3) => { const result = await Client4.getAllGroupsAssociatedToChannel(param1, param2, param3); @@ -242,10 +243,10 @@ export function getAllGroupsAssociatedToChannel(channelID: string, filterAllowRe filterAllowReference, includeMemberCount, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getGroupsAssociatedToTeam(teamID: string, q = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT, filterAllowReference = false): ActionFunc { +export function getGroupsAssociatedToTeam(teamID: string, q = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT, filterAllowReference = false): NewActionFuncAsync<{groups: Group[]; totalGroupCount: number}> { return bindClientFunc({ clientFunc: async (param1, param2, param3, param4, param5) => { const result = await Client4.getGroupsAssociatedToTeam(param1, param2, param3, param4, param5); @@ -259,10 +260,10 @@ export function getGroupsAssociatedToTeam(teamID: string, q = '', page = 0, perP perPage, filterAllowReference, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getGroupsAssociatedToChannel(channelID: string, q = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT, filterAllowReference = false): ActionFunc { +export function getGroupsAssociatedToChannel(channelID: string, q = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT, filterAllowReference = false): NewActionFuncAsync<{groups: Group[]; totalGroupCount: number}> { return bindClientFunc({ clientFunc: async (param1, param2, param3, param4, param5) => { const result = await Client4.getGroupsAssociatedToChannel(param1, param2, param3, param4, param5); @@ -276,10 +277,10 @@ export function getGroupsAssociatedToChannel(channelID: string, q = '', page = 0 perPage, filterAllowReference, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function patchGroup(groupID: string, patch: GroupPatch | CustomGroupPatch): ActionFunc { +export function patchGroup(groupID: string, patch: GroupPatch | CustomGroupPatch): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.patchGroup, onSuccess: [GroupTypes.PATCHED_GROUP], @@ -287,7 +288,7 @@ export function patchGroup(groupID: string, patch: GroupPatch | CustomGroupPatch groupID, patch, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getGroupsByUserId(userID: string): ActionFunc { @@ -300,7 +301,7 @@ export function getGroupsByUserId(userID: string): ActionFunc { }); } -export function getGroupsByUserIdPaginated(opts: GetGroupsForUserParams): ActionFunc { +export function getGroupsByUserIdPaginated(opts: GetGroupsForUserParams): NewActionFuncAsync { return bindClientFunc({ clientFunc: async (opts) => { const result = await Client4.getGroups(opts); @@ -310,21 +311,21 @@ export function getGroupsByUserIdPaginated(opts: GetGroupsForUserParams): Action params: [ opts, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getGroupStats(groupID: string): ActionFunc { +export function getGroupStats(groupID: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getGroupStats, onSuccess: [GroupTypes.RECEIVED_GROUP_STATS], params: [ groupID, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function createGroupWithUserIds(group: GroupCreateWithUserIds): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function createGroupWithUserIds(group: GroupCreateWithUserIds): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.createGroupWithUserIds(group); @@ -341,8 +342,8 @@ export function createGroupWithUserIds(group: GroupCreateWithUserIds): ActionFun }; } -export function addUsersToGroup(groupId: string, userIds: string[]): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function addUsersToGroup(groupId: string, userIds: string[]): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.addUsersToGroup(groupId, userIds); @@ -363,8 +364,8 @@ export function addUsersToGroup(groupId: string, userIds: string[]): ActionFunc }; } -export function removeUsersFromGroup(groupId: string, userIds: string[]): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function removeUsersFromGroup(groupId: string, userIds: string[]): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.removeUsersFromGroup(groupId, userIds); @@ -385,8 +386,8 @@ export function removeUsersFromGroup(groupId: string, userIds: string[]): Action }; } -export function searchGroups(params: GroupSearchParams): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function searchGroups(params: GroupSearchParams): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.searchGroups(params); @@ -410,8 +411,8 @@ export function searchGroups(params: GroupSearchParams): ActionFunc { }; } -export function archiveGroup(groupId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function archiveGroup(groupId: string): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.archiveGroup(groupId); @@ -432,8 +433,8 @@ export function archiveGroup(groupId: string): ActionFunc { }; } -export function restoreGroup(groupId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function restoreGroup(groupId: string): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.restoreGroup(groupId); @@ -454,8 +455,8 @@ export function restoreGroup(groupId: string): ActionFunc { }; } -export function createGroupTeamsAndChannels(userID: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function createGroupTeamsAndChannels(userID: string): NewActionFuncAsync<{user_id: string}> { + return async (dispatch, getState) => { try { await Client4.createGroupTeamsAndChannels(userID); } catch (error) { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/integrations.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/integrations.test.ts index 64b9e81445..7968346a31 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/integrations.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/integrations.test.ts @@ -8,7 +8,6 @@ import type {DialogSubmission, IncomingWebhook, OutgoingWebhook} from '@mattermo import * as Actions from 'mattermost-redux/actions/integrations'; import * as TeamsActions from 'mattermost-redux/actions/teams'; import {Client4} from 'mattermost-redux/client'; -import type {ActionResult} from 'mattermost-redux/types/actions'; import TestHelper from '../../test/test_helper'; import configureStore from '../../test/test_store'; @@ -34,13 +33,13 @@ describe('Actions.Integrations', () => { post('/hooks/incoming'). reply(201, TestHelper.testIncomingHook()); - const {data: created} = await Actions.createIncomingHook( + const {data: created} = await store.dispatch(Actions.createIncomingHook( { channel_id: TestHelper.basicChannel!.id, display_name: 'test', description: 'test', } as IncomingWebhook, - )(store.dispatch, store.getState) as ActionResult; + )); const state = store.getState(); @@ -54,20 +53,19 @@ describe('Actions.Integrations', () => { post('/hooks/incoming'). reply(201, TestHelper.testIncomingHook()); - const {data: created} = await Actions.createIncomingHook( + const {data: created} = await store.dispatch(Actions.createIncomingHook( { channel_id: TestHelper.basicChannel!.id, display_name: 'test', description: 'test', } as IncomingWebhook, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get(`/hooks/incoming/${created.id}`). reply(200, created); - await Actions.getIncomingHook(created.id)(store.dispatch, store.getState); - + await store.dispatch(Actions.getIncomingHook(created.id)); const state = store.getState(); const hooks = state.entities.integrations.incomingHooks; @@ -80,21 +78,20 @@ describe('Actions.Integrations', () => { post('/hooks/incoming'). reply(201, TestHelper.testIncomingHook()); - const {data: created} = await Actions.createIncomingHook( + const {data: created} = await store.dispatch(Actions.createIncomingHook( { channel_id: TestHelper.basicChannel!.id, display_name: 'test', description: 'test', } as IncomingWebhook, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get('/hooks/incoming'). query(true). reply(200, [created]); - await Actions.getIncomingHooks(TestHelper.basicTeam!.id)(store.dispatch, store.getState); - + await store.dispatch(Actions.getIncomingHooks(TestHelper.basicTeam!.id)); const state = store.getState(); const hooks = state.entities.integrations.incomingHooks; @@ -107,20 +104,19 @@ describe('Actions.Integrations', () => { post('/hooks/incoming'). reply(201, TestHelper.testIncomingHook()); - const {data: created} = await Actions.createIncomingHook( + const {data: created} = await store.dispatch(Actions.createIncomingHook( { channel_id: TestHelper.basicChannel!.id, display_name: 'test', description: 'test', } as IncomingWebhook, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). delete(`/hooks/incoming/${created.id}`). reply(200, OK_RESPONSE); - await Actions.removeIncomingHook(created.id)(store.dispatch, store.getState); - + await store.dispatch(Actions.removeIncomingHook(created.id)); const state = store.getState(); const hooks = state.entities.integrations.incomingHooks; @@ -132,13 +128,13 @@ describe('Actions.Integrations', () => { post('/hooks/incoming'). reply(201, TestHelper.testIncomingHook()); - const {data: created} = await Actions.createIncomingHook( + const {data: created} = await store.dispatch(Actions.createIncomingHook( { channel_id: TestHelper.basicChannel!.id, display_name: 'test', description: 'test', } as IncomingWebhook, - )(store.dispatch, store.getState) as ActionResult; + )); const updated = {...created}; updated.display_name = 'test2'; @@ -146,8 +142,7 @@ describe('Actions.Integrations', () => { nock(Client4.getBaseRoute()). put(`/hooks/incoming/${created.id}`). reply(200, updated); - await Actions.updateIncomingHook(updated)(store.dispatch, store.getState); - + await store.dispatch(Actions.updateIncomingHook(updated)); const state = store.getState(); const hooks = state.entities.integrations.incomingHooks; @@ -160,7 +155,7 @@ describe('Actions.Integrations', () => { post('/hooks/outgoing'). reply(201, TestHelper.testOutgoingHook()); - const {data: created} = await Actions.createOutgoingHook( + const {data: created} = await store.dispatch(Actions.createOutgoingHook( { channel_id: TestHelper.basicChannel!.id, team_id: TestHelper.basicTeam!.id, @@ -168,7 +163,7 @@ describe('Actions.Integrations', () => { trigger_words: [TestHelper.generateId()], callback_urls: ['http://localhost/notarealendpoint'], } as OutgoingWebhook, - )(store.dispatch, store.getState) as ActionResult; + )); const state = store.getState(); @@ -182,7 +177,7 @@ describe('Actions.Integrations', () => { post('/hooks/outgoing'). reply(201, TestHelper.testOutgoingHook()); - const {data: created} = await Actions.createOutgoingHook( + const {data: created} = await store.dispatch(Actions.createOutgoingHook( { channel_id: TestHelper.basicChannel!.id, team_id: TestHelper.basicTeam!.id, @@ -190,14 +185,13 @@ describe('Actions.Integrations', () => { trigger_words: [TestHelper.generateId()], callback_urls: ['http://localhost/notarealendpoint'], } as OutgoingWebhook, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get(`/hooks/outgoing/${created.id}`). reply(200, TestHelper.testOutgoingHook()); - await Actions.getOutgoingHook(created.id)(store.dispatch, store.getState); - + await store.dispatch(Actions.getOutgoingHook(created.id)); const state = store.getState(); const hooks = state.entities.integrations.outgoingHooks; @@ -210,7 +204,7 @@ describe('Actions.Integrations', () => { post('/hooks/outgoing'). reply(201, TestHelper.testOutgoingHook()); - const {data: created} = await Actions.createOutgoingHook( + const {data: created} = await store.dispatch(Actions.createOutgoingHook( { channel_id: TestHelper.basicChannel!.id, team_id: TestHelper.basicTeam!.id, @@ -218,15 +212,14 @@ describe('Actions.Integrations', () => { trigger_words: [TestHelper.generateId()], callback_urls: ['http://localhost/notarealendpoint'], } as OutgoingWebhook, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get('/hooks/outgoing'). query(true). reply(200, [TestHelper.testOutgoingHook()]); - await Actions.getOutgoingHooks(TestHelper.basicChannel!.id)(store.dispatch, store.getState); - + await store.dispatch(Actions.getOutgoingHooks(TestHelper.basicChannel!.id)); const state = store.getState(); const hooks = state.entities.integrations.outgoingHooks; @@ -239,7 +232,7 @@ describe('Actions.Integrations', () => { post('/hooks/outgoing'). reply(201, TestHelper.testOutgoingHook()); - const {data: created} = await Actions.createOutgoingHook( + const {data: created} = await store.dispatch(Actions.createOutgoingHook( { channel_id: TestHelper.basicChannel!.id, team_id: TestHelper.basicTeam!.id, @@ -247,14 +240,13 @@ describe('Actions.Integrations', () => { trigger_words: [TestHelper.generateId()], callback_urls: ['http://localhost/notarealendpoint'], } as OutgoingWebhook, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). delete(`/hooks/outgoing/${created.id}`). reply(200, OK_RESPONSE); - await Actions.removeOutgoingHook(created.id)(store.dispatch, store.getState); - + await store.dispatch(Actions.removeOutgoingHook(created.id)); const state = store.getState(); const hooks = state.entities.integrations.outgoingHooks; @@ -266,7 +258,7 @@ describe('Actions.Integrations', () => { post('/hooks/outgoing'). reply(201, TestHelper.testOutgoingHook()); - const {data: created} = await Actions.createOutgoingHook( + const {data: created} = await store.dispatch(Actions.createOutgoingHook( { channel_id: TestHelper.basicChannel!.id, team_id: TestHelper.basicTeam!.id, @@ -274,15 +266,14 @@ describe('Actions.Integrations', () => { trigger_words: [TestHelper.generateId()], callback_urls: ['http://localhost/notarealendpoint'], } as OutgoingWebhook, - )(store.dispatch, store.getState) as ActionResult; + )); const updated = {...created}; updated.display_name = 'test2'; nock(Client4.getBaseRoute()). put(`/hooks/outgoing/${created.id}`). reply(200, updated); - await Actions.updateOutgoingHook(updated)(store.dispatch, store.getState); - + await store.dispatch(Actions.updateOutgoingHook(updated)); const state = store.getState(); const hooks = state.entities.integrations.outgoingHooks; @@ -295,7 +286,7 @@ describe('Actions.Integrations', () => { post('/hooks/outgoing'). reply(201, TestHelper.testOutgoingHook()); - const {data: created} = await Actions.createOutgoingHook( + const {data: created} = await store.dispatch(Actions.createOutgoingHook( { channel_id: TestHelper.basicChannel!.id, team_id: TestHelper.basicTeam!.id, @@ -303,13 +294,12 @@ describe('Actions.Integrations', () => { trigger_words: [TestHelper.generateId()], callback_urls: ['http://localhost/notarealendpoint'], } as OutgoingWebhook, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). post(`/hooks/outgoing/${created.id}/regen_token`). reply(200, {...created, token: TestHelper.generateId()}); - await Actions.regenOutgoingHookToken(created.id)(store.dispatch, store.getState); - + await store.dispatch(Actions.regenOutgoingHookToken(created.id)); const state = store.getState(); const hooks = state.entities.integrations.outgoingHooks; @@ -326,9 +316,9 @@ describe('Actions.Integrations', () => { post('/teams'). reply(201, TestHelper.fakeTeamWithId()); - const {data: team} = await TeamsActions.createTeam( + const {data: team} = await store.dispatch(TeamsActions.createTeam( TestHelper.fakeTeam(), - )(store.dispatch, store.getState) as ActionResult; + )); const teamCommand = TestHelper.testCommand(team.id); @@ -336,9 +326,9 @@ describe('Actions.Integrations', () => { post('/commands'). reply(201, {...teamCommand, token: TestHelper.generateId(), id: TestHelper.generateId()}); - const {data: created} = await Actions.addCommand( + const {data: created} = await store.dispatch(Actions.addCommand( teamCommand, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get('/commands'). @@ -347,10 +337,9 @@ describe('Actions.Integrations', () => { trigger: 'system-command', }]); - await Actions.getCommands( + await store.dispatch(Actions.getCommands( team.id, - )(store.dispatch, store.getState); - + )); const teamCommands = store.getState().entities.integrations.commands; const executableCommands = store.getState().entities.integrations.executableCommands; expect(Object.keys({...teamCommands, ...executableCommands}).length).toBeTruthy(); @@ -365,9 +354,9 @@ describe('Actions.Integrations', () => { post('/teams'). reply(201, TestHelper.fakeTeamWithId()); - const {data: team} = await TeamsActions.createTeam( + const {data: team} = await store.dispatch(TeamsActions.createTeam( TestHelper.fakeTeam(), - )(store.dispatch, store.getState) as ActionResult; + )); const teamCommandWithAutocomplete = TestHelper.testCommand(team.id); @@ -375,9 +364,9 @@ describe('Actions.Integrations', () => { post('/commands'). reply(201, {...teamCommandWithAutocomplete, token: TestHelper.generateId(), id: TestHelper.generateId()}); - const {data: createdWithAutocomplete} = await Actions.addCommand( + const {data: createdWithAutocomplete} = await store.dispatch(Actions.addCommand( teamCommandWithAutocomplete, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get(`/teams/${team.id}/commands/autocomplete`). @@ -386,10 +375,9 @@ describe('Actions.Integrations', () => { trigger: 'system-command', }]); - await Actions.getAutocompleteCommands( + await store.dispatch(Actions.getAutocompleteCommands( team.id, - )(store.dispatch, store.getState); - + )); const teamCommands = store.getState().entities.integrations.commands; const systemCommands = store.getState().entities.integrations.systemCommands; expect(Object.keys({...teamCommands, ...systemCommands}).length).toEqual(2); @@ -400,19 +388,18 @@ describe('Actions.Integrations', () => { post('/teams'). reply(201, TestHelper.fakeTeamWithId()); - const {data: team} = await TeamsActions.createTeam( + const {data: team} = await store.dispatch(TeamsActions.createTeam( TestHelper.fakeTeam(), - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get('/commands'). query(true). reply(200, []); - await Actions.getCustomTeamCommands( + await store.dispatch(Actions.getCustomTeamCommands( team.id, - )(store.dispatch, store.getState); - + )); const noCommands = store.getState().entities.integrations.commands; expect(Object.keys(noCommands).length).toEqual(0); @@ -422,19 +409,18 @@ describe('Actions.Integrations', () => { post('/commands'). reply(201, {...command, token: TestHelper.generateId(), id: TestHelper.generateId()}); - const {data: created} = await Actions.addCommand( + const {data: created} = await store.dispatch(Actions.addCommand( command, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). get('/commands'). query(true). reply(200, []); - await Actions.getCustomTeamCommands( + await store.dispatch(Actions.getCustomTeamCommands( team.id, - )(store.dispatch, store.getState); - + )); const {commands} = store.getState().entities.integrations; expect(commands[created.id]).toBeTruthy(); expect(Object.keys(commands).length).toEqual(1); @@ -448,9 +434,9 @@ describe('Actions.Integrations', () => { post('/teams'). reply(201, TestHelper.fakeTeamWithId()); - const {data: team} = await TeamsActions.createTeam( + const {data: team} = await store.dispatch(TeamsActions.createTeam( TestHelper.fakeTeam(), - )(store.dispatch, store.getState) as ActionResult; + )); const args = { channel_id: TestHelper.basicChannel!.id, @@ -461,7 +447,7 @@ describe('Actions.Integrations', () => { post('/commands/execute'). reply(200, []); - await Actions.executeCommand('/echo message 5', args); + await store.dispatch(Actions.executeCommand('/echo message 5', args)); }); it('addCommand', async () => { @@ -469,9 +455,9 @@ describe('Actions.Integrations', () => { post('/teams'). reply(201, TestHelper.fakeTeamWithId()); - const {data: team} = await TeamsActions.createTeam( + const {data: team} = await store.dispatch(TeamsActions.createTeam( TestHelper.fakeTeam(), - )(store.dispatch, store.getState) as ActionResult; + )); const expected = TestHelper.testCommand(team.id); @@ -479,7 +465,7 @@ describe('Actions.Integrations', () => { post('/commands'). reply(201, {...expected, token: TestHelper.generateId(), id: TestHelper.generateId()}); - const {data: created} = await Actions.addCommand(expected)(store.dispatch, store.getState) as ActionResult; + const {data: created} = await store.dispatch(Actions.addCommand(expected)); const {commands} = store.getState().entities.integrations; expect(commands[created.id]).toBeTruthy(); @@ -507,9 +493,9 @@ describe('Actions.Integrations', () => { post('/teams'). reply(201, TestHelper.fakeTeamWithId()); - const {data: team} = await TeamsActions.createTeam( + const {data: team} = await store.dispatch(TeamsActions.createTeam( TestHelper.fakeTeam(), - )(store.dispatch, store.getState) as ActionResult; + )); const command = TestHelper.testCommand(team.id); @@ -517,18 +503,17 @@ describe('Actions.Integrations', () => { post('/commands'). reply(201, {...command, token: TestHelper.generateId(), id: TestHelper.generateId()}); - const {data: created} = await Actions.addCommand( + const {data: created} = await store.dispatch(Actions.addCommand( command, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). put(`/commands/${created.id}/regen_token`). reply(200, {...created, token: TestHelper.generateId()}); - await Actions.regenCommandToken( + await store.dispatch(Actions.regenCommandToken( created.id, - )(store.dispatch, store.getState); - + )); const {commands} = store.getState().entities.integrations; expect(commands[created.id]).toBeTruthy(); const updated = commands[created.id]; @@ -557,9 +542,9 @@ describe('Actions.Integrations', () => { post('/teams'). reply(201, TestHelper.fakeTeamWithId()); - const {data: team} = await TeamsActions.createTeam( + const {data: team} = await store.dispatch(TeamsActions.createTeam( TestHelper.fakeTeam(), - )(store.dispatch, store.getState) as ActionResult; + )); const command = TestHelper.testCommand(team.id); @@ -567,9 +552,9 @@ describe('Actions.Integrations', () => { post('/commands'). reply(201, {...command, token: TestHelper.generateId(), id: TestHelper.generateId()}); - const {data: created} = await Actions.addCommand( + const {data: created} = await store.dispatch(Actions.addCommand( command, - )(store.dispatch, store.getState) as ActionResult; + )); const expected = Object.assign({}, created); expected.trigger = 'modified'; @@ -581,10 +566,9 @@ describe('Actions.Integrations', () => { put(`/commands/${expected.id}`). reply(200, {...expected, update_at: 123}); - await Actions.editCommand( + await store.dispatch(Actions.editCommand( expected, - )(store.dispatch, store.getState); - + )); const {commands} = store.getState().entities.integrations; expect(commands[created.id]).toBeTruthy(); const actual = commands[created.id]; @@ -599,9 +583,9 @@ describe('Actions.Integrations', () => { post('/teams'). reply(201, TestHelper.fakeTeamWithId()); - const {data: team} = await TeamsActions.createTeam( + const {data: team} = await store.dispatch(TeamsActions.createTeam( TestHelper.fakeTeam(), - )(store.dispatch, store.getState) as ActionResult; + )); const command = TestHelper.testCommand(team.id); @@ -609,18 +593,17 @@ describe('Actions.Integrations', () => { post('/commands'). reply(201, {...command, token: TestHelper.generateId(), id: TestHelper.generateId()}); - const {data: created} = await Actions.addCommand( + const {data: created} = await store.dispatch(Actions.addCommand( command, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getBaseRoute()). delete(`/commands/${created.id}`). reply(200, OK_RESPONSE); - await Actions.deleteCommand( + await store.dispatch(Actions.deleteCommand( created.id, - )(store.dispatch, store.getState); - + )); const {commands} = store.getState().entities.integrations; expect(!commands[created.id]).toBeTruthy(); }); @@ -630,7 +613,7 @@ describe('Actions.Integrations', () => { post('/oauth/apps'). reply(201, TestHelper.fakeOAuthAppWithId()); - const {data: created} = await Actions.addOAuthApp(TestHelper.fakeOAuthApp())(store.dispatch, store.getState) as ActionResult; + const {data: created} = await store.dispatch(Actions.addOAuthApp(TestHelper.fakeOAuthApp())); const {oauthApps} = store.getState().entities.integrations; expect(oauthApps[created.id]).toBeTruthy(); @@ -641,14 +624,13 @@ describe('Actions.Integrations', () => { post('/oauth/apps'). reply(201, TestHelper.fakeOAuthAppWithId()); - const {data: created} = await Actions.addOAuthApp(TestHelper.fakeOAuthApp())(store.dispatch, store.getState) as ActionResult; + const {data: created} = await store.dispatch(Actions.addOAuthApp(TestHelper.fakeOAuthApp())); nock(Client4.getBaseRoute()). get(`/oauth/apps/${created.id}`). reply(200, created); - await Actions.getOAuthApp(created.id)(store.dispatch, store.getState); - + await store.dispatch(Actions.getOAuthApp(created.id)); const {oauthApps} = store.getState().entities.integrations; expect(oauthApps[created.id]).toBeTruthy(); }); @@ -658,7 +640,7 @@ describe('Actions.Integrations', () => { post('/oauth/apps'). reply(201, TestHelper.fakeOAuthAppWithId()); - const {data: created} = await Actions.addOAuthApp(TestHelper.fakeOAuthApp())(store.dispatch, store.getState) as ActionResult; + const {data: created} = await store.dispatch(Actions.addOAuthApp(TestHelper.fakeOAuthApp())); const expected = Object.assign({}, created); expected.name = 'modified'; @@ -673,8 +655,7 @@ describe('Actions.Integrations', () => { nock(Client4.getBaseRoute()). put(`/oauth/apps/${created.id}`).reply(200, nockReply); - await Actions.editOAuthApp(expected)(store.dispatch, store.getState); - + await store.dispatch(Actions.editOAuthApp(expected)); const {oauthApps} = store.getState().entities.integrations; expect(oauthApps[created.id]).toBeTruthy(); @@ -692,15 +673,14 @@ describe('Actions.Integrations', () => { post('/oauth/apps'). reply(201, TestHelper.fakeOAuthAppWithId()); - const {data: created} = await Actions.addOAuthApp(TestHelper.fakeOAuthApp())(store.dispatch, store.getState) as ActionResult; + const {data: created} = await store.dispatch(Actions.addOAuthApp(TestHelper.fakeOAuthApp())); const user = TestHelper.basicUser; nock(Client4.getBaseRoute()). get(`/users/${user!.id}/oauth/apps/authorized`). reply(200, [created]); - await Actions.getAuthorizedOAuthApps()(store.dispatch, store.getState); - + await store.dispatch(Actions.getAuthorizedOAuthApps()); const {oauthApps} = store.getState().entities.integrations; expect(oauthApps).toBeTruthy(); }); @@ -710,14 +690,13 @@ describe('Actions.Integrations', () => { post('/oauth/apps'). reply(201, TestHelper.fakeOAuthAppWithId()); - const {data: created} = await Actions.addOAuthApp(TestHelper.fakeOAuthApp())(store.dispatch, store.getState) as ActionResult; + const {data: created} = await store.dispatch(Actions.addOAuthApp(TestHelper.fakeOAuthApp())); nock(Client4.getBaseRoute()). delete(`/oauth/apps/${created.id}`). reply(200, OK_RESPONSE); - await Actions.deleteOAuthApp(created.id)(store.dispatch, store.getState); - + await store.dispatch(Actions.deleteOAuthApp(created.id)); const {oauthApps} = store.getState().entities.integrations; expect(!oauthApps[created.id]).toBeTruthy(); }); @@ -727,14 +706,13 @@ describe('Actions.Integrations', () => { post('/oauth/apps'). reply(201, TestHelper.fakeOAuthAppWithId()); - const {data: created} = await Actions.addOAuthApp(TestHelper.fakeOAuthApp())(store.dispatch, store.getState) as ActionResult; + const {data: created} = await store.dispatch(Actions.addOAuthApp(TestHelper.fakeOAuthApp())); nock(Client4.getBaseRoute()). post(`/oauth/apps/${created.id}/regen_secret`). reply(200, {...created, client_secret: TestHelper.generateId()}); - await Actions.regenOAuthAppSecret(created.id)(store.dispatch, store.getState); - + await store.dispatch(Actions.regenOAuthAppSecret(created.id)); const {oauthApps} = store.getState().entities.integrations; expect(oauthApps[created.id].client_secret !== created.client_secret).toBeTruthy(); }); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/integrations.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/integrations.ts index af4853bfaf..5173fb7e69 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/integrations.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/integrations.ts @@ -10,34 +10,34 @@ import {Client4} from 'mattermost-redux/client'; import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {DispatchFunc, GetStateFunc, ActionFunc} from 'mattermost-redux/types/actions'; +import type {DispatchFunc, GetStateFunc, ActionFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {logError} from './errors'; import {bindClientFunc, forceLogoutIfNecessary} from './helpers'; import {General} from '../constants'; -export function createIncomingHook(hook: IncomingWebhook): ActionFunc { +export function createIncomingHook(hook: IncomingWebhook): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.createIncomingWebhook, onSuccess: [IntegrationTypes.RECEIVED_INCOMING_HOOK], params: [ hook, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getIncomingHook(hookId: string): ActionFunc { +export function getIncomingHook(hookId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getIncomingWebhook, onSuccess: [IntegrationTypes.RECEIVED_INCOMING_HOOK], params: [ hookId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getIncomingHooks(teamId = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): ActionFunc { +export function getIncomingHooks(teamId = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getIncomingWebhooks, onSuccess: [IntegrationTypes.RECEIVED_INCOMING_HOOKS], @@ -46,11 +46,11 @@ export function getIncomingHooks(teamId = '', page = 0, perPage: number = Genera page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function removeIncomingHook(hookId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function removeIncomingHook(hookId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.removeIncomingWebhook(hookId); } catch (error) { @@ -71,37 +71,37 @@ export function removeIncomingHook(hookId: string): ActionFunc { }; } -export function updateIncomingHook(hook: IncomingWebhook): ActionFunc { +export function updateIncomingHook(hook: IncomingWebhook): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.updateIncomingWebhook, onSuccess: [IntegrationTypes.RECEIVED_INCOMING_HOOK], params: [ hook, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function createOutgoingHook(hook: OutgoingWebhook): ActionFunc { +export function createOutgoingHook(hook: OutgoingWebhook): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.createOutgoingWebhook, onSuccess: [IntegrationTypes.RECEIVED_OUTGOING_HOOK], params: [ hook, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getOutgoingHook(hookId: string): ActionFunc { +export function getOutgoingHook(hookId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getOutgoingWebhook, onSuccess: [IntegrationTypes.RECEIVED_OUTGOING_HOOK], params: [ hookId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getOutgoingHooks(channelId = '', teamId = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): ActionFunc { +export function getOutgoingHooks(channelId = '', teamId = '', page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getOutgoingWebhooks, onSuccess: [IntegrationTypes.RECEIVED_OUTGOING_HOOKS], @@ -111,11 +111,11 @@ export function getOutgoingHooks(channelId = '', teamId = '', page = 0, perPage: page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function removeOutgoingHook(hookId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function removeOutgoingHook(hookId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.removeOutgoingWebhook(hookId); } catch (error) { @@ -136,24 +136,24 @@ export function removeOutgoingHook(hookId: string): ActionFunc { }; } -export function updateOutgoingHook(hook: OutgoingWebhook): ActionFunc { +export function updateOutgoingHook(hook: OutgoingWebhook): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.updateOutgoingWebhook, onSuccess: [IntegrationTypes.RECEIVED_OUTGOING_HOOK], params: [ hook, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function regenOutgoingHookToken(hookId: string): ActionFunc { +export function regenOutgoingHookToken(hookId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.regenOutgoingHookToken, onSuccess: [IntegrationTypes.RECEIVED_OUTGOING_HOOK], params: [ hookId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getCommands(teamId: string): ActionFunc { @@ -178,34 +178,34 @@ export function getAutocompleteCommands(teamId: string, page = 0, perPage: numbe }); } -export function getCustomTeamCommands(teamId: string): ActionFunc { +export function getCustomTeamCommands(teamId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getCustomTeamCommands, onSuccess: [IntegrationTypes.RECEIVED_CUSTOM_TEAM_COMMANDS], params: [ teamId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function addCommand(command: Command): ActionFunc { +export function addCommand(command: Command): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.addCommand, onSuccess: [IntegrationTypes.RECEIVED_COMMAND], params: [ command, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function editCommand(command: Command): ActionFunc { +export function editCommand(command: Command): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.editCommand, onSuccess: [IntegrationTypes.RECEIVED_COMMAND], params: [ command, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function executeCommand(command: string, args: CommandArgs): ActionFunc { @@ -218,8 +218,8 @@ export function executeCommand(command: string, args: CommandArgs): ActionFunc { }); } -export function regenCommandToken(id: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function regenCommandToken(id: string): NewActionFuncAsync { + return async (dispatch, getState) => { let res; try { res = await Client4.regenCommandToken(id); @@ -244,8 +244,8 @@ export function regenCommandToken(id: string): ActionFunc { }; } -export function deleteCommand(id: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function deleteCommand(id: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.deleteCommand(id); } catch (error) { @@ -266,27 +266,27 @@ export function deleteCommand(id: string): ActionFunc { }; } -export function addOAuthApp(app: OAuthApp): ActionFunc { +export function addOAuthApp(app: OAuthApp): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.createOAuthApp, onSuccess: [IntegrationTypes.RECEIVED_OAUTH_APP], params: [ app, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function editOAuthApp(app: OAuthApp): ActionFunc { +export function editOAuthApp(app: OAuthApp): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.editOAuthApp, onSuccess: IntegrationTypes.RECEIVED_OAUTH_APP, params: [ app, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getOAuthApps(page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): ActionFunc { +export function getOAuthApps(page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getOAuthApps, onSuccess: [IntegrationTypes.RECEIVED_OAUTH_APPS], @@ -294,7 +294,7 @@ export function getOAuthApps(page = 0, perPage: number = General.PAGE_SIZE_DEFAU page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getAppsOAuthAppIDs(): ActionFunc { @@ -304,25 +304,25 @@ export function getAppsOAuthAppIDs(): ActionFunc { }); } -export function getAppsBotIDs(): ActionFunc { +export function getAppsBotIDs(): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getAppsBotIDs, onSuccess: [IntegrationTypes.RECEIVED_APPS_BOT_IDS], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getOAuthApp(appId: string): ActionFunc { +export function getOAuthApp(appId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getOAuthApp, onSuccess: [IntegrationTypes.RECEIVED_OAUTH_APP], params: [ appId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getAuthorizedOAuthApps(): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getAuthorizedOAuthApps(): NewActionFuncAsync { + return async (dispatch, getState) => { const state = getState(); const currentUserId = getCurrentUserId(state); @@ -341,15 +341,15 @@ export function getAuthorizedOAuthApps(): ActionFunc { }; } -export function deauthorizeOAuthApp(clientId: string): ActionFunc { +export function deauthorizeOAuthApp(clientId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.deauthorizeOAuthApp, params: [clientId], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function deleteOAuthApp(id: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function deleteOAuthApp(id: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.deleteOAuthApp(id); } catch (error) { @@ -370,14 +370,14 @@ export function deleteOAuthApp(id: string): ActionFunc { }; } -export function regenOAuthAppSecret(appId: string): ActionFunc { +export function regenOAuthAppSecret(appId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.regenOAuthAppSecret, onSuccess: [IntegrationTypes.RECEIVED_OAUTH_APP], params: [ appId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function submitInteractiveDialog(submission: DialogSubmission): ActionFunc { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/jobs.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/jobs.test.ts index e4b8e34302..cb7138511c 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/jobs.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/jobs.test.ts @@ -42,7 +42,7 @@ describe('Actions.Jobs', () => { data: {}, }); - await Actions.createJob(job)(store.dispatch, store.getState); + await store.dispatch(Actions.createJob(job)); const state = store.getState(); const jobs = state.entities.jobs.jobs; @@ -60,7 +60,7 @@ describe('Actions.Jobs', () => { data: {}, }); - await Actions.getJob('six4h67ja7ntdkek6g13dp3wka')(store.dispatch, store.getState); + await store.dispatch(Actions.getJob('six4h67ja7ntdkek6g13dp3wka')); const state = store.getState(); const jobs = state.entities.jobs.jobs; @@ -72,7 +72,7 @@ describe('Actions.Jobs', () => { post('/jobs/six4h67ja7ntdkek6g13dp3wka/cancel'). reply(200, OK_RESPONSE); - await Actions.cancelJob('six4h67ja7ntdkek6g13dp3wka')(store.dispatch, store.getState); + await store.dispatch(Actions.cancelJob('six4h67ja7ntdkek6g13dp3wka')); const state = store.getState(); const jobs = state.entities.jobs.jobs; @@ -91,7 +91,7 @@ describe('Actions.Jobs', () => { data: {}, }]); - await Actions.getJobs()(store.dispatch, store.getState); + await store.dispatch(Actions.getJobs()); const state = store.getState(); const jobs = state.entities.jobs.jobs; @@ -110,7 +110,7 @@ describe('Actions.Jobs', () => { data: {}, }]); - await Actions.getJobsByType('data_retention')(store.dispatch, store.getState); + await store.dispatch(Actions.getJobsByType('data_retention')); const state = store.getState(); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/jobs.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/jobs.ts index 7cff1112f5..62c7434b10 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/jobs.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/jobs.ts @@ -1,37 +1,37 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import type {JobType, Job} from '@mattermost/types/jobs'; +import type {JobType, Job, JobTypeBase} from '@mattermost/types/jobs'; import {JobTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; -import type {ActionFunc} from 'mattermost-redux/types/actions'; +import type {NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {bindClientFunc} from './helpers'; import {General} from '../constants'; -export function createJob(job: Job): ActionFunc { +export function createJob(job: JobTypeBase): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.createJob, onSuccess: JobTypes.RECEIVED_JOB, params: [ job, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getJob(id: string): ActionFunc { +export function getJob(id: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getJob, onSuccess: JobTypes.RECEIVED_JOB, params: [ id, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getJobs(page = 0, perPage: number = General.JOBS_CHUNK_SIZE): ActionFunc { +export function getJobs(page = 0, perPage: number = General.JOBS_CHUNK_SIZE): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getJobs, onSuccess: JobTypes.RECEIVED_JOBS, @@ -39,10 +39,10 @@ export function getJobs(page = 0, perPage: number = General.JOBS_CHUNK_SIZE): Ac page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getJobsByType(type: JobType, page = 0, perPage: number = General.JOBS_CHUNK_SIZE): ActionFunc { +export function getJobsByType(type: JobType, page = 0, perPage: number = General.JOBS_CHUNK_SIZE): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getJobsByType, onSuccess: [JobTypes.RECEIVED_JOBS, JobTypes.RECEIVED_JOBS_BY_TYPE], @@ -51,14 +51,14 @@ export function getJobsByType(type: JobType, page = 0, perPage: number = General page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function cancelJob(job: string): ActionFunc { +export function cancelJob(job: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.cancelJob, params: [ job, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/posts.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/posts.test.ts index 8068b27b49..2daa4709f2 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/posts.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/posts.test.ts @@ -14,7 +14,7 @@ import {createCustomEmoji} from 'mattermost-redux/actions/emojis'; import * as Actions from 'mattermost-redux/actions/posts'; import {loadMe} from 'mattermost-redux/actions/users'; import {Client4} from 'mattermost-redux/client'; -import type {ActionResult, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {GetStateFunc} from 'mattermost-redux/types/actions'; import {getPreferenceKey} from 'mattermost-redux/utils/preference_utils'; import TestHelper from '../../test/test_helper'; @@ -53,7 +53,7 @@ describe('Actions.Posts', () => { post('/posts'). reply(201, {...post, id: TestHelper.generateId()}); - await Actions.createPost(post)(store.dispatch, store.getState); + await store.dispatch(Actions.createPost(post)); const state: GlobalState = store.getState(); const createRequest = state.requests.posts.createPost; @@ -90,7 +90,7 @@ describe('Actions.Posts', () => { post('/posts'). reply(201, {...post, id: postId}); - await Actions.createPostImmediately(post)(store.dispatch, store.getState); + await store.dispatch(Actions.createPostImmediately(post)); const post2 = TestHelper.fakePostWithId(channelId); post2.root_id = postId; @@ -99,7 +99,7 @@ describe('Actions.Posts', () => { post('/posts'). reply(201, post2); - await Actions.createPostImmediately(post2)(store.dispatch, store.getState); + await store.dispatch(Actions.createPostImmediately(post2)); expect(store.getState().entities.posts.postsReplies[postId]).toBe(1); @@ -107,8 +107,8 @@ describe('Actions.Posts', () => { delete(`/posts/${post2.id}`). reply(200, OK_RESPONSE); - await Actions.deletePost(post2)(store.dispatch, store.getState); - await Actions.removePost(post2)(store.dispatch, store.getState); + await store.dispatch(Actions.deletePost(post2)); + await store.dispatch(Actions.removePost(post2)); expect(store.getState().entities.posts.postsReplies[postId]).toBe(0); }); @@ -127,7 +127,7 @@ describe('Actions.Posts', () => { post('/posts'). reply(400, createPostError); - await Actions.createPost(post)(store.dispatch, store.getState); + await store.dispatch(Actions.createPost(post)); await TestHelper.wait(50); let state = store.getState(); @@ -162,10 +162,10 @@ describe('Actions.Posts', () => { post('/posts'). reply(201, {...post, id: TestHelper.generateId(), file_ids: [files[0].id, files[1].id, files[2].id]}); - await Actions.createPost( + await store.dispatch(Actions.createPost( post, files, - )(store.dispatch, store.getState); + )); const state: GlobalState = store.getState(); const createRequest = state.requests.posts.createPost; @@ -221,9 +221,9 @@ describe('Actions.Posts', () => { put(`/posts/${post.id}/patch`). reply(200, post); - await Actions.editPost( + await store.dispatch(Actions.editPost( post, - )(store.dispatch, store.getState); + )); const state: GlobalState = store.getState(); const editRequest = state.requests.posts.editPost; @@ -248,7 +248,7 @@ describe('Actions.Posts', () => { nock(Client4.getBaseRoute()). post('/posts'). reply(201, TestHelper.fakePostWithId(channelId)); - await Actions.createPost(TestHelper.fakePost(channelId))(store.dispatch, store.getState); + await store.dispatch(Actions.createPost(TestHelper.fakePost(channelId))); const initialPosts = store.getState().entities.posts; const postId = Object.keys(initialPosts.posts)[0]; @@ -256,7 +256,7 @@ describe('Actions.Posts', () => { delete(`/posts/${postId}`). reply(200, OK_RESPONSE); - await Actions.deletePost(initialPosts.posts[postId])(store.dispatch, store.getState); + await store.dispatch(Actions.deletePost(initialPosts.posts[postId])); const state: GlobalState = store.getState(); const {posts} = state.entities.posts; @@ -289,7 +289,7 @@ describe('Actions.Posts', () => { nock(Client4.getBaseRoute()). post('/reactions'). reply(201, {user_id: TestHelper.basicUser!.id, post_id: post1.id, emoji_name: emojiName, create_at: 1508168444721}); - await Actions.addReaction(post1.id, emojiName)(store.dispatch, store.getState); + await store.dispatch(Actions.addReaction(post1.id, emojiName)); let reactions = store.getState().entities.posts.reactions; expect(reactions).toBeTruthy(); @@ -300,7 +300,7 @@ describe('Actions.Posts', () => { delete(`/posts/${post1.id}`). reply(200, OK_RESPONSE); - await Actions.deletePost(post1)(store.dispatch, store.getState); + await store.dispatch(Actions.deletePost(post1)); reactions = store.getState().entities.posts.reactions; expect(reactions).toBeTruthy(); @@ -382,7 +382,7 @@ describe('Actions.Posts', () => { nock(Client4.getBaseRoute()). post('/reactions'). reply(201, {user_id: TestHelper.basicUser!.id, post_id: post1.id, emoji_name: emojiName, create_at: 1508168444721}); - await Actions.addReaction(post1.id, emojiName)(store.dispatch, store.getState); + await store.dispatch(Actions.addReaction(post1.id, emojiName)); let reactions = store.getState().entities.posts.reactions; expect(reactions).toBeTruthy(); @@ -415,7 +415,7 @@ describe('Actions.Posts', () => { query(true). reply(200, response); - await Actions.getPostsUnread(channelId)(dispatch, getState); + await dispatch(Actions.getPostsUnread(channelId)); const {posts} = getState().entities.posts; expect(posts[post.id]).toBeTruthy(); @@ -476,7 +476,7 @@ describe('Actions.Posts', () => { query(true). reply(200, responseWithRecentPosts); - await Actions.getPostsUnread(channelId)(dispatch, getState); + await dispatch(Actions.getPostsUnread(channelId)); const {posts} = getState().entities.posts; expect(posts[recentPost.id]).toBeTruthy(); @@ -500,7 +500,7 @@ describe('Actions.Posts', () => { nock(Client4.getBaseRoute()). get(`/posts/${post.id}/thread?skipFetchThreads=false&collapsedThreads=true&collapsedThreadsExtended=false&direction=down&perPage=60`). reply(200, postList); - await Actions.getPostThread(post.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getPostThread(post.id)); const state: GlobalState = store.getState(); const getRequest = state.requests.posts.getPostThread; @@ -538,7 +538,7 @@ describe('Actions.Posts', () => { get(`/posts/${postId}/edit_history`). reply(200, data); - await Actions.getPostEditHistory(postId)(store.dispatch, store.getState); + await store.dispatch(Actions.getPostEditHistory(postId)); const state: GlobalState = store.getState(); const editHistory = state.entities.posts.postEditHistory; @@ -1029,7 +1029,7 @@ describe('Actions.Posts', () => { put(`/${TestHelper.basicUser!.id}/preferences`). reply(200, OK_RESPONSE); - Actions.flagPost(post1.id)(dispatch, getState); + dispatch(Actions.flagPost(post1.id)); const state = getState(); const prefKey = getPreferenceKey(Preferences.CATEGORY_FLAGGED_POST, post1.id); const preference = state.entities.preferences.myPreferences[prefKey]; @@ -1060,7 +1060,7 @@ describe('Actions.Posts', () => { nock(Client4.getUsersRoute()). put(`/${TestHelper.basicUser!.id}/preferences`). reply(200, OK_RESPONSE); - Actions.flagPost(post1.id)(dispatch, getState); + dispatch(Actions.flagPost(post1.id)); let state = getState(); const prefKey = getPreferenceKey(Preferences.CATEGORY_FLAGGED_POST, post1.id); const preference = state.entities.preferences.myPreferences[prefKey]; @@ -1069,7 +1069,7 @@ describe('Actions.Posts', () => { nock(Client4.getUsersRoute()). delete(`/${TestHelper.basicUser!.id}/preferences`). reply(200, OK_RESPONSE); - Actions.unflagPost(post1.id)(dispatch, getState); + dispatch(Actions.unflagPost(post1.id)); state = getState(); const unflagged = state.entities.preferences.myPreferences[prefKey]; if (unflagged) { @@ -1153,12 +1153,12 @@ describe('Actions.Posts', () => { nock(Client4.getBaseRoute()). get(`/posts/${post1.id}/thread?skipFetchThreads=false&collapsedThreads=true&collapsedThreadsExtended=false&direction=down&perPage=60`). reply(200, postList); - await Actions.getPostThread(post1.id)(dispatch, getState); + await dispatch(Actions.getPostThread(post1.id)); nock(Client4.getBaseRoute()). post(`/posts/${post1.id}/pin`). reply(200, OK_RESPONSE); - await Actions.pinPost(post1.id)(dispatch, getState); + await dispatch(Actions.pinPost(post1.id)); const state = getState(); const {stats} = state.entities.channels; @@ -1192,17 +1192,17 @@ describe('Actions.Posts', () => { nock(Client4.getBaseRoute()). get(`/posts/${post1.id}/thread?skipFetchThreads=false&collapsedThreads=true&collapsedThreadsExtended=false&direction=down&perPage=60`). reply(200, postList); - await Actions.getPostThread(post1.id)(dispatch, getState); + await dispatch(Actions.getPostThread(post1.id)); nock(Client4.getBaseRoute()). post(`/posts/${post1.id}/pin`). reply(200, OK_RESPONSE); - await Actions.pinPost(post1.id)(dispatch, getState); + await dispatch(Actions.pinPost(post1.id)); nock(Client4.getBaseRoute()). post(`/posts/${post1.id}/unpin`). reply(200, OK_RESPONSE); - await Actions.unpinPost(post1.id)(dispatch, getState); + await dispatch(Actions.unpinPost(post1.id)); const state = getState(); const {stats} = state.entities.channels; @@ -1235,7 +1235,7 @@ describe('Actions.Posts', () => { nock(Client4.getBaseRoute()). post('/reactions'). reply(201, {user_id: TestHelper.basicUser!.id, post_id: post1.id, emoji_name: emojiName, create_at: 1508168444721}); - await Actions.addReaction(post1.id, emojiName)(dispatch, getState); + await dispatch(Actions.addReaction(post1.id, emojiName)); const state = getState(); const reactions = state.entities.posts.reactions[post1.id]; @@ -1264,12 +1264,12 @@ describe('Actions.Posts', () => { nock(Client4.getBaseRoute()). post('/reactions'). reply(201, {user_id: TestHelper.basicUser!.id, post_id: post1.id, emoji_name: emojiName, create_at: 1508168444721}); - await Actions.addReaction(post1.id, emojiName)(dispatch, getState); + await dispatch(Actions.addReaction(post1.id, emojiName)); nock(Client4.getUsersRoute()). delete(`/${TestHelper.basicUser!.id}/posts/${post1.id}/reactions/${emojiName}`). reply(200, OK_RESPONSE); - await Actions.removeReaction(post1.id, emojiName)(dispatch, getState); + await dispatch(Actions.removeReaction(post1.id, emojiName)); const state = getState(); const reactions = state.entities.posts.reactions[post1.id]; @@ -1298,7 +1298,7 @@ describe('Actions.Posts', () => { nock(Client4.getBaseRoute()). post('/reactions'). reply(201, {user_id: TestHelper.basicUser!.id, post_id: post1.id, emoji_name: emojiName, create_at: 1508168444721}); - await Actions.addReaction(post1.id, emojiName)(dispatch, getState); + await dispatch(Actions.addReaction(post1.id, emojiName)); dispatch({ type: PostTypes.REACTION_DELETED, @@ -1308,7 +1308,7 @@ describe('Actions.Posts', () => { nock(Client4.getBaseRoute()). get(`/posts/${post1.id}/reactions`). reply(200, [{user_id: TestHelper.basicUser!.id, post_id: post1.id, emoji_name: emojiName, create_at: 1508168444721}]); - await Actions.getReactionsForPost(post1.id)(dispatch, getState); + await dispatch(Actions.getReactionsForPost(post1.id)); const state = getState(); const reactions = state.entities.posts.reactions[post1.id]; @@ -1325,13 +1325,13 @@ describe('Actions.Posts', () => { post('/emoji'). reply(201, {id: TestHelper.generateId(), create_at: 1507918415696, update_at: 1507918415696, delete_at: 0, creator_id: TestHelper.basicUser!.id, name: TestHelper.generateId()}); - const {data: created} = await createCustomEmoji( + const {data: created} = await dispatch(createCustomEmoji( { name: TestHelper.generateId(), creator_id: TestHelper.basicUser!.id, }, testImageData, - )(store.dispatch, store.getState) as ActionResult; + )); nock(Client4.getEmojisRoute()). get(`/name/${created.name}`). @@ -1343,7 +1343,7 @@ describe('Actions.Posts', () => { get(`/name/${missingEmojiName}`). reply(404, {message: 'Not found', status_code: 404}); - await Actions.getCustomEmojiForReaction(missingEmojiName)(dispatch, getState); + await dispatch(Actions.getCustomEmojiForReaction(missingEmojiName)); const state = getState(); const emojis = state.entities.emojis.customEmoji; @@ -1357,7 +1357,7 @@ describe('Actions.Posts', () => { post('/posts/posth67ja7ntdkek6g13dp3wka/actions/action7ja7ntdkek6g13dp3wka'). reply(200, {}); - const {data} = await Actions.doPostAction('posth67ja7ntdkek6g13dp3wka', 'action7ja7ntdkek6g13dp3wka', 'option')(store.dispatch, store.getState); + const {data} = await store.dispatch(Actions.doPostAction('posth67ja7ntdkek6g13dp3wka', 'action7ja7ntdkek6g13dp3wka', 'option')); expect(data).toEqual({}); }); @@ -1366,26 +1366,26 @@ describe('Actions.Posts', () => { post('/posts/posth67ja7ntdkek6g13dp3wka/actions/action7ja7ntdkek6g13dp3wka'). reply(200, {}); - const {data} = await Actions.doPostActionWithCookie('posth67ja7ntdkek6g13dp3wka', 'action7ja7ntdkek6g13dp3wka', '', 'option')(store.dispatch, store.getState); + const {data} = await store.dispatch(Actions.doPostActionWithCookie('posth67ja7ntdkek6g13dp3wka', 'action7ja7ntdkek6g13dp3wka', '', 'option')); expect(data).toEqual({}); }); it('addMessageIntoHistory', async () => { const {dispatch, getState} = store; - await Actions.addMessageIntoHistory('test1')(dispatch); + await dispatch(Actions.addMessageIntoHistory('test1')); let history = getState().entities.posts.messagesHistory.messages; expect(history.length === 1).toBeTruthy(); expect(history[0] === 'test1').toBeTruthy(); - await Actions.addMessageIntoHistory('test2')(dispatch); + await dispatch(Actions.addMessageIntoHistory('test2')); history = getState().entities.posts.messagesHistory.messages; expect(history.length === 2).toBeTruthy(); expect(history[1] === 'test2').toBeTruthy(); - await Actions.addMessageIntoHistory('test3')(dispatch); + await dispatch(Actions.addMessageIntoHistory('test3')); history = getState().entities.posts.messagesHistory.messages; expect(history.length === 3).toBeTruthy(); @@ -1395,32 +1395,32 @@ describe('Actions.Posts', () => { it('resetHistoryIndex', async () => { const {dispatch, getState} = store; - await Actions.addMessageIntoHistory('test1')(dispatch); - await Actions.addMessageIntoHistory('test2')(dispatch); - await Actions.addMessageIntoHistory('test3')(dispatch); + await dispatch(Actions.addMessageIntoHistory('test1')); + await dispatch(Actions.addMessageIntoHistory('test2')); + await dispatch(Actions.addMessageIntoHistory('test3')); let index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 3).toBeTruthy(); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.COMMENT]; expect(index === 3).toBeTruthy(); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)(dispatch); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)(dispatch); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.COMMENT)(dispatch); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.COMMENT)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 1).toBeTruthy(); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.COMMENT]; expect(index === 2).toBeTruthy(); - await Actions.resetHistoryIndex(Posts.MESSAGE_TYPES.POST)(dispatch); + await dispatch(Actions.resetHistoryIndex(Posts.MESSAGE_TYPES.POST)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 3).toBeTruthy(); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.COMMENT]; expect(index === 2).toBeTruthy(); - await Actions.resetHistoryIndex(Posts.MESSAGE_TYPES.COMMENT)(dispatch); + await dispatch(Actions.resetHistoryIndex(Posts.MESSAGE_TYPES.COMMENT)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 3).toBeTruthy(); @@ -1431,42 +1431,42 @@ describe('Actions.Posts', () => { it('moveHistoryIndexBack', async () => { const {dispatch, getState} = store; - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)(dispatch); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)); let index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === -1).toBeTruthy(); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)(dispatch); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === -1).toBeTruthy(); - await Actions.addMessageIntoHistory('test1')(dispatch); - await Actions.addMessageIntoHistory('test2')(dispatch); - await Actions.addMessageIntoHistory('test3')(dispatch); + await dispatch(Actions.addMessageIntoHistory('test1')); + await dispatch(Actions.addMessageIntoHistory('test2')); + await dispatch(Actions.addMessageIntoHistory('test3')); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 3).toBeTruthy(); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.COMMENT]; expect(index === 3).toBeTruthy(); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)(dispatch); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)(dispatch); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 1).toBeTruthy(); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.COMMENT]; expect(index === 3).toBeTruthy(); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)(dispatch); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)(dispatch); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 0).toBeTruthy(); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.COMMENT]; expect(index === 3).toBeTruthy(); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.COMMENT)(dispatch); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.COMMENT)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 0).toBeTruthy(); @@ -1477,51 +1477,51 @@ describe('Actions.Posts', () => { it('moveHistoryIndexForward', async () => { const {dispatch, getState} = store; - await Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.POST)(dispatch); + await dispatch(Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.POST)); let index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 0).toBeTruthy(); - await Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.POST)(dispatch); + await dispatch(Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.POST)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 0).toBeTruthy(); - await Actions.addMessageIntoHistory('test1')(dispatch); - await Actions.addMessageIntoHistory('test2')(dispatch); - await Actions.addMessageIntoHistory('test3')(dispatch); + await dispatch(Actions.addMessageIntoHistory('test1')); + await dispatch(Actions.addMessageIntoHistory('test2')); + await dispatch(Actions.addMessageIntoHistory('test3')); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 3).toBeTruthy(); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.COMMENT]; expect(index === 3).toBeTruthy(); - await Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.POST)(dispatch); - await Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.POST)(dispatch); + await dispatch(Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.POST)); + await dispatch(Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.POST)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 3).toBeTruthy(); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.COMMENT]; expect(index === 3).toBeTruthy(); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)(dispatch); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)(dispatch); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.COMMENT)(dispatch); - await Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.COMMENT)(dispatch); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.POST)); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.COMMENT)); + await dispatch(Actions.moveHistoryIndexBack(Posts.MESSAGE_TYPES.COMMENT)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 1).toBeTruthy(); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.COMMENT]; expect(index === 1).toBeTruthy(); - await Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.POST)(dispatch); + await dispatch(Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.POST)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 2).toBeTruthy(); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.COMMENT]; expect(index === 1).toBeTruthy(); - await Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.COMMENT)(dispatch); + await dispatch(Actions.moveHistoryIndexForward(Posts.MESSAGE_TYPES.COMMENT)); index = getState().entities.posts.messagesHistory.index[Posts.MESSAGE_TYPES.POST]; expect(index === 2).toBeTruthy(); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/posts.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/posts.ts index 6dd089f1d1..e979e79aa5 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/posts.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/posts.ts @@ -31,7 +31,7 @@ import {getAllGroupsByName} from 'mattermost-redux/selectors/entities/groups'; import * as PostSelectors from 'mattermost-redux/selectors/entities/posts'; import {getUnreadScrollPositionPreference, isCollapsedThreadsEnabled} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentUserId, getUsersByUsername} from 'mattermost-redux/selectors/entities/users'; -import type {ActionResult, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult, DispatchFunc, GetStateFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {isCombinedUserActivityPost} from 'mattermost-redux/utils/post_list'; import {logError} from './errors'; @@ -391,8 +391,8 @@ export function resetCreatePostRequest() { return {type: PostTypes.CREATE_POST_RESET_REQUEST}; } -export function deletePost(post: ExtendedPost) { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function deletePost(post: ExtendedPost): NewActionFuncAsync { + return async (dispatch, getState) => { const state = getState(); const delPost = {...post}; if (!post.root_id && isCollapsedThreadsEnabled(state)) { @@ -614,8 +614,8 @@ export function addReaction(postId: string, emojiName: string) { }; } -export function removeReaction(postId: string, emojiName: string) { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function removeReaction(postId: string, emojiName: string): NewActionFuncAsync { + return async (dispatch, getState) => { const currentUserId = getState().entities.users.currentUserId; try { @@ -720,7 +720,7 @@ export function flagPost(postId: string) { Client4.trackEvent('action', 'action_posts_flag'); - return savePreferences(currentUserId, [preference])(dispatch); + return dispatch(savePreferences(currentUserId, [preference])); }; } @@ -1103,11 +1103,11 @@ export async function getMentionsAndStatusesForPosts(postsArrayOrMap: Post[]|Pos const promises: any[] = []; if (userIdsToLoad.size > 0) { - promises.push(getProfilesByIds(Array.from(userIdsToLoad))(dispatch, getState)); + promises.push(dispatch(getProfilesByIds(Array.from(userIdsToLoad)))); } if (statusesToLoad.size > 0) { - promises.push(getStatusesByIds(Array.from(statusesToLoad))(dispatch, getState)); + promises.push(dispatch(getStatusesByIds(Array.from(statusesToLoad)))); } // Profiles of users mentioned in the posts @@ -1116,7 +1116,7 @@ export async function getMentionsAndStatusesForPosts(postsArrayOrMap: Post[]|Pos if (usernamesAndGroupsToLoad.size > 0) { // We need to load the profiles synchronously to filter them // out of the groups to check - const getProfilesPromise = getProfilesByUsernames(Array.from(usernamesAndGroupsToLoad))(dispatch, getState); + const getProfilesPromise = dispatch(getProfilesByUsernames(Array.from(usernamesAndGroupsToLoad))); promises.push(getProfilesPromise); const {data} = await getProfilesPromise as ActionResult; @@ -1131,7 +1131,7 @@ export async function getMentionsAndStatusesForPosts(postsArrayOrMap: Post[]|Pos per_page: 60, include_member_count: true, }; - promises.push(searchGroups(groupParams)(dispatch, getState)); + promises.push(dispatch(searchGroups(groupParams))); }); } @@ -1296,7 +1296,7 @@ export function unflagPost(postId: string) { Client4.trackEvent('action', 'action_posts_unflag'); - return deletePreferences(currentUserId, [preference])(dispatch, getState); + return dispatch(deletePreferences(currentUserId, [preference])); }; } diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.test.ts index 60b703e86e..afdad89fab 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.test.ts @@ -65,7 +65,7 @@ describe('Actions.Preferences', () => { nock(Client4.getUsersRoute()). get('/me/preferences'). reply(200, existingPreferences); - await Actions.getMyPreferences()(store.dispatch, store.getState); + await store.dispatch(Actions.getMyPreferences()); const state = store.getState(); const {myPreferences} = state.entities.preferences; @@ -98,7 +98,7 @@ describe('Actions.Preferences', () => { nock(Client4.getUsersRoute()). get('/me/preferences'). reply(200, existingPreferences); - await Actions.getMyPreferences()(store.dispatch, store.getState); + await store.dispatch(Actions.getMyPreferences()); const preferences = [ { @@ -118,7 +118,7 @@ describe('Actions.Preferences', () => { nock(Client4.getUsersRoute()). put(`/${TestHelper.basicUser!.id}/preferences`). reply(200, OK_RESPONSE); - await Actions.savePreferences(user.id, preferences)(store.dispatch); + await store.dispatch(Actions.savePreferences(user.id, preferences)); const state = store.getState(); const {myPreferences} = state.entities.preferences; @@ -167,15 +167,15 @@ describe('Actions.Preferences', () => { nock(Client4.getUsersRoute()). get('/me/preferences'). reply(200, existingPreferences); - await Actions.getMyPreferences()(store.dispatch, store.getState); + await store.dispatch(Actions.getMyPreferences()); nock(Client4.getUsersRoute()). post(`/${TestHelper.basicUser!.id}/preferences/delete`). reply(200, OK_RESPONSE); - await Actions.deletePreferences(user.id, [ + await store.dispatch(Actions.deletePreferences(user.id, [ existingPreferences[0], existingPreferences[2], - ])(store.dispatch, store.getState); + ])); const state = store.getState(); const {myPreferences} = state.entities.preferences; @@ -203,13 +203,13 @@ describe('Actions.Preferences', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await loadMe()(store.dispatch, store.getState); + await store.dispatch(loadMe()); // Test that a new preference is created if none exists nock(Client4.getUsersRoute()). put(`/${TestHelper.basicUser!.id}/preferences`). reply(200, OK_RESPONSE); - await Actions.makeDirectChannelVisibleIfNecessary(user2.id)(store.dispatch, store.getState); + await store.dispatch(Actions.makeDirectChannelVisibleIfNecessary(user2.id)); let state = store.getState(); let myPreferences = state.entities.preferences.myPreferences; @@ -225,7 +225,7 @@ describe('Actions.Preferences', () => { nock(Client4.getUsersRoute()). put(`/${TestHelper.basicUser!.id}/preferences`). reply(200, OK_RESPONSE); - await Actions.makeDirectChannelVisibleIfNecessary(user2.id)(store.dispatch, store.getState); + await store.dispatch(Actions.makeDirectChannelVisibleIfNecessary(user2.id)); const state2 = store.getState(); @@ -236,15 +236,15 @@ describe('Actions.Preferences', () => { nock(Client4.getUsersRoute()). put(`/${TestHelper.basicUser!.id}/preferences`). reply(200, OK_RESPONSE); - Actions.savePreferences(user.id, [{ + store.dispatch(Actions.savePreferences(user.id, [{ ...preference, value: 'false', - }])(store.dispatch); + }])); nock(Client4.getUsersRoute()). put(`/${TestHelper.basicUser!.id}/preferences`). reply(200, OK_RESPONSE); - await Actions.makeDirectChannelVisibleIfNecessary(user2.id)(store.dispatch, store.getState); + await store.dispatch(Actions.makeDirectChannelVisibleIfNecessary(user2.id)); state = store.getState(); myPreferences = state.entities.preferences.myPreferences; @@ -279,7 +279,7 @@ describe('Actions.Preferences', () => { nock(Client4.getUsersRoute()). get('/me/preferences'). reply(200, existingPreferences); - await Actions.getMyPreferences()(store.dispatch, store.getState); + await store.dispatch(Actions.getMyPreferences()); const newTheme = { type: 'Mattermost Dark', @@ -287,7 +287,7 @@ describe('Actions.Preferences', () => { nock(Client4.getUsersRoute()). put(`/${TestHelper.basicUser!.id}/preferences`). reply(200, OK_RESPONSE); - await Actions.saveTheme(team.id, newTheme)(store.dispatch, store.getState); + await store.dispatch(Actions.saveTheme(team.id, newTheme)); const state = store.getState(); const {myPreferences} = state.entities.preferences; @@ -303,7 +303,7 @@ describe('Actions.Preferences', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await loadMe()(store.dispatch, store.getState); + await store.dispatch(loadMe()); const theme = { type: 'Mattermost Dark', @@ -341,12 +341,12 @@ describe('Actions.Preferences', () => { nock(Client4.getUsersRoute()). get('/me/preferences'). reply(200, existingPreferences); - await Actions.getMyPreferences()(store.dispatch, store.getState); + await store.dispatch(Actions.getMyPreferences()); nock(Client4.getUsersRoute()). post(`/${user.id}/preferences/delete`). reply(200, OK_RESPONSE); - await Actions.deleteTeamSpecificThemes()(store.dispatch, store.getState); + await store.dispatch(Actions.deleteTeamSpecificThemes()); const state = store.getState(); const {myPreferences} = state.entities.preferences; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.ts index 1ab29c03d2..9a4affc345 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/preferences.ts @@ -65,8 +65,8 @@ export function makeDirectChannelVisibleIfNecessary(otherUserId: string): Action name: otherUserId, value: 'true', }; - getProfilesByIds([otherUserId])(dispatch, getState); - savePreferences(currentUserId, [preference])(dispatch); + dispatch(getProfilesByIds([otherUserId])); + dispatch(savePreferences(currentUserId, [preference])); } return {data: true}; @@ -91,13 +91,13 @@ export function makeGroupMessageVisibleIfNecessary(channelId: string): ActionFun }; if (channels[channelId]) { - getMyChannelMember(channelId)(dispatch, getState); + dispatch(getMyChannelMember(channelId)); } else { - getChannelAndMyMember(channelId)(dispatch, getState); + dispatch(getChannelAndMyMember(channelId)); } - getProfilesInChannel(channelId, 0)(dispatch, getState); - savePreferences(currentUserId, [preference])(dispatch); + dispatch(getProfilesInChannel(channelId, 0)); + dispatch(savePreferences(currentUserId, [preference])); } return {data: true}; @@ -165,7 +165,7 @@ export function saveTheme(teamId: string, theme: Theme): ActionFunc { value: JSON.stringify(theme), }; - await savePreferences(currentUserId, [preference])(dispatch); + await dispatch(savePreferences(currentUserId, [preference])); return {data: true}; }; } @@ -179,7 +179,7 @@ export function deleteTeamSpecificThemes(): ActionFunc { const toDelete = themePreferences.filter((pref) => pref.name !== ''); if (toDelete.length > 0) { - await deletePreferences(currentUserId, toDelete)(dispatch, getState); + await dispatch(deletePreferences(currentUserId, toDelete)); } return {data: true}; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/roles.test.js b/webapp/channels/src/packages/mattermost-redux/src/actions/roles.test.js index 57145d14f2..be6d3c8ac7 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/roles.test.js +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/roles.test.js @@ -1,6 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import cloneDeep from 'lodash/cloneDeep'; import nock from 'nock'; import * as Actions from 'mattermost-redux/actions/roles'; @@ -29,7 +30,7 @@ describe('Actions.Roles', () => { nock(Client4.getRolesRoute()). post('/names'). reply(200, [TestHelper.basicRoles.system_admin]); - await Actions.getRolesByNames(['system_admin'])(store.dispatch, store.getState); + await store.dispatch(Actions.getRolesByNames(['system_admin'])); const state = store.getState(); const request = state.requests.roles.getRolesByNames; @@ -47,7 +48,7 @@ describe('Actions.Roles', () => { nock(Client4.getRolesRoute()). get('/name/system_admin'). reply(200, TestHelper.basicRoles.system_admin); - await Actions.getRoleByName('system_admin')(store.dispatch, store.getState); + await store.dispatch(Actions.getRoleByName('system_admin')); const state = store.getState(); const request = state.requests.roles.getRolesByNames; @@ -66,7 +67,7 @@ describe('Actions.Roles', () => { get('/' + TestHelper.basicRoles.system_admin.id). reply(200, TestHelper.basicRoles.system_admin); - await Actions.getRole(TestHelper.basicRoles.system_admin.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getRole(TestHelper.basicRoles.system_admin.id)); const state = store.getState(); const request = state.requests.roles.getRole; @@ -87,7 +88,7 @@ describe('Actions.Roles', () => { const mock2 = nock(Client4.getRolesRoute()). post('/names', JSON.stringify(['test2'])). reply(200, []); - const fakeState = { + let fakeState = { entities: { general: { serverVersion: '4.3', @@ -99,19 +100,24 @@ describe('Actions.Roles', () => { }, }, }; - await Actions.loadRolesIfNeeded(['test'])(store.dispatch, () => fakeState); + store = configureStore(fakeState); + await store.dispatch(Actions.loadRolesIfNeeded(['test'])); expect(mock1.isDone()).toBe(false); expect(mock2.isDone()).toBe(false); + fakeState = cloneDeep(fakeState); fakeState.entities.roles.pending = new Set(); fakeState.entities.general.serverVersion = null; - await Actions.loadRolesIfNeeded(['test', 'test2'])(store.dispatch, () => fakeState); + store = configureStore(fakeState); + await store.dispatch(Actions.loadRolesIfNeeded(['test', 'test2'])); expect(mock1.isDone()).toBe(false); expect(mock2.isDone()).toBe(false); + fakeState = cloneDeep(fakeState); fakeState.entities.roles.pending = new Set(); fakeState.entities.general.serverVersion = '4.9'; - await Actions.loadRolesIfNeeded(['test', 'test2', ''])(store.dispatch, () => fakeState); + store = configureStore(fakeState); + await store.dispatch(Actions.loadRolesIfNeeded(['test', 'test2', ''])); expect(mock1.isDone()).toBe(false); expect(mock2.isDone()).toBe(true); }); @@ -122,7 +128,7 @@ describe('Actions.Roles', () => { put('/' + roleId + '/patch', JSON.stringify({id: roleId, test: 'test'})). reply(200, {}); - await Actions.editRole({id: roleId, test: 'test'})(store.dispatch, store.state); + await store.dispatch(Actions.editRole({id: roleId, test: 'test'})); expect(mock.isDone()).toBe(true); }); }); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/roles.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/roles.ts index f491ed68e6..eba6bcb109 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/roles.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/roles.ts @@ -6,7 +6,7 @@ import type {Role} from '@mattermost/types/roles'; import {RoleTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; import {getRoles} from 'mattermost-redux/selectors/entities/roles_helpers'; -import type {DispatchFunc, GetStateFunc, ActionFunc} from 'mattermost-redux/types/actions'; +import type {DispatchFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {bindClientFunc} from './helpers'; @@ -48,7 +48,7 @@ export function getRole(roleId: string) { }); } -export function editRole(role: Role) { +export function editRole(role: Partial): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.patchRole, onRequest: RoleTypes.EDIT_ROLE_REQUEST, @@ -58,7 +58,7 @@ export function editRole(role: Role) { role.id, role, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function setPendingRoles(roles: string[]) { @@ -68,8 +68,8 @@ export function setPendingRoles(roles: string[]) { }; } -export function loadRolesIfNeeded(roles: Iterable): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function loadRolesIfNeeded(roles: Iterable): NewActionFuncAsync> { + return async (dispatch, getState) => { const state = getState(); let pendingRoles = new Set(); @@ -107,7 +107,7 @@ export function loadRolesIfNeeded(roles: Iterable): ActionFunc { for (let i = 0; i < newRolesArray.length; i += General.MAX_GET_ROLES_BY_NAMES) { const chunk = newRolesArray.slice(i, i + General.MAX_GET_ROLES_BY_NAMES); - getRolesRequests.push(getRolesByNames(chunk)(dispatch, getState)); + getRolesRequests.push(dispatch(getRolesByNames(chunk))); } const result = await Promise.all(getRolesRequests); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/schemes.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/schemes.test.ts index f520cc0c5b..c7cab810ee 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/schemes.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/schemes.test.ts @@ -32,7 +32,7 @@ describe('Actions.Schemes', () => { query(true). reply(200, [mockScheme]); - await Actions.getSchemes('team')(store.dispatch, store.getState); + await store.dispatch(Actions.getSchemes('team')); const {schemes} = store.getState().entities.schemes; expect(Object.keys(schemes).length > 0).toBeTruthy(); @@ -44,7 +44,7 @@ describe('Actions.Schemes', () => { nock(Client4.getBaseRoute()). post('/schemes'). reply(201, mockScheme!); - await Actions.createScheme(TestHelper.mockScheme())(store.dispatch, store.getState); + await store.dispatch(Actions.createScheme(TestHelper.mockScheme())); const {schemes} = store.getState().entities.schemes; @@ -58,7 +58,7 @@ describe('Actions.Schemes', () => { get('/schemes/' + TestHelper.basicScheme!.id). reply(200, TestHelper.basicScheme!); - await Actions.getScheme(TestHelper.basicScheme!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getScheme(TestHelper.basicScheme!.id)); const state = store.getState(); const {schemes} = state.entities.schemes; @@ -77,7 +77,7 @@ describe('Actions.Schemes', () => { put('/schemes/' + TestHelper.basicScheme!.id + '/patch'). reply(200, scheme); - await Actions.patchScheme(TestHelper.basicScheme!.id, scheme)(store.dispatch, store.getState); + await store.dispatch(Actions.patchScheme(TestHelper.basicScheme!.id, scheme)); const state = store.getState(); const {schemes} = state.entities.schemes; @@ -93,7 +93,7 @@ describe('Actions.Schemes', () => { delete('/schemes/' + TestHelper.basicScheme!.id). reply(200, {status: 'OK'}); - await Actions.deleteScheme(TestHelper.basicScheme!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.deleteScheme(TestHelper.basicScheme!.id)); const state = store.getState(); const {schemes} = state.entities.schemes; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/schemes.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/schemes.ts index 11ef3ff52f..9e0a117ea3 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/schemes.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/schemes.ts @@ -1,28 +1,30 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import type {Channel} from '@mattermost/types/channels'; import type {Scheme, SchemeScope, SchemePatch} from '@mattermost/types/schemes'; +import type {Team} from '@mattermost/types/teams'; import {SchemeTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; -import type {ActionFunc, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {logError} from './errors'; import {bindClientFunc, forceLogoutIfNecessary} from './helpers'; import {General} from '../constants'; -export function getScheme(schemeId: string): ActionFunc { +export function getScheme(schemeId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getScheme, onSuccess: [SchemeTypes.RECEIVED_SCHEME], params: [ schemeId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getSchemes(scope: SchemeScope, page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): ActionFunc { +export function getSchemes(scope: SchemeScope, page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getSchemes, onSuccess: [SchemeTypes.RECEIVED_SCHEMES], @@ -31,21 +33,21 @@ export function getSchemes(scope: SchemeScope, page = 0, perPage: number = Gener page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function createScheme(scheme: Scheme): ActionFunc { +export function createScheme(scheme: Scheme): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.createScheme, onSuccess: [SchemeTypes.CREATED_SCHEME], params: [ scheme, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function deleteScheme(schemeId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function deleteScheme(schemeId: string): NewActionFuncAsync { + return async (dispatch, getState) => { let data = null; try { data = await Client4.deleteScheme(schemeId); @@ -61,7 +63,7 @@ export function deleteScheme(schemeId: string): ActionFunc { }; } -export function patchScheme(schemeId: string, scheme: SchemePatch): ActionFunc { +export function patchScheme(schemeId: string, scheme: SchemePatch): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.patchScheme, onSuccess: [SchemeTypes.PATCHED_SCHEME], @@ -69,10 +71,10 @@ export function patchScheme(schemeId: string, scheme: SchemePatch): ActionFunc { schemeId, scheme, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getSchemeTeams(schemeId: string, page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): ActionFunc { +export function getSchemeTeams(schemeId: string, page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getSchemeTeams, onSuccess: [SchemeTypes.RECEIVED_SCHEME_TEAMS], @@ -81,10 +83,10 @@ export function getSchemeTeams(schemeId: string, page = 0, perPage: number = Gen page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getSchemeChannels(schemeId: string, page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): ActionFunc { +export function getSchemeChannels(schemeId: string, page = 0, perPage: number = General.PAGE_SIZE_DEFAULT): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getSchemeChannels, onSuccess: [SchemeTypes.RECEIVED_SCHEME_CHANNELS], @@ -93,5 +95,5 @@ export function getSchemeChannels(schemeId: string, page = 0, perPage: number = page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/search.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/search.test.ts index f19184713e..a4700e6d60 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/search.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/search.test.ts @@ -58,7 +58,7 @@ describe('Actions.Search', () => { get(`/${TestHelper.basicChannel!.id}/members/me`). reply(201, {user_id: TestHelper.basicUser!.id, channel_id: TestHelper.basicChannel!.id}); - await Actions.searchPosts(TestHelper.basicTeam!.id, search1, false, false)(dispatch, getState); + await dispatch(Actions.searchPosts(TestHelper.basicTeam!.id, search1, false, false)); let state = getState(); let {recent, results} = state.entities.search; @@ -77,7 +77,7 @@ describe('Actions.Search', () => { post(`/${TestHelper.basicTeam!.id}/posts/search`). reply(200, {order: [], posts: {}}); - await Actions.searchPostsWithParams(TestHelper.basicTeam!.id, {terms: search1, page: 1} as SearchParameter)(dispatch, getState); + await dispatch(Actions.searchPostsWithParams(TestHelper.basicTeam!.id, {terms: search1, page: 1} as SearchParameter)); state = getState(); current = state.entities.search.current[TestHelper.basicTeam!.id]; recent = state.entities.search.recent; @@ -100,10 +100,10 @@ describe('Actions.Search', () => { //get(`/${TestHelper.basicChannel.id}/members/me`). //reply(201, {user_id: TestHelper.basicUser.id, channel_id: TestHelper.basicChannel.id}); // - //await Actions.searchPosts( + //await dispatch(Actions.searchPosts( //TestHelper.basicTeam.id, //search2 - //)(dispatch, getState); + //)); // //state = getState(); //recent = state.entities.search.recent; @@ -114,7 +114,7 @@ describe('Actions.Search', () => { //expect(results.length).toEqual(3); // Clear posts from the search store - //await Actions.clearSearch()(dispatch, getState); + //await dispatch(Actions.clearSearch()); //state = getState(); //recent = state.entities.search.recent; //results = state.entities.search.results; @@ -124,7 +124,7 @@ describe('Actions.Search', () => { //expect(results.length).toEqual(0); // Clear a recent term - //await Actions.removeSearchTerms(TestHelper.basicTeam.id, search2)(dispatch, getState); + //await dispatch(Actions.removeSearchTerms(TestHelper.basicTeam.id, search2)); //state = getState(); //recent = state.entities.search.recent; //results = state.entities.search.results; @@ -153,7 +153,7 @@ describe('Actions.Search', () => { get(`/${TestHelper.basicChannel!.id}/members/me`). reply(201, {user_id: TestHelper.basicUser!.id, channel_id: TestHelper.basicChannel!.id}); - await Actions.searchFiles(TestHelper.basicTeam!.id, search1, false, false)(dispatch, getState); + await dispatch(Actions.searchFiles(TestHelper.basicTeam!.id, search1, false, false)); let state = getState(); let {recent, fileResults} = state.entities.search; @@ -172,7 +172,7 @@ describe('Actions.Search', () => { post(`/${TestHelper.basicTeam!.id}/files/search`). reply(200, {order: [], file_infos: {}}); - await Actions.searchFilesWithParams(TestHelper.basicTeam!.id, {terms: search1, page: 1} as SearchParameter)(dispatch, getState); + await dispatch(Actions.searchFilesWithParams(TestHelper.basicTeam!.id, {terms: search1, page: 1} as SearchParameter)); state = getState(); current = state.entities.search.current[TestHelper.basicTeam!.id]; recent = state.entities.search.recent; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/search.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/search.ts index 9f40ce53f3..7a9790be16 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/search.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/search.ts @@ -4,14 +4,14 @@ import {batchActions} from 'redux-batched-actions'; import type {FileSearchResults, FileSearchResultItem} from '@mattermost/types/files'; -import type {PostList} from '@mattermost/types/posts'; +import type {PostList, PostSearchResults} from '@mattermost/types/posts'; import type {SearchParameter} from '@mattermost/types/search'; import {SearchTypes} from 'mattermost-redux/action_types'; import {Client4} from 'mattermost-redux/client'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {ActionResult, DispatchFunc, GetStateFunc, ActionFunc} from 'mattermost-redux/types/actions'; +import type {ActionResult, DispatchFunc, GetStateFunc, ActionFunc, NewActionFuncAsync, NewActionFuncOldVariantDoNotUse} from 'mattermost-redux/types/actions'; import {getChannelAndMyMember, getChannelMembers} from './channels'; import {logError} from './errors'; @@ -21,8 +21,8 @@ import {getMentionsAndStatusesForPosts, receivedPosts} from './posts'; const WEBAPP_SEARCH_PER_PAGE = 20; -export function getMissingChannelsFromPosts(posts: PostList['posts']): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getMissingChannelsFromPosts(posts: PostList['posts']): NewActionFuncOldVariantDoNotUse { + return async (dispatch, getState) => { const { channels, membersInChannel, @@ -67,8 +67,8 @@ export function getMissingChannelsFromFiles(files: Map { +export function searchPostsWithParams(teamId: string, params: SearchParameter): NewActionFuncAsync { + return async (dispatch, getState) => { const isGettingMore = params.page > 0; dispatch({ type: SearchTypes.SEARCH_POSTS_REQUEST, @@ -81,7 +81,7 @@ export function searchPostsWithParams(teamId: string, params: SearchParameter): const profilesAndStatuses = getMentionsAndStatusesForPosts(posts.posts, dispatch, getState); const missingChannels = dispatch(getMissingChannelsFromPosts(posts.posts)); - const arr: [Promise, Promise] = [profilesAndStatuses, missingChannels]; + const arr = [profilesAndStatuses, missingChannels]; await Promise.all(arr); } catch (error) { forceLogoutIfNecessary(error, dispatch, getState); @@ -117,8 +117,8 @@ export function searchPosts(teamId: string, terms: string, isOrSearch: boolean, return searchPostsWithParams(teamId, {terms, is_or_search: isOrSearch, include_deleted_channels: includeDeletedChannels, page: 0, per_page: WEBAPP_SEARCH_PER_PAGE}); } -export function getMorePostsForSearch(): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getMorePostsForSearch(): NewActionFuncAsync { + return async (dispatch, getState) => { const teamId = getCurrentTeamId(getState()); const {params, isEnd} = getState().entities.search.current[teamId]; if (!isEnd) { @@ -210,7 +210,7 @@ export function getFlaggedPosts(): ActionFunc { try { posts = await Client4.getFlaggedPosts(userId); - await Promise.all([getMentionsAndStatusesForPosts(posts.posts, dispatch, getState) as any, dispatch(getMissingChannelsFromPosts(posts.posts)) as any]); + await Promise.all([getMentionsAndStatusesForPosts(posts.posts, dispatch, getState), dispatch(getMissingChannelsFromPosts(posts.posts))]); } catch (error) { forceLogoutIfNecessary(error, dispatch, getState); dispatch({type: SearchTypes.SEARCH_FLAGGED_POSTS_FAILURE, error}); diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts index 692df925e3..410627ff4e 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.test.ts @@ -12,7 +12,6 @@ import * as Actions from 'mattermost-redux/actions/teams'; import {loadMe} from 'mattermost-redux/actions/users'; import {Client4} from 'mattermost-redux/client'; import {General, RequestStatus} from 'mattermost-redux/constants'; -import type {ActionResult} from 'mattermost-redux/types/actions'; import TestHelper from '../../test/test_helper'; import configureStore from '../../test/test_store'; @@ -55,12 +54,12 @@ describe('Actions.Teams', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await loadMe()(store.dispatch, store.getState); + await store.dispatch(loadMe()); nock(Client4.getBaseRoute()). get('/users/me/teams'). reply(200, [TestHelper.basicTeam]); - await Actions.getMyTeams()(store.dispatch, store.getState); + await store.dispatch(Actions.getMyTeams()); const teamsRequest = store.getState().requests.teams.getMyTeams; const {teams} = store.getState().entities.teams; @@ -78,7 +77,7 @@ describe('Actions.Teams', () => { get(`/users/${TestHelper.basicUser!.id}/teams`). reply(200, [TestHelper.basicTeam]); - await Actions.getTeamsForUser(TestHelper.basicUser!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getTeamsForUser(TestHelper.basicUser!.id)); const teamsRequest = store.getState().requests.teams.getTeams; const {teams} = store.getState().entities.teams; @@ -103,7 +102,7 @@ describe('Actions.Teams', () => { get('/teams'). query(true). reply(200, [team]); - await Actions.getTeams()(store.dispatch, store.getState); + await store.dispatch(Actions.getTeams()); const teamsRequest = store.getState().requests.teams.getTeams; const {teams} = store.getState().entities.teams; @@ -127,7 +126,7 @@ describe('Actions.Teams', () => { get('/teams'). query(true). reply(200, {teams: [team], total_count: 43}); - await Actions.getTeams(0, 1, true)(store.dispatch, store.getState); + await store.dispatch(Actions.getTeams(0, 1, true)); const teamsRequest = store.getState().requests.teams.getTeams; const {teams, totalCount} = store.getState().entities.teams; @@ -149,7 +148,7 @@ describe('Actions.Teams', () => { nock(Client4.getBaseRoute()). get(`/teams/${team.id}`). reply(200, team); - await Actions.getTeam(team.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getTeam(team.id)); const state = store.getState(); const {teams} = state.entities.teams; @@ -167,7 +166,7 @@ describe('Actions.Teams', () => { nock(Client4.getBaseRoute()). get(`/teams/name/${team.name}`). reply(200, team); - await Actions.getTeamByName(team.name)(store.dispatch, store.getState); + await store.dispatch(Actions.getTeamByName(team.name)); const state = store.getState(); const {teams} = state.entities.teams; @@ -180,9 +179,9 @@ describe('Actions.Teams', () => { nock(Client4.getBaseRoute()). post('/teams'). reply(201, TestHelper.fakeTeamWithId()); - await Actions.createTeam( + await store.dispatch(Actions.createTeam( TestHelper.fakeTeam(), - )(store.dispatch, store.getState); + )); const {teams, myMembers, currentTeamId} = store.getState().entities.teams; @@ -222,9 +221,9 @@ describe('Actions.Teams', () => { delete(`/teams/${secondTeam.id}`). reply(200, OK_RESPONSE); - await Actions.deleteTeam( + await store.dispatch(Actions.deleteTeam( secondTeam.id, - )(store.dispatch, store.getState); + )); const {teams, myMembers} = store.getState().entities.teams; if (teams[secondTeam.id]) { @@ -265,17 +264,17 @@ describe('Actions.Teams', () => { delete(`/teams/${secondTeam.id}`). reply(200, OK_RESPONSE); - await Actions.deleteTeam( + await store.dispatch(Actions.deleteTeam( secondTeam.id, - )(store.dispatch, store.getState); + )); nock(Client4.getBaseRoute()). post(`/teams/${secondTeam.id}/restore`). reply(200, secondTeam); - await Actions.unarchiveTeam( + await store.dispatch(Actions.unarchiveTeam( secondTeam.id, - )(store.dispatch, store.getState); + )); const {teams} = store.getState().entities.teams; expect(teams[secondTeam.id]).toEqual(secondTeam); @@ -293,7 +292,7 @@ describe('Actions.Teams', () => { nock(Client4.getBaseRoute()). put(`/teams/${team.id}`). reply(200, team); - await Actions.updateTeam(team as Team)(store.dispatch, store.getState); + await store.dispatch(Actions.updateTeam(team as Team)); const {teams} = store.getState().entities.teams; const updated = teams[TestHelper.basicTeam!.id]; @@ -315,7 +314,7 @@ describe('Actions.Teams', () => { nock(Client4.getBaseRoute()). put(`/teams/${team.id}/patch`). reply(200, team); - await Actions.patchTeam(team as Team)(store.dispatch, store.getState); + await store.dispatch(Actions.patchTeam(team as Team)); const {teams} = store.getState().entities.teams; const patched = teams[TestHelper.basicTeam!.id]; @@ -335,7 +334,7 @@ describe('Actions.Teams', () => { nock(Client4.getBaseRoute()). post(`/teams/${team!.id}/regenerate_invite_id`). reply(200, patchedTeam); - await Actions.regenerateTeamInviteId(team!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.regenerateTeamInviteId(team!.id)); const {teams} = store.getState().entities.teams; const patched = teams[TestHelper.basicTeam!.id]; @@ -389,7 +388,7 @@ describe('Actions.Teams', () => { query({params: {include_collapsed_threads: true}}). reply(200, [{team_id: team.id, msg_count: 0, mention_count: 0}]); - await Actions.joinTeam(team.invite_id, team.id)(store.dispatch, store.getState); + await store.dispatch(Actions.joinTeam(team.invite_id, team.id)); const state = store.getState(); @@ -408,13 +407,13 @@ describe('Actions.Teams', () => { nock(Client4.getUserRoute('me')). get('/teams/members'). reply(200, [{user_id: TestHelper.basicUser!.id, roles: 'team_user', team_id: TestHelper.basicTeam!.id}]); - await Actions.getMyTeamMembers()(store.dispatch, store.getState); + await store.dispatch(Actions.getMyTeamMembers()); nock(Client4.getUserRoute('me')). get('/teams/unread'). query({params: {include_collapsed_threads: true}}). reply(200, [{team_id: TestHelper.basicTeam!.id, msg_count: 0, mention_count: 0}]); - await Actions.getMyTeamUnreads(false)(store.dispatch, store.getState); + await store.dispatch(Actions.getMyTeamUnreads(false)); const members = store.getState().entities.teams.myMembers; const member = members[TestHelper.basicTeam!.id]; @@ -427,7 +426,7 @@ describe('Actions.Teams', () => { nock(Client4.getUserRoute(TestHelper.basicUser!.id)). get('/teams/members'). reply(200, [{user_id: TestHelper.basicUser!.id, team_id: TestHelper.basicTeam!.id}]); - await Actions.getTeamMembersForUser(TestHelper.basicUser!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getTeamMembersForUser(TestHelper.basicUser!.id)); const membersInTeam = store.getState().entities.teams.membersInTeam; @@ -451,7 +450,7 @@ describe('Actions.Teams', () => { nock(Client4.getBaseRoute()). get(`/teams/${TestHelper.basicTeam!.id}/members/${user.id}`). reply(200, {user_id: user.id, team_id: TestHelper.basicTeam!.id}); - await Actions.getTeamMember(TestHelper.basicTeam!.id, user.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getTeamMember(TestHelper.basicTeam!.id, user.id)); const members = store.getState().entities.teams.membersInTeam; @@ -473,18 +472,18 @@ describe('Actions.Teams', () => { nock(Client4.getTeamRoute(TestHelper.basicTeam!.id)). post('/members'). reply(201, {user_id: user1.id, team_id: TestHelper.basicTeam!.id}); - const {data: member1} = await Actions.addUserToTeam(TestHelper.basicTeam!.id, user1.id)(store.dispatch, store.getState) as ActionResult; + const {data: member1} = await store.dispatch(Actions.addUserToTeam(TestHelper.basicTeam!.id, user1.id)); nock(Client4.getTeamRoute(TestHelper.basicTeam!.id)). post('/members'). reply(201, {user_id: user2.id, team_id: TestHelper.basicTeam!.id}); - const {data: member2} = await Actions.addUserToTeam(TestHelper.basicTeam!.id, user2.id)(store.dispatch, store.getState) as ActionResult; + const {data: member2} = await store.dispatch(Actions.addUserToTeam(TestHelper.basicTeam!.id, user2.id)); nock(Client4.getBaseRoute()). get(`/teams/${TestHelper.basicTeam!.id}/members`). query(true). reply(200, [member1, member2, TestHelper.basicTeamMember]); - await Actions.getTeamMembers(TestHelper.basicTeam!.id, undefined, undefined, {})(store.dispatch, store.getState); + await store.dispatch(Actions.getTeamMembers(TestHelper.basicTeam!.id, undefined, undefined, {})); const membersInTeam = store.getState().entities.teams.membersInTeam; expect(membersInTeam[TestHelper.basicTeam!.id]).toBeTruthy(); @@ -519,10 +518,10 @@ describe('Actions.Teams', () => { nock(Client4.getBaseRoute()). post(`/teams/${TestHelper.basicTeam!.id}/members/ids`). reply(200, [{user_id: user1.id, team_id: TestHelper.basicTeam!.id}, {user_id: user2.id, team_id: TestHelper.basicTeam!.id}]); - await Actions.getTeamMembersByIds( + await store.dispatch(Actions.getTeamMembersByIds( TestHelper.basicTeam!.id, [user1.id, user2.id], - )(store.dispatch, store.getState); + )); const members = store.getState().entities.teams.membersInTeam; @@ -535,7 +534,7 @@ describe('Actions.Teams', () => { nock(Client4.getTeamRoute(TestHelper.basicTeam!.id)). get('/stats'). reply(200, {team_id: TestHelper.basicTeam!.id, total_member_count: 2605, active_member_count: 2571}); - await Actions.getTeamStats(TestHelper.basicTeam!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getTeamStats(TestHelper.basicTeam!.id)); const {stats} = store.getState().entities.teams; @@ -555,7 +554,7 @@ describe('Actions.Teams', () => { nock(Client4.getTeamRoute(TestHelper.basicTeam!.id)). post('/members'). reply(201, {user_id: user.id, team_id: TestHelper.basicTeam!.id}); - await Actions.addUserToTeam(TestHelper.basicTeam!.id, user.id)(store.dispatch, store.getState); + await store.dispatch(Actions.addUserToTeam(TestHelper.basicTeam!.id, user.id)); const members = store.getState().entities.teams.membersInTeam; expect(members[TestHelper.basicTeam!.id]).toBeTruthy(); @@ -576,7 +575,7 @@ describe('Actions.Teams', () => { nock(Client4.getTeamRoute(TestHelper.basicTeam!.id)). post('/members/batch'). reply(201, [{user_id: user.id, team_id: TestHelper.basicTeam!.id}, {user_id: user2.id, team_id: TestHelper.basicTeam!.id}]); - await Actions.addUsersToTeam(TestHelper.basicTeam!.id, [user.id, user2.id])(store.dispatch, store.getState); + await store.dispatch(Actions.addUsersToTeam(TestHelper.basicTeam!.id, [user.id, user2.id])); const members = store.getState().entities.teams.membersInTeam; const profilesInTeam = store.getState().entities.users.profilesInTeam; @@ -694,14 +693,14 @@ describe('Actions.Teams', () => { nock(Client4.getTeamRoute(TestHelper.basicTeam!.id)). post('/members'). reply(201, {user_id: user.id, team_id: TestHelper.basicTeam!.id}); - await Actions.addUserToTeam(TestHelper.basicTeam!.id, user.id)(store.dispatch, store.getState); + await store.dispatch(Actions.addUserToTeam(TestHelper.basicTeam!.id, user.id)); const roles = General.TEAM_USER_ROLE + ' ' + General.TEAM_ADMIN_ROLE; nock(Client4.getBaseRoute()). put(`/teams/${TestHelper.basicTeam!.id}/members/${user.id}/roles`). reply(200, {user_id: user.id, team_id: TestHelper.basicTeam!.id, roles}); - await Actions.updateTeamMemberRoles(TestHelper.basicTeam!.id, user.id, roles.split(' '))(store.dispatch, store.getState); + await store.dispatch(Actions.updateTeamMemberRoles(TestHelper.basicTeam!.id, user.id, roles.split(' '))); const members = store.getState().entities.teams.membersInTeam; @@ -714,7 +713,7 @@ describe('Actions.Teams', () => { nock(Client4.getTeamRoute(TestHelper.basicTeam!.id)). post('/invite/email'). reply(200, OK_RESPONSE); - const {data} = await Actions.sendEmailInvitesToTeam(TestHelper.basicTeam!.id, ['fakeemail1@example.com', 'fakeemail2@example.com'])(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.sendEmailInvitesToTeam(TestHelper.basicTeam!.id, ['fakeemail1@example.com', 'fakeemail2@example.com'])); expect(data).toEqual(OK_RESPONSE); }); @@ -723,14 +722,14 @@ describe('Actions.Teams', () => { get(`/teams/name/${TestHelper.basicTeam!.name}/exists`). reply(200, {exists: true}); - let {data: exists} = await Actions.checkIfTeamExists(TestHelper.basicTeam!.name)(store.dispatch, store.getState) as ActionResult; + let {data: exists} = await store.dispatch(Actions.checkIfTeamExists(TestHelper.basicTeam!.name)); expect(exists === true).toBeTruthy(); nock(Client4.getBaseRoute()). get('/teams/name/junk/exists'). reply(200, {exists: false}); - const {data} = await Actions.checkIfTeamExists('junk')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.checkIfTeamExists('junk')); exists = data; expect(exists === false).toBeTruthy(); @@ -752,7 +751,7 @@ describe('Actions.Teams', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await loadMe()(store.dispatch, store.getState); + await store.dispatch(loadMe()); let state = store.getState(); expect(state.entities.teams.teams[team!.id].invite_id).toEqual(''); @@ -767,7 +766,7 @@ describe('Actions.Teams', () => { get(''). reply(200, {...team, invite_id: 'inviteId'}); - const {data} = await Actions.setTeamIcon(team!.id, imageData as any)(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.setTeamIcon(team!.id, imageData as any)); expect(data).toEqual(OK_RESPONSE); state = store.getState(); @@ -790,7 +789,7 @@ describe('Actions.Teams', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await loadMe()(store.dispatch, store.getState); + await store.dispatch(loadMe()); let state = store.getState(); expect(state.entities.teams.teams[team!.id].invite_id).toEqual(''); @@ -803,7 +802,7 @@ describe('Actions.Teams', () => { get(''). reply(200, {...team, invite_id: 'inviteId'}); - const {data} = await Actions.removeTeamIcon(team!.id)(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.removeTeamIcon(team!.id)); expect(data).toEqual(OK_RESPONSE); state = store.getState(); @@ -815,7 +814,7 @@ describe('Actions.Teams', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await loadMe()(store.dispatch, store.getState); + await store.dispatch(loadMe()); const schemeId = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'; const {id} = TestHelper.basicTeam!; @@ -824,7 +823,7 @@ describe('Actions.Teams', () => { put('/teams/' + id + '/scheme'). reply(200, OK_RESPONSE); - await Actions.updateTeamScheme(id, schemeId)(store.dispatch, store.getState); + await store.dispatch(Actions.updateTeamScheme(id, schemeId)); const state = store.getState!(); const {teams} = state.entities.teams; @@ -844,7 +843,7 @@ describe('Actions.Teams', () => { `/teams/${teamID}/members_minus_group_members?group_ids=${groupIDs.join(',')}&page=${page}&per_page=${perPage}`). reply(200, {users: [], total_count: 0}); - const {error} = await Actions.membersMinusGroupMembers(teamID, groupIDs, page, perPage)(store.dispatch, store.getState) as ActionResult; + const {error} = await store.dispatch(Actions.membersMinusGroupMembers(teamID, groupIDs, page, perPage)); expect(error).toEqual(undefined); }); @@ -882,7 +881,7 @@ describe('Actions.Teams', () => { post('/teams/search'). reply(200, [TestHelper.basicTeam, userTeam]); - await store.dispatch(Actions.searchTeams('test', {page: 0})); + await store.dispatch(Actions.searchTeams('test', {page: 0, per_page: 1})); const moreRequest = store.getState().requests.teams.getTeams; if (moreRequest.status === RequestStatus.FAILURE) { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts index d57c391b43..842bc56d5b 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/teams.ts @@ -5,7 +5,9 @@ import type {AnyAction} from 'redux'; import {batchActions} from 'redux-batched-actions'; import type {ServerError} from '@mattermost/types/errors'; -import type {Team, TeamMembership, TeamMemberWithError, GetTeamMembersOpts, TeamsWithCount, TeamSearchOpts} from '@mattermost/types/teams'; +import type {UsersWithGroupsAndCount} from '@mattermost/types/groups'; +import type {ProductNotices} from '@mattermost/types/product_notices'; +import type {Team, TeamMembership, TeamMemberWithError, GetTeamMembersOpts, TeamsWithCount, TeamSearchOpts, TeamStats, TeamInviteWithError, NotPagedTeamSearchOpts, PagedTeamSearchOpts} from '@mattermost/types/teams'; import type {UserProfile} from '@mattermost/types/users'; import {ChannelTypes, TeamTypes, UserTypes} from 'mattermost-redux/action_types'; @@ -20,7 +22,7 @@ import {isCompatibleWithJoinViewTeamPermissions} from 'mattermost-redux/selector import {isCollapsedThreadsEnabled} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {GetStateFunc, DispatchFunc, ActionFunc, ActionResult} from 'mattermost-redux/types/actions'; +import type {GetStateFunc, DispatchFunc, ActionFunc, ActionResult, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import EventEmitter from 'mattermost-redux/utils/event_emitter'; async function getProfilesAndStatusesForMembers(userIds: string[], dispatch: DispatchFunc, getState: GetStateFunc) { @@ -105,14 +107,14 @@ export function getMyTeamUnreads(collapsedThreads: boolean, skipCurrentTeam = fa }; } -export function getTeam(teamId: string): ActionFunc { +export function getTeam(teamId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getTeam, onSuccess: TeamTypes.RECEIVED_TEAM, params: [ teamId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getTeamByName(teamName: string): ActionFunc { @@ -125,14 +127,14 @@ export function getTeamByName(teamName: string): ActionFunc { }); } -export function getTeams(page = 0, perPage: number = General.TEAMS_CHUNK_SIZE, includeTotalCount = false, excludePolicyConstrained = false): ActionFunc { +export function getTeams(page = 0, perPage: number = General.TEAMS_CHUNK_SIZE, includeTotalCount = false, excludePolicyConstrained = false): NewActionFuncAsync { return async (dispatch: DispatchFunc, getState: GetStateFunc) => { let data; dispatch({type: TeamTypes.GET_TEAMS_REQUEST, data}); try { - data = await Client4.getTeams(page, perPage, includeTotalCount, excludePolicyConstrained) as TeamsWithCount; + data = await Client4.getTeams(page, perPage, includeTotalCount, excludePolicyConstrained); } catch (error) { forceLogoutIfNecessary(error, dispatch, getState); dispatch({type: TeamTypes.GET_TEAMS_FAILURE, data}); @@ -143,7 +145,7 @@ export function getTeams(page = 0, perPage: number = General.TEAMS_CHUNK_SIZE, i const actions: AnyAction[] = [ { type: TeamTypes.RECEIVED_TEAMS_LIST, - data: includeTotalCount ? data.teams : data, + data: includeTotalCount ? (data as unknown as TeamsWithCount).teams : data, }, { type: TeamTypes.GET_TEAMS_SUCCESS, @@ -154,7 +156,7 @@ export function getTeams(page = 0, perPage: number = General.TEAMS_CHUNK_SIZE, i if (includeTotalCount) { actions.push({ type: TeamTypes.RECEIVED_TOTAL_TEAM_COUNT, - data: data.total_count, + data: (data as unknown as TeamsWithCount).total_count, }); } @@ -164,8 +166,10 @@ export function getTeams(page = 0, perPage: number = General.TEAMS_CHUNK_SIZE, i }; } -export function searchTeams(term: string, opts: TeamSearchOpts = {}): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function searchTeams(term: string, opts: PagedTeamSearchOpts): NewActionFuncAsync; +export function searchTeams(term: string, opts?: NotPagedTeamSearchOpts): NewActionFuncAsync; +export function searchTeams(term: string, opts: TeamSearchOpts = {}): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: TeamTypes.GET_TEAMS_REQUEST, data: null}); let response; @@ -180,10 +184,10 @@ export function searchTeams(term: string, opts: TeamSearchOpts = {}): ActionFunc // The type of the response is determined by whether or not page/perPage were set let teams; - if (!opts.page || !opts.per_page) { - teams = response as Team[]; + if (!(opts as PagedTeamSearchOpts).page || !(opts as PagedTeamSearchOpts).per_page) { + teams = response; } else { - teams = (response as TeamsWithCount).teams; + teams = response.teams; } dispatch(batchActions([ @@ -200,8 +204,8 @@ export function searchTeams(term: string, opts: TeamSearchOpts = {}): ActionFunc }; } -export function createTeam(team: Team): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function createTeam(team: Team): NewActionFuncAsync { + return async (dispatch, getState) => { let created; try { created = await Client4.createTeam(team); @@ -240,8 +244,8 @@ export function createTeam(team: Team): ActionFunc { }; } -export function deleteTeam(teamId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function deleteTeam(teamId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.deleteTeam(teamId); } catch (error) { @@ -273,8 +277,8 @@ export function deleteTeam(teamId: string): ActionFunc { }; } -export function unarchiveTeam(teamId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function unarchiveTeam(teamId: string): NewActionFuncAsync { + return async (dispatch, getState) => { let team: Team; try { team = await Client4.unarchiveTeam(teamId); @@ -293,34 +297,34 @@ export function unarchiveTeam(teamId: string): ActionFunc { }; } -export function updateTeam(team: Team): ActionFunc { +export function updateTeam(team: Team): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.updateTeam, onSuccess: TeamTypes.UPDATED_TEAM, params: [ team, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function patchTeam(team: Team): ActionFunc { +export function patchTeam(team: Partial & {id: string}): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.patchTeam, onSuccess: TeamTypes.PATCHED_TEAM, params: [ team, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function regenerateTeamInviteId(teamId: string): ActionFunc { +export function regenerateTeamInviteId(teamId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.regenerateTeamInviteId, onSuccess: TeamTypes.REGENERATED_TEAM_INVITE_ID, params: [ teamId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getMyTeamMembers(): ActionFunc { @@ -348,7 +352,7 @@ export function getMyTeamMembers(): ActionFunc { }; } -export function getTeamMembers(teamId: string, page = 0, perPage: number = General.TEAMS_CHUNK_SIZE, options: GetTeamMembersOpts): ActionFunc { +export function getTeamMembers(teamId: string, page = 0, perPage: number = General.TEAMS_CHUNK_SIZE, options?: GetTeamMembersOpts): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getTeamMembers, onRequest: TeamTypes.GET_TEAM_MEMBERS_REQUEST, @@ -360,7 +364,7 @@ export function getTeamMembers(teamId: string, page = 0, perPage: number = Gener perPage, options, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getTeamMember(teamId: string, userId: string): ActionFunc { @@ -387,8 +391,8 @@ export function getTeamMember(teamId: string, userId: string): ActionFunc { }; } -export function getTeamMembersByIds(teamId: string, userIds: string[]): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getTeamMembersByIds(teamId: string, userIds: string[]): NewActionFuncAsync { + return async (dispatch, getState) => { let members; try { const membersRequest = Client4.getTeamMembersByIds(teamId, userIds); @@ -411,7 +415,7 @@ export function getTeamMembersByIds(teamId: string, userIds: string[]): ActionFu }; } -export function getTeamsForUser(userId: string): ActionFunc { +export function getTeamsForUser(userId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getTeamsForUser, onRequest: TeamTypes.GET_TEAMS_REQUEST, @@ -420,30 +424,30 @@ export function getTeamsForUser(userId: string): ActionFunc { params: [ userId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getTeamMembersForUser(userId: string): ActionFunc { +export function getTeamMembersForUser(userId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getTeamMembersForUser, onSuccess: TeamTypes.RECEIVED_TEAM_MEMBERS, params: [ userId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getTeamStats(teamId: string): ActionFunc { +export function getTeamStats(teamId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getTeamStats, onSuccess: TeamTypes.RECEIVED_TEAM_STATS, params: [ teamId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function addUserToTeamFromInvite(token: string, inviteId: string): ActionFunc { +export function addUserToTeamFromInvite(token: string, inviteId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.addToTeamFromInvite, onRequest: TeamTypes.ADD_TO_TEAM_FROM_INVITE_REQUEST, @@ -453,11 +457,11 @@ export function addUserToTeamFromInvite(token: string, inviteId: string): Action token, inviteId, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function addUserToTeam(teamId: string, userId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function addUserToTeam(teamId: string, userId: string): NewActionFuncAsync { + return async (dispatch, getState) => { let member; try { member = await Client4.addToTeam(teamId, userId); @@ -512,8 +516,8 @@ export function addUsersToTeam(teamId: string, userIds: string[]): ActionFunc { }; } -export function addUsersToTeamGracefully(teamId: string, userIds: string[]): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function addUsersToTeamGracefully(teamId: string, userIds: string[]): NewActionFuncAsync { + return async (dispatch, getState) => { let result: TeamMemberWithError[]; try { result = await Client4.addUsersToTeamGracefully(teamId, userIds); @@ -542,8 +546,8 @@ export function addUsersToTeamGracefully(teamId: string, userIds: string[]): Act }; } -export function removeUserFromTeam(teamId: string, userId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function removeUserFromTeam(teamId: string, userId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.removeFromTeam(teamId, userId); } catch (error) { @@ -639,14 +643,14 @@ export function sendEmailGuestInvitesToChannels(teamId: string, channelIds: stri ], }); } -export function sendEmailInvitesToTeamGracefully(teamId: string, emails: string[]): ActionFunc { +export function sendEmailInvitesToTeamGracefully(teamId: string, emails: string[]): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.sendEmailInvitesToTeamGracefully, params: [ teamId, emails, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function sendEmailGuestInvitesToChannelsGracefully(teamId: string, channelIds: string[], emails: string[], message: string): ActionFunc { @@ -666,7 +670,7 @@ export function sendEmailInvitesToTeamAndChannelsGracefully( channelIds: string[], emails: string[], message: string, -): ActionFunc { +): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.sendEmailInvitesToTeamAndChannelsGracefully, params: [ @@ -675,7 +679,7 @@ export function sendEmailInvitesToTeamAndChannelsGracefully( emails, message, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getTeamInviteInfo(inviteId: string): ActionFunc { @@ -690,8 +694,8 @@ export function getTeamInviteInfo(inviteId: string): ActionFunc { }); } -export function checkIfTeamExists(teamName: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function checkIfTeamExists(teamName: string): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.checkIfTeamExists(teamName); @@ -727,8 +731,8 @@ export function joinTeam(inviteId: string, teamId: string): ActionFunc { dispatch(getMyTeamUnreads(isCollapsedThreadsEnabled(state))); await Promise.all([ - getTeam(teamId)(dispatch, getState), - getMyTeamMembers()(dispatch, getState), + dispatch(getTeam(teamId)), + dispatch(getMyTeamMembers()), ]); dispatch({type: TeamTypes.JOIN_TEAM_SUCCESS, data: null}); @@ -736,8 +740,8 @@ export function joinTeam(inviteId: string, teamId: string): ActionFunc { }; } -export function setTeamIcon(teamId: string, imageData: File): ActionFunc { - return async (dispatch: DispatchFunc) => { +export function setTeamIcon(teamId: string, imageData: File): NewActionFuncAsync { + return async (dispatch) => { await Client4.setTeamIcon(teamId, imageData); const team = await Client4.getTeam(teamId); dispatch({ @@ -748,8 +752,8 @@ export function setTeamIcon(teamId: string, imageData: File): ActionFunc { }; } -export function removeTeamIcon(teamId: string): ActionFunc { - return async (dispatch: DispatchFunc) => { +export function removeTeamIcon(teamId: string): NewActionFuncAsync { + return async (dispatch) => { await Client4.removeTeamIcon(teamId); const team = await Client4.getTeam(teamId); dispatch({ @@ -760,14 +764,14 @@ export function removeTeamIcon(teamId: string): ActionFunc { }; } -export function updateTeamScheme(teamId: string, schemeId: string): ActionFunc { +export function updateTeamScheme(teamId: string, schemeId: string): NewActionFuncAsync<{teamId: string; schemeId: string}> { return bindClientFunc({ clientFunc: async () => { await Client4.updateTeamScheme(teamId, schemeId); return {teamId, schemeId}; }, onSuccess: TeamTypes.UPDATED_TEAM_SCHEME, - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function updateTeamMemberSchemeRoles( @@ -775,14 +779,14 @@ export function updateTeamMemberSchemeRoles( userId: string, isSchemeUser: boolean, isSchemeAdmin: boolean, -): ActionFunc { +): NewActionFuncAsync { return bindClientFunc({ clientFunc: async () => { await Client4.updateTeamMemberSchemeRoles(teamId, userId, isSchemeUser, isSchemeAdmin); return {teamId, userId, isSchemeUser, isSchemeAdmin}; }, onSuccess: TeamTypes.UPDATED_TEAM_MEMBER_SCHEME_ROLES, - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function invalidateAllEmailInvites(): ActionFunc { @@ -791,7 +795,7 @@ export function invalidateAllEmailInvites(): ActionFunc { }); } -export function membersMinusGroupMembers(teamID: string, groupIDs: string[], page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): ActionFunc { +export function membersMinusGroupMembers(teamID: string, groupIDs: string[], page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.teamMembersMinusGroupMembers, onSuccess: TeamTypes.RECEIVED_TEAM_MEMBERS_MINUS_GROUP_MEMBERS, @@ -801,10 +805,10 @@ export function membersMinusGroupMembers(teamID: string, groupIDs: string[], pag page, perPage, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getInProductNotices(teamId: string, client: string, clientVersion: string): ActionFunc { +export function getInProductNotices(teamId: string, client: string, clientVersion: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getInProductNotices, params: [ @@ -812,7 +816,7 @@ export function getInProductNotices(teamId: string, client: string, clientVersio client, clientVersion, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function updateNoticesAsViewed(noticeIds: string[]): ActionFunc { diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/timezone.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/timezone.ts index 32e39f8e54..91db6c0c3f 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/timezone.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/timezone.ts @@ -25,7 +25,7 @@ export function autoUpdateTimezone(deviceTimezone: string) { timezone, }; - updateMe(updatedUser)(dispatch, getState); + dispatch(updateMe(updatedUser)); } return {data: true}; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/users.test.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/users.test.ts index d6f6f28a0c..2101a0d607 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/users.test.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/users.test.ts @@ -10,7 +10,6 @@ import type {UserProfile} from '@mattermost/types/users'; import {UserTypes} from 'mattermost-redux/action_types'; import * as Actions from 'mattermost-redux/actions/users'; import {Client4} from 'mattermost-redux/client'; -import type {ActionResult} from 'mattermost-redux/types/actions'; import deepFreeze from 'mattermost-redux/utils/deep_freeze'; import TestHelper from '../../test/test_helper'; @@ -54,7 +53,7 @@ describe('Actions.Users', () => { post('/users'). reply(201, {...userToCreate, id: TestHelper.generateId()}); - const {data: user} = await Actions.createUser(userToCreate, '', '', '')(store.dispatch, store.getState) as ActionResult; + const {data: user} = await store.dispatch(Actions.createUser(userToCreate, '', '', '')); const state = store.getState(); const {profiles} = state.entities.users; @@ -75,7 +74,7 @@ describe('Actions.Users', () => { get('/terms_of_service'). reply(200, response); - const {data} = await Actions.getTermsOfService()(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.getTermsOfService()); expect(data).toEqual(response); }); @@ -89,13 +88,13 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); nock(Client4.getBaseRoute()). post('/users/me/terms_of_service'). reply(200, OK_RESPONSE); - await Actions.updateMyTermsOfServiceStatus('1', true)(store.dispatch, store.getState); + await store.dispatch(Actions.updateMyTermsOfServiceStatus('1', true)); const {currentUserId} = store.getState().entities.users; const currentUser = store.getState().entities.users.profiles[currentUserId]; @@ -115,13 +114,13 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); nock(Client4.getBaseRoute()). post('/users/me/terms_of_service'). reply(200, OK_RESPONSE); - await Actions.updateMyTermsOfServiceStatus('1', false)(store.dispatch, store.getState); + await store.dispatch(Actions.updateMyTermsOfServiceStatus('1', false)); const {currentUserId, myAcceptedTermsOfServiceId} = store.getState().entities.users; @@ -134,7 +133,7 @@ describe('Actions.Users', () => { post('/users/logout'). reply(200, OK_RESPONSE); - await Actions.logout()(store.dispatch, store.getState); + await store.dispatch(Actions.logout()); const state = store.getState(); const logoutRequest = state.requests.users.logout; @@ -236,7 +235,7 @@ describe('Actions.Users', () => { query(true). reply(200, [TestHelper.basicUser]); - await Actions.getProfiles(0)(store.dispatch, store.getState); + await store.dispatch(Actions.getProfiles(0)); const {profiles} = store.getState().entities.users; expect(Object.keys(profiles).length).toBeTruthy(); @@ -253,7 +252,7 @@ describe('Actions.Users', () => { post('/users/ids'). reply(200, [user]); - await Actions.getProfilesByIds([user.id])(store.dispatch, store.getState); + await store.dispatch(Actions.getProfilesByIds([user.id])); const {profiles} = store.getState().entities.users; expect(profiles[user.id]).toBeTruthy(); @@ -270,7 +269,7 @@ describe('Actions.Users', () => { post('/users/ids'). reply(200, [user]); - await Actions.getMissingProfilesByIds([user.id])(store.dispatch, store.getState); + await store.dispatch(Actions.getMissingProfilesByIds([user.id])); const {profiles} = store.getState().entities.users; expect(profiles[user.id]).toBeTruthy(); @@ -287,7 +286,7 @@ describe('Actions.Users', () => { post('/users/usernames'). reply(200, [user]); - await Actions.getProfilesByUsernames([user.username])(store.dispatch, store.getState); + await store.dispatch(Actions.getProfilesByUsernames([user.username])); const {profiles} = store.getState().entities.users; expect(profiles[user.id]).toBeTruthy(); @@ -299,7 +298,7 @@ describe('Actions.Users', () => { query(true). reply(200, [TestHelper.basicUser]); - await Actions.getProfilesInTeam(TestHelper.basicTeam!.id, 0)(store.dispatch, store.getState); + await store.dispatch(Actions.getProfilesInTeam(TestHelper.basicTeam!.id, 0)); const {profilesInTeam, profiles} = store.getState().entities.users; const team = profilesInTeam[TestHelper.basicTeam!.id]; @@ -325,7 +324,7 @@ describe('Actions.Users', () => { query(true). reply(200, [user]); - await Actions.getProfilesNotInTeam(team!.id, false, 0)(store.dispatch, store.getState); + await store.dispatch(Actions.getProfilesNotInTeam(team!.id, false, 0)); const {profilesNotInTeam} = store.getState().entities.users; const notInTeam = profilesNotInTeam[team!.id]; @@ -346,7 +345,7 @@ describe('Actions.Users', () => { query(true). reply(200, [user]); - await Actions.getProfilesWithoutTeam(0)(store.dispatch, store.getState); + await store.dispatch(Actions.getProfilesWithoutTeam(0)); const {profilesWithoutTeam, profiles} = store.getState().entities.users; expect(profilesWithoutTeam).toBeTruthy(); @@ -361,10 +360,10 @@ describe('Actions.Users', () => { query(true). reply(200, [TestHelper.basicUser]); - await Actions.getProfilesInChannel( + await store.dispatch(Actions.getProfilesInChannel( TestHelper.basicChannel!.id, 0, - )(store.dispatch, store.getState); + )); const {profiles, profilesInChannel} = store.getState().entities.users; @@ -393,12 +392,12 @@ describe('Actions.Users', () => { query(true). reply(200, [user]); - await Actions.getProfilesNotInChannel( + await store.dispatch(Actions.getProfilesNotInChannel( TestHelper.basicTeam!.id, TestHelper.basicChannel!.id, false, 0, - )(store.dispatch, store.getState); + )); const {profiles, profilesNotInChannel} = store.getState().entities.users; @@ -415,7 +414,7 @@ describe('Actions.Users', () => { query(true). reply(200, [TestHelper.basicUser]); - await Actions.getProfilesInGroup(TestHelper.basicGroup!.id, 0)(store.dispatch, store.getState); + await store.dispatch(Actions.getProfilesInGroup(TestHelper.basicGroup!.id, 0)); const {profilesInGroup, profiles} = store.getState().entities.users; const group = profilesInGroup[TestHelper.basicGroup!.id]; @@ -438,9 +437,9 @@ describe('Actions.Users', () => { get(`/users/${user.id}`). reply(200, user); - await Actions.getUser( + await store.dispatch(Actions.getUser( user.id, - )(store.dispatch, store.getState); + )); const state = store.getState(); const {profiles} = state.entities.users; @@ -454,7 +453,7 @@ describe('Actions.Users', () => { get('/users/me'). reply(200, TestHelper.basicUser!); - await Actions.getMe()(store.dispatch, store.getState); + await store.dispatch(Actions.getMe()); const state = store.getState(); const {profiles, currentUserId} = state.entities.users; @@ -474,9 +473,9 @@ describe('Actions.Users', () => { get(`/users/username/${user.username}`). reply(200, user); - await Actions.getUserByUsername( + await store.dispatch(Actions.getUserByUsername( user.username, - )(store.dispatch, store.getState); + )); const state = store.getState(); const {profiles} = state.entities.users; @@ -496,9 +495,9 @@ describe('Actions.Users', () => { get(`/users/email/${user.email}`). reply(200, user); - await Actions.getUserByEmail( + await store.dispatch(Actions.getUserByEmail( user.email, - )(store.dispatch, store.getState); + )); const state = store.getState(); const {profiles} = state.entities.users; @@ -514,9 +513,9 @@ describe('Actions.Users', () => { post('/users/search'). reply(200, [user]); - await Actions.searchProfiles( + await store.dispatch(Actions.searchProfiles( user!.username, - )(store.dispatch, store.getState); + )); const state = store.getState(); const {profiles} = state.entities.users; @@ -530,9 +529,9 @@ describe('Actions.Users', () => { post('/users/status/ids'). reply(200, [{user_id: TestHelper.basicUser!.id, status: 'online', manual: false, last_activity_at: 1507662212199}]); - await Actions.getStatusesByIds( + await store.dispatch(Actions.getStatusesByIds( [TestHelper.basicUser!.id], - )(store.dispatch, store.getState); + )); const statuses = store.getState().entities.users.statuses; @@ -544,7 +543,7 @@ describe('Actions.Users', () => { nock(Client4.getBaseRoute()). get('/users/stats'). reply(200, {total_users_count: 2605}); - await Actions.getTotalUsersStats()(store.dispatch, store.getState); + await store.dispatch(Actions.getTotalUsersStats()); const {stats} = store.getState().entities.users; @@ -558,9 +557,9 @@ describe('Actions.Users', () => { get(`/users/${user!.id}/status`). reply(200, {user_id: user!.id, status: 'online', manual: false, last_activity_at: 1507662212199}); - await Actions.getStatus( + await store.dispatch(Actions.getStatus( user!.id, - )(store.dispatch, store.getState); + )); const statuses = store.getState().entities.users.statuses; expect(statuses[user!.id]).toBeTruthy(); @@ -571,9 +570,9 @@ describe('Actions.Users', () => { put(`/users/${TestHelper.basicUser!.id}/status`). reply(200, OK_RESPONSE); - await Actions.setStatus( + await store.dispatch(Actions.setStatus( {user_id: TestHelper.basicUser!.id, status: 'away'}, - )(store.dispatch, store.getState); + )); const statuses = store.getState().entities.users.statuses; expect(statuses[TestHelper.basicUser!.id] === 'away').toBeTruthy(); @@ -584,7 +583,7 @@ describe('Actions.Users', () => { get(`/users/${TestHelper.basicUser!.id}/sessions`). reply(200, [{id: TestHelper.generateId(), create_at: 1507756921338, expires_at: 1510348921338, last_activity_at: 1507821125630, user_id: TestHelper.basicUser!.id, device_id: '', roles: 'system_admin system_user'}]); - await Actions.getSessions(TestHelper.basicUser!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getSessions(TestHelper.basicUser!.id)); const sessions = store.getState().entities.users.mySessions; @@ -597,7 +596,7 @@ describe('Actions.Users', () => { get(`/users/${TestHelper.basicUser!.id}/sessions`). reply(200, [{id: TestHelper.generateId(), create_at: 1507756921338, expires_at: 1510348921338, last_activity_at: 1507821125630, user_id: TestHelper.basicUser!.id, device_id: '', roles: 'system_admin system_user'}]); - await Actions.getSessions(TestHelper.basicUser!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getSessions(TestHelper.basicUser!.id)); let sessions = store.getState().entities.users.mySessions; @@ -606,7 +605,7 @@ describe('Actions.Users', () => { nock(Client4.getBaseRoute()). post(`/users/${TestHelper.basicUser!.id}/sessions/revoke`). reply(200, OK_RESPONSE); - await Actions.revokeSession(TestHelper.basicUser!.id, sessions[0].id)(store.dispatch, store.getState); + await store.dispatch(Actions.revokeSession(TestHelper.basicUser!.id, sessions[0].id)); sessions = store.getState().entities.users.mySessions; expect(sessions.length === sessionsLength - 1).toBeTruthy(); @@ -622,7 +621,7 @@ describe('Actions.Users', () => { get(`/users/${TestHelper.basicUser!.id}/sessions`). reply(200, [{id: TestHelper.generateId(), create_at: 1507756921338, expires_at: 1510348921338, last_activity_at: 1507821125630, user_id: TestHelper.basicUser!.id, device_id: '', roles: 'system_admin system_user'}]); - await Actions.getSessions(TestHelper.basicUser!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getSessions(TestHelper.basicUser!.id)); const sessions = store.getState().entities.users.mySessions; @@ -630,14 +629,14 @@ describe('Actions.Users', () => { post(`/users/${TestHelper.basicUser!.id}/sessions/revoke`). reply(200, OK_RESPONSE); - const {data: revokeSessionResponse} = await Actions.revokeSession(TestHelper.basicUser!.id, sessions[0].id)(store.dispatch, store.getState) as ActionResult; + const {data: revokeSessionResponse} = await store.dispatch(Actions.revokeSession(TestHelper.basicUser!.id, sessions[0].id)); expect(revokeSessionResponse).toBe(true); nock(Client4.getBaseRoute()). get('/users'). reply(401, {}); - await Actions.getProfiles(0)(store.dispatch, store.getState); + await store.dispatch(Actions.getProfiles(0)); const basicUser = TestHelper.basicUser; nock(Client4.getBaseRoute()). @@ -661,7 +660,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); nock(Client4.getBaseRoute()). post('/users/login'). @@ -671,7 +670,7 @@ describe('Actions.Users', () => { nock(Client4.getBaseRoute()). get(`/users/${user!.id}/sessions`). reply(200, [{id: TestHelper.generateId(), create_at: 1507756921338, expires_at: 1510348921338, last_activity_at: 1507821125630, user_id: TestHelper.basicUser!.id, device_id: '', roles: 'system_admin system_user'}, {id: TestHelper.generateId(), create_at: 1507756921338, expires_at: 1510348921338, last_activity_at: 1507821125630, user_id: TestHelper.basicUser!.id, device_id: '', roles: 'system_admin system_user'}]); - await Actions.getSessions(user!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getSessions(user!.id)); sessions = store.getState().entities.users.mySessions; expect(sessions.length > 1).toBeTruthy(); @@ -679,14 +678,14 @@ describe('Actions.Users', () => { nock(Client4.getBaseRoute()). post(`/users/${user!.id}/sessions/revoke/all`). reply(200, OK_RESPONSE); - const {data} = await Actions.revokeAllSessionsForUser(user!.id)(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.revokeAllSessionsForUser(user!.id)); expect(data).toBe(true); nock(Client4.getBaseRoute()). get('/users'). query(true). reply(401, {}); - await Actions.getProfiles(0)(store.dispatch, store.getState); + await store.dispatch(Actions.getProfiles(0)); const logoutRequest = store.getState().requests.users.logout; if (logoutRequest.status === RequestStatus.FAILURE) { @@ -717,7 +716,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); nock(Client4.getBaseRoute()). post('/users/login'). @@ -727,7 +726,7 @@ describe('Actions.Users', () => { nock(Client4.getBaseRoute()). get(`/users/${user!.id}/sessions`). reply(200, [{id: TestHelper.generateId(), create_at: 1507756921338, expires_at: 1510348921338, last_activity_at: 1507821125630, user_id: TestHelper.basicUser!.id, device_id: '', roles: 'system_admin system_user'}, {id: TestHelper.generateId(), create_at: 1507756921338, expires_at: 1510348921338, last_activity_at: 1507821125630, user_id: TestHelper.basicUser!.id, device_id: '', roles: 'system_admin system_user'}]); - await Actions.getSessions(user!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getSessions(user!.id)); sessions = store.getState().entities.users.mySessions; expect(sessions.length > 1).toBeTruthy(); @@ -735,14 +734,14 @@ describe('Actions.Users', () => { nock(Client4.getBaseRoute()). post('/users/sessions/revoke/all'). reply(200, OK_RESPONSE); - const {data} = await Actions.revokeSessionsForAllUsers()(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.revokeSessionsForAllUsers()); expect(data).toBe(true); nock(Client4.getBaseRoute()). get('/users'). query(true). reply(401, {}); - await Actions.getProfiles(0)(store.dispatch, store.getState); + await store.dispatch(Actions.getProfiles(0)); const logoutRequest = store.getState().requests.users.logout; if (logoutRequest.status === RequestStatus.FAILURE) { @@ -765,7 +764,7 @@ describe('Actions.Users', () => { query(true). reply(200, [{id: TestHelper.generateId(), create_at: 1497285546645, user_id: TestHelper.basicUser!.id, action: '/api/v4/users/login', extra_info: 'success', ip_address: '::1', session_id: ''}]); - await Actions.getUserAudits(TestHelper.basicUser!.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getUserAudits(TestHelper.basicUser!.id)); const audits = store.getState().entities.users.myAudits; @@ -791,11 +790,11 @@ describe('Actions.Users', () => { query(true). reply(200, {users: [TestHelper.basicUser], out_of_channel: [user]}); - await Actions.autocompleteUsers( + await store.dispatch(Actions.autocompleteUsers( '', TestHelper.basicTeam!.id, TestHelper.basicChannel!.id, - )(store.dispatch, store.getState); + )); const autocompleteRequest = store.getState().requests.users.autocompleteUsers; const {profiles, profilesNotInChannel, profilesInChannel} = store.getState().entities.users; @@ -829,11 +828,11 @@ describe('Actions.Users', () => { query(true). reply(200, {users: [user]}); - await Actions.autocompleteUsers( + await store.dispatch(Actions.autocompleteUsers( '', TestHelper.basicTeam!.id, TestHelper.basicChannel!.id, - )(store.dispatch, store.getState); + )); const autocompleteRequest = store.getState().requests.users.autocompleteUsers; const {profiles, profilesNotInChannel, profilesInChannel} = store.getState().entities.users; @@ -854,7 +853,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const state = store.getState(); const currentUser = state.entities.users.profiles[state.entities.users.currentUserId]; @@ -875,7 +874,7 @@ describe('Actions.Users', () => { }, }); - await Actions.updateMe({ + await store.dispatch(Actions.updateMe({ notify_props: { ...notifyProps, comments: 'any', @@ -884,7 +883,7 @@ describe('Actions.Users', () => { mention_keys: '', user_id: currentUser.id, }, - } as UserProfile)(store.dispatch, store.getState); + } as UserProfile)); const updateRequest = store.getState().requests.users.updateMe; const {currentUserId, profiles} = store.getState().entities.users; @@ -905,7 +904,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const state = store.getState(); const currentUserId = state.entities.users.currentUserId; @@ -927,7 +926,7 @@ describe('Actions.Users', () => { }, }); - await Actions.patchUser({ + await store.dispatch(Actions.patchUser({ id: currentUserId, notify_props: { ...notifyProps, @@ -937,7 +936,7 @@ describe('Actions.Users', () => { mention_keys: '', user_id: currentUser.id, }, - } as UserProfile)(store.dispatch, store.getState); + } as UserProfile)); const {profiles} = store.getState().entities.users; const updateNotifyProps = profiles[currentUserId].notify_props; @@ -953,7 +952,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const currentUserId = store.getState().entities.users.currentUserId; @@ -961,7 +960,7 @@ describe('Actions.Users', () => { put(`/users/${currentUserId}/roles`). reply(200, OK_RESPONSE); - await Actions.updateUserRoles(currentUserId, 'system_user system_admin')(store.dispatch, store.getState); + await store.dispatch(Actions.updateUserRoles(currentUserId, 'system_user system_admin')); const {profiles} = store.getState().entities.users; const currentUserRoles = profiles[currentUserId].roles; @@ -974,7 +973,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const currentUserId = store.getState().entities.users.currentUserId; @@ -982,7 +981,7 @@ describe('Actions.Users', () => { put(`/users/${currentUserId}/mfa`). reply(200, OK_RESPONSE); - await Actions.updateUserMfa(currentUserId, false, '')(store.dispatch, store.getState); + await store.dispatch(Actions.updateUserMfa(currentUserId, false, '')); const {profiles} = store.getState().entities.users; const currentUserMfa = profiles[currentUserId].mfa_active; @@ -995,7 +994,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const beforeTime = new Date().getTime(); const currentUserId = store.getState().entities.users.currentUserId; @@ -1004,7 +1003,7 @@ describe('Actions.Users', () => { put(`/users/${currentUserId}/password`). reply(200, OK_RESPONSE); - await Actions.updateUserPassword(currentUserId, 'password1', 'password1')(store.dispatch, store.getState); + await store.dispatch(Actions.updateUserPassword(currentUserId, 'password1', 'password1')); const {profiles} = store.getState().entities.users; const currentUser = profiles[currentUserId]; @@ -1020,7 +1019,7 @@ describe('Actions.Users', () => { post('/users/me/mfa/generate'). reply(200, response); - const {data} = await Actions.generateMfaSecret('me')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.generateMfaSecret('me')); expect(data).toEqual(response); }); @@ -1030,14 +1029,14 @@ describe('Actions.Users', () => { post('/users'). reply(200, TestHelper.fakeUserWithId()); - const {data: user} = await Actions.createUser(TestHelper.fakeUser(), '', '', '')(store.dispatch, store.getState) as ActionResult; + const {data: user} = await store.dispatch(Actions.createUser(TestHelper.fakeUser(), '', '', '')); const beforeTime = new Date().getTime(); nock(Client4.getBaseRoute()). put(`/users/${user.id}/active`). reply(200, OK_RESPONSE); - await Actions.updateUserActive(user.id, false)(store.dispatch, store.getState); + await store.dispatch(Actions.updateUserActive(user.id, false)); const {profiles} = store.getState().entities.users; @@ -1050,7 +1049,7 @@ describe('Actions.Users', () => { post('/users/email/verify'). reply(200, OK_RESPONSE); - const {data} = await Actions.verifyUserEmail('sometoken')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.verifyUserEmail('sometoken')); expect(data).toEqual(OK_RESPONSE); }); @@ -1060,7 +1059,7 @@ describe('Actions.Users', () => { post('/users/email/verify/send'). reply(200, OK_RESPONSE); - const {data} = await Actions.sendVerificationEmail(TestHelper.basicUser!.email)(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.sendVerificationEmail(TestHelper.basicUser!.email)); expect(data).toEqual(OK_RESPONSE); }); @@ -1070,7 +1069,7 @@ describe('Actions.Users', () => { post('/users/password/reset'). reply(200, OK_RESPONSE); - const {data} = await Actions.resetUserPassword('sometoken', 'newpassword')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.resetUserPassword('sometoken', 'newpassword')); expect(data).toEqual(OK_RESPONSE); }); @@ -1080,7 +1079,7 @@ describe('Actions.Users', () => { post('/users/password/reset/send'). reply(200, OK_RESPONSE); - const {data} = await Actions.sendPasswordResetEmail(TestHelper.basicUser!.email)(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.sendPasswordResetEmail(TestHelper.basicUser!.email)); expect(data).toEqual(OK_RESPONSE); }); @@ -1090,7 +1089,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const testImageData = fs.createReadStream('src/packages/mattermost-redux/test/assets/images/test.png'); @@ -1101,7 +1100,7 @@ describe('Actions.Users', () => { post(`/users/${TestHelper.basicUser!.id}/image`). reply(200, OK_RESPONSE); - await Actions.uploadProfileImage(currentUserId, testImageData)(store.dispatch, store.getState); + await store.dispatch(Actions.uploadProfileImage(currentUserId, testImageData)); const {profiles} = store.getState().entities.users; const currentUser = profiles[currentUserId]; @@ -1115,7 +1114,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const currentUserId = store.getState().entities.users.currentUserId; @@ -1123,7 +1122,7 @@ describe('Actions.Users', () => { delete(`/users/${TestHelper.basicUser!.id}/image`). reply(200, OK_RESPONSE); - await Actions.setDefaultProfileImage(currentUserId)(store.dispatch, store.getState); + await store.dispatch(Actions.setDefaultProfileImage(currentUserId)); const {profiles} = store.getState().entities.users; const currentUser = profiles[currentUserId]; @@ -1137,7 +1136,7 @@ describe('Actions.Users', () => { post('/users/login/switch'). reply(200, {follow_link: '/login'}); - const {data} = await Actions.switchEmailToOAuth('gitlab', TestHelper.basicUser!.email, TestHelper.basicUser!.password)(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.switchEmailToOAuth('gitlab', TestHelper.basicUser!.email, TestHelper.basicUser!.password)); expect(data).toEqual({follow_link: '/login'}); }); @@ -1146,7 +1145,7 @@ describe('Actions.Users', () => { post('/users/login/switch'). reply(200, {follow_link: '/login'}); - const {data} = await Actions.switchOAuthToEmail('gitlab', TestHelper.basicUser!.email, TestHelper.basicUser!.password)(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.switchOAuthToEmail('gitlab', TestHelper.basicUser!.email, TestHelper.basicUser!.password)); expect(data).toEqual({follow_link: '/login'}); }); @@ -1156,7 +1155,7 @@ describe('Actions.Users', () => { post('/users/login/switch'). reply(200, {follow_link: '/login'}); - const {data} = await Actions.switchEmailToLdap(TestHelper.basicUser!.email, TestHelper.basicUser!.password, 'someid', 'somepassword')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.switchEmailToLdap(TestHelper.basicUser!.email, TestHelper.basicUser!.password, 'someid', 'somepassword')); expect(data).toEqual({follow_link: '/login'}); }); @@ -1167,7 +1166,7 @@ describe('Actions.Users', () => { post('/users/login/switch'). reply(200, {follow_link: '/login'}); - const {data} = await Actions.switchLdapToEmail('somepassword', TestHelper.basicUser!.email, TestHelper.basicUser!.password)(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.switchLdapToEmail('somepassword', TestHelper.basicUser!.email, TestHelper.basicUser!.password)); expect(data).toEqual({follow_link: '/login'}); done(); @@ -1182,7 +1181,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const currentUserId = store.getState().entities.users.currentUserId; @@ -1190,7 +1189,7 @@ describe('Actions.Users', () => { post(`/users/${currentUserId}/tokens`). reply(201, {id: 'someid', token: 'sometoken', description: 'test token', user_id: currentUserId}); - const {data} = await Actions.createUserAccessToken(currentUserId, 'test token')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.createUserAccessToken(currentUserId, 'test token')); const {myUserAccessTokens} = store.getState().entities.users; const {userAccessTokensByUser} = store.getState().entities.admin; @@ -1213,7 +1212,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const currentUserId = store.getState().entities.users.currentUserId; @@ -1221,13 +1220,13 @@ describe('Actions.Users', () => { post(`/users/${currentUserId}/tokens`). reply(201, {id: 'someid', token: 'sometoken', description: 'test token', user_id: currentUserId}); - const {data} = await Actions.createUserAccessToken(currentUserId, 'test token')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.createUserAccessToken(currentUserId, 'test token')); nock(Client4.getBaseRoute()). get(`/users/tokens/${data.id}`). reply(200, {id: data.id, description: 'test token', user_id: currentUserId}); - await Actions.getUserAccessToken(data.id)(store.dispatch, store.getState); + await store.dispatch(Actions.getUserAccessToken(data.id)); const {myUserAccessTokens} = store.getState().entities.users; const {userAccessTokensByUser, userAccessTokens} = store.getState().entities.admin; @@ -1249,7 +1248,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const currentUserId = store.getState().entities.users.currentUserId; @@ -1257,14 +1256,14 @@ describe('Actions.Users', () => { post(`/users/${currentUserId}/tokens`). reply(201, {id: 'someid', token: 'sometoken', description: 'test token', user_id: currentUserId}); - const {data} = await Actions.createUserAccessToken(currentUserId, 'test token')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.createUserAccessToken(currentUserId, 'test token')); nock(Client4.getBaseRoute()). get('/users/tokens'). query(true). reply(200, [{id: data.id, description: 'test token', user_id: currentUserId}]); - await Actions.getUserAccessTokens()(store.dispatch, store.getState); + await store.dispatch(Actions.getUserAccessTokens()); const {myUserAccessTokens} = store.getState().entities.users; const {userAccessTokensByUser, userAccessTokens} = store.getState().entities.admin; @@ -1286,7 +1285,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const currentUserId = store.getState().entities.users.currentUserId; @@ -1294,14 +1293,14 @@ describe('Actions.Users', () => { post(`/users/${currentUserId}/tokens`). reply(201, {id: 'someid', token: 'sometoken', description: 'test token', user_id: currentUserId}); - const {data} = await Actions.createUserAccessToken(currentUserId, 'test token')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.createUserAccessToken(currentUserId, 'test token')); nock(Client4.getBaseRoute()). get(`/users/${currentUserId}/tokens`). query(true). reply(200, [{id: data.id, description: 'test token', user_id: currentUserId}]); - await Actions.getUserAccessTokensForUser(currentUserId)(store.dispatch, store.getState); + await store.dispatch(Actions.getUserAccessTokensForUser(currentUserId)); const {myUserAccessTokens} = store.getState().entities.users; const {userAccessTokensByUser, userAccessTokens} = store.getState().entities.admin; @@ -1323,7 +1322,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const currentUserId = store.getState().entities.users.currentUserId; @@ -1331,7 +1330,7 @@ describe('Actions.Users', () => { post(`/users/${currentUserId}/tokens`). reply(201, {id: 'someid', token: 'sometoken', description: 'test token', user_id: currentUserId}); - const {data} = await Actions.createUserAccessToken(currentUserId, 'test token')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.createUserAccessToken(currentUserId, 'test token')); let {myUserAccessTokens} = store.getState().entities.users; let {userAccessTokensByUser, userAccessTokens} = store.getState().entities.admin; @@ -1351,7 +1350,7 @@ describe('Actions.Users', () => { post('/users/tokens/revoke'). reply(200, OK_RESPONSE); - await Actions.revokeUserAccessToken(data.id)(store.dispatch, store.getState); + await store.dispatch(Actions.revokeUserAccessToken(data.id)); myUserAccessTokens = store.getState().entities.users.myUserAccessTokens; userAccessTokensByUser = store.getState().entities.admin.userAccessTokensByUser; @@ -1371,7 +1370,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const currentUserId = store.getState().entities.users.currentUserId; @@ -1379,7 +1378,7 @@ describe('Actions.Users', () => { post(`/users/${currentUserId}/tokens`). reply(201, {id: 'someid', token: 'sometoken', description: 'test token', user_id: currentUserId}); - const {data} = await Actions.createUserAccessToken(currentUserId, 'test token')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.createUserAccessToken(currentUserId, 'test token')); const testId = data.id; let {myUserAccessTokens} = store.getState().entities.users; @@ -1400,7 +1399,7 @@ describe('Actions.Users', () => { post('/users/tokens/disable'). reply(200, OK_RESPONSE); - await Actions.disableUserAccessToken(testId)(store.dispatch, store.getState); + await store.dispatch(Actions.disableUserAccessToken(testId)); myUserAccessTokens = store.getState().entities.users.myUserAccessTokens; userAccessTokensByUser = store.getState().entities.admin.userAccessTokensByUser; @@ -1426,7 +1425,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const currentUserId = store.getState().entities.users.currentUserId; @@ -1434,7 +1433,7 @@ describe('Actions.Users', () => { post(`/users/${currentUserId}/tokens`). reply(201, {id: 'someid', token: 'sometoken', description: 'test token', user_id: currentUserId}); - const {data} = await Actions.createUserAccessToken(currentUserId, 'test token')(store.dispatch, store.getState) as ActionResult; + const {data} = await store.dispatch(Actions.createUserAccessToken(currentUserId, 'test token')); const testId = data.id; let {myUserAccessTokens} = store.getState().entities.users; @@ -1455,7 +1454,7 @@ describe('Actions.Users', () => { post('/users/tokens/enable'). reply(200, OK_RESPONSE); - await Actions.enableUserAccessToken(testId)(store.dispatch, store.getState); + await store.dispatch(Actions.enableUserAccessToken(testId)); myUserAccessTokens = store.getState().entities.users.myUserAccessTokens; userAccessTokensByUser = store.getState().entities.admin.userAccessTokensByUser; @@ -1481,7 +1480,7 @@ describe('Actions.Users', () => { store.dispatch({ type: UserTypes.LOGIN_SUCCESS, }); - await Actions.loadMe()(store.dispatch, store.getState); + await store.dispatch(Actions.loadMe()); const currentUserId = store.getState().entities.users.currentUserId; @@ -1489,9 +1488,9 @@ describe('Actions.Users', () => { post(`/users/${currentUserId}/tokens`). reply(201, {id: 'someid', token: 'sometoken', description: 'test token', user_id: currentUserId}); - await Actions.createUserAccessToken(currentUserId, 'test token')(store.dispatch, store.getState); + await store.dispatch(Actions.createUserAccessToken(currentUserId, 'test token')); - await Actions.clearUserAccessTokens()(store.dispatch, store.getState); + await store.dispatch(Actions.clearUserAccessTokens()); const {myUserAccessTokens} = store.getState().entities.users; diff --git a/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts b/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts index f869609d93..1a808dc4dd 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/actions/users.ts @@ -4,8 +4,10 @@ import type {AnyAction} from 'redux'; import {batchActions} from 'redux-batched-actions'; +import type {UserAutocomplete} from '@mattermost/types/autocomplete'; import type {ServerError} from '@mattermost/types/errors'; -import type {UserProfile, UserStatus, GetFilteredUsersStatsOpts, UsersStats, UserCustomStatus} from '@mattermost/types/users'; +import type {TermsOfService} from '@mattermost/types/terms_of_service'; +import type {UserProfile, UserStatus, GetFilteredUsersStatsOpts, UsersStats, UserCustomStatus, UserAccessToken, AuthChangeResponse} from '@mattermost/types/users'; import {UserTypes, AdminTypes} from 'mattermost-redux/action_types'; import {logError} from 'mattermost-redux/actions/errors'; @@ -19,7 +21,7 @@ import {General} from 'mattermost-redux/constants'; import {getServerVersion} from 'mattermost-redux/selectors/entities/general'; import {isCollapsedThreadsEnabled} from 'mattermost-redux/selectors/entities/preferences'; import {getCurrentUserId, getUsers} from 'mattermost-redux/selectors/entities/users'; -import type {ActionFunc, ActionResult, DispatchFunc, GetStateFunc} from 'mattermost-redux/types/actions'; +import type {ActionFunc, DispatchFunc, GetStateFunc, NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {isMinimumServerVersion} from 'mattermost-redux/utils/helpers'; export function generateMfaSecret(userId: string): ActionFunc { @@ -104,8 +106,8 @@ export function getTotalUsersStats(): ActionFunc { }); } -export function getFilteredUsersStats(options: GetFilteredUsersStatsOpts = {}, updateGlobalState = true): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getFilteredUsersStats(options: GetFilteredUsersStatsOpts = {}, updateGlobalState = true): NewActionFuncAsync { + return async (dispatch, getState) => { let stats: UsersStats; try { stats = await Client4.getFilteredUsersStats(options); @@ -126,8 +128,8 @@ export function getFilteredUsersStats(options: GetFilteredUsersStatsOpts = {}, u }; } -export function getProfiles(page = 0, perPage: number = General.PROFILE_CHUNK_SIZE, options: any = {}): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getProfiles(page = 0, perPage: number = General.PROFILE_CHUNK_SIZE, options: any = {}): NewActionFuncAsync { + return async (dispatch, getState) => { let profiles: UserProfile[]; try { @@ -158,8 +160,8 @@ export function getMissingProfilesByIds(userIds: string[]): ActionFunc { }); if (missingIds.length > 0) { - getStatusesByIds(missingIds)(dispatch, getState); - return getProfilesByIds(missingIds)(dispatch, getState); + dispatch(getStatusesByIds(missingIds)); + return dispatch(getProfilesByIds(missingIds)); } return {data: []}; @@ -182,7 +184,7 @@ export function getMissingProfilesByUsernames(usernames: string[]): ActionFunc { }); if (missingUsernames.length > 0) { - return getProfilesByUsernames(missingUsernames)(dispatch, getState); + return dispatch(getProfilesByUsernames(missingUsernames)); } return {data: []}; @@ -231,8 +233,8 @@ export function getProfilesByUsernames(usernames: string[]): ActionFunc { +export function getProfilesInTeam(teamId: string, page: number, perPage: number = General.PROFILE_CHUNK_SIZE, sort = '', options: any = {}): NewActionFuncAsync { + return async (dispatch, getState) => { let profiles; try { @@ -259,8 +261,8 @@ export function getProfilesInTeam(teamId: string, page: number, perPage: number }; } -export function getProfilesNotInTeam(teamId: string, groupConstrained: boolean, page: number, perPage: number = General.PROFILE_CHUNK_SIZE): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getProfilesNotInTeam(teamId: string, groupConstrained: boolean, page: number, perPage: number = General.PROFILE_CHUNK_SIZE): NewActionFuncAsync { + return async (dispatch, getState) => { let profiles; try { profiles = await Client4.getProfilesNotInTeam(teamId, groupConstrained, page, perPage); @@ -319,8 +321,8 @@ export enum ProfilesInChannelSortBy { Admin = 'admin', } -export function getProfilesInChannel(channelId: string, page: number, perPage: number = General.PROFILE_CHUNK_SIZE, sort = '', options: {active?: boolean} = {}): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getProfilesInChannel(channelId: string, page: number, perPage: number = General.PROFILE_CHUNK_SIZE, sort = '', options: {active?: boolean} = {}): NewActionFuncAsync { + return async (dispatch, getState) => { let profiles; try { @@ -384,8 +386,8 @@ export function getProfilesInGroupChannels(channelsIds: string[]): ActionFunc { }; } -export function getProfilesNotInChannel(teamId: string, channelId: string, groupConstrained: boolean, page: number, perPage: number = General.PROFILE_CHUNK_SIZE): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getProfilesNotInChannel(teamId: string, channelId: string, groupConstrained: boolean, page: number, perPage: number = General.PROFILE_CHUNK_SIZE): NewActionFuncAsync { + return async (dispatch, getState) => { let profiles; try { @@ -432,15 +434,15 @@ export function getMe(): ActionFunc { }; } -export function updateMyTermsOfServiceStatus(termsOfServiceId: string, accepted: boolean): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { - const response: ActionResult = await dispatch(bindClientFunc({ +export function updateMyTermsOfServiceStatus(termsOfServiceId: string, accepted: boolean): NewActionFuncAsync { + return async (dispatch, getState) => { + const response = await dispatch(bindClientFunc({ clientFunc: Client4.updateMyTermsOfServiceStatus, params: [ termsOfServiceId, accepted, ], - })); + })) as any; // HARRISONTODO Type bindClientFunc if ('data' in response) { if (accepted) { @@ -465,8 +467,8 @@ export function updateMyTermsOfServiceStatus(termsOfServiceId: string, accepted: }; } -export function getProfilesInGroup(groupId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE, sort = ''): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getProfilesInGroup(groupId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE, sort = ''): NewActionFuncAsync { + return async (dispatch, getState) => { let profiles; try { @@ -493,8 +495,8 @@ export function getProfilesInGroup(groupId: string, page = 0, perPage: number = }; } -export function getProfilesNotInGroup(groupId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getProfilesNotInGroup(groupId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): NewActionFuncAsync { + return async (dispatch, getState) => { let profiles; try { @@ -521,43 +523,43 @@ export function getProfilesNotInGroup(groupId: string, page = 0, perPage: number }; } -export function getTermsOfService(): ActionFunc { +export function getTermsOfService(): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getTermsOfService, - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function promoteGuestToUser(userId: string): ActionFunc { +export function promoteGuestToUser(userId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.promoteGuestToUser, params: [userId], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function demoteUserToGuest(userId: string): ActionFunc { +export function demoteUserToGuest(userId: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.demoteUserToGuest, params: [userId], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function createTermsOfService(text: string): ActionFunc { +export function createTermsOfService(text: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.createTermsOfService, params: [ text, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function getUser(id: string): ActionFunc { +export function getUser(id: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.getUser, onSuccess: UserTypes.RECEIVED_PROFILE, params: [ id, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } export function getUserByUsername(username: string): ActionFunc { @@ -587,8 +589,8 @@ export function getUserByEmail(email: string): ActionFunc { // statuses, we are only making one call for 75 ids. // We could maybe clean it up somewhat by storing the array of ids in redux state possbily? let ids: string[] = []; -const debouncedGetStatusesByIds = debounce(async (dispatch: DispatchFunc, getState: GetStateFunc) => { - getStatusesByIds([...new Set(ids)])(dispatch, getState); +const debouncedGetStatusesByIds = debounce(async (dispatch: DispatchFunc) => { + dispatch(getStatusesByIds([...new Set(ids)])); }, 20, false, () => { ids = []; }); @@ -670,8 +672,8 @@ export function getSessions(userId: string): ActionFunc { }); } -export function revokeSession(userId: string, sessionId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function revokeSession(userId: string, sessionId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.revokeSession(userId, sessionId); } catch (error) { @@ -690,8 +692,8 @@ export function revokeSession(userId: string, sessionId: string): ActionFunc { }; } -export function revokeAllSessionsForUser(userId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function revokeAllSessionsForUser(userId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.revokeAllSessionsForUser(userId); } catch (error) { @@ -744,8 +746,8 @@ export function getUserAudits(userId: string, page = 0, perPage: number = Genera export function autocompleteUsers(term: string, teamId = '', channelId = '', options?: { limit: number; -}): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +}): NewActionFuncAsync { + return async (dispatch, getState) => { dispatch({type: UserTypes.AUTOCOMPLETE_USERS_REQUEST, data: null}); let data; try { @@ -801,8 +803,8 @@ export function autocompleteUsers(term: string, teamId = '', channelId = '', opt }; } -export function searchProfiles(term: string, options: any = {}): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function searchProfiles(term: string, options: any = {}): NewActionFuncAsync { + return async (dispatch, getState) => { let profiles; try { profiles = await Client4.searchUsers(term, options); @@ -888,7 +890,7 @@ export function startPeriodicStatusUpdates(): ActionFunc { return; } - getStatusesByIds(userIds)(dispatch, getState); + dispatch(getStatusesByIds(userIds)); }, General.STATUS_INTERVAL, ); @@ -907,8 +909,8 @@ export function stopPeriodicStatusUpdates(): ActionFunc { }; } -export function updateMe(user: Partial): ActionFunc, ServerError> { - return async (dispatch: DispatchFunc) => { +export function updateMe(user: Partial): NewActionFuncAsync { + return async (dispatch) => { dispatch({type: UserTypes.UPDATE_ME_REQUEST, data: null}); let data; @@ -930,8 +932,8 @@ export function updateMe(user: Partial): ActionFunc { +export function patchUser(user: UserProfile): NewActionFuncAsync { + return async (dispatch) => { let data: UserProfile; try { data = await Client4.patchUser(user); @@ -946,8 +948,8 @@ export function patchUser(user: UserProfile): ActionFunc { }; } -export function updateUserRoles(userId: string, roles: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function updateUserRoles(userId: string, roles: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.updateUserRoles(userId, roles); } catch (error) { @@ -981,8 +983,8 @@ export function updateUserMfa(userId: string, activate: boolean, code = ''): Act }; } -export function updateUserPassword(userId: string, currentPassword: string, newPassword: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function updateUserPassword(userId: string, currentPassword: string, newPassword: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.updateUserPassword(userId, currentPassword, newPassword); } catch (error) { @@ -999,8 +1001,8 @@ export function updateUserPassword(userId: string, currentPassword: string, newP }; } -export function updateUserActive(userId: string, active: boolean): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function updateUserActive(userId: string, active: boolean): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.updateUserActive(userId, active); } catch (error) { @@ -1027,36 +1029,36 @@ export function verifyUserEmail(token: string): ActionFunc { }); } -export function sendVerificationEmail(email: string): ActionFunc { +export function sendVerificationEmail(email: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.sendVerificationEmail, params: [ email, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function resetUserPassword(token: string, newPassword: string): ActionFunc { +export function resetUserPassword(token: string, newPassword: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.resetUserPassword, params: [ token, newPassword, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function sendPasswordResetEmail(email: string): ActionFunc { +export function sendPasswordResetEmail(email: string): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.sendPasswordResetEmail, params: [ email, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function setDefaultProfileImage(userId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function setDefaultProfileImage(userId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.setDefaultProfileImage(userId); } catch (error) { @@ -1073,8 +1075,8 @@ export function setDefaultProfileImage(userId: string): ActionFunc { }; } -export function uploadProfileImage(userId: string, imageData: any): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function uploadProfileImage(userId: string, imageData: any): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.uploadProfileImage(userId, imageData); } catch (error) { @@ -1126,7 +1128,7 @@ export function switchEmailToLdap(email: string, emailPassword: string, ldapId: }); } -export function switchLdapToEmail(ldapPassword: string, email: string, emailPassword: string, mfaCode = ''): ActionFunc { +export function switchLdapToEmail(ldapPassword: string, email: string, emailPassword: string, mfaCode = ''): NewActionFuncAsync { return bindClientFunc({ clientFunc: Client4.switchLdapToEmail, params: [ @@ -1135,11 +1137,11 @@ export function switchLdapToEmail(ldapPassword: string, email: string, emailPass emailPassword, mfaCode, ], - }); + }) as any; // HARRISONTODO Type bindClientFunc } -export function createUserAccessToken(userId: string, description: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function createUserAccessToken(userId: string, description: string): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { @@ -1173,8 +1175,8 @@ export function createUserAccessToken(userId: string, description: string): Acti }; } -export function getUserAccessToken(tokenId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getUserAccessToken(tokenId: string): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.getUserAccessToken(tokenId); @@ -1226,8 +1228,8 @@ export function getUserAccessTokens(page = 0, perPage: number = General.PROFILE_ }; } -export function getUserAccessTokensForUser(userId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function getUserAccessTokensForUser(userId: string, page = 0, perPage: number = General.PROFILE_CHUNK_SIZE): NewActionFuncAsync { + return async (dispatch, getState) => { let data; try { data = await Client4.getUserAccessTokensForUser(userId, page, perPage); @@ -1259,8 +1261,8 @@ export function getUserAccessTokensForUser(userId: string, page = 0, perPage: nu }; } -export function revokeUserAccessToken(tokenId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function revokeUserAccessToken(tokenId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.revokeUserAccessToken(tokenId); } catch (error) { @@ -1278,8 +1280,8 @@ export function revokeUserAccessToken(tokenId: string): ActionFunc { }; } -export function disableUserAccessToken(tokenId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function disableUserAccessToken(tokenId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.disableUserAccessToken(tokenId); } catch (error) { @@ -1297,8 +1299,8 @@ export function disableUserAccessToken(tokenId: string): ActionFunc { }; } -export function enableUserAccessToken(tokenId: string): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function enableUserAccessToken(tokenId: string): NewActionFuncAsync { + return async (dispatch, getState) => { try { await Client4.enableUserAccessToken(tokenId); } catch (error) { diff --git a/webapp/channels/src/packages/mattermost-redux/src/constants/teams.ts b/webapp/channels/src/packages/mattermost-redux/src/constants/teams.ts index a6e1ef76a8..a8108f39d7 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/constants/teams.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/constants/teams.ts @@ -5,4 +5,4 @@ export default { TEAM_TYPE_OPEN: 'O', TEAM_TYPE_INVITE: 'I', SORT_USERNAME_OPTION: 'Username', -}; +} as const; diff --git a/webapp/channels/src/packages/mattermost-redux/src/types/actions.ts b/webapp/channels/src/packages/mattermost-redux/src/types/actions.ts index d42e8adfe8..9cd37a4b37 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/types/actions.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/types/actions.ts @@ -1,23 +1,35 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import type {AnyAction} from 'redux'; +import type {Action as ReduxAction, AnyAction} from 'redux'; import type {BatchAction} from 'redux-batched-actions'; +import type {ThunkAction} from 'redux-thunk'; import type {GlobalState} from '@mattermost/types/store'; +/** + * This file extends Redux's Dispatch type and bindActionCreators function to support Thunk actions by default. + * + * It specifically requires those action creators to return ThunkAction-derived types which are not compatible with + * our existing ActionFunc and Thunk types, and it requires NewActionFunc* + */ +import 'redux-thunk/extend-redux'; + export type GetStateFunc = () => GlobalState; export type GenericAction = AnyAction; -export type Thunk = (b: DispatchFunc, a: GetStateFunc) => Promise | ActionResult; +type Thunk = (b: DispatchFunc, a: GetStateFunc) => Promise | ActionResult; -export type Action = GenericAction | Thunk | BatchAction | ActionFunc; +type Action = GenericAction | Thunk | BatchAction | ActionFunc; +/** + * ActionResult should be the return value of most Thunk action creators. + */ export type ActionResult = { data?: Data; error?: Error; }; -export type DispatchFunc = (action: Action, getState?: GetStateFunc | null) => Promise; +export type DispatchFunc = (action: Action | NewActionFunc | NewActionFuncAsync | NewActionFuncOldVariantDoNotUse, getState?: GetStateFunc | null) => Promise; /** * Return type of a redux action. @@ -28,3 +40,21 @@ export type ActionFunc = ( dispatch: DispatchFunc, getState: GetStateFunc ) => Promise | Array>> | ActionResult; + +/** + * NewActionFunc should be the return type of most non-async Thunk action creators. If that action requires web app + * state, the second type parameter should be used to pass the version of GlobalState from 'types/store'. + */ +export type NewActionFunc = ThunkAction, State, unknown, ReduxAction>; + +/** + * NewActionFunc should be the return type of most async Thunk action creators. If that action requires web app + * state, the second type parameter should be used to pass the version of GlobalState from 'types/store'. + */ +export type NewActionFuncAsync = ThunkAction>, State, unknown, ReduxAction>; + +/** + * NewActionFuncOldVariantDoNotUse is a (hopefully) temporary type to let us migrate actions which previously returned + * an array of promises to use a ThunkAction without having to modify their logic yet. + */ +export type NewActionFuncOldVariantDoNotUse = ThunkAction; diff --git a/webapp/channels/src/plugins/channel_header_plug/index.ts b/webapp/channels/src/plugins/channel_header_plug/index.ts index 52360b69ef..ed2556e0ca 100644 --- a/webapp/channels/src/plugins/channel_header_plug/index.ts +++ b/webapp/channels/src/plugins/channel_header_plug/index.ts @@ -3,16 +3,14 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {appBarEnabled, appsEnabled, getChannelHeaderAppBindings} from 'mattermost-redux/selectors/entities/apps'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; -import type {GenericAction} from 'mattermost-redux/types/actions'; import {handleBindingClick, openAppsModal, postEphemeralCallResponseForChannel} from 'actions/apps'; import {getChannelHeaderPluginComponents, shouldShowAppBar} from 'selectors/plugins'; -import type {HandleBindingClick, OpenAppsModal, PostEphemeralCallResponseForChannel} from 'types/apps'; import type {GlobalState} from 'types/store'; import ChannelHeaderPlug from './channel_header_plug'; @@ -30,15 +28,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - handleBindingClick: HandleBindingClick; - postEphemeralCallResponseForChannel: PostEphemeralCallResponseForChannel; - openAppsModal: OpenAppsModal; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ handleBindingClick, postEphemeralCallResponseForChannel, openAppsModal, diff --git a/webapp/channels/src/plugins/index.js b/webapp/channels/src/plugins/index.js index ebac0fd8fd..fcc8b803f8 100644 --- a/webapp/channels/src/plugins/index.js +++ b/webapp/channels/src/plugins/index.js @@ -68,7 +68,7 @@ export async function initializePlugins() { return; } - const {data, error} = await getPlugins()(store.dispatch); + const {data, error} = await store.dispatch(getPlugins()); if (error) { console.error(error); //eslint-disable-line no-console return; @@ -214,7 +214,7 @@ export async function loadPluginsIfNecessary() { const oldManifests = store.getState().plugins.plugins; - const {error} = await getPlugins()(store.dispatch); + const {error} = await store.dispatch(getPlugins()); if (error) { console.error(error); //eslint-disable-line no-console return; diff --git a/webapp/channels/src/plugins/mobile_channel_header_plug/index.ts b/webapp/channels/src/plugins/mobile_channel_header_plug/index.ts index bf22ccbd41..9422546e6d 100644 --- a/webapp/channels/src/plugins/mobile_channel_header_plug/index.ts +++ b/webapp/channels/src/plugins/mobile_channel_header_plug/index.ts @@ -3,17 +3,15 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import type {ActionCreatorsMapObject, Dispatch} from 'redux'; +import type {Dispatch} from 'redux'; import {AppBindingLocations} from 'mattermost-redux/constants/apps'; import {appsEnabled, makeAppBindingsSelector} from 'mattermost-redux/selectors/entities/apps'; import {getMyCurrentChannelMembership} from 'mattermost-redux/selectors/entities/channels'; import {getTheme} from 'mattermost-redux/selectors/entities/preferences'; -import type {GenericAction} from 'mattermost-redux/types/actions'; import {handleBindingClick, openAppsModal, postEphemeralCallResponseForChannel} from 'actions/apps'; -import type {HandleBindingClick, OpenAppsModal, PostEphemeralCallResponseForChannel} from 'types/apps'; import type {GlobalState} from 'types/store'; import MobileChannelHeaderPlug from './mobile_channel_header_plug'; @@ -31,15 +29,9 @@ function mapStateToProps(state: GlobalState) { }; } -type Actions = { - handleBindingClick: HandleBindingClick; - postEphemeralCallResponseForChannel: PostEphemeralCallResponseForChannel; - openAppsModal: OpenAppsModal; -} - -function mapDispatchToProps(dispatch: Dispatch) { +function mapDispatchToProps(dispatch: Dispatch) { return { - actions: bindActionCreators, Actions>({ + actions: bindActionCreators({ handleBindingClick, postEphemeralCallResponseForChannel, openAppsModal, diff --git a/webapp/channels/src/reducers/views/emoji.ts b/webapp/channels/src/reducers/views/emoji.ts index 33892d5b2f..5e9320289a 100644 --- a/webapp/channels/src/reducers/views/emoji.ts +++ b/webapp/channels/src/reducers/views/emoji.ts @@ -26,10 +26,8 @@ function shortcutReactToLastPostEmittedFrom(state = '', action: GenericAction) { return Locations.CENTER; } else if (action.payload === Locations.RHS_ROOT) { return Locations.RHS_ROOT; - } else if (action.payload === Locations.NO_WHERE) { - return ''; } - return state; + return ''; case UserTypes.LOGOUT_SUCCESS: return ''; diff --git a/webapp/channels/src/utils/channel_utils.tsx b/webapp/channels/src/utils/channel_utils.tsx index 3c59158b3d..2e1448d932 100644 --- a/webapp/channels/src/utils/channel_utils.tsx +++ b/webapp/channels/src/utils/channel_utils.tsx @@ -10,7 +10,7 @@ import Permissions from 'mattermost-redux/constants/permissions'; import {getRedirectChannelNameForTeam} from 'mattermost-redux/selectors/entities/channels'; import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles'; import {getCurrentUserId} from 'mattermost-redux/selectors/entities/users'; -import type {GetStateFunc, DispatchFunc, ActionFunc} from 'mattermost-redux/types/actions'; +import type {NewActionFuncAsync} from 'mattermost-redux/types/actions'; import {openModal} from 'actions/views/modals'; import LocalStorageStore from 'stores/local_storage_store'; @@ -71,8 +71,8 @@ type JoinPrivateChannelPromptResult = { }; }; -export function joinPrivateChannelPrompt(team: Team, channelDisplayName: string, handleOnCancel = true): ActionFunc { - return async (dispatch: DispatchFunc, getState: GetStateFunc) => { +export function joinPrivateChannelPrompt(team: Team, channelDisplayName: string, handleOnCancel = true): NewActionFuncAsync { + return async (dispatch, getState) => { const result: JoinPrivateChannelPromptResult = await new Promise((resolve) => { const modalData = { modalId: ModalIdentifiers.JOIN_CHANNEL_PROMPT, diff --git a/webapp/channels/src/utils/text_formatting.tsx b/webapp/channels/src/utils/text_formatting.tsx index f0425285dc..7bf4f57030 100644 --- a/webapp/channels/src/utils/text_formatting.tsx +++ b/webapp/channels/src/utils/text_formatting.tsx @@ -51,7 +51,7 @@ export type Team = { display_name: string; }; -interface TextFormattingOptionsBase { +export interface TextFormattingOptionsBase { /** * If specified, this word is highlighted in the resulting html. diff --git a/webapp/channels/src/utils/utils.tsx b/webapp/channels/src/utils/utils.tsx index ef191b2800..bde32f7779 100644 --- a/webapp/channels/src/utils/utils.tsx +++ b/webapp/channels/src/utils/utils.tsx @@ -1419,7 +1419,7 @@ export async function handleFormattedTextClick(e: React.MouseEvent, currentRelat e.stopPropagation(); if (match && match.type === 'permalink' && isTeamSameWithCurrentTeam(state, match.teamName) && isReply && crtEnabled) { - focusPost(match.postId ?? '', linkAttribute.value, user.id, {skipRedirectReplyPermalink: true})(store.dispatch, store.getState); + store.dispatch(focusPost(match.postId ?? '', linkAttribute.value, user.id, {skipRedirectReplyPermalink: true})); } else { getHistory().push(linkAttribute.value); } diff --git a/webapp/platform/client/src/client4.ts b/webapp/platform/client/src/client4.ts index 3d864d016f..13ce25917d 100644 --- a/webapp/platform/client/src/client4.ts +++ b/webapp/platform/client/src/client4.ts @@ -82,6 +82,7 @@ import { CustomGroupPatch, GetGroupsParams, GetGroupsForUserParams, + GroupStats, } from '@mattermost/types/groups'; import {PostActionResponse} from '@mattermost/types/integration_actions'; import { @@ -123,6 +124,8 @@ import { TeamsWithCount, TeamUnread, TeamSearchOpts, + PagedTeamSearchOpts, + NotPagedTeamSearchOpts, } from '@mattermost/types/teams'; import {TermsOfService} from '@mattermost/types/terms_of_service'; import { @@ -1272,7 +1275,9 @@ export default class Client4 { ); }; - searchTeams = (term: string, opts: TeamSearchOpts) => { + searchTeams(term: string, opts: PagedTeamSearchOpts): Promise; + searchTeams(term: string, opts: NotPagedTeamSearchOpts): Promise; + searchTeams (term: string, opts: TeamSearchOpts): Promise { this.trackEvent('api', 'api_search_teams'); return this.doFetch( @@ -1325,7 +1330,7 @@ export default class Client4 { ); }; - getTeamMembers = (teamId: string, page = 0, perPage = PER_PAGE_DEFAULT, options: GetTeamMembersOpts) => { + getTeamMembers = (teamId: string, page = 0, perPage = PER_PAGE_DEFAULT, options?: GetTeamMembersOpts) => { return this.doFetch( `${this.getTeamMembersRoute(teamId)}${buildQueryString({page, per_page: perPage, ...options})}`, {method: 'get'}, @@ -1482,7 +1487,7 @@ export default class Client4 { sendEmailInvitesToTeamGracefully = (teamId: string, emails: string[]) => { this.trackEvent('api', 'api_teams_invite_members', {team_id: teamId}); - return this.doFetch( + return this.doFetch( `${this.getTeamRoute(teamId)}/invite/email?graceful=true`, {method: 'post', body: JSON.stringify(emails)}, ); @@ -1496,7 +1501,7 @@ export default class Client4 { ) => { this.trackEvent('api', 'api_teams_invite_members_to_channels', {team_id: teamId, channel_len: channelIds.length}); - return this.doFetch( + return this.doFetch( `${this.getTeamRoute(teamId)}/invite/email?graceful=true`, {method: 'post', body: JSON.stringify({emails, channelIds, message})}, ); @@ -1556,7 +1561,25 @@ export default class Client4 { // Channel Routes - getAllChannels = (page = 0, perPage = PER_PAGE_DEFAULT, notAssociatedToGroup = '', excludeDefaultChannels = false, includeTotalCount = false, includeDeleted = false, excludePolicyConstrained = false) => { + getAllChannels( + page: number | undefined, + perPage: number | undefined, + notAssociatedToGroup: string | undefined, + excludeDefaultChannels: boolean | undefined, + includeTotalCount: false | undefined, + includeDeleted: boolean | undefined, + excludePolicyConstrained: boolean | undefined + ): Promise; + getAllChannels( + page: number | undefined, + perPage: number | undefined, + notAssociatedToGroup: string | undefined, + excludeDefaultChannels: boolean | undefined, + includeTotalCount: true, + includeDeleted: boolean | undefined, + excludePolicyConstrained: boolean | undefined + ): Promise; + getAllChannels(page = 0, perPage = PER_PAGE_DEFAULT, notAssociatedToGroup = '', excludeDefaultChannels = false, includeTotalCount = false, includeDeleted = false, excludePolicyConstrained = false) { const queryData = { page, per_page: perPage, @@ -1867,7 +1890,9 @@ export default class Client4 { ); }; - searchAllChannels = (term: string, opts: ChannelSearchOpts = {}) => { + searchAllChannels(term: string, opts: {page: number; per_page: number} & ChannelSearchOpts): Promise; + searchAllChannels(term: string, opts: Omit | undefined): Promise; + searchAllChannels(term: string, opts: ChannelSearchOpts = {}) { const body = { term, ...opts, @@ -1879,7 +1904,7 @@ export default class Client4 { queryParams = {system_console: false}; delete body.nonAdminSearch; } - return this.doFetch( + return this.doFetch( `${this.getChannelsRoute()}/search${buildQueryString(queryParams)}`, {method: 'post', body: JSON.stringify(body)}, ); @@ -3520,7 +3545,7 @@ export default class Client4 { }; // Groups - linkGroupSyncable = (groupID: string, syncableID: string, syncableType: string, patch: SyncablePatch) => { + linkGroupSyncable = (groupID: string, syncableID: string, syncableType: string, patch: Partial) => { return this.doFetch( `${this.getGroupRoute(groupID)}/${syncableType}s/${syncableID}/link`, {method: 'post', body: JSON.stringify(patch)}, @@ -3549,7 +3574,7 @@ export default class Client4 { }; getGroupStats = (groupID: string) => { - return this.doFetch( + return this.doFetch( `${this.getGroupRoute(groupID)}/stats`, {method: 'get'}, ); @@ -3697,7 +3722,7 @@ export default class Client4 { ); }; - patchGroupSyncable = (groupID: string, syncableID: string, syncableType: string, patch: SyncablePatch) => { + patchGroupSyncable = (groupID: string, syncableID: string, syncableType: string, patch: Partial) => { return this.doFetch( `${this.getGroupRoute(groupID)}/${syncableType}s/${syncableID}/patch`, {method: 'put', body: JSON.stringify(patch)}, @@ -3741,7 +3766,7 @@ export default class Client4 { ); } - patchBot = (botUserId: string, botPatch: BotPatch) => { + patchBot = (botUserId: string, botPatch: Partial) => { return this.doFetch( `${this.getBotRoute(botUserId)}`, {method: 'put', body: JSON.stringify(botPatch)}, diff --git a/webapp/platform/types/src/teams.ts b/webapp/platform/types/src/teams.ts index a05eb2a1de..055089657c 100644 --- a/webapp/platform/types/src/teams.ts +++ b/webapp/platform/types/src/teams.ts @@ -97,12 +97,15 @@ export type TeamStats = { active_member_count: number; }; -export type TeamSearchOpts = { - page?: number; - per_page?: number; +export type TeamSearchOpts = PagedTeamSearchOpts | NotPagedTeamSearchOpts; +export type PagedTeamSearchOpts = { + page: number; + per_page: number; +} & NotPagedTeamSearchOpts; +export type NotPagedTeamSearchOpts = { allow_open_invite?: boolean; group_constrained?: boolean; -} +}; export type TeamInviteWithError = { email: string;