From 7ae0c1f91220fee34e5bc6bdd949995436a92882 Mon Sep 17 00:00:00 2001 From: basileus Date: Mon, 4 Dec 2023 01:55:06 +0200 Subject: [PATCH] feat(task-5): import api integration --- .../components/CSVFileImport.tsx | 40 +++++++++++-------- src/constants/apiPaths.ts | 4 +- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/components/pages/admin/PageProductImport/components/CSVFileImport.tsx b/src/components/pages/admin/PageProductImport/components/CSVFileImport.tsx index d11028c96..5b73a1455 100755 --- a/src/components/pages/admin/PageProductImport/components/CSVFileImport.tsx +++ b/src/components/pages/admin/PageProductImport/components/CSVFileImport.tsx @@ -1,6 +1,7 @@ import React from "react"; import Typography from "@mui/material/Typography"; import Box from "@mui/material/Box"; +import axios from "axios"; type CSVFileImportProps = { url: string; @@ -24,23 +25,30 @@ export default function CSVFileImport({ url, title }: CSVFileImportProps) { const uploadFile = async () => { console.log("uploadFile to", url); + console.log('file', file); - // Get the presigned URL - // const response = await axios({ - // method: "GET", - // url, - // params: { - // name: encodeURIComponent(file.name), - // }, - // }); - // console.log("File to upload: ", file.name); - // console.log("Uploading to: ", response.data); - // const result = await fetch(response.data, { - // method: "PUT", - // body: file, - // }); - // console.log("Result: ", result); - // setFile(""); + + if (file) { + // Get the presigned URL + const { data: { signedUrl }} = await axios({ + method: "GET", + url, + params: { + name: encodeURIComponent(file.name), + }, + }); + console.log("File to upload: ", file.name); + console.log("Uploading to: ", signedUrl); + const result = await fetch(signedUrl, { + mode: 'no-cors', + method: "PUT", + body: file, + }); + console.log("Result: ", result); + setFile(undefined); + } else { + throw new Error('File is undefined'); + } }; return ( diff --git a/src/constants/apiPaths.ts b/src/constants/apiPaths.ts index 6846a7534..6d32cbc0f 100755 --- a/src/constants/apiPaths.ts +++ b/src/constants/apiPaths.ts @@ -1,8 +1,8 @@ const API_PATHS = { product: "https://.execute-api.eu-west-1.amazonaws.com/dev", order: "https://.execute-api.eu-west-1.amazonaws.com/dev", - import: "https://.execute-api.eu-west-1.amazonaws.com/dev", - bff: "https://.execute-api.eu-west-1.amazonaws.com/dev", + import: "https://rzzqm10d2k.execute-api.us-east-1.amazonaws.com/dev", + bff: "https://rzzqm10d2k.execute-api.us-east-1.amazonaws.com/dev", cart: "https://.execute-api.eu-west-1.amazonaws.com/dev", };