NewGoLinkForm.jsx 1.72 KB
Newer Older
1 2
import React, { useState } from "react";
import NewGoLinkValidator from "../Molecules/NewGoLinkValidator";
3
import { Formik, Field, Form } from "formik";
4 5
import { GetCSRFToken } from "../../Utils/GetCSRFToken";
import { SingleDatePicker } from "react-dates";
6 7 8
import moment from "moment";
import { FormGroup, Button, Label, FormText } from "reactstrap";
import MasonstrappedFormInput from "../Molecules/MasonstrappedFormInput";
9 10 11

const NewGoLinkForm = props => {
  const [focused, setFocused] = useState(false);
12 13 14
  var today = new Date();
  var tomorrow = new Date();
  tomorrow.setDate(today.getDate() + 1);
15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
  return (
    <Formik
      //
      initialValues={{
        // shortcode: "",
        targetURL: ""
        // willExpire: false,
        // expires: moment(tomorrow)
      }}
      //
      validationSchema={NewGoLinkValidator}
      //
      onSubmit={({ targetURL }, { setSubmitting }) => {
        console.log("submitting..");
        console.log(targetURL);
        setSubmitting(false);
      }}
      //
      render={({
        values,
        isSubmitting,
        setFieldValue,
        errors,
        touched,
        handleBlur,
        handleChange
      }) => (
        <Form>
          <FormGroup>
            <Label for="targetURL">Target URL</Label>
            <Field
              name="targetURL"
              type="text"
              placeholder="https://longwebsitelink.com"
              component={MasonstrappedFormInput}
            />
            <FormText>Example help text that remains unchanged.</FormText>
          </FormGroup>

          <Button type="submit" disabled={isSubmitting} outline color="primary">
            Submit
          </Button>
        </Form>
      )}
    />
  );
62 63 64
};

export default NewGoLinkForm;