11'use client'
22
3- import { useMemo , useState } from 'react'
3+ import { useCallback , useMemo , useState } from 'react'
44import { useParams } from 'next/navigation'
55import { Badge , Button , Input as EmcnInput , Label , Skeleton , Switch } from '@/components/emcn'
6+ import type { MothershipEnvironment } from '@/lib/api/contracts'
67import { useSession } from '@/lib/auth/auth-client'
78import { cn } from '@/lib/core/utils/cn'
89import {
@@ -17,6 +18,12 @@ import { useImportWorkflow } from '@/hooks/queries/workflows'
1718
1819const PAGE_SIZE = 20 as const
1920
21+ const ENV_OPTIONS : { id : MothershipEnvironment ; label : string } [ ] = [
22+ { id : 'dev' , label : 'Dev' } ,
23+ { id : 'staging' , label : 'Staging' } ,
24+ { id : 'prod' , label : 'Prod' } ,
25+ ]
26+
2027export function Admin ( ) {
2128 const params = useParams ( )
2229 const workspaceId = params ?. workspaceId as string
@@ -63,6 +70,18 @@ export function Admin() {
6370 }
6471 }
6572
73+ const handleMothershipEnvironmentChange = useCallback (
74+ async ( nextEnvironment : MothershipEnvironment ) => {
75+ if ( nextEnvironment !== settings ?. mothershipEnvironment && ! updateSetting . isPending ) {
76+ await updateSetting . mutateAsync ( {
77+ key : 'mothershipEnvironment' ,
78+ value : nextEnvironment ,
79+ } )
80+ }
81+ } ,
82+ [ settings ?. mothershipEnvironment , updateSetting ]
83+ )
84+
6685 const handleImport = ( ) => {
6786 if ( ! workflowId . trim ( ) ) return
6887 importWorkflow . mutate (
@@ -119,13 +138,45 @@ export function Admin() {
119138 ] )
120139 return (
121140 < div className = 'flex h-full flex-col gap-6' >
122- < div className = 'flex items-center justify-between' >
123- < Label htmlFor = 'super-user-mode' > Super admin mode</ Label >
124- < Switch
125- id = 'super-user-mode'
126- checked = { settings ?. superUserModeEnabled ?? false }
127- onCheckedChange = { handleSuperUserModeToggle }
128- />
141+ < div className = 'flex flex-col gap-4' >
142+ < div className = 'flex items-center justify-between' >
143+ < Label htmlFor = 'super-user-mode' > Super admin mode</ Label >
144+ < Switch
145+ id = 'super-user-mode'
146+ checked = { settings ?. superUserModeEnabled ?? false }
147+ disabled = { updateSetting . isPending }
148+ onCheckedChange = { handleSuperUserModeToggle }
149+ />
150+ </ div >
151+
152+ { settings ?. superUserModeEnabled && (
153+ < div className = 'flex items-center justify-between gap-3' >
154+ < div className = 'flex flex-col gap-1' >
155+ < Label className = 'text-[var(--text-primary)] text-sm' > Mothership Environment</ Label >
156+ < p className = 'text-[var(--text-secondary)] text-xs' >
157+ Controls which Copilot backend this admin session talks to.
158+ </ p >
159+ </ div >
160+ < div className = 'flex gap-1' >
161+ { ENV_OPTIONS . map ( ( opt ) => (
162+ < button
163+ key = { opt . id }
164+ type = 'button'
165+ onClick = { ( ) => handleMothershipEnvironmentChange ( opt . id ) }
166+ disabled = { updateSetting . isPending }
167+ className = { cn (
168+ 'rounded-md px-3 py-1 font-medium text-sm transition-colors' ,
169+ ( settings ?. mothershipEnvironment ?? 'prod' ) === opt . id
170+ ? 'bg-[var(--surface-hover)] text-[var(--text-primary)]'
171+ : 'text-[var(--text-tertiary)] hover-hover:hover:text-[var(--text-secondary)]'
172+ ) }
173+ >
174+ { opt . label }
175+ </ button >
176+ ) ) }
177+ </ div >
178+ </ div >
179+ ) }
129180 </ div >
130181
131182 < div className = 'h-px bg-[var(--border-secondary)]' />
0 commit comments