diff --git a/src/components/App.js b/src/components/App.js index ae7414a..4a429cd 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -15,6 +15,7 @@ import IDSingle from "./root/Pages/IDSingle"; // Components import Home from "./root/Home"; import Navigation from "./root/Navigation"; +import Autobook from "./root/Pages/Autobook"; // Main app component, react-router comes from here, // and links to all of the sub pages @@ -73,6 +74,7 @@ class App extends Component { path="/booked" render={(props) => } /> + diff --git a/src/components/root/Pages/Autobook.js b/src/components/root/Pages/Autobook.js new file mode 100644 index 0000000..ed76b68 --- /dev/null +++ b/src/components/root/Pages/Autobook.js @@ -0,0 +1,75 @@ +import React, { Component } from "react"; +import { CredChecker } from "../common/Forms/CredChecker"; +import FormPage from "../common/Forms/FormPage"; +import { callAPI } from "../../actions/API"; +import { GenericForm } from "../common/Forms/GenericForm"; +import moment from "moment"; + +export default class Book extends Component { + constructor(props) { + super(props); + this.state = { + data: null, + timeslots: [], + }; + } + preBookedData = { + submit_time: moment().format("YYYY-MM-DD"), + dateTime: "2019-03-11T12:00:00.000Z", + migration_status: "Booked", + domain: null, + username: "", + original_server: null, + new_server: "", + agent_booked: "", + booked_time: "", + ticket_id: "", + brand: "", + migration_type: "cPanel", + booked_date: "", + term_date: "", + additional_domains: null, + notes: "", + }; + + componentDidMount() { + callAPI.get("/gettimeslots/").then((response) => { + this.setState({ + timeslots: response.data, + }); + // console.log(response.data); + }); + } + + credCallback = (credData) => { + console.log(credData); + this.setState({ + data: credData, + }); + console.log(this.state.data); + this.preBookedData.domain = this.state.data[0].data.main_domain; + this.preBookedData.additional_domains = this.state.data[0].data.other_domains; + this.preBookedData.username = this.state.data[1].username; + this.preBookedData.original_server = this.state.data[1].hostname; + console.log(this.preBookedData); + }; + render() { + if (this.state.data) { + return ( +
+ {console.log(this.preBookedData)} + {this.state.data[0].data.main_domain ? ( + + ) : ( +
+ )} +
+ ); + } else { + return ; + } + } +} diff --git a/src/components/root/Pages/Book.js b/src/components/root/Pages/Book.js index d2e346a..82836ea 100644 --- a/src/components/root/Pages/Book.js +++ b/src/components/root/Pages/Book.js @@ -1,6 +1,7 @@ import React, { Component } from "react"; import { callAPI } from "../../actions/API"; +import { CredChecker } from "../common/Forms/CredChecker"; import FormPage from "../common/Forms/FormPage"; // Parent page for the Book component, @@ -22,6 +23,7 @@ export default class Book extends Component { this.setState({ timeslots: response.data }) + console.log(response.data) }) } diff --git a/src/components/root/common/Forms/CredChecker.js b/src/components/root/common/Forms/CredChecker.js new file mode 100644 index 0000000..0d50e69 --- /dev/null +++ b/src/components/root/common/Forms/CredChecker.js @@ -0,0 +1,31 @@ +import React from "react"; +import { callAPI } from "../../../actions/API"; + +export const CredChecker = (props) => { + + const sendit = () => { + let values = { + hostname: document.getElementById("Host").value, + username: document.getElementById("User").value, + password: document.getElementById("Pass").value, + } + callAPI + .post('/checkcpanel/', values) + .then( (resp) => { + props.credCallback([resp, values]) + }) + console.log() + + } + return ( +
+
+
+
+
+
+
+ +
+ ) +} \ No newline at end of file diff --git a/src/components/root/common/Forms/GenericForm.js b/src/components/root/common/Forms/GenericForm.js index 1b5883c..abba04f 100644 --- a/src/components/root/common/Forms/GenericForm.js +++ b/src/components/root/common/Forms/GenericForm.js @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { Formik, Form, ErrorMessage } from "formik"; import * as Yup from "yup"; import moment from "moment"; @@ -10,462 +10,484 @@ import { builfArrayFromObject } from "../../../actions/Error"; export const GenericForm = (props) => { const [respID, setRespID] = useState(0); const [error, setError] = useState(0); + const [initial, setInitial] = useState({}); + const [set, setSet] = useState(false); + + useEffect(() => { + // console.log(initial); + // console.log(initial.domain); + + if (!set) { + console.log(typeof initial.domain); + if (props.data) { + setInitial(props.data); + setSet(true); + } else { + setInitial({ + 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: "", + }); + setSet(true); + } + } + }); 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 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" ? ( + console.log(initial); + if (set) { + 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}
- - + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
+ + +
+ +
+ + + +
+ +
+ + + +
+
+ + +
- ) : null} -
- - -
-
- - - +
+
+ + + +
+ +
+ + + +
+
+ + + +
-
- - - +
+
+ + + +
+ +
+ +