From 81dcd5be165ea57a0c7f3b31e54c78f3bdc9d20d Mon Sep 17 00:00:00 2001
From: manisha <manisha_kanyal.scsebtech@galgotiasuniversity.edu.in>
Date: May 27 2021 02:31:44 +0000
Subject: move API endpoints to a constant file


---

diff --git a/public/env.js b/public/env.js
index dd8a30a..b884ca9 100644
--- a/public/env.js
+++ b/public/env.js
@@ -1,4 +1,4 @@
 window.env = {
-    SUBDIR: '/',
-    ORACULUM_API_URL_v1: 'https://packager-dashboard.fedoraproject.org/api/v1/'
+  SUBDIR: "/",
+  ORACULUM_API_URL_v1: "https://packager-dashboard.fedoraproject.org/api/v1",
 };
diff --git a/src/actions/reduxActions.js b/src/actions/reduxActions.js
index 8b9d0c1..a564b51 100644
--- a/src/actions/reduxActions.js
+++ b/src/actions/reduxActions.js
@@ -4,76 +4,73 @@ import {
   MAX_RETRY_LIMIT,
   FIRST_RETRY_GAP,
 } from "../constants/ProjectConstants"
+import { endpoints } from "../constants/endpoints"
 
 export const loadDataResp = (payload) => ({
   type: ActionTypes.LOAD_DATA_RESP,
   payload: payload,
 })
 
-export const loadData = (
-  payload,
-  retryLimit = MAX_RETRY_LIMIT,
-  secondsToWait = FIRST_RETRY_GAP
-) => (dispatch) => {
-  dispatch({
-    type: ActionTypes.LOAD_DATA,
-    payload: payload,
-  })
-  dispatch(updateLandingPageApiCallStatus(API_CALL_STATUS_VALUES.STARTED))
-  fetch(window.env.ORACULUM_API_URL_v1 + "landing_page")
-    .then((blob) => blob.json())
-    .then((data) => {
-      dispatch(loadDataResp(data))
-      dispatch(updateLandingPageApiCallStatus(API_CALL_STATUS_VALUES.FULFILLED))
+export const loadData =
+  (payload, retryLimit = MAX_RETRY_LIMIT, secondsToWait = FIRST_RETRY_GAP) =>
+  (dispatch) => {
+    dispatch({
+      type: ActionTypes.LOAD_DATA,
+      payload: payload,
     })
-    .catch((error) => {
-      if (retryLimit > 0) {
-        dispatch(updateLandingPageApiCallStatus(API_CALL_STATUS_VALUES.RETRYING))
-        console.log("Failed to fetch, retrying", MAX_RETRY_LIMIT - retryLimit)
-        window.setTimeout(() => {
-          dispatch(loadData(payload, retryLimit - 1, secondsToWait * 2))
-        }, secondsToWait * 1000)
-      } else {
-        dispatch(updateLandingPageApiCallStatus(API_CALL_STATUS_VALUES.FAILED))
-        console.error("Error:", error)
-      }
-    })
-}
+    dispatch(updateLandingPageApiCallStatus(API_CALL_STATUS_VALUES.STARTED))
+    fetch(endpoints.landingPage)
+      .then((blob) => blob.json())
+      .then((data) => {
+        dispatch(loadDataResp(data))
+        dispatch(updateLandingPageApiCallStatus(API_CALL_STATUS_VALUES.FULFILLED))
+      })
+      .catch((error) => {
+        if (retryLimit > 0) {
+          dispatch(updateLandingPageApiCallStatus(API_CALL_STATUS_VALUES.RETRYING))
+          console.log("Failed to fetch, retrying", MAX_RETRY_LIMIT - retryLimit)
+          window.setTimeout(() => {
+            dispatch(loadData(payload, retryLimit - 1, secondsToWait * 2))
+          }, secondsToWait * 1000)
+        } else {
+          dispatch(updateLandingPageApiCallStatus(API_CALL_STATUS_VALUES.FAILED))
+          console.error("Error:", error)
+        }
+      })
+  }
 
 export const loadWizardDataResp = (payload) => ({
   type: ActionTypes.LOAD_WIZARD_DATA_RESP,
   payload: payload,
 })
 
-export const loadWizardData = (
-  payload,
-  retryLimit = MAX_RETRY_LIMIT,
-  secondsToWait = FIRST_RETRY_GAP
-) => (dispatch) => {
-  dispatch({
-    type: ActionTypes.LOAD_WIZARD_DATA,
-    payload: payload,
-  })
-  dispatch(updateWizardApiCallStatus(API_CALL_STATUS_VALUES.STARTED))
-  fetch(window.env.ORACULUM_API_URL_v1 + "actions/all")
-    .then((blob) => blob.json())
-    .then((data) => {
-      dispatch(loadWizardDataResp(data))
-      dispatch(updateWizardApiCallStatus(API_CALL_STATUS_VALUES.FULFILLED))
-    })
-    .catch((error) => {
-      if (retryLimit > 0) {
-        dispatch(updateWizardApiCallStatus(API_CALL_STATUS_VALUES.RETRYING))
-        console.log("Failed to fetch, retrying", MAX_RETRY_LIMIT - retryLimit)
-        window.setTimeout(() => {
-          dispatch(loadWizardData(payload, retryLimit - 1, secondsToWait * 2))
-        }, secondsToWait * 1000)
-      } else {
-        dispatch(updateWizardApiCallStatus(API_CALL_STATUS_VALUES.FAILED))
-        console.error("Error:", error)
-      }
+export const loadWizardData =
+  (payload, retryLimit = MAX_RETRY_LIMIT, secondsToWait = FIRST_RETRY_GAP) =>
+  (dispatch) => {
+    dispatch({
+      type: ActionTypes.LOAD_WIZARD_DATA,
+      payload: payload,
     })
-}
+    dispatch(updateWizardApiCallStatus(API_CALL_STATUS_VALUES.STARTED))
+    fetch(endpoints.allActions)
+      .then((blob) => blob.json())
+      .then((data) => {
+        dispatch(loadWizardDataResp(data))
+        dispatch(updateWizardApiCallStatus(API_CALL_STATUS_VALUES.FULFILLED))
+      })
+      .catch((error) => {
+        if (retryLimit > 0) {
+          dispatch(updateWizardApiCallStatus(API_CALL_STATUS_VALUES.RETRYING))
+          console.log("Failed to fetch, retrying", MAX_RETRY_LIMIT - retryLimit)
+          window.setTimeout(() => {
+            dispatch(loadWizardData(payload, retryLimit - 1, secondsToWait * 2))
+          }, secondsToWait * 1000)
+        } else {
+          dispatch(updateWizardApiCallStatus(API_CALL_STATUS_VALUES.FAILED))
+          console.error("Error:", error)
+        }
+      })
+  }
 
 export const updateLandingPageApiCallStatus = (status) => ({
   type: ActionTypes.UPDATE_LANDING_PAGE_API_CALL_STATUS,
diff --git a/src/constants/endpoints.js b/src/constants/endpoints.js
new file mode 100644
index 0000000..888d2e5
--- /dev/null
+++ b/src/constants/endpoints.js
@@ -0,0 +1,6 @@
+export const API_URL = window.env.ORACULUM_API_URL_v1;
+
+export const endpoints = {
+  landingPage: `${API_URL}/landing_page`,
+  allActions: `${API_URL}/actions/all`,
+};

