import React, { useState } from "react"; import "bootstrap/dist/css/bootstrap.min.css"; import moment from "moment"; import { Col, FormGroup, Row, Container, Label } from "reactstrap"; import { Formik, Form, Field } from "formik"; import * as Yup from "yup"; import { Input, Submit } from "formstrap"; import { callAPI } from "../../../actions/API"; import Msgbox from "../../../actions/Msgbox"; import { builfArrayFromObject } from "../../../actions/Error"; // Main form and POST Request to add migrations // found at /book under the web hosting migration tab // Things to add: // better date time picking. const InputValidation = Yup.object().shape({ domain: Yup.string() .matches( /^((https?):\/\/)?(www.)?[a-z0-9]+(\.[a-z]{2,}){1,3}(#?\/?[a-zA-Z0-9#]+)*\/?(\?[a-zA-Z0-9-_]+=[a-zA-Z0-9-%]+&?)?$/i, "Enter correct url!" ) .required("Please enter a domain"), username: Yup.string().min(2, "Too Short!").required("Required"), original_server: Yup.string() .required("Please enter a valid IPv4 or domain"), new_server: Yup.string() .required("Please enter a valid IPv4 or domain"), agent_booked: Yup.string() .min(2, "Too short!") .required("Please enter your name!"), booked_time: Yup.string().required("Time is needed!"), ticket_id: Yup.string().required("Please add a ticket ID!"), brand: Yup.string().required("Bush Did 911"), migration_type: Yup.string().required("Type is required!"), booked_date: Yup.date().required("Please enter a date!"), }); export const CPanelBooking = (timeslots) => { const [respID, setRespID] = useState(0); const [error, setError] = useState(0); const initialValues = { submit_time: moment().format("YYYY-MM-DD"), dateTime: "2019-03-11T12:00:00.000Z", }; const onSubmit = async (values, { setSubmitting, resetForm }) => { console.log(values); callAPI .post("/book/", values) .then(function (response) { // console.log(response); // add function here setRespID(response.data.id); setError(0); resetForm({ values: "" }); }) .catch(function (error) { setError(builfArrayFromObject(error.response.data)); setRespID(0); }); setSubmitting(false); }; return ( {({ handleSubmit, handleChange, handleBlur, values, touched, isValid, errors, }) => (
{timeslots.timeslots.map((slot) => )} Submit {respID ? : null} {error ? : null}
)}
); };