Skip to content

Commit

Permalink
upload lambda endpoint used for transfer (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel authored May 11, 2022
1 parent 6ad5afe commit f60bb58
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
37 changes: 20 additions & 17 deletions client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export async function fetchConfig(): Promise<Config> {
urlVideoIdleTips
videoRecorderMaxLength
classifierLambdaEndpoint
uploadLambdaEndpoint
}
}
`,
Expand Down Expand Up @@ -1650,22 +1651,24 @@ export async function importMentor(
mentor: string,
json: MentorExportJson,
replacedMentorDataChanges: ReplacedMentorDataChanges,
accessToken: string
): Promise<MentorGQL> {
const data = new FormData();
data.append(
"body",
JSON.stringify({
mentor: mentor,
mentorExportJson: json,
replacedMentorDataChanges: replacedMentorDataChanges,
})
accessToken: string,
uploadLambdaEndpoint?: string
): Promise<void> {
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, "");
}
2 changes: 2 additions & 0 deletions client/src/components/import-export/import-in-progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -150,6 +151,7 @@ export default function ImportInProgressDialog(props: {
function onClose() {
loadMentor();
setOpen(false);
navigate("/");
}

return (
Expand Down
5 changes: 4 additions & 1 deletion client/src/hooks/graphql/use-with-import-export.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,6 +79,7 @@ export function useWithImportExport(): UseWithImportExport {
[]
);
const [oldAnswersToRemove, setOldAnswersToRemove] = useState<AnswerGQL[]>([]);
const { state: configState } = useWithConfig();

async function onMentorExported(): Promise<void> {
if (!mentorId || isUpdating) {
Expand Down Expand Up @@ -140,7 +142,8 @@ export function useWithImportExport(): UseWithImportExport {
mentorId,
importedJson,
getReplacedMentorChanges(),
accessToken
accessToken,
configState.config?.uploadLambdaEndpoint
)
.then(() => {
setImportJson(undefined);
Expand Down
2 changes: 2 additions & 0 deletions client/src/hooks/graphql/use-with-setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface UseWithSetup {
setupSteps: SetupStep[];
idleTipsVideoUrl: string;
classifierLambdaEndpoint: string;
uploadLambdaEndpoint: string;
mentor?: Mentor;
isEdited: boolean;
isLoading: boolean;
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Config {
urlVideoIdleTips: string;
videoRecorderMaxLength: number;
classifierLambdaEndpoint: string;
uploadLambdaEndpoint: string;
}

export interface Connection<T> {
Expand Down
2 changes: 2 additions & 0 deletions cypress/cypress/support/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ export interface Config {
urlVideoIdleTips: string;
videoRecorderMaxLength: number;
classifierLambdaEndpoint: string;
uploadLambdaEndpoint: string;
}

export const CONFIG_DEFAULT: Config = {
googleClientId: "fake-google-client-id",
urlVideoIdleTips: "",
videoRecorderMaxLength: 300,
classifierLambdaEndpoint: "",
uploadLambdaEndpoint: "",
};

export function mockGQLConfig(config: Partial<Config>): MockGraphQLQuery {
Expand Down

0 comments on commit f60bb58

Please sign in to comment.