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 4 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
26 changes: 25 additions & 1 deletion dashboard/src/main/home/modals/PaymentSetupForm.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -15,7 +16,10 @@ import {
useSetDefaultPaymentMethod,
} 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 @@ -57,6 +61,26 @@ const PaymentSetupForm = ({ onCreate }: { onCreate: () => Promise<void> }) => {
// 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(
"<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 }
)
})
.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);
})
}
}

onCreate();
Expand Down
30 changes: 3 additions & 27 deletions dashboard/src/main/home/new-project/NewProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,36 +97,12 @@ 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 }
)
.then(() => {
api.inviteAdmin(
"<token>",
{},
{ 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);
Expand Down
Loading