diff --git a/apps/admin-dashboard/app/routes/_dashboard.admins.tsx b/apps/admin-dashboard/app/routes/_dashboard.admins.tsx index d500cf047..48c7aa8dd 100644 --- a/apps/admin-dashboard/app/routes/_dashboard.admins.tsx +++ b/apps/admin-dashboard/app/routes/_dashboard.admins.tsx @@ -1,4 +1,10 @@ -import { type LoaderFunctionArgs, Outlet, useLoaderData } from 'react-router'; +import { Plus } from 'react-feather'; +import { + Link, + type LoaderFunctionArgs, + Outlet, + useLoaderData, +} from 'react-router'; import { doesAdminHavePermission, @@ -7,8 +13,9 @@ import { } from '@oyster/core/admins'; import { type AdminRole } from '@oyster/core/admins/types'; import { AdminTable } from '@oyster/core/admins/ui'; -import { Dashboard } from '@oyster/ui'; +import { Button, Dashboard } from '@oyster/ui'; +import { Route } from '@/shared/constants'; import { ensureUserAuthenticated, user } from '@/shared/session.server'; export async function loader({ request }: LoaderFunctionArgs) { @@ -65,6 +72,7 @@ export default function Admins() { <> Admins + @@ -72,3 +80,13 @@ export default function Admins() { ); } + +function AddAdminButton() { + return ( + + + Add Admin + + + ); +} diff --git a/packages/core/src/modules/admins/admins.ts b/packages/core/src/modules/admins/admins.ts index bf68b2738..49d78ed29 100644 --- a/packages/core/src/modules/admins/admins.ts +++ b/packages/core/src/modules/admins/admins.ts @@ -117,18 +117,6 @@ export async function addAdmin({ }); } - const existingAdmin = await getAdmin({ - select: [], - where: { email }, - }); - - if (existingAdmin) { - return fail({ - code: 409, - error: 'An admin already exists with this email.', - }); - } - const adminId = id(); await db.transaction().execute(async (trx) => { @@ -153,6 +141,14 @@ export async function addAdmin({ role, }; }) + .onConflict((eb) => { + return eb.column('email').doUpdateSet({ + deletedAt: null, + firstName, + lastName, + role, + }); + }) .execute(); });