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, + }) => ( +
+
+
+ {/* Only show this on update */} + {props.type === "update" ? ( +
+ + + +
+ ) : null} +
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
+ + + +
+ +
+ + + +
+ +
+ + + +
+
+ + + +
+
+
+
+ + + +
+ +
+ + + +
+
+ + + +
+
+
+
+ + + +
+ +
+ +