Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Adds a new join page

Terry Suttond95d668c6799
diff --git a/studio/hooks/queries/useOrganizationDetail.ts b/studio/hooks/queries/useOrganizationDetail.ts
index 5941957cfd8..cb492e62123 100644
--- a/studio/hooks/queries/useOrganizationDetail.ts
+++ b/studio/hooks/queries/useOrganizationDetail.ts
@@ -6,7 +6,26 @@ import { API_URL } from 'lib/constants'
export function useOrganizationDetail(slug: string) {
const url = `${API_URL}/props/org/${slug}`
const { data, error } = useSWR<any>(url, get)
- const { members, products } = data ?? []
+ let { members, products } = data ?? []
+ if (data) {
+
+ members = [...members,
+ {
+ id: 200,
+ is_owner: false,
+ profile: {
+ id: 98, username: 'supaterry', primary_email: '[email protected]', expired: true
+ }
+ },
+ {
+ id: 201,
+ is_owner: false,
+ profile: {
+ id: 99, username: 'timapple', primary_email: '[email protected]', expired: true
+ }
+ },
+ ]
+}
const anyError = data?.error || error
function mutateOrgMembers(updatedMembers: Member[], revalidate?: boolean) {
diff --git a/studio/package-lock.json b/studio/package-lock.json
index fb454e8e61b..a451cee0252 100644
--- a/studio/package-lock.json
+++ b/studio/package-lock.json
@@ -46,6 +46,7 @@
"path-to-regexp": "^6.2.0",
"prism-react-renderer": "^1.2.1",
"react": "^17.0.2",
+ "react-auth-code-input": "^3.2.0",
"react-beautiful-dnd": "^13.1.0",
"react-contexify": "^5.0.0",
"react-csv": "^2.0.3",
@@ -22864,6 +22865,17 @@
"node": ">=0.10.0"
}
},
+ "node_modules/react-auth-code-input": {
+ "version": "3.2.0",
+ "resolved": "https://registry.npmjs.org/react-auth-code-input/-/react-auth-code-input-3.2.0.tgz",
+ "integrity": "sha512-ctTudLbvX//4OiX3nRMAWMD3h84ROQzY+lzO09SFJ54L+w8lOl0yV6hFTyPD9drT/eVgfZScpCGlN+R5b3x/nw==",
+ "engines": {
+ "node": ">=10"
+ },
+ "peerDependencies": {
+ "react": ">=16.0.0"
+ }
+ },
"node_modules/react-beautiful-dnd": {
"version": "13.1.0",
"resolved": "https://registry.npmjs.org/react-beautiful-dnd/-/react-beautiful-dnd-13.1.0.tgz",
@@ -46503,6 +46515,12 @@
"object-assign": "^4.1.1"
}
},
+ "react-auth-code-input": {
+ "version": "3.2.0",
+ "resolved": "https://registry.npmjs.org/react-auth-code-input/-/react-auth-code-input-3.2.0.tgz",
+ "integrity": "sha512-ctTudLbvX//4OiX3nRMAWMD3h84ROQzY+lzO09SFJ54L+w8lOl0yV6hFTyPD9drT/eVgfZScpCGlN+R5b3x/nw==",
+ "requires": {}
+ },
"react-beautiful-dnd": {
"version": "13.1.0",
"resolved": "https://registry.npmjs.org/react-beautiful-dnd/-/react-beautiful-dnd-13.1.0.tgz",
diff --git a/studio/package.json b/studio/package.json
index 9351e173452..7d0090d648f 100644
--- a/studio/package.json
+++ b/studio/package.json
@@ -50,6 +50,7 @@
"path-to-regexp": "^6.2.0",
"prism-react-renderer": "^1.2.1",
"react": "^17.0.2",
+ "react-auth-code-input": "^3.2.0",
"react-beautiful-dnd": "^13.1.0",
"react-contexify": "^5.0.0",
"react-csv": "^2.0.3",
diff --git a/studio/pages/_app.tsx b/studio/pages/_app.tsx
index 9420bc43e17..9b4d0badaa7 100644
--- a/studio/pages/_app.tsx
+++ b/studio/pages/_app.tsx
@@ -10,6 +10,7 @@ import 'styles/contextMenu.scss'
import 'styles/react-data-grid-logs.scss'
import 'styles/date-picker.scss'
import 'styles/grid.scss'
+import 'styles/join-organization-auth-code.scss'
import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
diff --git a/studio/pages/org/[slug]/join.tsx b/studio/pages/org/[slug]/join.tsx
new file mode 100644
index 00000000000..1b348d6198b
--- /dev/null
+++ b/studio/pages/org/[slug]/join.tsx
@@ -0,0 +1,118 @@
+import { AccountLayout } from 'components/layouts'
+import { NextPageWithLayout } from 'types'
+import AuthCode, { AuthCodeRef } from 'react-auth-code-input';
+import { useState } from 'react';
+import { useRef } from 'react';
+import { Button } from '@supabase/ui';
+import router, {useRouter} from 'next/router';
+import { useOrganizationDetail, useStore } from 'hooks'
+import { post, } from 'lib/common/fetch'
+import { API_URL } from 'lib/constants'
+import { Transition } from '@headlessui/react';
+
+const JoinOrg: NextPageWithLayout = () => {
+ const router = useRouter();
+ const slug = router.query.slug;
+ return (
+ <div className="mt-8 space-y-4 p-4 pt-0">
+ <div className="space-y-4">
+ <h2 className="text-xl">Join organization</h2>
+ <p className="text-md">We sent an invite code to <u>[email protected]</u> to join this organization.</p>
+ </div>
+
+ <div className='mt-12'>
+ <p className="text-md my-6">Enter or paste the code to join:</p>
+ <div className='mb-6'>
+ <InviteCodeInput />
+ </div>
+
+ <p className='mt-8 text-scale-900 text-sm'>Didn't get the email? <u>Resend the code</u></p>
+ </div>
+ </div>
+ )
+}
+
+const InviteCodeInput = () => {
+ const router = useRouter();
+ const slug = router.query.slug;
+ const { ui } = useStore()
+ const [result, setResult] = useState<string | null>();
+ const [isValidInviteCode, setIsValidInviteCode] = useState( false );
+ const [isInputDirty, setIsInputDirty] = useState( false );
+ const [isSubmitting, setIsSubmitting] = useState( false )
+ const AuthInputRef = useRef<AuthCodeRef>( null );
+ const AuthInputFormRef = useRef<HTMLFormElement>( null );
+
+
+ function handleOnChange( res: string ) {
+ res.length < 15 ? setIsValidInviteCode(false) : setIsValidInviteCode(true)
+ res.length > 0 ? setIsInputDirty(true) : setIsInputDirty(false)
+ setResult( res );
+ };
+
+ async function handleSubmitForm( e: any ) {
+ e.preventDefault();
+ setIsSubmitting( true )
+
+ // Need proper endpoint
+ const response = await post( `${API_URL}/organizations/${slug}/join?code=${result}`, {} )
+ if ( response.error ) {
+ ui.setNotification( {
+ category: 'error',
+ message: `Failed to join organization: ${response.error.message}`,
+ } )
+ setIsSubmitting( false )
+ } else {
+ setIsSubmitting( false )
+ router.push( '/' )
+ }
+ }
+
+ return (
+ <form onSubmit={handleSubmitForm} ref={AuthInputFormRef}>
+ <div>
+ <AuthCode ref={AuthInputRef} allowedCharacters='alpha' onChange={handleOnChange} length={15} autoFocus={true} containerClassName="join-auth-code-container flex items-center max-w-full" inputClassName="w-[44px]" />
+
+ <div className='flex items-center gap-2 mt-8'>
+ <Button disabled={!isValidInviteCode} htmlType="submit" loading={isSubmitting} size="small">
+ Join this organization
+ </Button>
+
+
+ <Transition
+ show={isInputDirty}
+ enter="transition ease-out duration-500"
+ enterFrom="transform opacity-0 -translate-x-10"
+ enterTo="transform opacity-100 translate-x-0"
+ >
+ <Button
+ htmlType="reset"
+ type='text'
+ size="small"
+ onClick={() => AuthInputRef.current?.clear()}
+ >
+ Clear
+ </Button>
+ </Transition>
+
+ </div>
+ </div>
+ </form>
+ );
+}
+
+JoinOrg.getLayout = ( page ) => (
+ <AccountLayout
+ title="Join Org"
+ breadcrumbs={[
+ {
+ key: `join-org`,
+ label: 'Join Org',
+ },
+ ]}
+ >
+ {page}
+ </AccountLayout>
+)
+
+export default JoinOrg
diff --git a/studio/pages/org/[slug]/settings.tsx b/studio/pages/org/[slug]/settings.tsx
index a8b1d97e5f4..2870685bc87 100644
--- a/studio/pages/org/[slug]/settings.tsx
+++ b/studio/pages/org/[slug]/settings.tsx
@@ -1,5 +1,5 @@
import { createContext, useEffect, useContext, useState } from 'react'
-import { useRouter } from 'next/router'
+import router, { useRouter } from 'next/router'
import { observer, useLocalObservable } from 'mobx-react-lite'
import { toJS } from 'mobx'
import { pluckJsonSchemaFields, pluckObjectFields, timeout } from 'lib/helpers'
@@ -59,10 +59,12 @@ const OrgSettingsLayout = withAuth(
get filteredMembers() {
const temp = this.members.filter((x: any) => {
let profile = x.profile
- return (
- profile.username.includes(this.membersFilterString) ||
- profile.primary_email.includes(this.membersFilterString)
- )
+ if(profile) {
+ return (
+ profile.username.includes(this.membersFilterString) ||
+ profile.primary_email.includes(this.membersFilterString)
+ )
+ }
})
return temp.sort((a: any, b: any) => a.profile.username.localeCompare(b.profile.username))
},
@@ -125,15 +127,16 @@ export default observer(OrgSettings)
const OrganizationSettings = observer(() => {
const PageState: any = useContext(PageContext)
const { ui } = useStore()
+
const {
- members,
+ members,// members retrieved here
products,
isError: isOrgDetailError,
} = useOrganizationDetail(ui.selectedOrganization?.slug || '')
useEffect(() => {
if (!isOrgDetailError) {
- PageState.members = members ?? []
+ PageState.members = members ?? [] // members retrieved here
PageState.products = products ?? []
}
}, [members, products, isOrgDetailError])
@@ -150,10 +153,39 @@ const OrganizationSettings = observer(() => {
const TabsView = observer(() => {
const { ui, app } = useStore()
const [selectedTab, setSelectedTab] = useState('GENERAL')
-
+ console.log(router)
const organization = ui.selectedOrganization
const projects = app.projects.list((x: Project) => x.organization_id == organization?.id)
+ // useEffect(() => {
+ // if (window.location.hash) {
+ // console.log('has hash')
+ // changeTab(window.location.hash.slice(1).toUpperCase());
+ // console.log(window.location.hash.slice(1).toUpperCase())
+ // }
+ // },[])
+
+ // function onHashChangeStart() {
+ // console.log('route changed')
+ // changeTab(window.location.hash);
+ // }
+
+// useEffect(() => {
+// const onHashChangeStart = () => {
+// console.log(`Path changing`);
+// };
+
+// router.events.on("hashChangeStart", onHashChangeStart);
+
+// return () => {
+// router.events.off("hashChangeStart", onHashChangeStart);
+// };
+// }, [router.events]);
+
+ // function changeTab(id: any) {
+ // //router.push(`/org/${toJS(PageState.organization.slug)}/settings#${id.toLowerCase()}`)
+ // }
+
return (
<>
<div className="space-y-3">
@@ -472,6 +504,7 @@ const invite_status = 'pending';
const MembersView = observer(() => {
const PageState: any = useContext(PageContext)
+ console.log(toJS(PageState.members))
return (
<div className="rounded">
@@ -509,11 +542,12 @@ const MembersView = observer(() => {
</Table.td>
<Table.td>
- {!x.is_owner && invite_status === 'pending' && <Badge color="yellow">Pending</Badge>}
+ {x.profile.expired ? <Badge color="red">Expired</Badge> : <Badge color="yellow">Invited</Badge>}
</Table.td>
<Table.td>
<Typography.Text type="secondary">
+ {console.log(x)}
{x.is_owner ? 'Owner' : 'Developer'}
</Typography.Text>
</Table.td>