config#ONBOARD_URL TypeScript Examples

The following examples show how to use config#ONBOARD_URL. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Registration.tsx    From glific-frontend with GNU Affero General Public License v3.0 4 votes vote down vote up
Registration: React.SFC<RegistrationProps> = (props) => {
  const { title, buttonText, handleStep } = props;
  const [registrationError, setRegistrationError] = useState<any>('');
  const [code, setCode] = useState('shortcode');
  const [redirect, setRedirect] = useState(false);

  if (redirect) {
    handleStep();
  }

  const formFields = (shortcode: string) => [
    {
      component: Input,
      name: 'name',
      type: 'text',
      placeholder: 'NGO name',
    },
    {
      component: PhoneInput,
      name: 'phone',
      type: 'phone',
      placeholder: 'NGO WhatsApp number',
      helperText: 'Please enter a phone number.',
    },
    {
      component: Input,
      name: 'app_name',
      type: 'text',
      placeholder: 'App name',
    },
    {
      component: Input,
      name: 'api_key',
      type: 'text',
      placeholder: 'GupShup API keys',
      helperText: HelperLink,
    },
    {
      component: Input,
      name: 'shortcode',
      type: 'text',
      placeholder: 'URL Shortcode',
      endAdornment: InfoAdornment,
      helperText: `www.${shortcode}.tides.coloredcow.com`,
      inputProp: {
        onChange: (event: any) => {
          const { value } = event.target;
          let text = 'shortcode';
          if (value) text = value;
          setCode(text);
        },
      },
    },
    {
      component: Input,
      name: 'email',
      type: 'text',
      placeholder: 'Your email id',
    },
  ];

  const handleSubmit = (values: any, captcha: any, setErrors: any, setLoading: any) => {
    if (captcha) {
      axios
        .post(ONBOARD_URL, values)
        .then(({ data }: { data: any }) => {
          if (data.is_valid) {
            setRedirect(true);
          } else {
            setRegistrationError(data.messages?.global);
            if (setErrors && setLoading) {
              const errors = data.messages;
              delete errors.global;
              setErrors(errors);
              setLoading(false);
            }
          }
        })
        .catch(() => {
          setRegistrationError({
            global: 'Sorry! an error occured. Please contact the technical team for support',
          });
          setLoading(false);
        });
    }
  };

  return (
    <Organization
      pageTitle={title}
      buttonText={buttonText}
      formFields={formFields(code)}
      validationSchema={FormSchema}
      saveHandler={handleSubmit}
      errorMessage={registrationError}
      initialFormValues={initialFormValues}
    />
  );
}