DebugDelete.jsx 1.11 KB
Newer Older
David Haynes's avatar
David Haynes committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
import React from "react";
import * as Yup from "yup";
import { GetCSRFToken } from "../../Utils";
import { Formik, Field, Form, ErrorMessage } from "formik";

const DebugDeleteYup = Yup.object().shape({
  short: Yup.string()
    .required("Required")
    .max(20, "Too Long!")
});

const DebugDelete = () => (
  <div>
    <Formik
      initialValues={{ short: "" }}
      validationSchema={DebugDeleteYup}
      onSubmit={(values, { setSubmitting }) => {
        const deleteURL = "/api/golinks/" + values.short;
        fetch(deleteURL, {
          method: "delete",
          headers: {
            "Content-Type": "application/json",
            "X-CSRFToken": GetCSRFToken()
          }
        })
          .then(response => console.log(response))
          .then(setSubmitting(false));
      }}
      render={({ isSubmitting }) => (
        <Form>
          {"Short: "}
          <Field name="short" />
          <ErrorMessage name="short" />
David Haynes's avatar
David Haynes committed
34
          <br />
David Haynes's avatar
David Haynes committed
35 36 37 38 39 40 41 42 43 44
          <button type="submit" disabled={isSubmitting}>
            Submit
          </button>
        </Form>
      )}
    />
  </div>
);

export default DebugDelete;