From 9c439459d7606be01bef340a24b176d08b800828 Mon Sep 17 00:00:00 2001 From: Andrei Soroker Date: Mon, 16 Sep 2024 11:33:55 -0700 Subject: [PATCH] Allow deleting inactive projects; add warning --- server/lib/supafana/web/router.ex | 9 +++- server/lib/supafana/web/utils.ex | 8 ++- storefront/src/ui/SupafanaProject.tsx | 78 ++++++++++++++++++--------- 3 files changed, 67 insertions(+), 28 deletions(-) diff --git a/server/lib/supafana/web/router.ex b/server/lib/supafana/web/router.ex index 54ccd4b..94c9c8b 100644 --- a/server/lib/supafana/web/router.ex +++ b/server/lib/supafana/web/router.ex @@ -621,6 +621,13 @@ defmodule Supafana.Web.Router do false -> forbid(conn, "Project #{project_ref} does not belong to your Supabase organization") + {:ok, _, _} -> + send_resp( + conn, + 400, + "Project must be restored to provision" + ) + {:ok, service_key} -> case Supafana.Azure.Api.check_deployment(project_ref) do {:ok, %{"properties" => %{"provisioningState" => "Failed"}}} -> @@ -675,7 +682,7 @@ defmodule Supafana.Web.Router do false -> forbid(conn, "Project #{project_ref} does not belong to your Supabase organization") - {:ok, _} -> + _ -> Supafana.Web.Task.schedule( operation: :delete_vm, project_ref: project_ref, diff --git a/server/lib/supafana/web/utils.ex b/server/lib/supafana/web/utils.ex index ea18920..531e70a 100644 --- a/server/lib/supafana/web/utils.ex +++ b/server/lib/supafana/web/utils.ex @@ -36,7 +36,13 @@ defmodule Supafana.Web.Utils do {:ok, service_key} _ -> - false + case Supafana.Supabase.Management.project_health(access_token, project_ref) do + {:ok, health} -> + {:ok, :inactive, health} + + _ -> + false + end end end end diff --git a/storefront/src/ui/SupafanaProject.tsx b/storefront/src/ui/SupafanaProject.tsx index 546fce7..676d24e 100644 --- a/storefront/src/ui/SupafanaProject.tsx +++ b/storefront/src/ui/SupafanaProject.tsx @@ -213,20 +213,33 @@ const SupafanaProject = ({ {(["Failed"].includes(state) || (plan === "Supafana Pro" && ["Deleted"].includes(state))) && ( - + {project.status.startsWith("ACTIVE") ? ( + + ) : ( + + You’ll have to{" "} + + restore + {" "} + this project to provision Supafana + + )} )} {plan === "Trial" && trialEnded && state === "Deleted" && ( @@ -239,18 +252,31 @@ const SupafanaProject = ({ )} {plan === "Trial" && !trialEnded && state === "Deleted" && ( - + {project.status.startsWith("ACTIVE") ? ( + + ) : ( + + You’ll have to{" "} + + restore + {" "} + this project to provision Supafana + + )} )}