Commit b67231a2 authored by David Haynes's avatar David Haynes 🙆

really bad first passing working DebugUpdate

parent ec65da65
Pipeline #3591 passed with stage
in 1 minute and 32 seconds
import React from "react";
import * as Yup from "yup";
import { Formik, Field, Form, ErrorMessage } from "formik";
import { GetCSRFToken } from "../../Utils";
const DebugUpdateYup = Yup.object().shape({
destination: Yup.string()
.url()
.max(1000, "Too Long!"),
oldshort: Yup.string()
.required("Required")
.max(20, "Too Long!"),
newshort: Yup.string()
.required("Required")
.max(20, "Too Long!")
// expires: Yup.date()
// .nullable()
// .min(new Date(new Date().getTime() + 24 * 60 * 60 * 1000))
});
const DebugUpdate = () => (
<div>
<Formik
initialValues={{
oldshort: "",
newshort: "",
newdestination: "",
expires: null
}}
validationSchema={DebugUpdateYup}
onSubmit={(
{ newshort, oldshort, expires, destination },
{ setSubmitting }
) => {
const updateURL = "/api/golinks/" + oldshort + "/";
const payload = {
short: newshort,
destination: destination,
expires: expires
};
fetch(updateURL, {
method: "put",
headers: {
"Content-Type": "application/json",
"X-CSRFToken": GetCSRFToken()
},
body: JSON.stringify(payload)
})
.then(response => console.log(response))
.then(setSubmitting(false));
}}
render={({ isSubmitting }) => (
<Form>
{"Old Short: "}
<Field name="oldshort" />
<ErrorMessage name="oldshort" />
{"New Destination: "}
<Field name="destination" placeholder="https://longwebsitelink.com" />
<ErrorMessage name="destination" component="div" />
{"New Short: "}
<Field name="newshort" />
<ErrorMessage name="newshort" />
{"New Expires: "}
<Field type="select" name="expires" placeholder="leave blank" />
<ErrorMessage name="expires" />
<button type="submit" disabled={isSubmitting}>
Submit
</button>
</Form>
)}
/>
</div>
);
export default DebugUpdate;
......@@ -2,5 +2,6 @@ import AuthButton from "./AuthButton";
import DebugRead from "./DebugRead";
import DebugCreate from "./DebugCreate";
import DebugDelete from "./DebugDelete";
import DebugUpdate from "./DebugUpdate";
export { AuthButton, DebugRead, DebugCreate, DebugDelete };
export { AuthButton, DebugRead, DebugCreate, DebugDelete, DebugUpdate };
import React from "react";
import { PageTemplate, DebugRead, DebugCreate, DebugDelete } from "Components";
import {
PageTemplate,
DebugRead,
DebugCreate,
DebugDelete,
DebugUpdate
} from "Components";
class DebugCRUD extends React.Component {
constructor(props) {
......@@ -20,6 +26,8 @@ class DebugCRUD extends React.Component {
<DebugRead />
<h3>Update</h3>
<DebugUpdate />
<h3>Delete</h3>
<DebugDelete />
</div>
......
import { AuthButton, DebugRead, DebugCreate, DebugDelete } from "./Molecules";
import {
AuthButton,
DebugRead,
DebugCreate,
DebugDelete,
DebugUpdate
} from "./Molecules";
import { NavBar } from "./Organisms";
import { HomePage, AboutPage, DhaynesPage, DebugCRUD } from "./Pages";
import { PageTemplate } from "./Templates";
......@@ -9,6 +15,7 @@ export {
DebugRead,
DebugCreate,
DebugDelete,
DebugUpdate,
//Organisms
NavBar,
//Pages
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment