Skip to content

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

Small refactors after testing org oauth apps settings

Joshen Lim7a417dadf21e
diff --git a/studio/components/interfaces/Organization/OAuthApps/DeleteAppModal.tsx b/studio/components/interfaces/Organization/OAuthApps/DeleteAppModal.tsx
index d0e3ee7b9e0..7e72ca16a5e 100644
--- a/studio/components/interfaces/Organization/OAuthApps/DeleteAppModal.tsx
+++ b/studio/components/interfaces/Organization/OAuthApps/DeleteAppModal.tsx
@@ -18,19 +18,12 @@ const DeleteAppModal = ({ selectedApp, onClose }: DeleteAppModalProps) => {
if (!slug) return console.error('Slug is required')
if (!selectedApp?.id) return console.error('App ID is required')
- try {
- await deleteOAuthApp({ slug, id: selectedApp?.id })
- ui.setNotification({
- category: 'success',
- message: `Successfully deleted the app "${selectedApp?.name}"`,
- })
- onClose()
- } catch (error) {
- ui.setNotification({
- category: 'error',
- message: `Failed to delete OAuth app: ${(error as any).message}`,
- })
- }
+ await deleteOAuthApp({ slug, id: selectedApp?.id })
+ ui.setNotification({
+ category: 'success',
+ message: `Successfully deleted the app "${selectedApp?.name}"`,
+ })
+ onClose()
}
return (
diff --git a/studio/components/interfaces/Organization/OAuthApps/OAuthAppRow.tsx b/studio/components/interfaces/Organization/OAuthApps/OAuthAppRow.tsx
index 52765963ce2..6157cf4748d 100644
--- a/studio/components/interfaces/Organization/OAuthApps/OAuthAppRow.tsx
+++ b/studio/components/interfaces/Organization/OAuthApps/OAuthAppRow.tsx
@@ -32,26 +32,40 @@ const OAuthAppRow = ({ app, onSelectEdit, onSelectDelete }: OAuthAppRowProps) =>
{!!app.icon ? '' : `${app.name[0]}`}
</div>
</Table.td>
- <Table.td>{app.name}</Table.td>
<Table.td>
- <span className="font-mono truncate">{app.client_id}</span>
- <Button
- type="default"
- icon={
- isCopied ? <IconCheck className="text-brand-900" strokeWidth={3} /> : <IconClipboard />
- }
- className="ml-2 px-1"
- onClick={() => {
- copyToClipboard(app.client_id)
- setIsCopied(true)
- setTimeout(() => {
- setIsCopied(false)
- }, 3000)
- }}
- />
+ <p title={app.name} className="truncate">
+ {app.name}
+ </p>
</Table.td>
<Table.td>
- <span className="font-mono">{app.client_secret_alias}...</span>
+ <div className="flex items-center">
+ <p className="font-mono truncate w-[220px]" title={app.client_id}>
+ {app.client_id}
+ </p>
+ <Button
+ type="default"
+ icon={
+ isCopied ? (
+ <IconCheck className="text-brand-900" strokeWidth={3} />
+ ) : (
+ <IconClipboard />
+ )
+ }
+ className="ml-2 px-1"
+ onClick={() => {
+ copyToClipboard(app.client_id)
+ setIsCopied(true)
+ setTimeout(() => {
+ setIsCopied(false)
+ }, 3000)
+ }}
+ />
+ </div>
+ </Table.td>
+ <Table.td>
+ <span className="font-mono" title={app.client_secret_alias}>
+ {app.client_secret_alias}...
+ </span>
</Table.td>
<Table.td>{dayjs(app.created_at).format('DD/MM/YYYY, HH:mm:ss')}</Table.td>
<Table.td align="right">
diff --git a/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx b/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx
index 73505311f17..f976597b385 100644
--- a/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx
+++ b/studio/components/interfaces/Organization/OAuthApps/OAuthApps.tsx
@@ -22,14 +22,15 @@ import { ScaffoldContainerLegacy } from 'components/layouts/Scaffold'
const OAuthApps = () => {
const { slug } = useParams()
- const [createdApp, setCreatedApp] = useState<OAuthAppCreateResponse>()
const [showPublishModal, setShowPublishModal] = useState(false)
+ const [createdApp, setCreatedApp] = useState<OAuthAppCreateResponse>()
const [selectedAppToUpdate, setSelectedAppToUpdate] = useState<OAuthApp>()
const [selectedAppToDelete, setSelectedAppToDelete] = useState<OAuthApp>()
const [selectedAppToRevoke, setSelectedAppToRevoke] = useState<AuthorizedApp>()
const {
data: publishedApps,
+ error: publishedAppsError,
isLoading: isLoadingPublishedApps,
isSuccess: isSuccessPublishedApps,
isError: isErrorPublishedApps,
@@ -53,7 +54,7 @@ const OAuthApps = () => {
return (
<>
<ScaffoldContainerLegacy>
- <div>
+ <div className="space-y-4">
<div className="flex items-center justify-between">
<div>
<p>Published Apps</p>
@@ -75,7 +76,10 @@ const OAuthApps = () => {
)}
{isErrorPublishedApps && (
- <AlertError className="mt-4" subject="Failed to retrieve published OAuth apps" />
+ <AlertError
+ error={publishedAppsError}
+ subject="Failed to retrieve published OAuth apps"
+ />
)}
{createdApp !== undefined && (
@@ -98,7 +102,6 @@ const OAuthApps = () => {
copy
readOnly
size="small"
- // layout="horizontal"
label="Client ID"
className="max-w-xl input-mono"
value={createdApp.client_id}
@@ -108,7 +111,6 @@ const OAuthApps = () => {
copy
readOnly
size="small"
- // layout="horizontal"
label="Client secret"
className="max-w-xl input-mono"
value={createdApp.client_secret}
@@ -127,13 +129,12 @@ const OAuthApps = () => {
</div>
) : (
<Table
- className="mt-4"
head={[
<Table.th key="icon" className="w-[30px]"></Table.th>,
<Table.th key="name">Name</Table.th>,
<Table.th key="client-id">Client ID</Table.th>,
<Table.th key="client-secret">Client Secret</Table.th>,
- <Table.th key="client-secret">Created at</Table.th>,
+ <Table.th key="created-at">Created at</Table.th>,
<Table.th key="delete-action"></Table.th>,
]}
body={
diff --git a/studio/components/interfaces/Organization/OAuthApps/PublishAppSidePanel.tsx b/studio/components/interfaces/Organization/OAuthApps/PublishAppSidePanel.tsx
index de1f900066d..6ed4b3a5cb6 100644
--- a/studio/components/interfaces/Organization/OAuthApps/PublishAppSidePanel.tsx
+++ b/studio/components/interfaces/Organization/OAuthApps/PublishAppSidePanel.tsx
@@ -14,26 +14,27 @@ import { Badge, Button, Dropdown, Form, IconEdit, IconUpload, Input, Modal, Side
import { uploadAttachment } from 'lib/upload'
import AuthorizeRequesterDetails from './AuthorizeRequesterDetails'
-export interface PublishAppModalProps {
+export interface PublishAppSidePanelProps {
visible: boolean
selectedApp?: OAuthApp
onClose: () => void
onCreateSuccess: (app: OAuthAppCreateResponse) => void
}
-const PublishAppModal = ({
+const PublishAppSidePanel = ({
visible,
selectedApp,
onClose,
onCreateSuccess,
-}: PublishAppModalProps) => {
+}: PublishAppSidePanelProps) => {
const { ui } = useStore()
const { slug } = useParams()
const uploadButtonRef = useRef<any>()
- const { mutateAsync: createOAuthApp, isLoading: isCreating } = useOAuthAppCreateMutation()
- const { mutateAsync: updateOAuthApp, isLoading: isUpdating } = useOAuthAppUpdateMutation()
- const isSubmitting = isCreating || isUpdating
+ const { mutateAsync: createOAuthApp } = useOAuthAppCreateMutation()
+ const { mutateAsync: updateOAuthApp } = useOAuthAppUpdateMutation()
+ // [Joshen] Separate submitting state as there are additional async logic involved in the creation
+ const [isSubmitting, setIsSubmitting] = useState(false)
const [showPreview, setShowPreview] = useState(false)
const [iconFile, setIconFile] = useState<File>()
const [iconUrl, setIconUrl] = useState<string>()
@@ -43,6 +44,7 @@ const PublishAppModal = ({
useEffect(() => {
if (visible) {
setErrors({})
+ setIsSubmitting(false)
setIconFile(undefined)
if (selectedApp !== undefined) {
@@ -100,42 +102,49 @@ const PublishAppModal = ({
setErrors({})
}
+ setIsSubmitting(true)
const { name, website } = values
const uploadedIconUrl =
iconFile !== undefined
? await uploadAttachment('oauth-app-icons', `${slug}/${uuidv4()}.png`, iconFile)
: iconUrl
- if (selectedApp === undefined) {
- // Create application
- const res = await createOAuthApp({
- slug,
- name,
- website,
- redirect_uris,
- icon: uploadedIconUrl,
- })
- ui.setNotification({
- category: 'success',
- message: `Successfully created OAuth app "${name}"!`,
- })
- onClose()
- onCreateSuccess(res)
- } else {
- // Update application
- await updateOAuthApp({
- id: selectedApp.id,
- slug,
- name,
- website,
- redirect_uris,
- icon: uploadedIconUrl === undefined ? null : uploadedIconUrl,
- })
- ui.setNotification({
- category: 'success',
- message: `Successfully updated OAuth app "${name}"!`,
- })
- onClose()
+ try {
+ if (selectedApp === undefined) {
+ // Create application
+ const res = await createOAuthApp({
+ slug,
+ name,
+ website,
+ redirect_uris,
+ icon: uploadedIconUrl,
+ })
+ ui.setNotification({
+ category: 'success',
+ message: `Successfully created OAuth app "${name}"!`,
+ })
+ onClose()
+ onCreateSuccess(res)
+ } else {
+ // Update application
+ await updateOAuthApp({
+ id: selectedApp.id,
+ slug,
+ name,
+ website,
+ redirect_uris,
+ icon: uploadedIconUrl === undefined ? null : uploadedIconUrl,
+ })
+ ui.setNotification({
+ category: 'success',
+ message: `Successfully updated OAuth app "${name}"!`,
+ })
+ onClose()
+ setIsSubmitting(false)
+ }
+ } catch (error) {
+ } finally {
+ setIsSubmitting(false)
}
}
@@ -370,4 +379,4 @@ const PublishAppModal = ({
)
}
-export default PublishAppModal
+export default PublishAppSidePanel