82 lines
3.2 KiB
TypeScript
82 lines
3.2 KiB
TypeScript
import { useState } from 'react';
|
|
import { Frame, card, button } from '@/pages/investment/shared';
|
|
import { contextApi } from '@/lib/investor-context';
|
|
import { createOperationKey } from '@/lib/operation-key';
|
|
type Plan = {
|
|
migration: string;
|
|
hash: string;
|
|
code_hash: string;
|
|
target: { database: string; port: number };
|
|
installed: boolean;
|
|
ready: boolean;
|
|
reasons: string[];
|
|
};
|
|
export default function ContextInstallation({ plan: initial }: { plan: Plan }) {
|
|
const [plan, setPlan] = useState(initial);
|
|
const [message, setMessage] = useState('');
|
|
const [busy, setBusy] = useState(false);
|
|
return (
|
|
<Frame title="Instalação do contexto do investidor">
|
|
<section className={card + ' space-y-3'}>
|
|
<p>
|
|
Prévia sem escrita. Apenas {plan.migration}; zero
|
|
importações, publicações, permissões ou dados de
|
|
investimento.
|
|
</p>
|
|
<p>
|
|
Destino: {plan.target.database}:{plan.target.port} ·{' '}
|
|
{plan.installed ? 'Já instalada' : 'Ausente'}
|
|
</p>
|
|
<p className="break-all">
|
|
Revisão de código e compilação: {plan.code_hash}
|
|
</p>
|
|
{plan.reasons.map((r) => (
|
|
<p role="alert" key={r}>
|
|
{r}
|
|
</p>
|
|
))}
|
|
<button
|
|
className={button}
|
|
disabled={busy}
|
|
onClick={() => {
|
|
setBusy(true);
|
|
void contextApi<Plan>(
|
|
'/management/investor-context-installation',
|
|
)
|
|
.then(setPlan)
|
|
.catch((e) => setMessage(e.message))
|
|
.finally(() => setBusy(false));
|
|
}}
|
|
>
|
|
Atualizar prévia
|
|
</button>
|
|
<button
|
|
className={button}
|
|
disabled={busy || !plan.ready}
|
|
onClick={() => {
|
|
setBusy(true);
|
|
void contextApi(
|
|
'/management/investor-context-installation',
|
|
{
|
|
hash: plan.hash,
|
|
operation_key: createOperationKey(),
|
|
confirm: true,
|
|
},
|
|
)
|
|
.then(() =>
|
|
setMessage(
|
|
'Instalação nominal verificada. Nenhum dossier ou classificação foi importado.',
|
|
),
|
|
)
|
|
.catch((e) => setMessage(e.message))
|
|
.finally(() => setBusy(false));
|
|
}}
|
|
>
|
|
Confirmar instalação nominal
|
|
</button>
|
|
{message && <p role="status">{message}</p>}
|
|
</section>
|
|
</Frame>
|
|
);
|
|
}
|