Skip to content

Commit e54091e

Browse files
committed
dev(process): call backend for export task attempt
1 parent 418ffff commit e54091e

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/api/interfaces.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ export interface IMarkSubsampleReq {
9797
date?: string;
9898
}
9999

100+
export interface IExportSubsampleReq {
101+
task: ITask;
102+
subsample: SubSample;
103+
}
104+
100105
export interface VignetteData {
101106
scan: string;
102107
matrix: string;

src/api/zooprocess-api.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axiosInstance from './axiosInstance.ts';
22
import * as I from './interfaces.ts';
33
import type { AxiosError } from 'axios';
4-
import type { SubSample } from './interfaces.ts';
4+
import type { IExportSubsampleReq, SubSample } from './interfaces.ts';
55

66
export interface Login {
77
email: string;
@@ -141,6 +141,21 @@ export async function listEcoTaxaProjects(token: string, ecotaxaToken: string) {
141141

142142
return response.data;
143143
}
144+
145+
export async function exportToEcoTaxa(
146+
token: string,
147+
projectId: string,
148+
sampleId: string,
149+
subsampleId: string,
150+
ecotaxaToken: string,
151+
ecoTaxaProjectId: number
152+
) {
153+
const api = await axiosInstance({ token: token });
154+
const url = `/projects/${projectId}/samples/${sampleId}/subsamples/${subsampleId}/export`;
155+
const req = { token: ecotaxaToken, projid: ecoTaxaProjectId };
156+
const response = await api.post<I.IExportSubsampleReq>(url, req);
157+
return response.data;
158+
}
144159
/////////////////////////////////
145160
// UNUSED BELOW
146161
/////////////////////////////////

src/app/features/subsample/process/page.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { type Key, useEffect, useState } from 'react';
22
import {
3+
exportToEcoTaxa,
34
getProject,
45
getSubSample,
56
getTask,
@@ -229,7 +230,21 @@ export const SubsampleProcessPage = () => {
229230

230231
const handleProjectSubmit = () => {
231232
if (selectedProjectId) {
232-
// TODO
233+
exportToEcoTaxa(
234+
authState.accessToken!,
235+
projectId,
236+
sampleId,
237+
subsampleId,
238+
ecotaxaToken!,
239+
selectedProjectId
240+
)
241+
.then(result => {
242+
setSubsample(result.subsample);
243+
setTask(result.task);
244+
})
245+
.catch(error => {
246+
setError('Failed to export to EcoTaxa: ' + error.message);
247+
});
233248
}
234249
};
235250

@@ -268,7 +283,7 @@ export const SubsampleProcessPage = () => {
268283
role="alert"
269284
>
270285
<span className="block sm:inline">
271-
Project selected:{selectedProjectId}
286+
Selected project:{selectedProjectId}
272287
{ecotaxaProjects.find(p => p.projid === selectedProjectId)?.title}
273288
</span>
274289
</div>

0 commit comments

Comments
 (0)