From 969dbf759eb0a83da0d2c027bac5781cb1cd14f3 Mon Sep 17 00:00:00 2001 From: Max Didur Date: Tue, 16 Jan 2024 05:49:32 +0300 Subject: [PATCH] Send api request on button click --- src/main/components/calculator/Calculator.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/components/calculator/Calculator.tsx b/src/main/components/calculator/Calculator.tsx index 08bb08c..745905c 100644 --- a/src/main/components/calculator/Calculator.tsx +++ b/src/main/components/calculator/Calculator.tsx @@ -1,7 +1,8 @@ import React from 'react'; import { ContextCalculate } from '../../context/ContextCalculate' import { useContext } from 'react'; -import classes from './Calculator.module.css'; +import classes from './Calculator.module.css'; +import axios from "axios"; const Calculator: React.FC = () => { @@ -38,16 +39,17 @@ const Calculator: React.FC = () => { if (unmaskedValue.length === 11) { const data = { phoneNumber: phoneValue.replace(/\D/g,''), - choosenOperator: choosenOperator, + chosenOperator: choosenOperator, minutesSelectedOption: minutesSelection, - internetSeletedOption: internetSelection, + internetSelectedOption: internetSelection, rent: isRentChecked, redeem: isRedeemChecked, socials: [isFbActive, isVkActive, isOkActive, isInstActive, isTtActive], - totalAmount: totalAmount, + totalAmount: totalAmount } const SelectedOptionsToBackend = JSON.stringify(data); - console.log(SelectedOptionsToBackend); + axios.post('https://tariff-server-meatael.amvera.io/api/add/', data) + .finally(() => console.log(SelectedOptionsToBackend)) } else { setErrorState(2); window.scrollTo({