Skip to content

Commit

Permalink
feat(web-ongoing-operations): upload page
Browse files Browse the repository at this point in the history
Signed-off-by: Louis BENSI <[email protected]>
  • Loading branch information
louisbensiovh committed Feb 17, 2025
1 parent f23a75a commit 68cb626
Show file tree
Hide file tree
Showing 10 changed files with 423 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
"domain_operations_progress_instructions": "Instructions pour accélérer le transfert :",
"domain_operations_progress_instructions_7": "Vous pouvez contacter le prestataire actuel de votre domaine afin que celui-ci donne son accord.",
"domain_operations_progress_step_askForAuthInfo": "Erreur au niveau du authInfo",
"domain_upload_comment": "Commentaire de l'opération",
"domain_upload_data": "Vous pouvez modifier les données relatives à l'opération",
"wizard_cancel": "Annuler",
"wizard_confirm": "Confirmer"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { apiClient } from '@ovh-ux/manager-core-api';

// Actions
export const operation = async (
universe: string,
id: number,
operationType: string,
): Promise<any> => {
return apiClient.v6.post(`/me/task/${universe}/${id}/${operationType}`);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { apiClient } from '@ovh-ux/manager-core-api';
import { OdsFile } from '@ovhcloud/ods-components';
import axios from 'axios';

export type MeDocument = {
id: string;
putUrl: string;
};

export type Tag = {
key: string;
value: string;
};

export type MeDocumentResponse = {
putUrl: string;
size: number;
id: string;
expirationDate?: string;
getUrl: string;
creationDate: string;
validationDate: string;
name: string;
tags: Tag[];
};

export const getMeDocument = async (id: string): Promise<MeDocument> => {
return apiClient.v6
.get(`/me/document/${id}`)
.then((res) => res.data as MeDocumentResponse);
};

const postMeDocument = async (
filename: string,
): Promise<MeDocumentResponse> => {
return apiClient.v6
.post(`/me/document`, {
name: filename,
})
.then((res) => res.data as MeDocumentResponse);
};

const postMeDocumentCors = async (origin: string): Promise<void> => {
return apiClient.v6.post(`/me/document/cors`, {
origin,
});
};

const customAxiosInstance = axios.create({});

const saveDocumentFile = async (
putUrl: string,
file: OdsFile,
): Promise<void> => {
return customAxiosInstance.put(putUrl, file, {
headers: {
'Content-type': 'multipart/form-data',
},
});
};

export const saveFile = async (file: OdsFile) => {
const response = await postMeDocument(file.name);
await postMeDocumentCors(window.location.origin);
await saveDocumentFile(response.putUrl, file);
return response.id;
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ export const getmeTaskDomainId = async (
params: GetmeTaskDomainIdParams,
): Promise<any> => apiClient.v6.get(`${taskMeDomain}/${params.id}`);

/**
* Get information about domain related tasks : Get the domain task nic
*/
export const getmeTaskDomainNicList = async (id: string): Promise<any> =>
apiClient.v6.get(`/me/task/domain/${id}/argument`);

/**
* Get information about domain related tasks : Get the domain task argument
*/
export const getmeTaskDomainArgument = async (
id: string,
nic: string,
): Promise<any> => apiClient.v6.get(`/me/task/domain/${id}/argument/${nic}`);

/**
* Get listing with iceberg V6
*/
Expand All @@ -46,6 +60,18 @@ export const getListingIcebergV6 = async ({
return { data, status, totalCount };
};

export type UpdateTaskBody = {
value: string;
};

export const updateTask = async (
taskID: number,
key: string,
body: UpdateTaskBody,
): Promise<void> => {
return apiClient.v6.put(`/me/task/domain/${taskID}/argument/${key}`, body);
};

// DNS
/**
* Get information about dns related tasks : List of dns tasks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { operation } from '@/data/api/actions';

export const useDoOperation = async (
universe: string,
id: number,
operationType: string,
) => {
try {
return await operation(universe, id, operationType);
} catch (e) {
return null;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import Dns from '@/pages/dashboard/dns/Dns';
vi.mock('react-router-dom', () => ({
useNavigate: vi.fn(),
}));

vi.mock('@/data/api/web-ongoing-operations', () => ({
getmeTaskDnsList: vi.fn(),
}));

const queryClient = new QueryClient();
const wrapper = ({ children }: any) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);

describe('Dns datagrid', () => {
it('displays loading spinner while main request are loading', async () => {
(useQuery as jest.Mock).mockReturnValue({ data: [], isLoading: true });
Expand Down
Loading

0 comments on commit 68cb626

Please sign in to comment.