forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'MM-34128' of github.com:brightscout-alpha/mattermost-we…
…bapp into MM-34128 * 'MM-34128' of github.com:brightscout-alpha/mattermost-webapp: (104 commits) Mm 34578 add subscribe now button (mattermost#7894) fix subcription typo in the code (mattermost#7930) Fixing keys in Cypress (mattermost#7931) fix test on LDAP groups, code theme and incoming webhook (mattermost#7919) upgrade cypress to v7.1.0 (mattermost#7923) Adding missing Zephyr keys to existing E2E tests (mattermost#7920) Prod test fixes (mattermost#7918) [MM-11264] Added statuses to channel invite modal (mattermost#7787) [MM_20388/ GH_16718] Migrate 'components/signup/signup_email' module and associated tests to TypeScript (mattermost#7699) MM-34569 - remove step 3 to guests (mattermost#7838) add mfa metadata to specs accordingly (mattermost#7896) fix test for forgot password based on new email template (mattermost#7892) fix CI run of Cypress and add flag to sort specs to first (mattermost#7913) cast to lowercase before comparing (mattermost#7769) Migrating a few stragglers from the TS migration (mattermost#7770) update tests and keys of search date filters (mattermost#7893) [MM-34523] New trial card for license page (mattermost#7826) Feature: In-product support for Cloud Trial (mattermost#7907) Cypress/E2E: Update tests and keys of search date filters (remaining) (mattermost#7895) Mm 29656 (mattermost#7820) ...
- Loading branch information
Showing
858 changed files
with
42,429 additions
and
14,562 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import {Client4} from 'mattermost-redux/client'; | ||
import {Action, ActionFunc, DispatchFunc} from 'mattermost-redux/types/actions'; | ||
import {AppCallResponse, AppForm, AppCallType, AppCallRequest} from 'mattermost-redux/types/apps'; | ||
import {AppCallTypes, AppCallResponseTypes} from 'mattermost-redux/constants/apps'; | ||
|
||
import {openModal} from 'actions/views/modals'; | ||
|
||
import AppsForm from 'components/apps_form'; | ||
|
||
import {ModalIdentifiers} from 'utils/constants'; | ||
import {getSiteURL, shouldOpenInNewTab} from 'utils/url'; | ||
import {browserHistory} from 'utils/browser_history'; | ||
import {makeCallErrorResponse} from 'utils/apps'; | ||
|
||
export function doAppCall<Res=unknown>(call: AppCallRequest, type: AppCallType, intl: any): ActionFunc { | ||
return async (dispatch: DispatchFunc) => { | ||
try { | ||
const res = await Client4.executeAppCall(call, type) as AppCallResponse<Res>; | ||
const responseType = res.type || AppCallResponseTypes.OK; | ||
|
||
switch (responseType) { | ||
case AppCallResponseTypes.OK: | ||
return {data: res}; | ||
case AppCallResponseTypes.ERROR: | ||
return {data: res}; | ||
case AppCallResponseTypes.FORM: | ||
if (!res.form) { | ||
const errMsg = intl.formatMessage({ | ||
id: 'apps.error.responses.form.no_form', | ||
defaultMessage: 'Response type is `form`, but no form was included in response.', | ||
}); | ||
return {data: makeCallErrorResponse(errMsg)}; | ||
} | ||
|
||
if (type === AppCallTypes.SUBMIT) { | ||
dispatch(openAppsModal(res.form, call)); | ||
} | ||
|
||
return {data: res}; | ||
case AppCallResponseTypes.NAVIGATE: | ||
if (!res.navigate_to_url) { | ||
const errMsg = intl.formatMessage({ | ||
id: 'apps.error.responses.navigate.no_url', | ||
defaultMessage: 'Response type is `navigate`, but no url was included in response.', | ||
}); | ||
return {data: makeCallErrorResponse(errMsg)}; | ||
} | ||
|
||
if (type !== AppCallTypes.SUBMIT) { | ||
const errMsg = intl.formatMessage({ | ||
id: 'apps.error.responses.navigate.no_submit', | ||
defaultMessage: 'Response type is `navigate`, but the call was not a submission.', | ||
}); | ||
return {data: makeCallErrorResponse(errMsg)}; | ||
} | ||
|
||
if (shouldOpenInNewTab(res.navigate_to_url, getSiteURL())) { | ||
window.open(res.navigate_to_url); | ||
return {data: res}; | ||
} | ||
|
||
browserHistory.push(res.navigate_to_url.slice(getSiteURL().length)); | ||
return {data: res}; | ||
default: { | ||
const errMsg = intl.formatMessage({ | ||
id: 'apps.error.responses.unknown_type', | ||
defaultMessage: 'App response type not supported. Response type: {type}.', | ||
}, {type: responseType}); | ||
return {data: makeCallErrorResponse(errMsg)}; | ||
} | ||
} | ||
} catch (error) { | ||
const errMsg = error.message || intl.formatMessage({ | ||
id: 'apps.error.responses.unexpected_error', | ||
defaultMessage: 'Received an unexpected error.', | ||
}); | ||
return {data: makeCallErrorResponse(errMsg)}; | ||
} | ||
}; | ||
} | ||
|
||
export function openAppsModal(form: AppForm, call: AppCallRequest): Action { | ||
return openModal({ | ||
modalId: ModalIdentifiers.APPS_MODAL, | ||
dialogType: AppsForm, | ||
dialogProps: { | ||
form, | ||
call, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.