Skip to content

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

refactor invite user modal

Joshen Lim1972670986d0
diff --git a/studio/components/interfaces/Organization/TeamSettings/InviteMemberModal.tsx b/studio/components/interfaces/Organization/TeamSettings/InviteMemberModal.tsx
index 2bba0184f2f..a0144efc040 100644
--- a/studio/components/interfaces/Organization/TeamSettings/InviteMemberModal.tsx
+++ b/studio/components/interfaces/Organization/TeamSettings/InviteMemberModal.tsx
@@ -1,29 +1,26 @@
-import { Button, Form, IconMail, Input, Modal, Select } from '@supabase/ui'
-import { useOrganizationDetail, useStore } from 'hooks'
-import { get, post } from 'lib/common/fetch'
-import { API_URL } from 'lib/constants'
-import { isNil } from 'lodash'
import { toJS } from 'mobx'
+import { isNil } from 'lodash'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
-import useSWR from 'swr'
-import { Member } from 'types'
import { object, string } from 'yup'
+import { Button, Form, IconMail, Input, Modal, Select } from '@supabase/ui'
+
+import { Member } from 'types'
+import { useOrganizationDetail, useOrganizationRoles, useStore } from 'hooks'
+import { post } from 'lib/common/fetch'
+import { API_URL } from 'lib/constants'
function InviteMemberModal({ organization, members = [], user }: any) {
const [isOpen, setIsOpen] = useState(false)
const [loading, setLoading] = useState(false)
const { ui } = useStore()
-
const router = useRouter()
const { slug } = router.query
+ const { roles } = useOrganizationRoles((slug as string) || '')
const { mutateOrgMembers } = useOrganizationDetail(ui.selectedOrganization?.slug || '')
- // to do: move to a store @joshenlim
- const { data: roles, error: rolesError } = useSWR(`${API_URL}/organizations/${slug}/roles`, get)
-
const initialValues = { email: '', role: '' }
const schema = object({
diff --git a/studio/hooks/queries/useOrganizationRoles.ts b/studio/hooks/queries/useOrganizationRoles.ts
index 87109720fb5..6b5582b5d6b 100644
--- a/studio/hooks/queries/useOrganizationRoles.ts
+++ b/studio/hooks/queries/useOrganizationRoles.ts
@@ -3,6 +3,11 @@ import { get } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { Role } from 'types'
+// [Joshen] Putting roles in a hook for now for simplicity
+// Unless we plan to support CRUD on roles i think it can stay as a hook
+// otherwise, best to shift it to a store. If we do shift it, have it in the
+// App store to prevent confusion with PG roles
+
export function useOrganizationRoles(slug: string) {
const url = `${API_URL}/organizations/${slug}/roles`
const { data, error } = useSWR<any>(url, get)