chore: fix import template (#11963)

This commit is contained in:
akash-codemonk 2022-03-18 17:38:10 +05:30 committed by GitHub
parent 5cdda5a450
commit f24b93da83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 16 deletions

View File

@ -51,7 +51,7 @@ class TemplatesAPI extends Api {
static importTemplate(
templateId: string,
organizationId: string,
): AxiosPromise<any> {
): AxiosPromise<ImportTemplateResponse> {
return Api.post(
TemplatesAPI.baseUrl +
`/app-templates/${templateId}/import/${organizationId}`,

View File

@ -5,7 +5,7 @@ import {
ReduxActionTypes,
} from "constants/ReduxActionConstants";
import { all, put, takeEvery, call } from "redux-saga/effects";
import TemplatesAPI from "api/TemplatesApi";
import TemplatesAPI, { ImportTemplateResponse } from "api/TemplatesApi";
import { BUILDER_PAGE_URL } from "constants/routes";
import history from "utils/history";
import { getDefaultPageId } from "./ApplicationSagas";
@ -40,24 +40,27 @@ function* importTemplateToOrganisationSaga(
action: ReduxAction<{ templateId: string; organizationId: string }>,
) {
try {
const response = yield call(
const response: ImportTemplateResponse = yield call(
TemplatesAPI.importTemplate,
action.payload.templateId,
action.payload.organizationId,
);
const application: ApplicationPayload = {
...response,
defaultPageId: getDefaultPageId(response.pages),
};
const pageURL = BUILDER_PAGE_URL({
applicationId: application.id,
pageId: application.defaultPageId,
});
yield put({
type: ReduxActionTypes.IMPORT_TEMPLATE_TO_ORGANISATION_SUCCESS,
payload: response,
});
history.push(pageURL);
const isValid = yield validateResponse(response);
if (isValid) {
const application: ApplicationPayload = {
...response.data,
defaultPageId: getDefaultPageId(response.data.pages),
};
const pageURL = BUILDER_PAGE_URL({
applicationId: application.id,
pageId: application.defaultPageId,
});
yield put({
type: ReduxActionTypes.IMPORT_TEMPLATE_TO_ORGANISATION_SUCCESS,
payload: response.data,
});
history.push(pageURL);
}
} catch (error) {
yield put({
type: ReduxActionErrorTypes.IMPORT_TEMPLATE_TO_ORGANISATION_ERROR,