Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move ccp connection to cc link #4616

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion dashboard/src/main/home/modals/PaymentSetupForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import React, { useState } from "react";
import React, { useState, useContext } from "react";
import {
PaymentElement,
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";

import Button from "components/porter/Button";
import Error from "components/porter/Error";
Expand All @@ -13,9 +22,13 @@ import SaveButton from "components/SaveButton";
import {
useCreatePaymentMethod,
useSetDefaultPaymentMethod,
checkIfProjectHasPayment,
} from "lib/hooks/useStripe";

import { Context } from "shared/Context";

const PaymentSetupForm = ({ onCreate }: { onCreate: () => Promise<void> }) => {
const { currentProject } = useContext(Context);
const stripe = useStripe();
const elements = useElements();

Expand Down Expand Up @@ -59,6 +72,31 @@ const PaymentSetupForm = ({ onCreate }: { onCreate: () => Promise<void> }) => {
await setDefaultPaymentMethod(setupIntent?.payment_method as string);
}

if (currentProject?.sandbox_enabled) {
const { hasPaymentEnabled, refetchPaymentEnabled } = checkIfProjectHasPayment();

if (!hasPaymentEnabled) {
await api.connectProjectToCluster(
"<token>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user adds another payment method, this will create another cluster connection right? Should we limit to one credit card?

{},
{ id: currentProject.id }
)
.then(() => {
api.inviteAdmin(
"<token>",
{},
{ project_id: currentProject.id }
)
onCreate();
})
.catch((err: any) => {
setErrorMessage(err.message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The payment method will be added to Stripe even if this call fails, is there another way to create the cluster if that happens?

setLoading(false);
return;
})
}
}

onCreate();
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling onCreate here also causes the modal to close even when there are errors, I would just wrap everything into a try catch block and only call OnCreate and setLoading(false) after the api calls have completed


Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/main/home/new-project/NewProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ export const NewProjectFC = () => {
}
)
.then((res) => res.data as ProjectListType[]);

setProjects(projectList);
setCurrentProject(project);
trackCreateNewProject();

if (project?.sandbox_enabled) {
await api
.connectProjectToCluster("<token>", {}, { id: project.id })
Expand Down
Loading