-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(procedures): dgpr removal of mocks (#13934)
ref: MANAGER-15473 Signed-off-by: Omar ALKABOUSS MOUSSANA <[email protected]>
- Loading branch information
1 parent
05beac0
commit c56d686
Showing
15 changed files
with
167 additions
and
267 deletions.
There are no files selected for viewing
45 changes: 0 additions & 45 deletions
45
packages/manager/apps/procedures/src/data/api/documentsApi.ts
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
packages/manager/apps/procedures/src/data/api/proceduresApi.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,59 @@ | ||
import { v6 } from '@ovh-ux/manager-core-api'; | ||
import axios from 'axios'; | ||
import { Procedure } from '@/types/procedure'; | ||
|
||
export type UploadLink = { | ||
link: string; | ||
method: string; | ||
headers: any; | ||
}; | ||
|
||
const s3AxiosInstance = axios.create({}); | ||
|
||
const uploadDocument: (link: UploadLink, file: File) => Promise<void> = ( | ||
link, | ||
file, | ||
) => { | ||
return s3AxiosInstance.put(link.link, file, { | ||
headers: { | ||
...link.headers, | ||
}, | ||
}); | ||
}; | ||
|
||
export const getProceduresAPI = (procedure: Procedure) => { | ||
const uri = `/me/procedure/${procedure}`; | ||
|
||
const getStatus: <TResponse>() => Promise<TResponse> = async () => { | ||
const { data } = await v6.get(uri); | ||
return data; | ||
}; | ||
|
||
const getDocumentsLinks = <TData extends { numberOfDocuments: number }>( | ||
dataQuery: TData, | ||
): Promise<UploadLink[]> => { | ||
return v6 | ||
.post(uri, dataQuery) | ||
.then(({ data: dataResponse }) => dataResponse.uploadLinks); | ||
}; | ||
|
||
const finalize: () => Promise<void> = () => { | ||
return v6.post(`${uri}/finalize`).then(({ data }) => data); | ||
}; | ||
|
||
const uploadDocuments: ( | ||
files: File[], | ||
links: UploadLink[], | ||
) => Promise<void> = async (files, links) => { | ||
await Promise.all( | ||
links.map((link, index) => uploadDocument(link, files[index])), | ||
); | ||
return finalize(); | ||
}; | ||
|
||
return { | ||
getStatus, | ||
getDocumentsLinks, | ||
uploadDocuments, | ||
}; | ||
}; |
71 changes: 0 additions & 71 deletions
71
packages/manager/apps/procedures/src/data/api/rgdp/rgdpApi.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
50 changes: 0 additions & 50 deletions
50
packages/manager/apps/procedures/src/data/hooks/rgdp/useRGDP.tsx
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
packages/manager/apps/procedures/src/data/hooks/useDocuments.tsx
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
packages/manager/apps/procedures/src/data/hooks/useProcedures.tsx
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,66 @@ | ||
import { useMutation, useQuery } from '@tanstack/react-query'; | ||
import { AxiosError } from 'axios'; | ||
import { getProceduresAPI, UploadLink } from '@/data/api/proceduresApi'; | ||
import { Procedure } from '@/types/procedure'; | ||
|
||
export type UploadDocumentsProps = { | ||
files: File[]; | ||
links: UploadLink[]; | ||
}; | ||
|
||
export const useProcedures = (procedure: Procedure) => { | ||
const { getStatus, getDocumentsLinks, uploadDocuments } = getProceduresAPI( | ||
procedure, | ||
); | ||
|
||
const useStatus = <TResponse,>() => | ||
useQuery<TResponse, AxiosError>({ | ||
queryKey: ['getStatus', procedure], | ||
queryFn: getStatus, | ||
retry: 0, | ||
}); | ||
|
||
const useUploadLinks = <TData extends { numberOfDocuments: number }>({ | ||
onSuccess, | ||
onError, | ||
}: { | ||
onSuccess: (links: UploadLink[]) => void; | ||
onError: () => void; | ||
}) => | ||
useMutation({ | ||
mutationFn: (data: TData) => getDocumentsLinks(data), | ||
onSuccess: (links) => { | ||
onSuccess?.(links); | ||
}, | ||
onError: () => { | ||
onError?.(); | ||
}, | ||
}); | ||
|
||
const useUploadDocuments = ({ | ||
onSuccess, | ||
onError, | ||
}: { | ||
onSuccess: () => void; | ||
onError: () => void; | ||
}) => | ||
useMutation({ | ||
mutationFn: ({ files, links }: UploadDocumentsProps) => { | ||
return uploadDocuments(files, links); | ||
}, | ||
onSuccess: () => { | ||
onSuccess?.(); | ||
}, | ||
onError: () => { | ||
// TODO: add logs to better understand what is going wrong on procedure finalization (MANAGER-15281) | ||
onError?.(); | ||
}, | ||
retry: 1, | ||
retryDelay: 3000, | ||
}); | ||
return { | ||
useStatus, | ||
useUploadLinks, | ||
useUploadDocuments, | ||
}; | ||
}; |
11 changes: 0 additions & 11 deletions
11
packages/manager/apps/procedures/src/data/hooks/useStatus.tsx
This file was deleted.
Oops, something went wrong.
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.