import { useState, useEffect, useRef } from 'react'; import { useParams, useLocation } from 'react-router'; import { useEnvironmentStore } from '../../../api/environment-store'; import { useEnvironments } from '../../../api/queries/admin/environments'; import { useApps, useAppVersions } from '../../../api/queries/admin/apps'; import { PageLoader } from '../../../components/PageLoader'; import { IdentitySection } from './IdentitySection'; import { deriveAppName } from './utils/deriveAppName'; import styles from './AppDeploymentPage.module.css'; export default function AppDeploymentPage() { const { appId } = useParams<{ appId?: string }>(); const location = useLocation(); const selectedEnv = useEnvironmentStore((s) => s.environment); const { data: environments = [], isLoading: envLoading } = useEnvironments(); const { data: apps = [], isLoading: appsLoading } = useApps(selectedEnv); const isNetNew = location.pathname.endsWith('/apps/new'); const app = isNetNew ? null : apps.find((a) => a.slug === appId) ?? null; const env = environments.find((e) => e.slug === selectedEnv); const { data: versions = [] } = useAppVersions(selectedEnv, app?.slug); const currentVersion = versions.slice().sort((a, b) => b.version - a.version)[0] ?? null; // Form state const [name, setName] = useState(''); const [stagedJar, setStagedJar] = useState(null); const lastDerivedRef = useRef(''); // Initialize name when app loads useEffect(() => { if (app) setName(app.displayName); }, [app]); // Auto-derive from staged JAR (net-new mode only, don't overwrite manual edits) useEffect(() => { if (!stagedJar || app) return; const derived = deriveAppName(stagedJar.name); if (!name || name === lastDerivedRef.current) { setName(derived); lastDerivedRef.current = derived; } }, [stagedJar, app, name]); if (envLoading || appsLoading) return ; if (!env) return
Select an environment first.
; const mode: 'net-new' | 'deployed' = app ? 'deployed' : 'net-new'; return (

{app ? app.displayName : 'Create Application'}

); }