UNPKG

mattermost-redux

Version:

Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client

77 lines (76 loc) 3.46 kB
"use strict"; // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. Object.defineProperty(exports, "__esModule", { value: true }); exports.createRecap = createRecap; exports.getRecaps = getRecaps; exports.getRecap = getRecap; exports.markRecapAsRead = markRecapAsRead; exports.regenerateRecap = regenerateRecap; exports.deleteRecap = deleteRecap; const action_types_1 = require("mattermost-redux/action_types"); const errors_1 = require("mattermost-redux/actions/errors"); const client_1 = require("mattermost-redux/client"); const helpers_1 = require("./helpers"); function createRecap(title, channelIds, agentId) { return (0, helpers_1.bindClientFunc)({ clientFunc: () => client_1.Client4.createRecap({ title, channel_ids: channelIds, agent_id: agentId }), onRequest: action_types_1.RecapTypes.CREATE_RECAP_REQUEST, onSuccess: [action_types_1.RecapTypes.CREATE_RECAP_SUCCESS, action_types_1.RecapTypes.RECEIVED_RECAP], onFailure: action_types_1.RecapTypes.CREATE_RECAP_FAILURE, }); } function getRecaps(page = 0, perPage = 60) { return (0, helpers_1.bindClientFunc)({ clientFunc: () => client_1.Client4.getRecaps(page, perPage), onRequest: action_types_1.RecapTypes.GET_RECAPS_REQUEST, onSuccess: [action_types_1.RecapTypes.GET_RECAPS_SUCCESS, action_types_1.RecapTypes.RECEIVED_RECAPS], onFailure: action_types_1.RecapTypes.GET_RECAPS_FAILURE, }); } function getRecap(recapId) { return (0, helpers_1.bindClientFunc)({ clientFunc: () => client_1.Client4.getRecap(recapId), onRequest: action_types_1.RecapTypes.GET_RECAP_REQUEST, onSuccess: [action_types_1.RecapTypes.GET_RECAP_SUCCESS, action_types_1.RecapTypes.RECEIVED_RECAP], onFailure: action_types_1.RecapTypes.GET_RECAP_FAILURE, }); } function markRecapAsRead(recapId) { return (0, helpers_1.bindClientFunc)({ clientFunc: () => client_1.Client4.markRecapAsRead(recapId), onRequest: action_types_1.RecapTypes.MARK_RECAP_READ_REQUEST, onSuccess: [action_types_1.RecapTypes.MARK_RECAP_READ_SUCCESS, action_types_1.RecapTypes.RECEIVED_RECAP], onFailure: action_types_1.RecapTypes.MARK_RECAP_READ_FAILURE, }); } function regenerateRecap(recapId) { return (0, helpers_1.bindClientFunc)({ clientFunc: () => client_1.Client4.regenerateRecap(recapId), onRequest: action_types_1.RecapTypes.REGENERATE_RECAP_REQUEST, onSuccess: [action_types_1.RecapTypes.REGENERATE_RECAP_SUCCESS, action_types_1.RecapTypes.RECEIVED_RECAP], onFailure: action_types_1.RecapTypes.REGENERATE_RECAP_FAILURE, }); } function deleteRecap(recapId) { return async (dispatch, getState) => { dispatch({ type: action_types_1.RecapTypes.DELETE_RECAP_REQUEST, data: recapId }); try { await client_1.Client4.deleteRecap(recapId); dispatch({ type: action_types_1.RecapTypes.DELETE_RECAP_SUCCESS, data: { recapId }, }); return { data: true }; } catch (error) { dispatch((0, errors_1.logError)(error)); (0, helpers_1.forceLogoutIfNecessary)(error, dispatch, getState); dispatch({ type: action_types_1.RecapTypes.DELETE_RECAP_FAILURE, error, }); return { error }; } }; }