Sindbad~EG File Manager

Current Path : /var/www/html/amopropiedades.com/wp-content/plugins/leadin/scripts/shared/Form/hooks/
Upload File :
Current File : /var/www/html/amopropiedades.com/wp-content/plugins/leadin/scripts/shared/Form/hooks/useForms.ts

import { useState } from 'react';
import debounce from 'lodash/debounce';
import { usePostAsyncBackgroundMessage } from '../../../iframe/useBackgroundApp';
import { DEFAULT_OPTIONS } from '../../../constants/defaultFormOptions';
import { ProxyMessages } from '../../../iframe/integratedMessages';
import { IForm } from '../../types';

export default function useForms() {
  const proxy = usePostAsyncBackgroundMessage();
  const [formApiError, setFormApiError] = useState<any>(null);

  const search = debounce(
    (search: string, callback: Function) => {
      return proxy({
        key: ProxyMessages.FetchForms,
        payload: {
          search,
        },
      })
        .then(forms => {
          callback([
            ...forms.map((form: IForm) => ({
              label: form.name,
              value: form.guid,
            })),
            DEFAULT_OPTIONS,
          ]);
        })
        .catch(error => {
          setFormApiError(error);
        });
    },
    300,
    { trailing: true }
  );

  return {
    search,
    formApiError,
    reset: () => setFormApiError(null),
  };
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists