The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Pull profile info into join screen
Terry Suttonb2acec971c1c
diff --git a/studio/pages/org/[slug]/join.tsx b/studio/pages/org/[slug]/join.tsxindex 104909a6e85..84af61cdcf9 100644--- a/studio/pages/org/[slug]/join.tsx+++ b/studio/pages/org/[slug]/join.tsx@@ -6,57 +6,91 @@ import { NextPageWithLayout } from 'types'import { toJS } from 'mobx'import { Button, Typography } from '@supabase/ui';import { useState } from 'react';-import router, {useRouter} from 'next/router';+import router, { useRouter } from 'next/router';import Link from 'next/link';-+import { API_URL } from 'lib/constants'+import { get } from 'lib/common/fetch'+import { useEffect } from 'react'const User = () => {const router = useRouter()- const { ui } = useStore()+ const {email, slug, token} = router.query;+ const { app, ui } = useStore()const user = ui.profileconst [isSubmitting, setIsSubmitting] = useState( false )- console.log('router', router.query)- console.log('join-a user:', toJS(user))-- return (- <div className="flex h-full min-h-screen w-full flex-col place-items-center items-center justify-center bg-secondary px-3">- <div className="mt-16 space-y-4 p-12 max-w-md mx-auto border-2 rounded-md ">- <div className="space-y-4">- <Link href="/">- <a className="flex items-center gap-4">- <img- src="/img/supabase-logo.svg"- alt="Supabase"- className="h-[30px] block cursor-pointer rounded"- />- <Typography.Title level={3} className="mb-0">Supabase</Typography.Title>-- </a>- </Link>-- <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>+ // console.log( 'router', router.query )+ // console.log( 'join-a user:', toJS( user ) )+ console.log( 'ui org slug:', toJS( ui.selectedOrganization?.slug ) )- <div className='flex items-center gap-2 mt-8'>- <Button htmlType="submit" loading={isSubmitting} size="small">- Join this organization- </Button>+ //console.log('org name: ', toJS(app.organizations.data['91']))+ //console.log('org name: ', toJS(app.organizations.list()))++ // const organizationsLinks = app.organizations+ // .list()+ // .map((x: any) => ({+ // isActive: router.pathname.startsWith('/org/') && ui.selectedOrganization?.slug == x.slug,+ // label: x.name,+ // href: `/org/${x.slug}/settings`,+ // }))- <Button htmlType="submit" loading={isSubmitting} size="small" type="text">- Decline- </Button>- </div>- </div>- </div>- )-}+ async function handleSubmitForm() {+ setIsSubmitting( true )-export default withAuth(observer(User))+ // curl -X GET 'http://localhost:8080/platform/organizations/slug/members/join?token=XXX'+ const response = await get( `${API_URL}/organizations/${slug}/members/join?token=${token}`, {} )+ if ( response.error ) {+ ui.setNotification( {+ category: 'error',+ message: `Failed to join organization: ${response.error.message}`,+ } )+ setIsSubmitting( false )+ } else {+ setIsSubmitting( false )+ router.push( '/' )+ }+ }+ return (+ <div className="flex flex-col items-center justify-center w-full h-full min-h-screen px-3 place-items-center bg-secondary">+ <div className="max-w-md p-12 mx-auto mt-16 space-y-4 border-2 rounded-md ">+ <div className="space-y-4">+ <Link href="/">+ <a className="flex items-center gap-4">+ <img+ src="/img/supabase-logo.svg"+ alt="Supabase"+ className="h-[30px] block cursor-pointer rounded"+ />+ <Typography.Title level={3} className="mb-0">Supabase</Typography.Title>+ </a>+ </Link>+ <h2 className="text-xl">Join ORG NAME</h2>+ <p className="text-md">We sent an invite code to <u>{email}</u> to join this organization.</p>+ </div>+ {/* Check that the user in the query param matches the current logged in users email */}+ {user && user?.primary_email == email && (+ <div className='flex items-center gap-2 mt-8'>+ <Button onClick={handleSubmitForm} htmlType="submit" loading={isSubmitting} size="small">+ Join this organization+ </Button>++ <Button htmlType="submit" loading={isSubmitting} size="small" type="text">+ Decline+ </Button>+ </div>+ )}++ {user?.primary_email !== email && (+ <div className='pt-4 mt-4 border-t'>Sign to that account to accept this invitation.</div>+ )}+ </div>+ </div>+ )+}+export default withAuth( observer( User ) )\ No newline at end of filediff --git a/studio/pages/org/[slug]/join2.tsx b/studio/pages/org/[slug]/join2.tsxnew file mode 100644index 00000000000..73fa0931794--- /dev/null+++ b/studio/pages/org/[slug]/join2.tsx@@ -0,0 +1,138 @@++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 { getAccessToken, get } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'+import { Transition } from '@headlessui/react';+import { useEffect } from 'react';++const JoinOrg: NextPageWithLayout = () => {+ const router = useRouter();+ const slug = router.query.slug;+ console.log(router);+ 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>+ </div>+ </div>+ )+}++const InviteCodeInput = () => {+ const router = useRouter();+ const slug = router.query.slug;+ const { ui } = useStore()+ const [result, setResult] = useState('');+ 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 );++ useEffect(() => {+ if(router.query.token) {+ console.log('yup')+ setResult(router.query.token)+ }+ })+ 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 ) {+ //const access_token = getAccessToken()+ e.preventDefault();+ setIsSubmitting( true )++ // Need proper endpoint+ const response = await get( `${API_URL}/organizations/${slug}/join?token=${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='alphanumeric'+ onChange={handleOnChange}+ length={15}+ autoFocus={true}+ containerClassName="join-auth-code-container flex items-center max-w-full"+ inputClassName="w-[34px]"+ /> */}++ <div className='flex items-center gap-2 mt-8'>+ <Button disabled={!isValidInviteCode} htmlType="submit" loading={isSubmitting} size="small">+ Join this organization+ </Button>++ <Button htmlType="submit" loading={isSubmitting} size="small" type="text">+ Decline+ </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