From 8169bc53b569f34874d4abf6d3b8d53b38cc7f0b Mon Sep 17 00:00:00 2001 From: sunguroku Date: Tue, 7 May 2024 14:28:38 -0400 Subject: [PATCH 1/4] move ccp connection to cc link --- .../src/main/home/modals/PaymentSetupForm.tsx | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/dashboard/src/main/home/modals/PaymentSetupForm.tsx b/dashboard/src/main/home/modals/PaymentSetupForm.tsx index 2be65658d6..04ba0570dc 100644 --- a/dashboard/src/main/home/modals/PaymentSetupForm.tsx +++ b/dashboard/src/main/home/modals/PaymentSetupForm.tsx @@ -1,10 +1,11 @@ -import React, { useState } from "react"; +import React, { useState, useContext } from "react"; import { PaymentElement, useElements, useStripe, } from "@stripe/react-stripe-js"; import styled from "styled-components"; +import api from "shared/api"; import Button from "components/porter/Button"; import Error from "components/porter/Error"; @@ -15,7 +16,10 @@ import { useSetDefaultPaymentMethod, } from "lib/hooks/useStripe"; +import { Context } from "shared/Context"; + const PaymentSetupForm = ({ onCreate }: { onCreate: () => Promise }) => { + const { currentProject } = useContext(Context); const stripe = useStripe(); const elements = useElements(); @@ -57,6 +61,26 @@ const PaymentSetupForm = ({ onCreate }: { onCreate: () => Promise }) => { // Confirm the setup and set as default if (setupIntent?.payment_method !== null) { await setDefaultPaymentMethod(setupIntent?.payment_method as string); + + // create cluster on first payment setup for sandbox + if (currentProject?.sandbox_enabled) { + await api.connectProjectToCluster( + "", + {}, + { id: currentProject.id } + ) + .then(() => { + api.inviteAdmin( + "", + {}, + { project_id: currentProject.id } + ) + }) + .catch((err: any) => { + setErrorMessage(err.message); + setLoading(false); + }) + } } onCreate(); From 2ec06aba96be693a024fad12640a0d7509f3d8dd Mon Sep 17 00:00:00 2001 From: sunguroku Date: Tue, 7 May 2024 14:33:59 -0400 Subject: [PATCH 2/4] remove from new project --- .../src/main/home/new-project/NewProject.tsx | 29 ++----------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/dashboard/src/main/home/new-project/NewProject.tsx b/dashboard/src/main/home/new-project/NewProject.tsx index b3f70450e3..56ac931a48 100644 --- a/dashboard/src/main/home/new-project/NewProject.tsx +++ b/dashboard/src/main/home/new-project/NewProject.tsx @@ -100,33 +100,8 @@ export const NewProjectFC = () => { setProjects(projectList); setCurrentProject(project); trackCreateNewProject(); - - if (project?.sandbox_enabled) { - await api.connectProjectToCluster( - "", - {}, - { id: project.id } - ) - .then(() => { - api.inviteAdmin( - "", - {}, - { project_id: project.id } - ) - .then(() => { - setButtonStatus("successful"); - pushFiltered("/apps", []); - }) - }) - .catch((err) => { - setButtonStatus("Couldn't create project, try again."); - console.log(err) - }) - - } else { - setButtonStatus("successful"); - pushFiltered("/onboarding", []); - } + setButtonStatus("successful"); + pushFiltered("/onboarding", []); } catch (error) { setButtonStatus("Couldn't create project, try again."); console.log(error); From 6ee75462e64be4ce87822104e8e41152b9f2a805 Mon Sep 17 00:00:00 2001 From: sunguroku Date: Tue, 7 May 2024 14:34:09 -0400 Subject: [PATCH 3/4] remove from new project --- dashboard/src/main/home/new-project/NewProject.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/dashboard/src/main/home/new-project/NewProject.tsx b/dashboard/src/main/home/new-project/NewProject.tsx index 56ac931a48..f2a1ea9a7a 100644 --- a/dashboard/src/main/home/new-project/NewProject.tsx +++ b/dashboard/src/main/home/new-project/NewProject.tsx @@ -97,6 +97,7 @@ export const NewProjectFC = () => { } ) .then((res) => res.data as ProjectListType[]); + setProjects(projectList); setCurrentProject(project); trackCreateNewProject(); From 3bceea26b3a5196e7f288cb015a957acc27ef538 Mon Sep 17 00:00:00 2001 From: sunguroku Date: Wed, 8 May 2024 16:09:59 -0400 Subject: [PATCH 4/4] temp --- .../src/main/home/modals/PaymentSetupForm.tsx | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/dashboard/src/main/home/modals/PaymentSetupForm.tsx b/dashboard/src/main/home/modals/PaymentSetupForm.tsx index 04ba0570dc..94386a401d 100644 --- a/dashboard/src/main/home/modals/PaymentSetupForm.tsx +++ b/dashboard/src/main/home/modals/PaymentSetupForm.tsx @@ -4,6 +4,14 @@ import { useElements, useStripe, } from "@stripe/react-stripe-js"; + +import { + ClientSecretResponse, + PaymentMethodValidator, + type PaymentMethod, + type PaymentMethodList, +} from "lib/billing/types"; + import styled from "styled-components"; import api from "shared/api"; @@ -14,6 +22,7 @@ import SaveButton from "components/SaveButton"; import { useCreatePaymentMethod, useSetDefaultPaymentMethod, + checkIfProjectHasPayment, } from "lib/hooks/useStripe"; import { Context } from "shared/Context"; @@ -61,9 +70,12 @@ const PaymentSetupForm = ({ onCreate }: { onCreate: () => Promise }) => { // Confirm the setup and set as default if (setupIntent?.payment_method !== null) { await setDefaultPaymentMethod(setupIntent?.payment_method as string); + } + + if (currentProject?.sandbox_enabled) { + const { hasPaymentEnabled, refetchPaymentEnabled } = checkIfProjectHasPayment(); - // create cluster on first payment setup for sandbox - if (currentProject?.sandbox_enabled) { + if (!hasPaymentEnabled) { await api.connectProjectToCluster( "", {}, @@ -75,11 +87,13 @@ const PaymentSetupForm = ({ onCreate }: { onCreate: () => Promise }) => { {}, { project_id: currentProject.id } ) + onCreate(); }) .catch((err: any) => { setErrorMessage(err.message); setLoading(false); - }) + return; + }) } }