import { useId, useState } from 'react' import { useTranslation } from 'react-i18next' import { CircleCheckGlassIcon, TriangleAlertGlassIcon } from '@thesvg/ui-react' import { Field, FieldDescription, FieldLabel } from '@/components/ui/field' import { Input } from '@/components/ui/input' import { Textarea } from '@/components/ui/textarea' import { Button } from '@/components/ui/button' import { Alert, AlertDescription } from '@/components/ui/alert' import { toast } from '@/components/ui/toast' import { ociSessionCommand } from '../../lib/ociSession' import { formatRelativeTime } from '../../lib/relativeTime' import { useCreateOracleSessionAccount, useImportOracleSession, } from '../../queries/cloudAccounts' import type { OracleSessionCheck, OracleSessionInput, } from '../../types/cloudAccounts' // Format examples, not translatable copy. const FORMAT = { region: 'eu-frankfurt-1', compartment: 'ocid1.compartment.oc1...', } as const // Browser session login for testing: files are pasted, checked offline, then stored sealed. export function OracleSessionForm({ label, onSaved, }: Readonly<{ label: string; onSaved: () => void }>) { const { t } = useTranslation('nodes') const uid = useId() const [region, setRegion] = useState('') const [compartment, setCompartment] = useState('') const [profile, setProfile] = useState('') const [token, setToken] = useState('') const [key, setKey] = useState('') const [check, setCheck] = useState(null) const importer = useImportOracleSession() const create = useCreateOracleSessionAccount() const canSubmit = token.trim() !== '' && key.trim() !== '' const body = (): OracleSessionInput => ({ profile_config: profile.trim() || undefined, session_token: token.trim(), private_key_pem: key, region: region.trim() || undefined, compartment_ocid: compartment.trim() || undefined, }) const error = create.isError ? create.error.message : importer.isError ? importer.error.message : null function runCheck() { setCheck(null) importer.mutate(body(), { onSuccess: setCheck }) } function submit(e: React.FormEvent) { e.preventDefault() if (!canSubmit) return create.mutate( { ...body(), tenancy_ocid: check?.tenancy_ocid, region: check?.region }, { onSuccess: () => { setToken('') setKey('') toast.add({ title: t('oracle.session.saved', { provider: label }), type: 'success', }) onSaved() }, }, ) } return (

{t('oracle.session.intro')}

{t('oracle.form.region')} setRegion(e.target.value)} placeholder={FORMAT.region} className="font-mono text-xs" spellCheck={false} /> {t('oracle.session.command')} {ociSessionCommand(region)} {t('oracle.session.commandHelp')} {t('oracle.form.compartment')} setCompartment(e.target.value)} placeholder={FORMAT.compartment} className="font-mono text-xs" spellCheck={false} /> {t('oracle.session.profile')}