HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/fintechfuel/node_modules/intl-tel-input/react/src/IntlTelInput.js
/* eslint-disable react/jsx-filename-extension */
import React, { useRef, useEffect } from 'react';
import PropTypes from 'prop-types';
import intlTelInput from "../../build/js/intlTelInput";

const IntlTelInput = ({
  initialValue,
  onChangeNumber,
  onChangeCountry,
  onChangeValidity,
  onChangeErrorCode,
  initOptions,
}) => {
  const inputRef = useRef(null);
  const itiRef = useRef(null);
  
  const update = () => {
    const num = itiRef.current.getNumber();
    const countryIso = itiRef.current.getSelectedCountryData().iso2;
    // note: this number will be in standard E164 format, but any container component can use
    // intlTelInputUtils.formatNumber() to convert this to another format
    // as well as intlTelInputUtils.getNumberType() etc. if need be
    onChangeNumber(num);
    onChangeCountry(countryIso);

    if (itiRef.current.isValidNumber()) {
      onChangeValidity(true);
      onChangeErrorCode(null);
    } else {
      const errorCode = itiRef.current.getValidationError();
      onChangeValidity(false);
      onChangeErrorCode(errorCode);
    }
  };
  
  useEffect(() => {
    itiRef.current = intlTelInput(inputRef.current, initOptions);
    inputRef.current.addEventListener("countrychange", update);
    return () => {
      inputRef.current.removeEventListener("countrychange", update);
      itiRef.current.destroy();
    }
  }, []);
  
  return (
    <input
      type="phone"
      ref={inputRef}
      onInput={update}
      defaultValue={initialValue}
     />
  );
};

IntlTelInput.propTypes = {
    initialValue: PropTypes.string,
    onChangeNumber: PropTypes.func,
    onChangeCountry: PropTypes.func,
    onChangeValidity: PropTypes.func,
    onChangeErrorCode: PropTypes.func,
    initOptions: PropTypes.shape({
        allowDropdown: PropTypes.bool,
        autoInsertDialCode: PropTypes.bool,
        autoPlaceholder: PropTypes.string,
        containerClass: PropTypes.string,
        countrySearch: PropTypes.bool,
        customPlaceholder: PropTypes.func,
        dropdownContainer: PropTypes.node,
        excludeCountries: PropTypes.arrayOf(PropTypes.string),
        fixDropdownWidth: PropTypes.bool,
        formatAsYouType: PropTypes.bool,
        formatOnDisplay: PropTypes.bool,
        geoIpLookup: PropTypes.func,
        hiddenInput: PropTypes.func,
        i18n: PropTypes.objectOf(PropTypes.string),
        initialCountry: PropTypes.string,
        nationalMode: PropTypes.bool,
        onlyCountries: PropTypes.arrayOf(PropTypes.string),
        placeholderNumberType: PropTypes.string,
        preferredCountries: PropTypes.arrayOf(PropTypes.string),
        showFlags: PropTypes.bool,
        showSelectedDialCode: PropTypes.bool,
        useFullscreenPopup: PropTypes.bool,
        utilsScript: PropTypes.string,
    }),
};

IntlTelInput.defaultProps = {
    initialValue: "",
    onChangeNumber: () => {},
    onChangeCountry: () => {},
    onChangeValidity: () => {},
    onChangeErrorCode: () => {},
    initOptions: {},
};

export default IntlTelInput;