1
0
Fork 0

Replace axios with built-in Fetch API

Decreases size of the bundle from 375 to 347 KB

Signed-off-by: Egor Savkin <es@m-labs.hk>
This commit is contained in:
Egor Savkin 2023-11-21 16:48:21 +08:00
parent f11ebc1152
commit b7087711aa
3 changed files with 13 additions and 7 deletions

View File

@ -16,7 +16,6 @@
"@babel/core": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"@babel/preset-react": "^7.22.15",
"axios": "^1.6.0",
"babel-loader": "^9.1.3",
"babel-preset-minify": "^0.5.2",
"bootstrap": "^5.3.0",

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,6 @@
'use strict';
import React from "react";
import axios from "axios";
import { createRoot } from "react-dom/client";
import PropTypes from "prop-types";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
@ -1910,11 +1909,18 @@ class Shop extends React.PureComponent {
this.setState({isProcessing: true});
axios.post(data.API_RFQ, {
fetch(data.API_RFQ, {
method: "POST",
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
email,
note,
configuration: JSON.stringify(crate)
})
}).then(response => {
if (response.status !== 200) {
throw Error("Response status is not OK: " + response.status + ".\n" + response);
}
this.setState({
isProcessing: false,
shouldShowRFQFeedback: true,
@ -1922,6 +1928,7 @@ class Shop extends React.PureComponent {
isProcessingComplete: true,
});
}).catch(err => {
console.error("Request failed, reason:", err)
this.setState({isProcessing: false}, () => {
alert("We cannot receive your request. Try using the export by coping the configuration and send it to us at sales[at]m-labs.hk");
});