[MM-34203] Send team id on bindings call (#5316)

* send team id on bindings call

* lint
This commit is contained in:
Michael Kochell 2021-04-29 10:23:58 -04:00 committed by GitHub
parent 3eaa538707
commit f3b7c3a978
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View file

@ -2,10 +2,11 @@
// See LICENSE.txt for license information.
import type {AppBinding, AppCallRequest, AppCallResponse, AppCallType} from '@mm-redux/types/apps';
import {buildQueryString} from '@mm-redux/utils/helpers';
export interface ClientAppsMix {
executeAppCall: (call: AppCallRequest, type: AppCallType) => Promise<AppCallResponse>;
getAppsBindings: (userID: string, channelID: string) => Promise<AppBinding[]>;
getAppsBindings: (userID: string, channelID: string, teamID: string) => Promise<AppBinding[]>;
}
const ClientApps = (superclass: any) => class extends superclass {
@ -25,9 +26,16 @@ const ClientApps = (superclass: any) => class extends superclass {
);
}
getAppsBindings = async (userID: string, channelID: string) => {
getAppsBindings = async (userID: string, channelID: string, teamID: string) => {
const params = {
user_id: userID,
channel_id: channelID,
team_id: teamID,
user_agent: 'mobile',
};
return this.doFetch(
this.getAppsProxyRoute() + `/api/v1/bindings?user_id=${userID}&channel_id=${channelID}&user_agent_type=mobile`,
`${this.getAppsProxyRoute()}/api/v1/bindings${buildQueryString(params)}`,
{method: 'get'},
);
}

View file

@ -1,15 +1,22 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {AppsTypes} from '@mm-redux/action_types';
import {Client4} from '@client/rest';
import {ActionFunc} from '@mm-redux/types/actions';
import {ActionFunc, DispatchFunc, GetStateFunc} from '@mm-redux/types/actions';
import {getChannel} from '@mm-redux/selectors/entities/channels';
import {bindClientFunc} from './helpers';
export function fetchAppBindings(userID: string, channelID: string): ActionFunc {
return bindClientFunc({
clientFunc: () => Client4.getAppsBindings(userID, channelID),
onSuccess: AppsTypes.RECEIVED_APP_BINDINGS,
});
return async (dispatch: DispatchFunc, getState: GetStateFunc) => {
const channel = getChannel(getState(), channelID);
const teamID = channel?.team_id || '';
return dispatch(bindClientFunc({
clientFunc: () => Client4.getAppsBindings(userID, channelID, teamID),
onSuccess: AppsTypes.RECEIVED_APP_BINDINGS,
}));
};
}