How do I validate the name of files uploaded using yup and react

Viewed 22
const SUPPORTED_NAMES = ['Account', 'Location', 'SS'];

const validationSchema = yup.object({
  files: yup
    .mixed()
    .test('required', 'You need to provide a file', (value) => {
      if (value.length > 0) {
        return true;
      }
      return false;
    })
    .test(
      'fileName',
      'Unsupported name',
      (value) => value && SUPPORTED_NAMES.includes(value.name)
    ),
});

The issue I have now is that my validation is not supporting any file name. I want to be able to only upload files that includes the values from SUPPORTED_NAMES and be able to submit it.

0 Answers
Related