From f60bb5822bbe37dc6c4df899c47a1bf1b3998aaa Mon Sep 17 00:00:00 2001 From: Aaron shiel <57824522+aaronshiel@users.noreply.github.com> Date: Wed, 11 May 2022 00:58:03 -0700 Subject: [PATCH] upload lambda endpoint used for transfer (#187) --- client/src/api.ts | 37 ++++++++++--------- .../import-export/import-in-progress.tsx | 2 + .../hooks/graphql/use-with-import-export.tsx | 5 ++- client/src/hooks/graphql/use-with-setup.tsx | 2 + client/src/types.ts | 1 + cypress/cypress/support/functions.ts | 2 + 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/client/src/api.ts b/client/src/api.ts index 566140c3..0a6d2bac 100644 --- a/client/src/api.ts +++ b/client/src/api.ts @@ -237,6 +237,7 @@ export async function fetchConfig(): Promise { urlVideoIdleTips videoRecorderMaxLength classifierLambdaEndpoint + uploadLambdaEndpoint } } `, @@ -1650,22 +1651,24 @@ export async function importMentor( mentor: string, json: MentorExportJson, replacedMentorDataChanges: ReplacedMentorDataChanges, - accessToken: string -): Promise { - const data = new FormData(); - data.append( - "body", - JSON.stringify({ - mentor: mentor, - mentorExportJson: json, - replacedMentorDataChanges: replacedMentorDataChanges, - }) + accessToken: string, + uploadLambdaEndpoint?: string +): Promise { + return execHttp( + "POST", + urljoin(uploadLambdaEndpoint || UPLOAD_ENTRYPOINT, "/transfer/mentor"), + { + axiosConfig: { + data: JSON.stringify({ + mentor: mentor, + mentorExportJson: json, + replacedMentorDataChanges: replacedMentorDataChanges, + }), + headers: { + "Content-Type": "application/json", + }, + }, + accessToken, + } ); - const result = await uploadRequest.post("/transfer/mentor/", data, { - headers: { - "Content-Type": "multipart/form-data", - Authorization: `Bearer ${accessToken}`, - }, - }); - return getDataFromAxiosResponse(result, ""); } diff --git a/client/src/components/import-export/import-in-progress.tsx b/client/src/components/import-export/import-in-progress.tsx index 289bfd35..9ba98d3f 100644 --- a/client/src/components/import-export/import-in-progress.tsx +++ b/client/src/components/import-export/import-in-progress.tsx @@ -28,6 +28,7 @@ import { import { useWithLogin } from "store/slices/login/useWithLogin"; import useActiveMentor from "store/slices/mentor/useActiveMentor"; import { isImportComplete } from "hooks/graphql/use-with-import-status"; +import { navigate } from "@reach/router"; const useStyles = makeStyles(() => ({ progressIcon: { @@ -150,6 +151,7 @@ export default function ImportInProgressDialog(props: { function onClose() { loadMentor(); setOpen(false); + navigate("/"); } return ( diff --git a/client/src/hooks/graphql/use-with-import-export.tsx b/client/src/hooks/graphql/use-with-import-export.tsx index 916bd115..2ce85a57 100644 --- a/client/src/hooks/graphql/use-with-import-export.tsx +++ b/client/src/hooks/graphql/use-with-import-export.tsx @@ -26,6 +26,7 @@ import { AnswerGQL, SubjectGQL, SubjectQuestionGQL } from "types-gql"; import { useAppSelector } from "store/hooks"; import { useWithImportStatus } from "./use-with-import-status"; import { useWithSubjects } from "./use-with-subjects"; +import { useWithConfig } from "store/slices/config/useWithConfig"; export interface UseWithImportExport { importedJson?: MentorExportJson; @@ -78,6 +79,7 @@ export function useWithImportExport(): UseWithImportExport { [] ); const [oldAnswersToRemove, setOldAnswersToRemove] = useState([]); + const { state: configState } = useWithConfig(); async function onMentorExported(): Promise { if (!mentorId || isUpdating) { @@ -140,7 +142,8 @@ export function useWithImportExport(): UseWithImportExport { mentorId, importedJson, getReplacedMentorChanges(), - accessToken + accessToken, + configState.config?.uploadLambdaEndpoint ) .then(() => { setImportJson(undefined); diff --git a/client/src/hooks/graphql/use-with-setup.tsx b/client/src/hooks/graphql/use-with-setup.tsx index 5ad86601..b9ebdd4a 100644 --- a/client/src/hooks/graphql/use-with-setup.tsx +++ b/client/src/hooks/graphql/use-with-setup.tsx @@ -61,6 +61,7 @@ interface UseWithSetup { setupSteps: SetupStep[]; idleTipsVideoUrl: string; classifierLambdaEndpoint: string; + uploadLambdaEndpoint: string; mentor?: Mentor; isEdited: boolean; isLoading: boolean; @@ -258,6 +259,7 @@ export function useWithSetup(search?: { i?: string }): UseWithSetup { idleTipsVideoUrl: configState.config?.urlVideoIdleTips || "", classifierLambdaEndpoint: configState.config?.classifierLambdaEndpoint || "", + uploadLambdaEndpoint: configState.config?.uploadLambdaEndpoint || "", mentor: editedMentor, isEdited: isMentorEdited, isLoading: isMentorLoading, diff --git a/client/src/types.ts b/client/src/types.ts index e0c4345d..93e788e5 100644 --- a/client/src/types.ts +++ b/client/src/types.ts @@ -13,6 +13,7 @@ export interface Config { urlVideoIdleTips: string; videoRecorderMaxLength: number; classifierLambdaEndpoint: string; + uploadLambdaEndpoint: string; } export interface Connection { diff --git a/cypress/cypress/support/functions.ts b/cypress/cypress/support/functions.ts index 7c99f71c..b49a6768 100644 --- a/cypress/cypress/support/functions.ts +++ b/cypress/cypress/support/functions.ts @@ -82,6 +82,7 @@ export interface Config { urlVideoIdleTips: string; videoRecorderMaxLength: number; classifierLambdaEndpoint: string; + uploadLambdaEndpoint: string; } export const CONFIG_DEFAULT: Config = { @@ -89,6 +90,7 @@ export const CONFIG_DEFAULT: Config = { urlVideoIdleTips: "", videoRecorderMaxLength: 300, classifierLambdaEndpoint: "", + uploadLambdaEndpoint: "", }; export function mockGQLConfig(config: Partial): MockGraphQLQuery {