diff --git a/src/components/Abonnement.js b/src/components/Abonnement.js index e9c1081..6c6b496 100644 --- a/src/components/Abonnement.js +++ b/src/components/Abonnement.js @@ -30,6 +30,8 @@ import SendIcon from '@mui/icons-material/Send'; import { confirmAlert } from 'react-confirm-alert'; // Import import { RiAddCircleLine } from "react-icons/ri"; import img_loading_spin from "./../mysy_img/mysy_spin_loading.gif"; +import 'react-tooltip/dist/react-tooltip.css' +import { Tooltip } from 'react-tooltip' function Abonnement(props) { @@ -644,6 +646,15 @@ function Abonnement(props) { const [new_nb_formations, setnew_nb_formations] = useState(); function Change_Partne_Nb_Ftion() { + setcode_promo_code(""); + setcode_promo_type(""); + setcode_promo_valeur(""); + setcode_promo_text_to_display(""); + + sethandleOnblur_Code_Promo_api(""); + sethandleOnblur_Code_Promo_result(""); + sethandleOnblur_Code_Promo_message(""); + setchangepartnb_ftion(true); setnew_nb_formations(parnternbformation); get_production_service_by_pack(); @@ -676,6 +687,14 @@ function Abonnement(props) { } function annule_enreg_new_ftion() { + setcode_promo_code(""); + setcode_promo_type(""); + setcode_promo_valeur(""); + setcode_promo_text_to_display(""); + + sethandleOnblur_Code_Promo_api(""); + sethandleOnblur_Code_Promo_result(""); + sethandleOnblur_Code_Promo_message(""); setchangepartnb_ftion(false); } @@ -775,8 +794,13 @@ function Abonnement(props) { form.append("token", stored_cookie); form.append("periodicite", "mensuel"); - form.append("discount", "0"); + //form.append("discount", "0"); form.append("pack", currentpack); + form.append("discount_code", code_promo_code); + form.append("discount_type", code_promo_type); + form.append("discount_valeur", code_promo_valeur); + form.append("discount_qty", new_nb_formations); + /* /!\ : Important, il faut preciser le nombre d'article envoyé avec ceci : form.append("nb_product", nb_article); @@ -793,12 +817,13 @@ function Abonnement(props) { form.append("0", JSON.stringify({ - "code": currentpack, "prix": packprice, "comment": "nc", "qty": new_nb_formations, "pack_products": prod_service + "code": currentpack, "prix": packprice, "comment": "nc", "qty": new_nb_formations, + "pack_products": prod_service })); //form.append("1", JSON.stringify({ "code": "art_supp", "prix": "120", "comment": "nc" })); - + setLoading(true); var myurl = process.env.REACT_APP_API_URL + "myclass/api/createOrder/"; @@ -838,7 +863,7 @@ function Abonnement(props) { setLoading(false); }); - // setLoading(false); + // setLoading(false); } @@ -954,14 +979,80 @@ function Abonnement(props) { return; } - confirmSNEwAbonnement(); } + const [code_promo_code, setcode_promo_code] = useState(""); + const [code_promo_type, setcode_promo_type] = useState(""); + const [code_promo_valeur, setcode_promo_valeur] = useState(""); + const [code_promo_text_to_display, setcode_promo_text_to_display] = useState(""); + + const [handleOnblur_Code_Promo_api, sethandleOnblur_Code_Promo_api] = useState(""); + const [handleOnblur_Code_Promo_result, sethandleOnblur_Code_Promo_result] = useState(""); + const [handleOnblur_Code_Promo_message, sethandleOnblur_Code_Promo_message] = useState(""); + + const handleOnblur_Code_Promo = (event) => { + + setcode_promo_code(""); + setcode_promo_type(""); + setcode_promo_valeur(""); + setcode_promo_text_to_display(""); + + sethandleOnblur_Code_Promo_api(""); + sethandleOnblur_Code_Promo_result(""); + sethandleOnblur_Code_Promo_message(""); + + + setcode_promo_code(event.target.value); + //console.log(" ### event.target.value = ", event.target.value); + const formData = new FormData(); + const url = process.env.REACT_APP_API_URL + "myclass/api/Get_Given_Code_Promo/"; + formData.append('token', stored_part); + formData.append('code_promo', event.target.value); + + axios.post(url, formData).then(res => { + //console.log(" In getCurrentUserData res.data.status = " + res.data.status); + //console.log(" In getCurrentUserData res.data.message = " + res.data.message); + if (String(res.data.status) === "true") { + + sethandleOnblur_Code_Promo_api("true"); + sethandleOnblur_Code_Promo_result(res.data.message); + + var mycodepromo_data = JSON.parse(res.data.message); + if (mycodepromo_data) { + //console.log(' mycodepromo_data = ', mycodepromo_data); + if (mycodepromo_data.type) { + setcode_promo_type(mycodepromo_data.type); + } + if (mycodepromo_data.valeur) { + setcode_promo_valeur(mycodepromo_data.valeur); + } + + if (String(mycodepromo_data.type).toLocaleLowerCase() === "fix") { + setcode_promo_text_to_display("- " + mycodepromo_data.valeur + " €") + } + else if (String(mycodepromo_data.type).toLocaleLowerCase() === "percent") { + setcode_promo_text_to_display("- " + mycodepromo_data.valeur + " % ") + } + + } + } + else { + + sethandleOnblur_Code_Promo_api("false"); + sethandleOnblur_Code_Promo_message(res.data.message); + } + + }).catch((error) => { + console.warn('Erro handleOnblur_Code_Promo = ', error); + sethandleOnblur_Code_Promo_api("false"); + }) + } + return (