function* submitBrandSettingsForm(action) {
  const state = store.getState();
  const { form } = action.payload;
  const fields = getFields(form)(state);
  const brandID = getRecordID(form)(state);

  try {
    if (!fields.getIn(['name', 'isValid'])) throw new Error('Please input a brand name');
    if (!fields.getIn(['image', 'isValid'])) throw new Error('Please input an image URL');
    if (!fields.getIn(['url', 'isValid'])) throw new Error('Please input a URL');

    const updatedRecord = yield api.update('brand', brandID, {
      name: fields.getIn(['name', 'value']),
      image: fields.getIn(['image', 'value']),
      url: fields.getIn(['url', 'value']),
      background: fields.getIn(['background', 'value']),
      text: fields.getIn(['text', 'value']),
      secondary: fields.getIn(['secondary', 'value']),
    });

    yield put(syncStore('brand', updatedRecord));
    yield put(submitFormSuccess(form));
  } catch (e) {
    yield put(submitFormError(form, e));
  }
}
function* submitCompanySettingsForm(action) {
  const state = store.getState();
  const { form } = action.payload;
  const fields = getFields(form)(state);
  const companyID = getRecordID(form)(state);

  try {
    if (!fields.getIn(['name', 'isValid'])) throw new Error('Please input a company name');
    if (!fields.getIn(['street', 'isValid'])) throw new Error('Please input a street address');
    if (!fields.getIn(['city', 'isValid'])) throw new Error('Please input a city');
    if (!fields.getIn(['state', 'isValid'])) throw new Error('Please input a state');
    if (!fields.getIn(['zip', 'isValid'])) throw new Error('Please input a zip code');
    if (!fields.getIn(['phone', 'isValid'])) throw new Error('Please input a phone number');
    if (!fields.getIn(['url', 'isValid'])) throw new Error('Please input a valid URL');
    if (!fields.getIn(['email', 'isValid'])) throw new Error('Please input a valid email');
    if (!fields.getIn(['description', 'isValid'])) throw new Error('Please input a description');

    const updatedRecord = yield api.update('company', companyID, {
      name: fields.getIn(['name', 'value']),
      street: fields.getIn(['street', 'value']),
      streetTwo: fields.getIn(['streetTwo', 'value']),
      city: fields.getIn(['city', 'value']),
      state: fields.getIn(['state', 'value']),
      zip: fields.getIn(['zip', 'value']),
      country: fields.getIn(['country', 'value']),
      phone: fields.getIn(['phone', 'value']),
      fax: fields.getIn(['fax', 'value']),
      url: fields.getIn(['url', 'value']),
      email: fields.getIn(['email', 'value']),
      description: fields.getIn(['description', 'value']),
      yearEstablished: fields.getIn(['yearEstablished', 'value']),
      numberEmployees: fields.getIn(['numberEmployees', 'value']),
      annualRevenue: fields.getIn(['annualRevenue', 'value']),
      businessOwnership: fields.getIn(['businessOwnership', 'value']),
      oldName: fields.getIn(['oldName', 'value']),
      oldStreet: fields.getIn(['oldStreet', 'value']),
      oldStreetTwo: fields.getIn(['oldStreetTwo', 'value']),
      oldCity: fields.getIn(['oldCity', 'value']),
      oldState: fields.getIn(['oldState', 'value']),
      oldZip: fields.getIn(['oldZip', 'value']),
      oldCountry: fields.getIn(['oldCountry', 'value']),
      oldPhone: fields.getIn(['oldPhone', 'value']),
      oldFax: fields.getIn(['oldFax', 'value']),
      oldUrl: fields.getIn(['oldUrl', 'value']),
      oldEmail: fields.getIn(['oldEmail', 'value']),
      oldDescription: fields.getIn(['oldDescription', 'value']),
      approved: false,
      lastUpdated: moment().format('L'),
    });

    yield put(syncStore('company', updatedRecord));
    yield put(submitFormSuccess(form));

    browserHistory.push('/company/people');
  } catch (e) {
    yield put(submitFormError(form, e));
  }
}