Commit 35506d49 authored by David Haynes's avatar David Haynes 🙆

Really sketch implementation of submitting go links

- to be abstracted and prettified
parent b74653e6
Pipeline #3574 passed with stage
in 1 minute and 13 seconds
......@@ -3,13 +3,16 @@ import { Formik, Field, Form, ErrorMessage } from "formik";
import * as Yup from "yup";
import { PageTemplate, DebugRead } from "Components";
const SignupSchema = Yup.object().shape({
password: Yup.string()
.min(2, "Too Short!")
.max(50, "Too Long!"),
email: Yup.string()
.email("Invalid email")
const DebugCreate = Yup.object().shape({
destination: Yup.string()
.url()
.max(1000, "Too Long!"),
short: Yup.string()
.required("Required")
.max(20, "Too Long!")
// expires: Yup.date()
// .nullable()
// .min(new Date(new Date().getTime() + 24 * 60 * 60 * 1000))
});
class DebugCRUD extends React.Component {
......@@ -18,6 +21,22 @@ class DebugCRUD extends React.Component {
this.state = {};
}
getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != "") {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == name + "=") {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
render() {
return (
<PageTemplate>
......@@ -26,20 +45,29 @@ class DebugCRUD extends React.Component {
<h3>Create</h3>
<Formik
initialValues={{ email: "", password: "" }}
validationSchema={SignupSchema}
initialValues={{ destination: "", short: "", expires: null }}
validationSchema={DebugCreate}
onSubmit={(values, { setSubmitting }) => {
setTimeout(() => {
console.log(JSON.stringify(values, null, 2));
setSubmitting(false);
}, 400);
fetch("/api/golinks/", {
method: "post",
headers: {
"Content-Type": "application/json",
"X-CSRFToken": this.getCookie("csrftoken")
},
body: JSON.stringify(values)
}).then(response => console.log(response));
}}
render={({ isSubmitting }) => (
<Form>
<Field type="email" name="email" placeholder="Email" />
<ErrorMessage name="email" component="div" />
<Field type="password" name="password" />
<ErrorMessage name="password" />
<Field
name="destination"
placeholder="https://longwebsitelink.com"
/>{" "}
<ErrorMessage name="destination" component="div" />
<Field name="short" />
<ErrorMessage name="short" />
<Field type="select" name="expires" />
<ErrorMessage name="expires" />
<button type="submit" disabled={isSubmitting}>
Submit
</button>
......@@ -51,50 +79,7 @@ class DebugCRUD extends React.Component {
<DebugRead />
<h3>Update</h3>
<Formik
initialValues={{ email: "", password: "" }}
validationSchema={SignupSchema}
onSubmit={(values, { setSubmitting }) => {
setTimeout(() => {
console.log(JSON.stringify(values, null, 2));
setSubmitting(false);
}, 400);
}}
render={({ isSubmitting }) => (
<Form>
<Field type="email" name="email" placeholder="Email" />
<ErrorMessage name="email" component="div" />
<Field type="password" name="password" />
<ErrorMessage name="password" />
<button type="submit" disabled={isSubmitting}>
Submit
</button>
</Form>
)}
/>
<h3>Delete</h3>
<Formik
initialValues={{ email: "", password: "" }}
validationSchema={SignupSchema}
onSubmit={(values, { setSubmitting }) => {
setTimeout(() => {
console.log(JSON.stringify(values, null, 2));
setSubmitting(false);
}, 400);
}}
render={({ isSubmitting }) => (
<Form>
<Field type="email" name="email" placeholder="Email" />
<ErrorMessage name="email" component="div" />
<Field type="password" name="password" />
<ErrorMessage name="password" />
<button type="submit" disabled={isSubmitting}>
Submit
</button>
</Form>
)}
/>
</div>
</PageTemplate>
);
......
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