🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@bigbinary/neeto-form-frontend

Package Overview
Dependencies
Maintainers
12
Versions
242
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bigbinary/neeto-form-frontend

Neeto Form Engine Frontend

npmnpm
Version
1.0.46
Version published
Weekly downloads
742
195.62%
Maintainers
12
Weekly downloads
 
Created
Source

@bigbinary/neeto-form-frontend

neetoFormEngine-frontend is the library that manages forms across neeto products.

Installation

yarn add @bigbinary/neeto-form-frontend

neetoFormEngine-frontend has a few peer dependencies that are required for the proper functioning of the package. Install all the peer dependencies using the below command:

yarn add @bigbinary/neetoui @bigbinary/neeto-icons ramda@^0.28.0 classnames@^2.3.1 formik@2.2.9 @bigbinary/neeto-commons-frontend

Import stylesheet from the following location:

@import "@bigbinary/neeto-form-frontend/dist/main.css";

This package relies on the host project's tailwind configuration. So add neeto-form-frontend to your project's tailwind.config.js file:

module.exports = {
  purge: {
    content: [
      // ... other content directories
      "./node_modules/@bigbinary/neeto-form-frontend/**/*.js",
    ],
  },
  // ... other tailwind config options
};

Add NeetoFormProvider to the root of your application:

import React from "react";

import { NeetoFormProvider } from "@bigbinary/neeto-form-frontend";

const App = () => {
  return (
    <>
      <NeetoFormProvider>{/* Other children */}</NeetoFormProvider>
    </>
  );
};

Components

BuildForm component is used to render a form builder.

import { BuildForm } from "@bigbinary/neeto-form-frontend";
proptypedescription
idstringForm id
onUpdatefunctionCallback for form update
buildRequestArgsobjectArguments for build request
showAddQuestionDividerbooleanTo show add question divider
nonRemovableFieldsstring[]Field kinds that cant be deleted from a form. Accepts array of kinds: name, email, phone, rating, checkbox, dropdown
submitButtonPropsobjectProps for submit button
cancelButtonPropsobjectProps for cancel button
requiredFieldsstring[]Fields that are required. Provided fields will be treated as required by default in the External form, the checkbox for toggling required will be hidden for the fields. Accepts array of kinds: name, email, phone, rating, checkbox, dropdown
questionKindsobject[]To override default question kinds
isKindAlreadyActivefunctionTo override the logic for equality checking of question kinds. The function will receive activeQuestions and kind as arguments
getActiveKindDetailsfunctionTo override the logic for extracting the details of the specified item. The function will receive allQuestionKinds and item as arguments and returns kind, label, FieldComponent, FieldIcon and isSingular props for the specified item
showLoaderbooleanTo specify whether we need to show a page loader while loading questions. If specified as true a page loader will be displayed otherwise placeholder data will be shown while loading questions. The default value will be false
kindUniqueOnstring[]To specify the prop used for uniquely identifying each question kind. Accepts the path of the prop as a string[]. The default value will be ["type"]
isFieldRequired(item: Item) => boolean;To specify whether a question is required or not. The function will receive item as an argument and returns a boolean value. Fields that return true will be treated as required by default in the External form
isFieldLabelDisabled(item: Item) => boolean;To specify whether a question label input is disabled or not. The function will receive item as an argument and returns a boolean value.
isQuestionDeletable(item: Item) => boolean;To specify whether a question is deletable or not. The function will receive item as an argument and returns a boolean value. Fields that return true cannot be removed from a form.
allowAdditionalGuestsbooleanTo specify whether we need to allow additional guests input field in the form. If specified as true a checkbox will be displayed in the form to allow additional guests. The default value will be false. (neetoCal specific)

ExternalForm component is used to render a form.

import { ExternalForm } from "@bigbinary/neeto-form-frontend";
proptypedescription
formIdstringForm id
customSubmitHandlerfunctionCustom submit handler to be called instead of internal submit handlers
onBeforeSubmit(responses, formikValues) => updatedResponsesCallback for before form submit, if the form responses needs to be updated, return the updated responses from this callback. The updated responses will be sent to the server. If the callback doesn't return anythong or returns a falsy value, the form will submit with the original responses.
onCreateSuccessfunctionCallback for form creation success
showTitlebooleanTo show form title
submitRequestArgsobjectArguments for form submit request payload
footerReact.ComponentTo render a Footer Component
submitButtonPropsobjectProps for submit button
cancelButtonPropsobjectProps for cancel button
resetButtonPropsobjectProps for reset button
showPrefixIconsbooleanTo show prefix icons in input fields
displayThankYoubooleanTo show thank you message after form submit
classNamestringTo apply custom class to the form wrapper
submissionIdstringTo set submission id for updating the form
previewbooleanTo show form in preview mode
preserveValuesbooleanTo preserve form values in localStorage
formTitlestringTo set form title
titlePropsobjectTo set props for form title
clearValuesOnSubmitbooleanTo clear local storage values on submit
clearValuesOnResetbooleanTo clear local storage values on reset
formDomPropsobjectTo set props for form element
initialValuesobjectTo set initial values for form
editorPropsobjectTo set neetoEditor props for rich_text input field
onChangefunctionCallback for form field values change
customValidator(question) => Yup.Schema or nullCustom validator for form fields, it should return an yup validation schema based on the question proeprties. To make use of the default validation for a question type, return null

Submission component is used to render a form result.

import { Submission } from "@bigbinary/neeto-form-frontend";
proptypedescription
formIdstringForm id
submissionIdstringSubmission id
classNamestringTo apply custom class component wrapper
questionLabelPropsobjectTo override props for question label
answerPropsobjectTo override props for answer text

Fields component provides access to all the components used in building forms.

import { Fields } from "@bigbinary/neeto-form-frontend";

const {
  Email,
  Dropdown,
  ShortText,
  LongText,
  MultipleChoice,
  SingleChoice,
  Phone,
  Rating,
  Terms,
  StarRating,
} = Fields;

Following components are currently available:

  • Email
  • Dropdown
  • ShortText
  • LongText
  • MultipleChoice
  • SingleChoice
  • Phone
  • Rating
  • Terms
  • StarRating
  • Additional guests (neetoCal specific)
  • Condition

Hooks

useBuildFormState hook is used to get the form state.

import { useBuildFormState, BuildForm } from "@bigbinary/neeto-form-frontend";

const FormBuilder = () => {
  const {
    values,
    dirty,
    isSubmitting,
    isValid,
    submitForm,
    resetForm,
    errors,
  } = useBuildFormState();

  return <BuildForm />;
};

useFormSubmission hook is used to fetch the form submission data.

import { useFormSubmission } from "@bigbinary/neeto-form-frontend";

const Component = () => {
  const { submission, isLoading } = useFormSubmission({
    formId: "form-id",
    submissionId: "submission-id",
  });

  return <></>;
};

useForms hook is used to fetch all the forms.

useForm hook is used to fetch all details of a form.

useCreateForm hooks is used to create a form.

useUpdateForm hooks is used to update a form.

useDeleteForm hooks is used to delete a form.

The usage is as follows.

import {
  useForm,
  useForm,
  useCreateForm,
  useUpdateForm,
  useDeleteForm,
} from "@bigbinary/neeto-form-frontend";

const Component = () => {
  const { data: forms, isLoading } = useForms();
  const { data: form, isLoading } = useForm({ formId: "form-id" });

  const { mutate: createForm, isLoading } = useCreateForm();
  createForm(payload);

  const { mutate: updateForm, isLoading } = useUpdateForm();
  updateForm({ id: "form-id", values: payload });

  const { mutate: deleteForm, isLoading } = useDeleteForm();
  deleteForm("form-id");

  return <></>;
};

useCreate, useUpdate & useDelete uses react-query's useMutation hook under the hood.

useForm & useForms uses react-query's useQuery hook under the hood.

We can pass in extra options supported by react-query to these hooks. We can also destructure all react-query supported props from the response.

Development

Install all the dependencies by executing the following command

yarn install

To test run and test the package locally, first configure neeto-form-engine in the host application.

Build the application locally:

yarn build

Use yalc to link the package locally.

Run yalc push on the package root directory.

Then run the below command on the host application root directory

yalc add @bigbinary/neeto-form-frontend

Building and releasing.

The @bigbinary/neeto-form-frontend package gets published to NPM when we merge a PR with patch, minor or major label to the main branch. The patch label is used for bug fixes, minor label is used for new features and major label is used for breaking changes. You can checkout the Create and publish releases workflow in GitHub Actions to get a live update.

In case if you missed to add the label, you can manually publish the package. For that first you need to create a PR to update the version number in the package.json file and merge it to the main branch. After merging the PR, you need to create a new github release from main branch. Whenever a new release is created with a new version number, the github actions will automatically publish the built package to npm. You can checkout the Publish to npm workflow in GitHub Actions to get a live update.

Please note that before publishing the package, you need to verify the functionality in some of the neeto web-apps locally using yalc package manager. The usage of yalc is explained in this video: https://youtu.be/QBiYGP0Rhe0

Used in

FAQs

Package last updated on 29 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts