diff --git a/app/[installer-slug]/actions.ts b/app/[installer-slug]/actions.ts index afc5aa4..0b2bee8 100644 --- a/app/[installer-slug]/actions.ts +++ b/app/[installer-slug]/actions.ts @@ -78,3 +78,45 @@ export async function reprovisionInstall( return res.json(); } + +export async function deployComponents( + id: string, +): Promise> { + const res = await fetch( + `${NUON_API_URL}/v1/installs/${id}/components/deploy-all`, + { + cache: "no-store", + headers: { + Authorization: `Bearer ${process?.env?.NUON_API_TOKEN}`, + "X-Nuon-Org-ID": process.env?.NUON_ORG_ID || "", + }, + method: "POST", + }, + ); + + if (!res.ok) { + console.debug(await res.json()); + throw new Error("Can't fetch install"); + } + + return res.json(); +} + +export async function redeployInstall( + id: string, + app: Record, + formData: FormData, +) { + const updateRes = await updateInstall(id, app, formData); + if (updateRes.error) { + return updateRes.json(); + } + + const reproRes = await reprovisionInstall(id); + if (reproRes.error) { + return reproRes.json(); + } + + const compRes = await deployComponents(id); + return await compRes.json(); +} diff --git a/app/[installer-slug]/page.tsx b/app/[installer-slug]/page.tsx index 538e1d4..635fcd9 100644 --- a/app/[installer-slug]/page.tsx +++ b/app/[installer-slug]/page.tsx @@ -1,8 +1,7 @@ import { createInstall, getInstall, - updateInstall, - reprovisionInstall, + redeployInstall, } from "@/app/[installer-slug]/actions"; import { getAppBySlug, getInstaller } from "@/common"; import { Link } from "@/components"; @@ -46,8 +45,7 @@ export default async function Installer({ params, searchParams }) { searchParams={searchParams} createInstall={createInstall} getInstall={getInstall} - updateInstall={updateInstall} - reprovisionInstall={reprovisionInstall} + redeployInstall={redeployInstall} regions={regions} /> diff --git a/app/[installer-slug]/util.ts b/app/[installer-slug]/util.ts index 2d25438..d5c6184 100644 --- a/app/[installer-slug]/util.ts +++ b/app/[installer-slug]/util.ts @@ -2,6 +2,8 @@ export function installRequestBody( app: Record, formData: FormData, ) { + console.log("formData: ", formData); + const data = Object.fromEntries(formData); const inputs = Object.keys(data).reduce( (acc: Record, key) => { diff --git a/components/InstallStepper/index.tsx b/components/InstallStepper/index.tsx index cf4073a..6df93c5 100644 --- a/components/InstallStepper/index.tsx +++ b/components/InstallStepper/index.tsx @@ -31,9 +31,8 @@ const InstallStepper = ({ searchParams, regions, createInstall, - updateInstall, getInstall, - reprovisionInstall, + redeployInstall, }) => { const [activeStep, setActiveStep] = React.useState(0); const [isLastStep, setIsLastStep] = React.useState(false); @@ -72,14 +71,8 @@ const InstallStepper = ({ } installID = res.id; } else { - // if we've already created the install, update it and reprovision - const updateRes = updateInstall(formData); - if (updateRes.error) { - setError(updateRes); - return; - } - - const reproRes = reprovisionInstall(install.id); + // if we've already created the install, redeploy it + const reproRes = await redeployInstall(install.id, app, formData); if (reproRes.error) { setError(reproRes); return; @@ -308,12 +301,7 @@ const InstallStepper = ({
- +
@@ -325,4 +313,22 @@ const InstallStepper = ({ ); }; +const InstallButton = ({ install }) => { + const loading = install.status === "provisioning"; + + let label = "Create Install"; + if (install.id.length > 0) label = "Update Install"; + if (loading) label == ""; + + return ( + + ); +}; + export default InstallStepper;