Skip to content

Commit

Permalink
Merge pull request #2 from flotiq/feature/24748-build-app-on-co-save
Browse files Browse the repository at this point in the history
build the application on the object form submission
  • Loading branch information
rgembalik committed May 24, 2024
2 parents df8a02c + 7a8fa00 commit b2f0910
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plugin-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "flotiq.deploy-netlify",
"name": "Deploy Netlify",
"description": "Integration with Netlify",
"version": "1.0.0",
"version": "1.1.0",
"repository": "https://github.com/flotiq/flotiq-ui-plugin-deploy-netlify",
"url": "https://localhost:3053/index.js",
"permissions": []
Expand Down
44 changes: 44 additions & 0 deletions plugins/form-submit/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export const handleAfterSubmitPlugin = (
{ success, contentObject },
toast,
getPluginSettings,
) => {
const ctdName = contentObject?.internal?.contentType;
const settings = getPluginSettings();

if (!success || !ctdName || !settings) return;

const settingsForCtd = JSON.parse(settings)?.builds?.filter(
(plugin) =>
plugin.content_types.length === 0 ||
plugin.content_types.find((ctd) => ctd === ctdName),
);

if (!settingsForCtd.length) return null;

settingsForCtd.map((item) =>
fetch(item.build_webhook_url, {
method: `POST`,
body: '{}',
headers: {
'content-type': 'application/json;charset=UTF-8',
},
})
.then(async ({ ok, status }) => {
if (!ok)
throw Error(
`Failed to fetch Netlify build URL: ${item.build_instance_url}. Status: ${status}`,
);
})
.catch((error) => {
console.log(error);
if (error.message) {
toast.error(error.message);
} else {
toast.error(
`Failed to fetch Netlify build URL: ${item.build_instance_url}`,
);
}
}),
);
};
10 changes: 7 additions & 3 deletions plugins/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { registerFn } from '../common/plugin-element-cache';
import pluginInfo from '../plugin-manifest.json';
import { handlePanelPlugin } from './deply-netlify';
import cssString from 'inline:./sidebar-panel/style/style.css';
import { handlePanelPlugin } from './sidebar-panel';
import { handleManagePlugin } from './manage';
import cssString from 'inline:./deply-netlify/style/style.css';
import { handleAfterSubmitPlugin } from './form-submit';

registerFn(pluginInfo, (handler) => {
registerFn(pluginInfo, (handler, _, { toast, getPluginSettings }) => {
if (!document.getElementById(`${pluginInfo.id}-styles`)) {
const style = document.createElement('style');
style.id = `${pluginInfo.id}-styles`;
Expand All @@ -18,4 +19,7 @@ registerFn(pluginInfo, (handler) => {
handler.on('flotiq.form.sidebar-panel::add', (data) =>
handlePanelPlugin(data, pluginInfo),
);
handler.on('flotiq.form::after-submit', (data) =>
handleAfterSubmitPlugin(data, toast, getPluginSettings),
);
});
File renamed without changes.
File renamed without changes.

0 comments on commit b2f0910

Please sign in to comment.