-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web-ongoing-operations): upload page
Signed-off-by: Louis BENSI <[email protected]>
- Loading branch information
1 parent
f23a75a
commit 68cb626
Showing
10 changed files
with
423 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/manager/apps/web-ongoing-operations/src/data/api/actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}; |
67 changes: 67 additions & 0 deletions
67
packages/manager/apps/web-ongoing-operations/src/data/api/document.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/manager/apps/web-ongoing-operations/src/hooks/actions/useActions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.