diff --git a/tfweb/src/lib/i18n/en.json b/tfweb/src/lib/i18n/en.json index 74cda5c..7b3d1fd 100644 --- a/tfweb/src/lib/i18n/en.json +++ b/tfweb/src/lib/i18n/en.json @@ -92,6 +92,10 @@ "subnetprompt": "What subnets would you like to allow?", "subnethelp": "Comma-separated list of subnets in CIDR notation. This will constrain which subnets can be applied to client certs. Default: empty (any)", "groupprompt": "What groups would you like to allow?", - "grouphelp": "Comma-separated list of groups. This will constrain which groups can be applied to client certs. Default: empty (any)" + "grouphelp": "Comma-separated list of groups. This will constrain which groups can be applied to client certs. Default: empty (any)", + "apierror": { + "orgcreate": "Unable to create organization", + "TypeError: NetworkError when attempting to fetch resource": "Unable to contact the backend. Please try again later." + } } } \ No newline at end of file diff --git a/tfweb/src/lib/util.ts b/tfweb/src/lib/util.ts index 2a17aba..b78c055 100644 --- a/tfweb/src/lib/util.ts +++ b/tfweb/src/lib/util.ts @@ -1,4 +1,4 @@ -export async function fetch_timeout(resource: RequestInfo | URL, options = {}) { +export async function fetch_timeout(resource: RequestInfo | URL, options: RequestInit | undefined = {}) { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const { timeout = 8000 } = options; diff --git a/tfweb/src/routes/org/new/+page.svelte b/tfweb/src/routes/org/new/+page.svelte index a3bf266..137bca5 100644 --- a/tfweb/src/routes/org/new/+page.svelte +++ b/tfweb/src/routes/org/new/+page.svelte @@ -8,6 +8,8 @@ import {get_user_info} from "$lib/auth"; import {org} from "$lib/orgs"; import type {Organization} from "$lib/orgs"; + import {API_ROOT} from "$lib/config"; + import {fetch_timeout} from "$lib/util"; let logger = new Logger("admin/+page.svelte"); logSetup(); @@ -73,8 +75,34 @@ let showAdditionalConstraints = false; - function newOrg() { - + async function doCreateFlow() { + // STEP ONE: Create the org + logger.info("Creating base organization"); + let created_org_id; + try { + let resp = await fetch_timeout(`${API_ROOT}/v1/org`, { + 'method': 'POST', + 'headers': { + 'Authorization': 'Bearer ' + api_token + } + }); + if (resp.code !== 200) { + let err = await resp.json().errors[0].message; + logger.error(`${await resp.json().errors[0]}`); + fullPageError = true; + fullPageErrorTitle = t('neworg.apierror.orgcreate'); + fullPageErrorSubtitle = t('neworg.apierror.' + err); + return; + } + created_org_id = resp.json().org_id; + logger.info("Able to create base organization with id " + created_org_id); + } catch (e) { + logger.error(`${e}`); + fullPageError = true; + fullPageErrorTitle = t('neworg.apierror.orgcreate'); + fullPageErrorSubtitle = t('neworg.apierror.' + `${e}`.replaceAll('.', '')); + return; + } } @@ -90,7 +118,7 @@