diff --git a/src/components/root/Pages/IDSingle.js b/src/components/root/Pages/IDSingle.js
index 44f6fa8..c8c702a 100644
--- a/src/components/root/Pages/IDSingle.js
+++ b/src/components/root/Pages/IDSingle.js
@@ -2,6 +2,7 @@ import React, { Component } from "react";
import ReportSingleMigration from "../common/Forms/ReportSingleMigration";
import { callAPI } from "../../actions/API";
+import { GenericForm } from "../common/Forms/GenericForm";
// This class will populate a form from a UUID in the address bar,
// e.g. /migrations/a7740b79-a7d9-4de7-b01e-00522fa4455a
@@ -14,6 +15,7 @@ export default class Reports extends Component {
super(props);
this.state = {
migs: [],
+ timeslots: [],
};
}
componentDidMount() {
@@ -31,17 +33,28 @@ export default class Reports extends Component {
.catch(function (error) {
console.log(error);
});
+
+ callAPI.get("/gettimeslots/").then((response) => {
+ this.setState({
+ timeslots: response.data,
+ });
+ });
}
render() {
- return (
-
- {/* {this.state.migs} */}
-
-
- );
+ if (this.state.migs.id) {
+ console.log(this.state.migs);
+ return (
+
+
Update migration
+
+
+ );
+ }
+ return ;
}
}
diff --git a/src/components/root/common/Forms/CPanelForm.js b/src/components/root/common/Forms/CPanelForm.js
index ea23e11..6ca84e2 100644
--- a/src/components/root/common/Forms/CPanelForm.js
+++ b/src/components/root/common/Forms/CPanelForm.js
@@ -34,7 +34,7 @@ export const CPanelForm = (timeslots) => {
validationSchema={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,
+ /^((https?):\/\/)?(www.)?[a-z0-9-]+(\.[a-z]{2,}){1,3}(#?\/?[a-zA-Z0-9#]+)*\/?(\?[a-zA-Z0-9-_]+=[a-zA-Z0-9-%]+&?)?$/i,
"Required field"
)
.required("Required field"),
@@ -182,7 +182,7 @@ export const CPanelForm = (timeslots) => {
>
{timeslots.timeslots.map((slot) => (
-
+
))}
{
const [activeTab, setActiveTab] = useState("1");
@@ -51,7 +52,8 @@ const FormPage = ({ timeslots, item }) => {
-
+ {/* */}
+
diff --git a/src/components/root/common/Forms/GenericForm.js b/src/components/root/common/Forms/GenericForm.js
new file mode 100644
index 0000000..1b5883c
--- /dev/null
+++ b/src/components/root/common/Forms/GenericForm.js
@@ -0,0 +1,471 @@
+import React, { useState } from "react";
+import { Formik, Form, ErrorMessage } from "formik";
+import * as Yup from "yup";
+import moment from "moment";
+
+import { callAPI } from "../../../actions/API";
+import Msgbox from "../../../actions/Msgbox";
+import { builfArrayFromObject } from "../../../actions/Error";
+
+export const GenericForm = (props) => {
+ const [respID, setRespID] = useState(0);
+ const [error, setError] = useState(0);
+
+ const getInitial = () => {
+ let initial = {};
+ // console.log(migData);
+ if (props.data) {
+ initial = props.data;
+ } else {
+ initial = {
+ submit_time: moment().format("YYYY-MM-DD"),
+ dateTime: "2019-03-11T12:00:00.000Z",
+ migration_status: "Booked",
+ domain: "",
+ username: "",
+ original_server: "",
+ new_server: "",
+ agent_booked: "",
+ booked_time: "",
+ ticket_id: "",
+ brand: "",
+ migration_type: "",
+ booked_date: "",
+ term_date: "",
+ additional_domains: "",
+ notes: "",
+ };
+ }
+ return initial;
+ };
+
+ return (
+ {
+ console.log(values);
+ if (values.term_date === "") {
+ values.term_date = null; // Complains on dev but not on live #whocares
+ }
+ if (props.type === "update") {
+ callAPI
+ .put(`/${props.data.id}/`, values)
+ .then(function (response) {
+ setRespID(response.data.ticket_id);
+ setError(0);
+ })
+ .catch(function (error) {
+ setError(builfArrayFromObject(error.response.data));
+ setRespID(0);
+ });
+ } else {
+ callAPI
+ .post("/book/", values)
+ .then(function (response) {
+ setRespID(response.data.id);
+ resetForm({ values: "" });
+ })
+ .catch(function (error) {
+ setError(builfArrayFromObject(error.response.data));
+ setRespID(0);
+ });
+ }
+ }}
+ render={({
+ errors,
+ touched,
+ handleChange,
+ values,
+ handleBlur,
+ handleReset,
+ }) => (
+
+
+ {respID ? (
+ props.type === "update" ? (
+
+ ) : (
+
+ )
+ ) : null}
+ {error ?
: null}
+
+ )}
+ />
+ );
+};
diff --git a/src/components/root/common/Forms/__CPanelBooking b/src/components/root/common/Forms/__CPanelBooking
deleted file mode 100644
index a4ca2b9..0000000
--- a/src/components/root/common/Forms/__CPanelBooking
+++ /dev/null
@@ -1,229 +0,0 @@
-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,
- }) => (
-
- )}
-
- );
-};