github.com/replicatedhq/ship@v0.55.0/web/init/src/redux/data/kustomizeSettings/actions.js (about) 1 import "isomorphic-fetch"; 2 import { loadingData } from "../../ui/main/actions"; 3 //import { Utilities } from "../../../utilities/utilities"; 4 5 export const constants = { 6 RECEIVE_METADATA: "RECEIVE_METADATA", 7 SET_HELM_CHART_ERROR: "SET_HELM_CHART_ERROR" 8 }; 9 10 export function receiveMetadata(payload) { 11 return { 12 type: constants.RECEIVE_METADATA, 13 payload 14 }; 15 } 16 17 export function setHelmChartError(error) { 18 return { 19 type: constants.SET_HELM_CHART_ERROR, 20 payload: error 21 } 22 } 23 24 export function getMetadata(loaderType = "getMetadata") { 25 return async (dispatch, getState) => { 26 const { apiEndpoint } = getState(); 27 let response; 28 dispatch(loadingData(loaderType, true)); 29 try { 30 const url = `${apiEndpoint}/metadata`; 31 response = await fetch(url, { 32 method: "GET", 33 headers: { 34 "Accept": "application/json", 35 }, 36 }); 37 if (!response.ok) { 38 dispatch(loadingData(loaderType, false)); 39 return; 40 } 41 const body = await response.json(); 42 dispatch(loadingData(loaderType, false)); 43 dispatch(receiveMetadata(body)); 44 } catch (error) { 45 console.log(error); 46 // if (Utilities.isFailedToFetchErr(error.message)) { 47 // dispatch(receiveHelmChartMetadata({ currentStep: {}, phase: "loading"})); 48 // } else { 49 // dispatch(setHelmChartError(error.message)); 50 // } 51 return; 52 } 53 }; 54 } 55 56 export function saveHelmChartValues(payload, loaderType = "saveHelmChartValues") { 57 return async (dispatch, getState) => { 58 const { apiEndpoint } = getState(); 59 let response; 60 dispatch(loadingData(loaderType, true)); 61 const url = `${apiEndpoint}/helm-values`; 62 response = await fetch(url, { 63 method: "POST", 64 body: JSON.stringify(payload), 65 headers: { 66 "Accept": "application/json", 67 "Content-Type": "application/json" 68 } 69 }); 70 if (!response.ok) { 71 dispatch(loadingData(loaderType, false)); 72 if (response.status === 400) { 73 return response.json(); 74 } 75 throw new Error("Internal server error"); 76 } 77 const body = await response.blob(); 78 dispatch(loadingData(loaderType, false)); 79 return body; 80 }; 81 }