mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
handle validation
This commit is contained in:
1 parent
eec5c6f1f3
commit
414bc60bc8
4 files changed
+77
-16
No files matched your search
+23
-3
@@ -302,16 +302,36 @@ export class Billing {
|
||||
);
|
||||
}
|
||||
|
||||
async validateOrganization(
|
||||
organizationId: string,
|
||||
invites: string[],
|
||||
): Promise<Organization> {
|
||||
const path = `/organizations/${organizationId}/validate`;
|
||||
const params = {
|
||||
organizationId,
|
||||
invites,
|
||||
};
|
||||
const uri = new URL(this.client.config.endpoint + path);
|
||||
return await this.client.call(
|
||||
'PATCH',
|
||||
uri,
|
||||
{
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
async createOrganization(
|
||||
organizationId: string,
|
||||
name: string,
|
||||
billingPlan: string,
|
||||
paymentMethodId: string,
|
||||
billingAddressId: string = undefined,
|
||||
couponId: string = undefined,
|
||||
billingAddressId: string = null,
|
||||
couponId: string = null,
|
||||
invites: Array<string> = [],
|
||||
budget: number = undefined,
|
||||
taxId: string = undefined
|
||||
taxId: string = null
|
||||
): Promise<Organization | CreateOrgAuth> {
|
||||
const path = `/organizations`;
|
||||
const params = {
|
||||
|
||||
@@ -116,7 +116,8 @@ export async function confirmPayment(
|
||||
orgId: string,
|
||||
clientSecret: string,
|
||||
paymentMethodId: string,
|
||||
route?: string
|
||||
route?: string,
|
||||
returnError: boolean = false
|
||||
) {
|
||||
try {
|
||||
const url =
|
||||
@@ -128,10 +129,13 @@ export async function confirmPayment(
|
||||
clientSecret: clientSecret,
|
||||
confirmParams: {
|
||||
return_url: url,
|
||||
payment_method: paymentMethod.providerMethodId
|
||||
}
|
||||
payment_method: paymentMethod.providerMethodId,
|
||||
},
|
||||
});
|
||||
if (error) {
|
||||
if (returnError) {
|
||||
return error;
|
||||
}
|
||||
throw error.message;
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -88,6 +88,14 @@
|
||||
if (anyOrgFree) {
|
||||
billingPlan = BillingPlan.PRO;
|
||||
}
|
||||
if($page.url.searchParams.has('type')) {
|
||||
const type = $page.url.searchParams.get('type');
|
||||
if(type === 'confirmed') {
|
||||
const organizationId= $page.url.searchParams.get('id');
|
||||
const invites = $page.url.searchParams.getAll('invites');
|
||||
await validate(organizationId, invites);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
async function loadPaymentMethods() {
|
||||
@@ -99,6 +107,27 @@
|
||||
return (org as Organization).$id !== undefined;
|
||||
}
|
||||
|
||||
async function validate(organizationId: string, invites: string[]) {
|
||||
try {
|
||||
let org = await sdk.forConsole.billing.validateOrganization(organizationId, invites);
|
||||
if (isOrganization(org)) {
|
||||
await preloadData(`${base}/console/organization-${org.$id}`);
|
||||
await goto(`${base}/console/organization-${org.$id}`);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${org.name ?? 'Organization'} has been created`
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: e.message
|
||||
});
|
||||
trackError(e, Submit.OrganizationCreate);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function create() {
|
||||
try {
|
||||
let org: Organization | CreateOrgAuth;
|
||||
@@ -126,8 +155,15 @@
|
||||
|
||||
if (!isOrganization(org) && org.status == 402) {
|
||||
let clientSecret = org.clientSecret;
|
||||
await confirmPayment('', clientSecret, paymentMethodId);
|
||||
// throw new Error('Payment requires authentication');
|
||||
let params = new URLSearchParams();
|
||||
params.append('type', 'confirmed');
|
||||
params.append('id', org.teamId);
|
||||
for (let index = 0; index < collaborators.length; index++) {
|
||||
const invite = collaborators[index];
|
||||
params.append('invites', invite);
|
||||
}
|
||||
await confirmPayment('', clientSecret, paymentMethodId, '/console/create-organization?'+params.toString());
|
||||
await validate(org.teamId, collaborators);
|
||||
}
|
||||
|
||||
//Add budget
|
||||
@@ -167,13 +203,15 @@
|
||||
members_invited: collaborators?.length
|
||||
});
|
||||
|
||||
await invalidate(Dependencies.ACCOUNT);
|
||||
await preloadData(`${base}/console/organization-${org.$id}`);
|
||||
await goto(`${base}/console/organization-${org.$id}`);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${name ?? 'Organization'} has been created`
|
||||
});
|
||||
if(isOrganization(org)) {
|
||||
await invalidate(Dependencies.ACCOUNT);
|
||||
await preloadData(`${base}/console/organization-${org.$id}`);
|
||||
await goto(`${base}/console/organization-${org.$id}`);
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: `${org.name ?? 'Organization'} has been created`
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
invoiceList = await sdk.forConsole.billing.listInvoices($page.params.organization, [
|
||||
Query.limit(limit),
|
||||
Query.offset(offset),
|
||||
Query.notEqual('from', $organization.billingCurrentInvoiceDate),
|
||||
Query.orderDesc('$createdAt')
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user