Skip to content

Commit 7a8fa00

Browse files
committed
build the application on the object form submission
1 parent 7568cc3 commit 7a8fa00

File tree

5 files changed

+52
-4
lines changed

5 files changed

+52
-4
lines changed

plugin-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "flotiq.deploy-netlify",
33
"name": "Deploy Netlify",
44
"description": "Integration with Netlify",
5-
"version": "1.0.0",
5+
"version": "1.1.0",
66
"repository": "https://github.com/flotiq/flotiq-ui-plugin-deploy-netlify",
77
"url": "https://localhost:3053/index.js",
88
"permissions": []

plugins/form-submit/index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
export const handleAfterSubmitPlugin = (
2+
{ success, contentObject },
3+
toast,
4+
getPluginSettings,
5+
) => {
6+
const ctdName = contentObject?.internal?.contentType;
7+
const settings = getPluginSettings();
8+
9+
if (!success || !ctdName || !settings) return;
10+
11+
const settingsForCtd = JSON.parse(settings)?.builds?.filter(
12+
(plugin) =>
13+
plugin.content_types.length === 0 ||
14+
plugin.content_types.find((ctd) => ctd === ctdName),
15+
);
16+
17+
if (!settingsForCtd.length) return null;
18+
19+
settingsForCtd.map((item) =>
20+
fetch(item.build_webhook_url, {
21+
method: `POST`,
22+
body: '{}',
23+
headers: {
24+
'content-type': 'application/json;charset=UTF-8',
25+
},
26+
})
27+
.then(async ({ ok, status }) => {
28+
if (!ok)
29+
throw Error(
30+
`Failed to fetch Netlify build URL: ${item.build_instance_url}. Status: ${status}`,
31+
);
32+
})
33+
.catch((error) => {
34+
console.log(error);
35+
if (error.message) {
36+
toast.error(error.message);
37+
} else {
38+
toast.error(
39+
`Failed to fetch Netlify build URL: ${item.build_instance_url}`,
40+
);
41+
}
42+
}),
43+
);
44+
};

plugins/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { registerFn } from '../common/plugin-element-cache';
22
import pluginInfo from '../plugin-manifest.json';
3-
import { handlePanelPlugin } from './deply-netlify';
3+
import cssString from 'inline:./sidebar-panel/style/style.css';
4+
import { handlePanelPlugin } from './sidebar-panel';
45
import { handleManagePlugin } from './manage';
5-
import cssString from 'inline:./deply-netlify/style/style.css';
6+
import { handleAfterSubmitPlugin } from './form-submit';
67

7-
registerFn(pluginInfo, (handler) => {
8+
registerFn(pluginInfo, (handler, _, { toast, getPluginSettings }) => {
89
if (!document.getElementById(`${pluginInfo.id}-styles`)) {
910
const style = document.createElement('style');
1011
style.id = `${pluginInfo.id}-styles`;
@@ -18,4 +19,7 @@ registerFn(pluginInfo, (handler) => {
1819
handler.on('flotiq.form.sidebar-panel::add', (data) =>
1920
handlePanelPlugin(data, pluginInfo),
2021
);
22+
handler.on('flotiq.form::after-submit', (data) =>
23+
handleAfterSubmitPlugin(data, toast, getPluginSettings),
24+
);
2125
});

0 commit comments

Comments
 (0)