PromucFlow_constructor/app/client/src/api/PageApi.tsx

86 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-09-09 09:08:54 +00:00
import Api from "./Api";
import { ContainerWidgetProps } from "../widgets/ContainerWidget";
import { ApiResponse } from "./ApiResponses";
import { WidgetProps } from "../widgets/BaseWidget";
import { RenderMode } from "../constants/WidgetConstants";
import { PageAction } from "../constants/ActionConstants";
export interface FetchPageRequest {
2019-08-29 11:22:09 +00:00
pageId: string;
renderMode: RenderMode;
}
export interface FetchPublishedPageRequest {
pageId: string;
layoutId: string;
}
export interface SavePageRequest {
dsl: ContainerWidgetProps<WidgetProps>;
layoutId: string;
pageId: string;
}
2019-09-13 09:56:11 +00:00
export interface PageLayout {
id: string;
dsl: Partial<ContainerWidgetProps<any>>;
actions: PageAction[];
2019-09-13 09:56:11 +00:00
}
export type FetchPageResponse = ApiResponse & {
data: {
id: string;
name: string;
applicationId: string;
layouts: Array<PageLayout>;
};
};
export type FetchPublishedPageResponse = ApiResponse & {
2019-10-24 09:23:50 +00:00
data: {
id: string;
dsl: Partial<ContainerWidgetProps<any>>;
};
};
2019-09-27 16:05:33 +00:00
export interface SavePageResponse extends ApiResponse {
2019-08-29 11:22:09 +00:00
pageId: string;
}
class PageApi extends Api {
2019-09-24 12:36:03 +00:00
static url = "v1/pages";
static getLayoutUpdateURL = (pageId: string, layoutId: string) => {
2019-09-24 12:36:03 +00:00
return `v1/layouts/${layoutId}/pages/${pageId}`;
};
2019-09-09 09:08:54 +00:00
static getPublishedPageURL = (pageId: string, layoutId: string) => {
return `v1/layouts/${layoutId}/pages/${pageId}/view`;
};
static fetchPage(pageRequest: FetchPageRequest): Promise<FetchPageResponse> {
return Api.get(PageApi.url + "/" + pageRequest.pageId);
}
static savePage(savePageRequest: SavePageRequest): Promise<SavePageResponse> {
const body = { dsl: savePageRequest.dsl };
return Api.put(
PageApi.getLayoutUpdateURL(
savePageRequest.pageId,
savePageRequest.layoutId,
),
undefined,
body,
);
}
static fetchPublishedPage(
pageRequest: FetchPublishedPageRequest,
): Promise<FetchPublishedPageResponse> {
return Api.get(
PageApi.getPublishedPageURL(pageRequest.pageId, pageRequest.layoutId),
);
}
}
2019-09-09 09:08:54 +00:00
export default PageApi;