feature/doda-endpoints-faltantes
This commit is contained in:
@@ -478,6 +478,56 @@ export async function getDodaAltaStatus(
|
||||
return api.get<DodaAltaStatusResponse>(`/v1/a76/doda/alta-status/${taskId}`);
|
||||
}
|
||||
|
||||
export async function postDodaConsulta(
|
||||
dodaId: number,
|
||||
companyId: number,
|
||||
variant: 'doda' | 'pita' = 'doda'
|
||||
): Promise<ApiResponse<DodaAltaResponse>> {
|
||||
const params = new URLSearchParams({
|
||||
company_id: companyId.toString(),
|
||||
variant,
|
||||
});
|
||||
return api.post<DodaAltaResponse>(`/v1/a76/doda/${dodaId}/consulta?${params}`, {});
|
||||
}
|
||||
|
||||
export async function getDodaConsultaStatus(
|
||||
taskId: string
|
||||
): Promise<ApiResponse<DodaAltaStatusResponse>> {
|
||||
return api.get<DodaAltaStatusResponse>(`/v1/a76/doda/consulta-status/${taskId}`);
|
||||
}
|
||||
|
||||
export async function postDodaConsultaApply(
|
||||
dodaId: number,
|
||||
taskId: string,
|
||||
companyId: number
|
||||
): Promise<ApiResponse<Record<string, unknown>>> {
|
||||
const params = new URLSearchParams({
|
||||
company_id: companyId.toString(),
|
||||
});
|
||||
return api.post<Record<string, unknown>>(
|
||||
`/v1/a76/doda/${dodaId}/consulta-apply/${taskId}?${params}`,
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
export async function postDodaEliminar(
|
||||
dodaId: number,
|
||||
companyId: number,
|
||||
variant: 'doda' | 'pita' = 'doda'
|
||||
): Promise<ApiResponse<DodaAltaResponse>> {
|
||||
const params = new URLSearchParams({
|
||||
company_id: companyId.toString(),
|
||||
variant,
|
||||
});
|
||||
return api.post<DodaAltaResponse>(`/v1/a76/doda/${dodaId}/eliminar?${params}`, {});
|
||||
}
|
||||
|
||||
export async function getDodaEliminarStatus(
|
||||
taskId: string
|
||||
): Promise<ApiResponse<DodaAltaStatusResponse>> {
|
||||
return api.get<DodaAltaStatusResponse>(`/v1/a76/doda/eliminar-status/${taskId}`);
|
||||
}
|
||||
|
||||
export async function getDodaElegibilidad(
|
||||
dodaId: number,
|
||||
companyId: number,
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
getDodaAltaStatus,
|
||||
type DodaAltaStatusResponse
|
||||
} from '$lib/api/dashboard/a76/general_catalogs/doda';
|
||||
import type { ApiResponse } from '$lib/api';
|
||||
import { m } from '$lib/i18n/messages';
|
||||
|
||||
let {
|
||||
@@ -14,6 +15,9 @@
|
||||
taskId,
|
||||
dodaId,
|
||||
variant = 'doda',
|
||||
title = m['sidebar.doda_alta.progress_title'](),
|
||||
description = 'Task ID',
|
||||
getStatus = getDodaAltaStatus,
|
||||
onComplete,
|
||||
onCancel
|
||||
}: {
|
||||
@@ -21,6 +25,9 @@
|
||||
taskId: string;
|
||||
dodaId?: number;
|
||||
variant?: 'doda' | 'pita';
|
||||
title?: string;
|
||||
description?: string;
|
||||
getStatus?: (taskId: string) => Promise<ApiResponse<DodaAltaStatusResponse>>;
|
||||
onComplete?: (result: DodaAltaStatusResponse) => void;
|
||||
onCancel?: () => void;
|
||||
} = $props();
|
||||
@@ -84,7 +91,7 @@
|
||||
if (!taskId || !pollingActive || pollInFlight) return;
|
||||
pollInFlight = true;
|
||||
try {
|
||||
const res = await getDodaAltaStatus(taskId);
|
||||
const res = await getStatus(taskId);
|
||||
|
||||
if (res.error) {
|
||||
consecutivePollErrors += 1;
|
||||
@@ -151,8 +158,8 @@
|
||||
<Dialog.Root bind:open>
|
||||
<Dialog.Content class="max-w-md">
|
||||
<Dialog.Header>
|
||||
<Dialog.Title>{m['sidebar.doda_alta.progress_title']()}</Dialog.Title>
|
||||
<Dialog.Description>Alta {variantLabel} — Task ID: {taskId}</Dialog.Description>
|
||||
<Dialog.Title>{title}</Dialog.Title>
|
||||
<Dialog.Description>{description} {variantLabel} — Task ID: {taskId}</Dialog.Description>
|
||||
</Dialog.Header>
|
||||
|
||||
<div class="space-y-4 py-2">
|
||||
|
||||
@@ -35,7 +35,14 @@
|
||||
deleteDoda,
|
||||
exportDodaPedimentosDetail,
|
||||
postDodaAlta,
|
||||
postDodaConsulta,
|
||||
postDodaConsultaApply,
|
||||
postDodaEliminar,
|
||||
getDodaAltaStatus,
|
||||
getDodaElegibilidad,
|
||||
getDodaConsultaStatus,
|
||||
getDodaEliminarStatus,
|
||||
type DodaAltaStatusResponse,
|
||||
type Doda
|
||||
} from '$lib/api/dashboard/a76/general_catalogs/doda';
|
||||
|
||||
@@ -71,9 +78,13 @@
|
||||
let exportDialogOpen = $state(false);
|
||||
let currentTaskId = $state('');
|
||||
let currentVariant = $state<'doda' | 'pita'>('doda');
|
||||
let progressMode = $state<'alta' | 'consulta' | 'eliminar'>('alta');
|
||||
let altaLoading = $state(false);
|
||||
let consultaLoading = $state(false);
|
||||
let eliminarExternoLoading = $state(false);
|
||||
let deleteLoading = $state(false);
|
||||
let pedimentosExportLoading = $state(false);
|
||||
const hasIntegration = $derived(!!(selectedDoda?.integration_number || '').trim());
|
||||
|
||||
$effect(() => {
|
||||
if (data.dodas) {
|
||||
@@ -223,11 +234,94 @@
|
||||
}
|
||||
}
|
||||
|
||||
function onAltaComplete() {
|
||||
progressDialogOpen = false;
|
||||
reloadDodas();
|
||||
toast.success(m['sidebar.doda_alta.progress_success']());
|
||||
async function handleConsultar() {
|
||||
if (!selectedDoda || !companyStore.activeCompany || consultaLoading) return;
|
||||
if (!hasIntegration) {
|
||||
toast.error('El DODA aún no está generado para consultar.');
|
||||
return;
|
||||
}
|
||||
consultaLoading = true;
|
||||
try {
|
||||
const resp = await postDodaConsulta(selectedDoda.id, companyStore.activeCompany.id, altaVariant);
|
||||
if (resp.error || !resp.data?.task_id) {
|
||||
toast.error(resp.error || 'Error al enviar consulta DODA');
|
||||
return;
|
||||
}
|
||||
progressMode = 'consulta';
|
||||
currentTaskId = resp.data.task_id;
|
||||
currentVariant = altaVariant;
|
||||
progressDialogOpen = true;
|
||||
} finally {
|
||||
consultaLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleEliminarExterno() {
|
||||
if (!selectedDoda || !companyStore.activeCompany || eliminarExternoLoading) return;
|
||||
if (!hasIntegration) {
|
||||
toast.error('El DODA aún no está generado para eliminar externamente.');
|
||||
return;
|
||||
}
|
||||
if (!confirm('¿Deseas eliminar este DODA en el servicio externo para volver a editarlo?')) return;
|
||||
eliminarExternoLoading = true;
|
||||
try {
|
||||
const resp = await postDodaEliminar(selectedDoda.id, companyStore.activeCompany.id, altaVariant);
|
||||
if (resp.error || !resp.data?.task_id) {
|
||||
toast.error(resp.error || 'Error al enviar eliminación DODA');
|
||||
return;
|
||||
}
|
||||
progressMode = 'eliminar';
|
||||
currentTaskId = resp.data.task_id;
|
||||
currentVariant = altaVariant;
|
||||
progressDialogOpen = true;
|
||||
} finally {
|
||||
eliminarExternoLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function onProgressComplete(_result: DodaAltaStatusResponse) {
|
||||
progressDialogOpen = false;
|
||||
if (progressMode === 'consulta' && selectedDoda && companyStore.activeCompany) {
|
||||
const applyResp = await postDodaConsultaApply(
|
||||
selectedDoda.id,
|
||||
currentTaskId,
|
||||
companyStore.activeCompany.id
|
||||
);
|
||||
if (applyResp.error) {
|
||||
toast.error(`Consulta completada, pero no se pudo aplicar al DODA: ${applyResp.error}`);
|
||||
}
|
||||
}
|
||||
await reloadDodas();
|
||||
if (progressMode === 'eliminar') {
|
||||
toast.success('Eliminación DODA completada. El registro quedó editable nuevamente.');
|
||||
} else if (progressMode === 'consulta') {
|
||||
toast.success('Consulta DODA completada y aplicada al registro.');
|
||||
} else {
|
||||
toast.success(m['sidebar.doda_alta.progress_success']());
|
||||
}
|
||||
}
|
||||
|
||||
const progressTitle = $derived(
|
||||
progressMode === 'consulta'
|
||||
? 'Consulta DODA'
|
||||
: progressMode === 'eliminar'
|
||||
? 'Eliminación DODA'
|
||||
: m['sidebar.doda_alta.progress_title']()
|
||||
);
|
||||
const progressDescription = $derived(
|
||||
progressMode === 'consulta'
|
||||
? 'Consulta'
|
||||
: progressMode === 'eliminar'
|
||||
? 'Eliminación'
|
||||
: 'Alta'
|
||||
);
|
||||
const progressStatusGetter = $derived(
|
||||
progressMode === 'consulta'
|
||||
? getDodaConsultaStatus
|
||||
: progressMode === 'eliminar'
|
||||
? getDodaEliminarStatus
|
||||
: getDodaAltaStatus
|
||||
);
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col gap-6 p-6 h-[calc(100svh-4rem)] group-has-data-[collapsible=icon]/sidebar-wrapper:h-[calc(100svh-3rem)] overflow-hidden">
|
||||
@@ -343,11 +437,38 @@
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onclick={handleEdit}
|
||||
disabled={selectedDodaIds.length !== 1}
|
||||
disabled={selectedDodaIds.length !== 1 || hasIntegration}
|
||||
>
|
||||
<Pencil size={16} class="mr-2" />
|
||||
{m['sidebar.doda_alta.action_edit']()}
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
onclick={handleConsultar}
|
||||
disabled={selectedDodaIds.length !== 1 || !hasIntegration || consultaLoading}
|
||||
>
|
||||
{#if consultaLoading}
|
||||
<Loader2 size={16} class="mr-2 animate-spin" />
|
||||
{:else}
|
||||
<Search size={16} class="mr-2" />
|
||||
{/if}
|
||||
Consultar DODA
|
||||
</Button>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
class="border border-amber-500/30 bg-amber-500/10 text-amber-700 hover:bg-amber-500/20"
|
||||
onclick={handleEliminarExterno}
|
||||
disabled={selectedDodaIds.length !== 1 || !hasIntegration || eliminarExternoLoading}
|
||||
>
|
||||
{#if eliminarExternoLoading}
|
||||
<Loader2 size={16} class="mr-2 animate-spin" />
|
||||
{:else}
|
||||
<Trash2 size={16} class="mr-2" />
|
||||
{/if}
|
||||
Eliminar DODA
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
@@ -385,7 +506,7 @@
|
||||
<Button
|
||||
size="sm"
|
||||
onclick={handleAlta}
|
||||
disabled={selectedDodaIds.length !== 1 || altaLoading}
|
||||
disabled={selectedDodaIds.length !== 1 || altaLoading || hasIntegration}
|
||||
title={altaVariant === 'pita' ? 'PITA' : 'DODA'}
|
||||
>
|
||||
{#if altaLoading}
|
||||
@@ -408,7 +529,10 @@
|
||||
taskId={currentTaskId}
|
||||
dodaId={selectedDoda?.id}
|
||||
variant={currentVariant}
|
||||
onComplete={onAltaComplete}
|
||||
title={progressTitle}
|
||||
description={progressDescription}
|
||||
getStatus={progressStatusGetter}
|
||||
onComplete={onProgressComplete}
|
||||
onCancel={() => (progressDialogOpen = false)}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user