<commit_before>import React from 'react';
import Relay from 'react-relay';
import GCForm from './forms/GCForm';
import Form from 'react-formal';
import yup from 'yup';
import moment from 'moment';
import {Card, CardActions, CardExpandable, CardTitle, CardHeader, CardText, FlatButton, TextField, DropDownMenu, SelectField, DatePicker, TimePicker, Checkbox} from 'material-ui';
import {BernieText, BernieColors} from './styles/bernie-css';

const InfoHeader = ({content}) => (
  <h3 style={BernieText.smallHeader}>{content}</h3>
);

let GCSelectField = ({name, floatingLabelText, selectedIndex, onChange, valueMember, menuItems, fullWidth}) => (
  <div>
    <SelectField
      selectedIndex={selectedIndex}
      floatingLabelText={floatingLabelText}
      menuItems={menuItems}
      fullWidth={fullWidth}
      floatingLabelStyle={{transform: 'perspective(1px) scale(0.75) translate3d(2px, -28px, 0)'}}
      onChange={onChange}
    />
    <input
      name={name}
      value={menuItems[selectedIndex]['payload']}
      readOnly
      // style={{display:'none'}}
    />
  </div>
);

class Event {
  constructor(bsdEvent) {
    this.node = bsdEvent;
    this.dateTime = {
      startDate: moment(bsdEvent.startDate),
      duration: {
        h: Math.floor(bsdEvent.duration/60),
        m: bsdEvent.duration % 60
      }
    };
  }
}

// Pull in valid event types and titles later
const eventTypeOptions = [
   { payload: 1, text: 'Test event 1' },
   { payload: 2, text: 'Test event 2' },
   { payload: 3, text: 'Phonebank' }
];

export class EventEdit extends React.Component {
  constructor(props) {
    super(props);

    let event = this.props.event.node;
    event['dateTime'] = {
      startDate: moment(event.startDate),
      duration: {
        h: Math.floor(event.duration/60),
        m: event.duration % 60
      }
    };

    let eventTypeIndex = 0;
    eventTypeOptions.forEach((type, index) => {
      if (type.text == event.eventType.name){
        eventTypeIndex = index;
      }
    });

    this.state = {
      event: event,
      eventTypeIndex: eventTypeIndex
    };
  }

  renderForm() {
    let event = this.state.event;
    const defaultStr = yup.string().default('');  
    const eventSchema = yup.object({
      name: yup.string().default(event.name)
        .required('An event name is required'),

      eventTypeId: yup.number()
        .default(eventTypeOptions[this.state.eventTypeIndex]['payload'])
        .required('Please select an event type'),

      description: yup.string().default(event.description)
        .required('An event description is required'),

      rsvpReminderHours: yup.number()
        .default(event.rsvpReminderHours)
        .min(0)
        .nullable(),

      startDate: yup.date()
        .default(event.dateTime.startDate.toDate())
        .required('Please select a date'),
  
      duration: yup.object({
        h: yup.number()
          .default(event.dateTime.duration.h)
          .min(0)
          .nullable()
          .required('Please enter a number of hours'),

        m: yup.number()
          .default(event.dateTime.duration.m)
          .min(0).max(59)
          .nullable()
          .required('Please enter a number of minutes'),
      }),

      venue: yup.object({
        name: yup.string().default(event.venueName)
          .required('please enter a venue name'),

        addr1: yup.string().default(event.venueAddr1)
          .required('please enter an event address'),

        addr2: yup.string().default(event.venueAddr2)
          .nullable(),

        city: yup.string().default(event.venueCity)
          .required('please enter a city'),

        state: yup.string().default(event.venueState)
          .required('please enter a state'),

        zip: yup.string().default(event.venueZip)
          .required('please enter a zip code'),

        country: yup.string().default(event.venueCountry)
          .required('please enter a country'),

        directions: yup.string().default(event.venueDirections)
          .nullable(),

        capacity: yup.number()
          .default(event.capacity)
          .min(0)
          .required('please enter an event capacity'),
      }),

      contactPhone: yup.string()
        .default(event.contactPhone)
        .required('A contact phone number is required'),

      publicPhone: yup.boolean()
        .default(event.publicPhone),

      hostReceiveRsvpEmails: yup.boolean()
        .default(event.hostReceiveRsvpEmails),

      rsvpUseReminderEmail: yup.boolean()
        .default(event.rsvpUseReminderEmail),

      attendeeVolunteerShow: yup.boolean()
        .default(event.attendeeVolunteerShow),

      attendeeVolunteerMessage: yup.string()
        .default(event.attendeeVolunteerMessage),

      isSearchable: yup.boolean()
        .default((event.isSearchable == 1)),

      flagApproval: yup.boolean()
        .default(false)

    });
    
    const form = (
      <GCForm
        schema={eventSchema}
        defaultValue={eventSchema.default()}
        onSubmit={function(data){console.log(data)}}
        onError={function(data){console.log(data)}}
      >

        <InfoHeader content='Event Information' />

        <Form.Field
          name='name'
          floatingLabelText='Event Name'
          fullWidth={true}
        />

        <GCSelectField
          name="eventTypeId"
          floatingLabelText="Event Type"
          selectedIndex={this.state.eventTypeIndex}
          menuItems={eventTypeOptions}
          fullWidth={true}
          onChange={(event, index) => {
            this.setState({
              eventTypeIndex: index<commit_msg>Convert to fat arrow functions<commit_after>import React from 'react';
import Relay from 'react-relay';
import GCForm from './forms/GCForm';
import Form from 'react-formal';
import yup from 'yup';
import moment from 'moment';
import {Card, CardActions, CardExpandable, CardTitle, CardHeader, CardText, FlatButton, TextField, DropDownMenu, SelectField, DatePicker, TimePicker, Checkbox} from 'material-ui';
import {BernieText, BernieColors} from './styles/bernie-css';

const InfoHeader = ({content}) => (
  <h3 style={BernieText.smallHeader}>{content}</h3>
);

let GCSelectField = ({name, floatingLabelText, selectedIndex, onChange, valueMember, menuItems, fullWidth}) => (
  <div>
    <SelectField
      selectedIndex={selectedIndex}
      floatingLabelText={floatingLabelText}
      menuItems={menuItems}
      fullWidth={fullWidth}
      floatingLabelStyle={{transform: 'perspective(1px) scale(0.75) translate3d(2px, -28px, 0)'}}
      onChange={onChange}
    />
    <input
      name={name}
      value={menuItems[selectedIndex]['payload']}
      readOnly
      // style={{display:'none'}}
    />
  </div>
);

class Event {
  constructor(bsdEvent) {
    this.node = bsdEvent;
    this.dateTime = {
      startDate: moment(bsdEvent.startDate),
      duration: {
        h: Math.floor(bsdEvent.duration/60),
        m: bsdEvent.duration % 60
      }
    };
  }
}

// Pull in valid event types and titles later
const eventTypeOptions = [
   { payload: 1, text: 'Test event 1' },
   { payload: 2, text: 'Test event 2' },
   { payload: 3, text: 'Phonebank' }
];

export class EventEdit extends React.Component {
  constructor(props) {
    super(props);

    let event = this.props.event.node;
    event['dateTime'] = {
      startDate: moment(event.startDate),
      duration: {
        h: Math.floor(event.duration/60),
        m: event.duration % 60
      }
    };

    let eventTypeIndex = 0;
    eventTypeOptions.forEach((type, index) => {
      if (type.text == event.eventType.name){
        eventTypeIndex = index;
      }
    });

    this.state = {
      event: event,
      eventTypeIndex: eventTypeIndex
    };
  }

  renderForm() {
    let event = this.state.event;
    const defaultStr = yup.string().default('');  
    const eventSchema = yup.object({
      name: yup.string().default(event.name)
        .required('An event name is required'),

      eventTypeId: yup.number()
        .default(eventTypeOptions[this.state.eventTypeIndex]['payload'])
        .required('Please select an event type'),

      description: yup.string().default(event.description)
        .required('An event description is required'),

      rsvpReminderHours: yup.number()
        .default(event.rsvpReminderHours)
        .min(0)
        .nullable(),

      startDate: yup.date()
        .default(event.dateTime.startDate.toDate())
        .required('Please select a date'),
  
      duration: yup.object({
        h: yup.number()
          .default(event.dateTime.duration.h)
          .min(0)
          .nullable()
          .required('Please enter a number of hours'),

        m: yup.number()
          .default(event.dateTime.duration.m)
          .min(0).max(59)
          .nullable()
          .required('Please enter a number of minutes'),
      }),

      venue: yup.object({
        name: yup.string().default(event.venueName)
          .required('please enter a venue name'),

        addr1: yup.string().default(event.venueAddr1)
          .required('please enter an event address'),

        addr2: yup.string().default(event.venueAddr2)
          .nullable(),

        city: yup.string().default(event.venueCity)
          .required('please enter a city'),

        state: yup.string().default(event.venueState)
          .required('please enter a state'),

        zip: yup.string().default(event.venueZip)
          .required('please enter a zip code'),

        country: yup.string().default(event.venueCountry)
          .required('please enter a country'),

        directions: yup.string().default(event.venueDirections)
          .nullable(),

        capacity: yup.number()
          .default(event.capacity)
          .min(0)
          .required('please enter an event capacity'),
      }),

      contactPhone: yup.string()
        .default(event.contactPhone)
        .required('A contact phone number is required'),

      publicPhone: yup.boolean()
        .default(event.publicPhone),

      hostReceiveRsvpEmails: yup.boolean()
        .default(event.hostReceiveRsvpEmails),

      rsvpUseReminderEmail: yup.boolean()
        .default(event.rsvpUseReminderEmail),

      attendeeVolunteerShow: yup.boolean()
        .default(event.attendeeVolunteerShow),

      attendeeVolunteerMessage: yup.string()
        .default(event.attendeeVolunteerMessage),

      isSearchable: yup.boolean()
        .default((event.isSearchable == 1)),

      flagApproval: yup.boolean()
        .default(false)

    });
    
    const form = (
      <GCForm
        schema={eventSchema}
        defaultValue={eventSchema.default()}
        onSubmit={(data) => {
          console.log(data)
        }}
        onError={(data) => {
          console.log(data)
        }}
        id='editForm'
      >

        <InfoHeader content='Event Information' />

        <Form.Field
          name='name'
          floatingLabelText='Event Name'
          fullWidth={true}
        />

        <GCSelectField
          name="eventTypeId"
          floatingLabelText="Event Type"
          selectedIndex={this.state.eventTypeIndex}
          menuItems={eventTypeOptions}
          fullWidth={true}
          onChange={(event, index) => {
            this.setState({
              eventTypeIndex: index
{'fraction_non_alphanumeric': 0.13197206753292673, 'fraction_numerical': 0.006364359586316627, 'mean_word_length': 2.4941321803582457, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '393332', 'n_tokens_mistral': 3408, 'n_tokens_neox': 3309, 'n_words': 674}