From 43490bbcba251c0088d3eeb46a81db241c9643b4 Mon Sep 17 00:00:00 2001
From: Patrick Fic <>
Date: Tue, 22 Sep 2020 11:11:15 -0700
Subject: [PATCH] Resolved CORS errors for document upload BOD-407
---
bodyshop_translations.babel | 21 +++++++++++++++++++
client/src/App/App.container.jsx | 2 +-
.../documents-upload.utility.js | 16 +++++++-------
...obs-documents-gallery.delete.component.jsx | 8 ++++++-
client/src/translations/en_us/common.json | 1 +
client/src/translations/es/common.json | 1 +
client/src/translations/fr/common.json | 1 +
7 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel
index c34ca4682..d3354b19e 100644
--- a/bodyshop_translations.babel
+++ b/bodyshop_translations.babel
@@ -7082,6 +7082,27 @@
+
+ deleting_cloudinary
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
getpresignurl
false
diff --git a/client/src/App/App.container.jsx b/client/src/App/App.container.jsx
index ca114ff0e..54c796803 100644
--- a/client/src/App/App.container.jsx
+++ b/client/src/App/App.container.jsx
@@ -22,7 +22,7 @@ import App from "./App";
moment.locale("en-US");
-axios.interceptors.request.use(
+export const axiosAuthInterceptorId = axios.interceptors.request.use(
async (config) => {
if (!config.headers.Authorization) {
const token =
diff --git a/client/src/components/documents-upload/documents-upload.utility.js b/client/src/components/documents-upload/documents-upload.utility.js
index 7700a0232..3b10ae9f5 100644
--- a/client/src/components/documents-upload/documents-upload.utility.js
+++ b/client/src/components/documents-upload/documents-upload.utility.js
@@ -5,8 +5,12 @@ import { client } from "../../App/App.container";
import { INSERT_NEW_DOCUMENT } from "../../graphql/documents.queries";
import i18n from "i18next";
import { logImEXEvent } from "../../firebase/firebase.utils";
-
+import { axiosAuthInterceptorId } from "../../App/App.container";
//Context: currentUserEmail, bodyshop, jobid, invoiceid
+
+var cleanAxios = axios.create();
+cleanAxios.interceptors.request.eject(axiosAuthInterceptorId);
+
export const handleUpload = (ev, context) => {
console.log("ev", ev);
@@ -102,12 +106,10 @@ export const uploadToS3 = (
formData.append("timestamp", timestamp);
formData.append("signature", signature);
- axios
- .post(
- `${process.env.REACT_APP_CLOUDINARY_ENDPOINT}/upload`,
- formData,
- options
- )
+ cleanAxios
+ .post(`${process.env.REACT_APP_CLOUDINARY_ENDPOINT}/upload`, formData, {
+ ...options,
+ })
.then((response) => {
console.log("Upload Response", response);
client
diff --git a/client/src/components/jobs-documents-gallery/jobs-documents-gallery.delete.component.jsx b/client/src/components/jobs-documents-gallery/jobs-documents-gallery.delete.component.jsx
index 7142170f0..939e2d035 100644
--- a/client/src/components/jobs-documents-gallery/jobs-documents-gallery.delete.component.jsx
+++ b/client/src/components/jobs-documents-gallery/jobs-documents-gallery.delete.component.jsx
@@ -6,6 +6,12 @@ import { useMutation } from "@apollo/react-hooks";
import { DELETE_DOCUMENT } from "../../graphql/documents.queries";
import { logImEXEvent } from "../../firebase/firebase.utils";
+import { axiosAuthInterceptorId } from "../../App/App.container";
+//Context: currentUserEmail, bodyshop, jobid, invoiceid
+
+var cleanAxios = axios.create();
+cleanAxios.interceptors.request.eject(axiosAuthInterceptorId);
+
export default function JobsDocumentsDeleteButton({
galleryImages,
deletionCallback,
@@ -37,7 +43,7 @@ export default function JobsDocumentsDeleteButton({
formData.append("timestamp", timestamp);
formData.append("signature", signature);
- axios
+ cleanAxios
.post(
`${process.env.REACT_APP_CLOUDINARY_ENDPOINT}/destroy`,
formData,
diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json
index 1c8739bc2..7e603c673 100644
--- a/client/src/translations/en_us/common.json
+++ b/client/src/translations/en_us/common.json
@@ -472,6 +472,7 @@
},
"errors": {
"deletes3": "Error deleting document from storage. ",
+ "deleting_cloudinary": "Error deleting document from storage. {{message}}",
"getpresignurl": "Error obtaining presigned URL for document. {{message}}",
"insert": "Unable to upload file. {{message}}",
"nodocuments": "There are no documents."
diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json
index b6c3fe3b9..61bc64028 100644
--- a/client/src/translations/es/common.json
+++ b/client/src/translations/es/common.json
@@ -472,6 +472,7 @@
},
"errors": {
"deletes3": "Error al eliminar el documento del almacenamiento.",
+ "deleting_cloudinary": "",
"getpresignurl": "Error al obtener la URL prescrita para el documento. {{message}}",
"insert": "Incapaz de cargar el archivo. {{message}}",
"nodocuments": "No hay documentos"
diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json
index 62e3045e0..49c4c93c3 100644
--- a/client/src/translations/fr/common.json
+++ b/client/src/translations/fr/common.json
@@ -472,6 +472,7 @@
},
"errors": {
"deletes3": "Erreur lors de la suppression du document du stockage.",
+ "deleting_cloudinary": "",
"getpresignurl": "Erreur lors de l'obtention de l'URL présignée pour le document. {{message}}",
"insert": "Incapable de télécharger le fichier. {{message}}",
"nodocuments": "Il n'y a pas de documents."