import { runInAction } from 'mobx'
import { observer, useLocalObservable } from 'mobx-react-lite'
import { useRouter } from 'next/router'
import { ChangeEvent, createContext, useContext, useEffect, useState } from 'react'
import { Button, Input, Select } from 'ui'
import VercelIntegrationLayout from 'components/layouts/VercelIntegrationLayout'
import { useOrganizationCreateMutation } from 'data/organizations/organization-create-mutation'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
const PageContext = createContext(null)
function SetupOrg() {
const PageState = useLocalObservable(() => ({
token: '',
teamId: '',
externalId: '',
configurationId: '',
next: '',
selectedOrg: undefined,
vercelProjectId: undefined,
selectMenuOpened: false,
shouldShowOrgCreationUI: false,
get queryParams() {
return {
token: this.token,
teamId: this.teamId,
'external-id': this.externalId,
configurationId: this.configurationId,
// @ts-ignore
supabaseOrgId: this.selectedOrg.id,
vercelProjectId: this.vercelProjectId,
next: this.next,
}
},
get canContinue() {
return !!this.selectedOrg
},
loadInitialData() {
this.getQueryParams()
},
getQueryParams() {
const params = new URLSearchParams(window.location.search)
this.configurationId = params.get('configurationId') as string
this.vercelProjectId = params.get('vercelProjectId') as any
this.next = params.get('next') as string
this.externalId = params.get('external-id') as string
this.token = params.get('token') as string
this.teamId = params.get('teamId') as string
},
toggleSelectMenu(value: any) {
this.selectMenuOpened = value
},
}))
const { data: organizations } = useOrganizationsQuery()
useEffect(() => {
PageState.loadInitialData()
PageState.shouldShowOrgCreationUI = organizations?.length == 0
}, [organizations])
return (
// @ts-ignore
Create a new organization
) : ( <>You do not have any organization
You will need an organization to deploy this project
> )}