<commit_before>import React from 'react';
import fileUploadUI from 'platform/forms-system/src/js/definitions/file';
import environment from 'platform/utilities/environment';
import { representativeFields } from 'applications/caregivers/definitions/constants';
import { RepresentativeDocumentUploadDescription } from 'applications/caregivers/components/AdditionalInfo';
import recordEvent from 'platform/monitoring/record-event';

const createPayload = (file, formId, password) => {
  const payload = new FormData();
  payload.append('attachment[file_data]', file);
  payload.append('form_id', formId);
  payload.append('name', file.name);

  // password for encrypted PDFs
  if (password) {
    payload.append('attachment[password]', password);
  }

  return payload;
};

const parseResponse = (fileInfo, file) => {
  recordEvent({
    'caregivers-poa-document-guid': fileInfo.data.attributes.guid,
    'caregivers-poa-document-confirmation-code': fileInfo.data.id,
  });

  return {
    guid: fileInfo.data.attributes.guid,
    confirmationCode: fileInfo.data.id,
    name: file.name,
  };
};

export default {
  uiSchema: {
    'ui:description': RepresentativeDocumentUploadDescription(),
    'ui:title': () => (
      <h3 className="vads-u-font-size--h4 vads-u-margin--0">
        Upload your legal representative document
        <span className="vads-u-margin-left--0p5 vads-u-color--secondary-dark vads-u-font-size--sm vads-u-font-weight--normal vads-u-font-family--sans">
          (*Required)
        </span>
      </h3>
    ),
    [representativeFields.documentUpload]: fileUploadUI(' ', {
      buttonText: 'Upload',
      classNames: 'poa-document-upload',
      multiple: false,
      fileUploadUrl: `${environment.API_URL}/v0/form1010cg/attachments`,
      fileTypes: ['pdf', 'doc', 'docx', 'jpg', 'jpeg', 'rtf', 'png'],
      maxSize: 1024 * 1024 * 10,
      hideLabelText: true,
      createPayload,
      parseResponse,
      attachmentName: {
        'ui:title': 'Document name',
        'ui:options': {
          useDlWrap: true,
        },
      },
    }),
  },
  schema: {
    type: 'object',
    required: [representativeFields.documentUpload],<commit_msg>fix(1010cg): update poa document upload file type limit (#17414)<commit_after>import React from 'react';
import fileUploadUI from 'platform/forms-system/src/js/definitions/file';
import environment from 'platform/utilities/environment';
import { representativeFields } from 'applications/caregivers/definitions/constants';
import { RepresentativeDocumentUploadDescription } from 'applications/caregivers/components/AdditionalInfo';
import recordEvent from 'platform/monitoring/record-event';

const createPayload = (file, formId, password) => {
  const payload = new FormData();
  payload.append('attachment[file_data]', file);
  payload.append('form_id', formId);
  payload.append('name', file.name);

  // password for encrypted PDFs
  if (password) {
    payload.append('attachment[password]', password);
  }

  return payload;
};

const parseResponse = (fileInfo, file) => {
  recordEvent({
    'caregivers-poa-document-guid': fileInfo.data.attributes.guid,
    'caregivers-poa-document-confirmation-code': fileInfo.data.id,
  });

  return {
    guid: fileInfo.data.attributes.guid,
    confirmationCode: fileInfo.data.id,
    name: file.name,
  };
};

export default {
  uiSchema: {
    'ui:description': RepresentativeDocumentUploadDescription(),
    'ui:title': () => (
      <h3 className="vads-u-font-size--h4 vads-u-margin--0">
        Upload your legal representative document
        <span className="vads-u-margin-left--0p5 vads-u-color--secondary-dark vads-u-font-size--sm vads-u-font-weight--normal vads-u-font-family--sans">
          (*Required)
        </span>
      </h3>
    ),
    [representativeFields.documentUpload]: fileUploadUI(' ', {
      buttonText: 'Upload',
      classNames: 'poa-document-upload',
      multiple: false,
      fileUploadUrl: `${environment.API_URL}/v0/form1010cg/attachments`,
      fileTypes: ['pdf', 'jpg', 'jpeg', 'png'],
      maxSize: 1024 * 1024 * 10,
      hideLabelText: true,
      createPayload,
      parseResponse,
      attachmentName: {
        'ui:title': 'Document name',
        'ui:options': {
          useDlWrap: true,
        },
      },
    }),
  },
  schema: {
    type: 'object',
    required: [representativeFields.documentUpload],
{'fraction_non_alphanumeric': 0.14487793748574035, 'fraction_numerical': 0.01163586584531143, 'mean_word_length': 3.5289256198347108, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '986817', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1329, 'n_words': 256}