diff --git a/GomezMorinFrontEnd/src/pages/Login/index.jsx b/GomezMorinFrontEnd/src/pages/Login/index.jsx index 4d02672..eeaba56 100644 --- a/GomezMorinFrontEnd/src/pages/Login/index.jsx +++ b/GomezMorinFrontEnd/src/pages/Login/index.jsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React from "react"; import InputForm from "../../components/InputForm"; import Button from "../../components/Button"; import IconTitle from "../../components/IconTitle"; @@ -8,7 +8,6 @@ import { useForm, FormProvider } from "react-hook-form"; import { loginUser } from "../../queries/queryAuth"; import { useNavigate } from "react-router-dom"; import { setAccessToken, setUser } from "../../states/authSlice"; -import { useSelector } from "react-redux"; import jwt_decode from "jwt-decode"; import { useDispatch } from "react-redux"; /** @@ -20,19 +19,8 @@ import { useDispatch } from "react-redux"; const Login = () => { const methods = useForm(); const navigate = useNavigate(); - const [userName, setUserName] = useState(""); - const [password, setPassword] = useState(""); const dispatch = useDispatch(); - const handleInputChange = (event) => { - const { name, value } = event.target; - if (name === "userName") { - setUserName(value); - } else { - setPassword(value); - } - }; - const onSubmitUser = async (data) => { try { const response = await loginUser(data); @@ -65,7 +53,6 @@ const Login = () => { placeholder="Ingresa tu Usuario" defaultValue="" value={userName} - onChange={handleInputChange} /> @@ -77,7 +64,6 @@ const Login = () => { placeholder="Ingresa tu ContraseƱa" defaultValue="" value={password} - onChange={handleInputChange} /> diff --git a/GomezMorinFrontEnd/src/pages/RequestForm/index.jsx b/GomezMorinFrontEnd/src/pages/RequestForm/index.jsx index 2a7a548..044fb05 100644 --- a/GomezMorinFrontEnd/src/pages/RequestForm/index.jsx +++ b/GomezMorinFrontEnd/src/pages/RequestForm/index.jsx @@ -8,6 +8,8 @@ import SpecificForm from "./SpecificForm"; import SendForm from "./SendForm"; import { useDispatch } from "react-redux"; import { useSelector } from "react-redux"; +import { createRequest } from "../../queries/queryRequestForm"; + import { showUserForm, showInitialForm, @@ -29,6 +31,7 @@ const RequestForm = () => { const typeEvent = useSelector((state) => state.form.typeEventForm); const methods = useForm(); const setValue = methods.setValue; + const userId = useSelector((state) => state.auth.id); const dispatch = useDispatch(); const formState = useSelector((state) => state.form.formState); @@ -56,7 +59,7 @@ const RequestForm = () => { * * @param {Object} data - The data collected from the form. */ - const onSubmit = (data) => { + const onSubmit = async (data) => { if (formState === "UserForm") { dispatch(showUserForm()); } @@ -79,6 +82,11 @@ const RequestForm = () => { if (formState === "SubmitForm") { /* Submit Form Logic */ + try { + await createRequest({ ...data, userId: userId }); + } catch (err) { + alert(err.response.data.message); + } } }; diff --git a/GomezMorinFrontEnd/src/queries/queryRequestForm.js b/GomezMorinFrontEnd/src/queries/queryRequestForm.js new file mode 100644 index 0000000..02165b4 --- /dev/null +++ b/GomezMorinFrontEnd/src/queries/queryRequestForm.js @@ -0,0 +1,167 @@ +import axios from "axios"; + +const baseURL = import.meta.env.VITE_BASEURL; + +/** + * Creates an Axios request with the given data + * + * @param {object} data - An object containing the data required to create the request + * @param {string} data.typeEvent - Type of the event + * @param {string} data.nameEvent - Name of the event + * @param {string} data.targetAudience - Target audience of the event + * @param {string} data.generalDescription - General description of the event + * @param {string} data.startDay - Start day of the event + * @param {string} data.startTime - Start time of the event + * @param {string} data.endDay - End day of the event + * @param {string} data.endTime - End time of the event + * @param {string} data.openingDay - Opening day of the event + * @param {string} data.inauguration - Inauguration of the event + * @param {string} data.authorities - Authorities of the event + * @param {string} data.place - Place of the event + * @param {string} data.cost - Cost of the event + * @param {string} data.fee - Fee of the event + * @param {string} data.socialNetwork - Social network of the event + * @param {string} data.ineDoc - INE document of the requester + * @param {string} data.addressDoc - Address document of the requester + * @param {string} data.curpDoc - CURP document of the requester + * @param {string} data.extraDoc - Extra document of the requester + * @param {string} data.requestDate - Date of the request + * @param {string} data.nameRequester - Name of the requester + * @param {string} data.cellphone - Cellphone number of the requester + * @param {string} data.phoneEmergency - Emergency phone number of the requester + * @param {string} data.email - Email of the requester + * @param {string} data.direction - Direction of the event + * @param {string} data.postalCode - Postal code of the event + * @param {string} data.street - Street of the event + * @param {string} data.colony - Colony of the event + * @param {string} data.publicEvent - Public or private event + * @param {string} data.chairNumber - Number of chairs required for the event + * @param {string} data.specificDescription - Specific description of the event + * @param {string} data.assistance - Assistance required for the event + * @param {string} data.ages - Ages allowed for the event + * @param {string} data.requiredSpace - Required space for the event + * @param {string} data.equipment - Equipment required for the event + * @param {string} data.selfEquipment - Self equipment for the event + * @param {string} data.softInstallation - Soft installation for the event + * @param {string} data.electricInstallation - Electric installation for the event + * @param {string} data.mounting - Mounting for the event + * @param {string} data.tableNumber - Number of tables required for the event + * @param {string} data.openingDayDate - Opening day date of the event + * @param {string} data.openingDayTime - Opening day time of the event + * @param {string} data.sound - Sound required for the event + * @param {string} data.microphone - Microphone required for the event + * @returns {Promise} A promise that resolves with the response data from the server + */ + +export const createRequest = async (data) => { + const formData = new FormData(); + const { + typeEvent, + nameEvent, + targetAudience, + generalDescription, + startDay, + startTime, + endDay, + endTime, + openingDay, + inauguration, + authorities, + place, + cost, + fee, + socialNetwork, + ineDoc, + addressDoc, + curpDoc, + extraDoc, + requestDate, + nameRequester, + cellphone, + phoneEmergency, + email, + direction, + postalCode, + street, + colony, + publicEvent, + chairNumber, + specificDescription, + assistance, + ages, + requiredSpace, + equipment, + selfEquipment, + softInstallation, + electricInstallation, + mounting, + tableNumber, + openingDayDate, + openingDayTime, + sound, + microphone, + userId, + } = data; + + formData.append("typeEvent", typeEvent); + formData.append("nameEvent", nameEvent); + formData.append("targetAudience", targetAudience); + formData.append("generalDescription", generalDescription); + formData.append("startDay", startDay); + formData.append("startTime", startTime); + formData.append("endDay", endDay); + formData.append("endTime", endTime); + formData.append("openingDay", openingDay); + formData.append("inauguration", inauguration); + formData.append("authorities", authorities); + formData.append("place", place); + formData.append("cost", cost); + formData.append("fee", fee); + formData.append("socialNetwork", socialNetwork); + formData.append("requestDate", requestDate); + formData.append("nameRequester", nameRequester); + formData.append("cellphone", cellphone); + formData.append("phoneEmergency", phoneEmergency); + formData.append("email", email); + formData.append("direction", direction); + formData.append("postalCode", postalCode); + formData.append("street", street); + formData.append("colony", colony); + formData.append("publicEvent", publicEvent); + formData.append("chairNumber", chairNumber); + formData.append("specificDescription", specificDescription); + formData.append("assistance", assistance); + formData.append("ages", ages); + formData.append("requiredSpace", requiredSpace); + formData.append("equipment", equipment); + formData.append("selfEquipment", selfEquipment); + formData.append("softInstallation", softInstallation); + formData.append("electricInstallation", electricInstallation); + formData.append("mounting", mounting); + formData.append("tableNumber", tableNumber); + formData.append("openingDayDate", openingDayDate); + formData.append("openingDayTime", openingDayTime); + formData.append("sound", sound); + formData.append("microphone", microphone); + formData.append("userPtr", userId); + + const arrayFile = [ineDoc[0], addressDoc[0], curpDoc[0]]; + + if (extraDoc) { + arrayFile.push(extraDoc[0]); + } + + formData.append("file", arrayFile); + + try { + const response = await axios({ + url: `${baseURL}/solicitudes/solicitud`, + method: "POST", + data: formData, + headers: { "Content-Type": "multipart/form-data" }, + }); + return response.data; + } catch (err) { + return Promise.reject(err); + } +};