The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Refactor delete org button into its own component
Joshen Limd6a52397b927
diff --git a/studio/components/interfaces/Organization/DeleteOrganizationButton.tsx b/studio/components/interfaces/Organization/DeleteOrganizationButton.tsxnew file mode 100644index 00000000000..9d08ff2ee8c--- /dev/null+++ b/studio/components/interfaces/Organization/DeleteOrganizationButton.tsx@@ -0,0 +1,123 @@+import { useState, useContext } from 'react'+import { useRouter } from 'next/router'+import { observer } from 'mobx-react-lite'+import { Button, Form, Modal, Input } from '@supabase/ui'++import { useStore } from 'hooks'+import { delete_ } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'+import { PageContext } from 'pages/org/[slug]/settings'++const DeleteOrganizationButton = observer(() => {+ const PageState: any = useContext(PageContext)+ const router = useRouter()+ const { ui } = useStore()++ const { slug: orgSlug, name: orgName } = PageState.organization++ const [isOpen, setIsOpen] = useState(false)+ const [value, setValue] = useState('')++ const onValidate = (values: any) => {+ const errors: any = {}+ if (!values.orgName) {+ errors.orgName = 'Enter the name of the organization.'+ }+ if (values.orgName !== orgSlug) {+ errors.orgName = 'Value entered does not match name of the organization.'+ }+ return errors+ }++ const onConfirmDelete = async (values: any, { setSubmitting }: any) => {+ setSubmitting(true)+ const response = await delete_(`${API_URL}/organizations/${orgSlug}`)+ if (response.error) {+ ui.setNotification({+ category: 'error',+ message: `Failed to delete organization: ${response.error.message}`,+ })+ setSubmitting(false)+ } else {+ PageState.onOrgDeleted(PageState.organization)+ setSubmitting(false)+ router.push('/')+ ui.setNotification({+ category: 'success',+ message: `Successfully deleted ${orgName}`,+ })+ }+ }++ return (+ <>+ <div className="mt-2">+ <Button onClick={() => setIsOpen(true)} type="danger">+ Delete organization+ </Button>+ </div>+ <Modal+ closable+ hideFooter+ size="small"+ visible={isOpen}+ onCancel={() => setIsOpen(false)}+ header={+ <div className="flex items-baseline gap-2">+ <h5 className="text-scale-1200 text-sm">Delete organisation</h5>+ <span className="text-scale-900 text-xs">Are you sure?</span>+ </div>+ }+ >+ <Form+ validateOnBlur+ initialValues={{ orgName: '' }}+ onSubmit={onConfirmDelete}+ validate={onValidate}+ >+ {({ isSubmitting }: { isSubmitting: boolean }) => (+ <div className="space-y-4 py-3">+ <Modal.Content>+ <p className="text-scale-900 text-sm">+ This action <span className="text-scale-1200">cannot</span> be undone. This will+ permanently delete the <span className="text-scale-1200">{orgName}</span>{' '}+ organization and remove all of its projects.+ </p>+ </Modal.Content>+ <Modal.Seperator />+ <Modal.Content>+ <Input+ id="orgName"+ label={+ <span>+ Please type <span className="font-bold">{orgSlug}</span> to confirm+ </span>+ }+ onChange={(e) => setValue(e.target.value)}+ value={value}+ placeholder="Type in the orgnaization name"+ className="w-full"+ />+ </Modal.Content>+ <Modal.Seperator />+ <Modal.Content>+ <Button+ block+ danger+ size="small"+ type="danger"+ htmlType="submit"+ loading={isSubmitting}+ >+ I understand, delete this organization+ </Button>+ </Modal.Content>+ </div>+ )}+ </Form>+ </Modal>+ </>+ )+})++export default DeleteOrganizationButtondiff --git a/studio/components/interfaces/Organization/index.ts b/studio/components/interfaces/Organization/index.tsindex 97ce7937b61..dba072cb192 100644--- a/studio/components/interfaces/Organization/index.ts+++ b/studio/components/interfaces/Organization/index.ts@@ -1,4 +1,6 @@import BillingSettings from './BillingSettings/BillingSettings'import InvoicesSettings from './InvoicesSettings/InvoicesSettings'+import InviteMemberModal from './InviteMemberModal'+import DeleteOrganizationButton from './DeleteOrganizationButton'-export { BillingSettings, InvoicesSettings }+export { BillingSettings, InvoicesSettings, InviteMemberModal, DeleteOrganizationButton }diff --git a/studio/pages/org/[slug]/settings.tsx b/studio/pages/org/[slug]/settings.tsxindex dc8dff77e13..7785da53126 100644--- a/studio/pages/org/[slug]/settings.tsx+++ b/studio/pages/org/[slug]/settings.tsx@@ -1,3 +1,4 @@+import Image from 'next/image'import { createContext, useEffect, useContext, useState } from 'react'import { useRouter } from 'next/router'import { observer, useLocalObservable } from 'mobx-react-lite'@@ -16,30 +17,32 @@ import {Alert,Input,Dropdown,- Modal,IconSearch,IconUser,- Form,} from '@supabase/ui'-import { API_URL } from 'lib/constants'import { useOrganizationDetail, useStore, withAuth } from 'hooks'+import { Member, NextPageWithLayout, Project } from 'types'+import { API_URL } from 'lib/constants'import { post, delete_, patch } from 'lib/common/fetch'-import { AccountLayoutWithoutAuth } from 'components/layouts'-import { BillingSettings, InvoicesSettings } from 'components/interfaces/Organization'-import Table from 'components/to-be-cleaned/Table'import Panel from 'components/ui/Panel'-import { confirmAlert } from 'components/to-be-cleaned/ModalsDeprecated/ConfirmModal'-import InviteMemberModal from 'components/interfaces/Organization/InviteMemberModal'+import { AccountLayoutWithoutAuth } from 'components/layouts'import TextConfirmModal from 'components/ui/Modals/TextConfirmModal'+import {+ BillingSettings,+ InvoicesSettings,+ InviteMemberModal,+ DeleteOrganizationButton,+} from 'components/interfaces/Organization'++import Table from 'components/to-be-cleaned/Table'import SchemaFormPanel from 'components/to-be-cleaned/forms/SchemaFormPanel'-import { Member, NextPageWithLayout, Project } from 'types'-import Image from 'next/image'+import { confirmAlert } from 'components/to-be-cleaned/ModalsDeprecated/ConfirmModal'// [Joshen] Low prio refactor: Bring out general and team settings into their own components too-const PageContext = createContext(null)+export const PageContext = createContext(null)// Invite is expired if older than 24hrsfunction inviteExpired(timestamp: Date) {@@ -179,22 +182,10 @@ const TabsView = observer(() => {</section><nav className=""><Tabs onChange={(id: any) => setSelectedTab(id)} type="underlined">- {/* @ts-ignore */}- <Tabs.Panel id="GENERAL" label="General">- <></>- </Tabs.Panel>- {/* @ts-ignore */}- <Tabs.Panel id="TEAM" label="Team">- <></>- </Tabs.Panel>- {/* @ts-ignore */}- <Tabs.Panel id="BILLING" label="Billing">- <></>- </Tabs.Panel>- {/* @ts-ignore */}- <Tabs.Panel id="INVOICES" label="Invoices">- <></>- </Tabs.Panel>+ <Tabs.Panel id="GENERAL" label="General" />+ <Tabs.Panel id="TEAM" label="Team" />+ <Tabs.Panel id="BILLING" label="Billing" />+ <Tabs.Panel id="INVOICES" label="Invoices" /></Tabs></nav></div>@@ -289,123 +280,13 @@ const OrgDeletePanel = observer(() => {<p className="text-red-900">Make sure you have made a backup if you want to keep your data</p>- <OrgDeleteModal />+ <DeleteOrganizationButton /></Alert></Panel.Content></Panel>)})-const OrgDeleteModal = observer(() => {- const PageState: any = useContext(PageContext)- const router = useRouter()- const { ui } = useStore()-- const { slug: orgSlug, name: orgName } = PageState.organization-- const [isOpen, setIsOpen] = useState(false)- const [value, setValue] = useState('')-- function toggle() {- setIsOpen(!isOpen)- }-- return (- <>- <div className="mt-2">- <Button onClick={toggle} type="danger">- Delete organization- </Button>- </div>- <Modal- visible={isOpen}- onCancel={toggle}- header={- <div className="flex items-baseline gap-2">- <h5 className="text-scale-1200 text-sm">Delete organisation</h5>- <span className="text-scale-900 text-xs">Are you sure?</span>- </div>- }- size="small"- hideFooter- closable- >- <Form- initialValues={{- orgName: '',- }}- validateOnBlur- onSubmit={async (values: any, { setSubmitting }: any) => {- setSubmitting(true)- const response = await delete_(`${API_URL}/organizations/${orgSlug}`)- if (response.error) {- ui.setNotification({- category: 'error',- message: `Failed to delete organization: ${response.error.message}`,- })- setSubmitting(false)- } else {- PageState.onOrgDeleted(PageState.organization)- setSubmitting(false)- router.push('/')- }- }}- validate={(values) => {- const errors: any = {}- if (!values.orgName) {- errors.orgName = 'Enter the name of the organization.'- }- if (values.orgName !== orgSlug) {- errors.orgName = 'Value entered does not match name of the organization.'- }- return errors- }}- >- {({ isSubmitting }: { isSubmitting: boolean }) => (- <div className="space-y-4 py-3">- <Modal.Content>- <p className="text-scale-900 text-sm">- This action <span className="text-scale-1200">cannot</span> be undone. This will- permanently delete the <span className="text-scale-1200">{orgName}</span>{' '}- organization and remove all of its projects.- </p>- </Modal.Content>- <Modal.Seperator />- <Modal.Content>- <Input- id="orgName"- label={- <span>- Please type <Typography.Text strong>{orgSlug}</Typography.Text> to confirm- </span>- }- onChange={(e) => setValue(e.target.value)}- value={value}- placeholder="Type in the orgnaization name"- className="w-full"- />- </Modal.Content>- <Modal.Seperator />- <Modal.Content>- <Button- type="danger"- htmlType="submit"- loading={isSubmitting}- size="small"- block- danger- >- I understand, delete this organization- </Button>- </Modal.Content>- </div>- )}- </Form>- </Modal>- </>- )-})-const TeamSettings = observer(() => {const PageState: any = useContext(PageContext)const { ui } = useStore()@@ -574,19 +455,18 @@ const MembersView = observer(() => {})const OwnerDropdown = observer(({ members, member }: any) => {- const PageState: any = useContext(PageContext)const { ui } = useStore()const { mutateOrgMembers } = useOrganizationDetail(ui.selectedOrganization?.slug || '')- const [isOpen, setIsOpen] = useState(false)++ const PageState: any = useContext(PageContext)const [loading, setLoading] = useState(false)// handle modal visibilityconst [ownerTransferIsVisble, setOwnerTransferIsVisble] = useState(false)- const { id: orgId, slug: orgSlug, stripe_customer_id, name: orgName } = PageState.organization+ const { id: orgId, slug: orgSlug, name: orgName } = PageState.organizationasync function handleMemberDelete() {- setIsOpen(false)await timeout(200)confirmAlert({