NewGoLinkForm.jsx 2.94 KB
Newer Older
David Haynes's avatar
David Haynes committed
1 2
import React, { useState } from "react";
import NewGoLinkValidator from "../Molecules/NewGoLinkValidator";
David Haynes's avatar
David Haynes committed
3
import { Formik, Field, Form } from "formik";
David Haynes's avatar
David Haynes committed
4 5
import { GetCSRFToken } from "../../Utils/GetCSRFToken";
import { SingleDatePicker } from "react-dates";
David Haynes's avatar
David Haynes committed
6
import moment from "moment";
7 8 9 10 11 12 13 14 15 16 17
import {
  FormGroup,
  Button,
  Label,
  FormText,
  Row,
  Col,
  InputGroup,
  InputGroupAddon,
  InputGroupText
} from "reactstrap";
David Haynes's avatar
David Haynes committed
18
import MasonstrappedFormInput from "../Molecules/MasonstrappedFormInput";
David Haynes's avatar
David Haynes committed
19

20 21 22 23 24 25 26 27 28
const divStyle = {
  display: "block"
};

const style2 = {
  borderTopLeftRadius: "0rem",
  borderBottomLeftRadius: "0rem"
};

David Haynes's avatar
David Haynes committed
29 30
const NewGoLinkForm = props => {
  const [focused, setFocused] = useState(false);
David Haynes's avatar
David Haynes committed
31 32 33
  var today = new Date();
  var tomorrow = new Date();
  tomorrow.setDate(today.getDate() + 1);
David Haynes's avatar
David Haynes committed
34

David Haynes's avatar
David Haynes committed
35 36 37 38
  return (
    <Formik
      //
      initialValues={{
39
        shortcode: "",
David Haynes's avatar
David Haynes committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        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>
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
          <Row>
            <Col md="12">
              <FormGroup>
                <Label for="targetURL">Target URL</Label>
                <Field
                  name="targetURL"
                  type="text"
                  placeholder="https://longwebsitelink.com"
                  component={MasonstrappedFormInput}
                />
                <FormText>The URL that you would like to shorten.</FormText>
              </FormGroup>
            </Col>
          </Row>

          <Row>
            <Col>
              <FormGroup>
                <Label for="shortcode">Shortcode</Label>
                <InputGroup>
                  <InputGroupAddon addonType="prepend" style={divStyle}>
                    https://go.gmu.edu/
                  </InputGroupAddon>
                  <Field
                    name="shortcode"
                    type="text"
                    placeholder=""
                    className="form-control"
                    style={style2}
                    component={MasonstrappedFormInput}
                  />
                </InputGroup>
                <FormText>The unique address for your target URL.</FormText>
              </FormGroup>
            </Col>
          </Row>

          <legend />
David Haynes's avatar
David Haynes committed
101

102 103 104 105 106 107 108 109 110 111 112 113
          <Row>
            <Col>
              <Button
                type="submit"
                disabled={isSubmitting}
                outline
                color="primary"
              >
                Submit
              </Button>
            </Col>
          </Row>
David Haynes's avatar
David Haynes committed
114 115 116 117
        </Form>
      )}
    />
  );
David Haynes's avatar
David Haynes committed
118 119 120
};

export default NewGoLinkForm;