Skip to content

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

Update users orgs

Terry Sutton53239f7765f5
diff --git a/studio/pages/org/[slug]/join.tsx b/studio/pages/org/[slug]/join.tsx
index f2edea15348..3efcf2f8b8a 100644
--- a/studio/pages/org/[slug]/join.tsx
+++ b/studio/pages/org/[slug]/join.tsx
@@ -20,10 +20,10 @@ interface TokenInfo {
const User = () => {
const router = useRouter()
const { slug, token } = router.query
- const { ui } = useStore()
- const [isSubmitting, setIsSubmitting] = useState( false )
+ const { app, ui } = useStore()
+ const [isSubmitting, setIsSubmitting] = useState(false)
const [tokenValidationInfo, setTokenValidationInfo] = useState<TokenInfo>()
- const [tokenInfoLoaded, setTokenInfoLoaded] = useState( false )
+ const [tokenInfoLoaded, setTokenInfoLoaded] = useState(false)
const {
token_does_not_exist,
email_match,
@@ -33,56 +33,57 @@ const User = () => {
invite_id,
} = tokenValidationInfo || {}
- useEffect( () => {
+ useEffect(() => {
let cancel = false
async function fetchTokenInfo() {
- const response = await get( `${API_URL}/organizations/${slug}/members/join?token=${token}`, {} )
- if ( !cancel ) {
- setTokenValidationInfo( response )
- setTokenInfoLoaded( true )
+ const response = await get(`${API_URL}/organizations/${slug}/members/join?token=${token}`, {})
+ if (!cancel) {
+ setTokenValidationInfo(response)
+ setTokenInfoLoaded(true)
}
}
- if ( router.query.token ) {
+ if (router.query.token) {
fetchTokenInfo()
}
return () => {
cancel = true
}
- }, [] )
+ }, [])
async function handleJoinOrganization() {
- setIsSubmitting( true )
- const response = await post( `${API_URL}/organizations/${slug}/members/join?token=${token}`, {} )
- if ( response.error ) {
- ui.setNotification( {
+ setIsSubmitting(true)
+ const response = await post(`${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 )
+ })
+ setIsSubmitting(false)
} else {
- setIsSubmitting( false )
- router.push( '/' )
+ setIsSubmitting(false)
+ app.organizations.load()
+ router.push('/')
}
}
async function handleDeclineJoinOrganization() {
- setIsSubmitting( true )
+ setIsSubmitting(true)
const response = await delete_(
`${API_URL}/organizations/${slug}/members/invite?invited_id=${invite_id}`,
{}
)
- if ( response.error ) {
- ui.setNotification( {
+ if (response.error) {
+ ui.setNotification({
category: 'error',
message: `Failed to decline invitation: ${response.error.message}`,
- } )
- setIsSubmitting( false )
+ })
+ setIsSubmitting(false)
} else {
- setIsSubmitting( false )
- router.push( '/' )
+ setIsSubmitting(false)
+ router.push('/')
}
}
@@ -144,15 +145,17 @@ const User = () => {
{tokenInfoLoaded && (
<div className="mt-4 flex gap-4 border-t pt-4 text-sm">
- {token_does_not_exist || !email_match || expired_token && <IconAlertCircle size={24} strokeWidth={2} />}
+ {token_does_not_exist ||
+ !email_match ||
+ (expired_token && <IconAlertCircle size={24} strokeWidth={2} />)}
{token_does_not_exist
? 'The invite token is invalid. Try copying and pasting the link from the invite email, or ask the organization owner to invite you again.'
: !email_match
- ? 'The email address does not match. Are you signed in with right GitHub account?'
- : expired_token
- ? 'The invite token has expired. Please request a new one from the organization owner.'
- : ''}
+ ? 'The email address does not match. Are you signed in with right GitHub account?'
+ : expired_token
+ ? 'The invite token has expired. Please request a new one from the organization owner.'
+ : ''}
</div>
)}
</div>