1.23.5 • Published 3 months ago

@tdcerhverv/contactform v1.23.5

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

ContactForm

Modular Contact Forms for TDC.dk open pages.

Installation

npm install @tdcerhverv/contactform

Standard Contact Form

A baseline contact form with no out-of-the-box integrations The <StandardContactForm /> is a formik-integrated modular form which should serve as the basis for all forms on TDC.dk. It is built using Material UI and Formik.

Usage

import { StandardContactForm, FormSubmission, ISubmissionState, FeedbackDialog } from '@tdcerhverv/contactform'

Props

The props for this component are defined as follows:

export interface IStandardContactForm extends IContactFormBase {
    fieldSections: IFieldSections[]
    onSubmit: FormSubmission
}

export interface IContactFormBase {
    formId: string
    optionalLabel?: string
    submitButtonDisplay?: 'RIGHT' | 'LEFT' | 'CENTER' | 'STRETCH' | 'BETWEEN'
    buttonText?: string
    buttonTextSending?: string
    alertText?: string
    modal?: IModal
    formSubmissionState: ISubmissionState | null
    setFormSubmissionState: (formSubmissionState: ISubmissionState | null) => void
    persistState: boolean
    inlineAnnouncement?: IAlert
    preFilledMessage?: string
    environment?: Environment
}

export interface IFieldSections {
    sectionTitle?: string
    fields: InputField[]
}

Required Props:

  • formId is a string to identify the form
  • onSubmit is a function that defines how to handle form submission. FormSubmission is a type alias for (values: unknown, formikHelpers: FormikHelpers<unknown>) => Promise<boolean>
  • setFormSubmissionState is a passed down useState hook, that returns the state of the form after submission. This can be used to display any kind of feedback to the user

Optional Props:

  • fieldSections is a two dimensional array which takes sections as objects. The sections include an array of fields and an optional section title (sectionTitle). Sections provide a visual distinction between groups of fields (there is 24px spacing between fields, while sections are seperated with a divider component. If you do not want multiple sections in your form, simply add 1 section which includes all inputfields.
  • submitButtonDisplay allows you yo change the flexbox properties and alignment of the "send" button
  • buttonText allows you to change the text in the form's submission button. Default value is "Send"
  • buttonTextSending allows you the change the text in the form's submission button while the form is submitting. Default value is "Sender Besked"
  • alertText allows you to change the text of the alert that is displayed when a field is not filled correctly. Default value is "Der er felter, som ikke er udfyldt korrekt"
  • modal This prop task two required props. One is the close dialog handle function, and the other is the inner text for cancel button. This this props is provided, the form is now able to control the open/close state of a dialog.
  • inlineAnnouncement This prop allows to have an inline Announcement at the top of the form in case any additonal information should be displayed to the user. The prop takes an object of type IAlert which can be seen below. The description can take markdown or a string.
  • preFilledMessage When this is added the string will be added as initial value for the MESSAGE field.
interface IAlert {
    title: string
    description: {
        description: string
    }
    severity: 'error' | 'warning' | 'success' | 'info'
}

Optional Field Props:

  • fieldWidth An optional prop that can be used to define the width of a field. if given no value, fields will default to 100% width except for number fields. The prop takes a string or an int

FormSubmission

import { StandardContactForm, FormSubmission, ISubmissionState, FeedbackDialog } from '@tdcerhverv/contactform'

const [formSubmissionState, setFormSubmissionState] = useState<ISubmissionState | null>(null)

//simple submission handler to display form values in an alert
const handleSubmission: FormSubmission = (values, _formikHelpers) => {
    alert(JSON.stringify(values, null, '\t'))
}

;<StandardContactForm formId="myForm" onSubmit={handleSubmission} setFormSubmissionState={setFormSubmissionState} />
{
    formSubmissionState && <FeedbackDialog {...formSubmissionState} />
}

Validation

The <StandardContactForm /> uses a combination of Formik and Yup to provide a standard validation schema to all forms.

Individual fields have the following validation rules and error messages:

Field NameValidation RuleError Message
EMAILyup.string.email()Angiv venligst en gyldig E-mail adresse
MESSAGEyup.string.min(10)Beskeden skal bestå af mindst 10 tegn.

Any fields which are not specified here are given the yup.mixed() validation rule, with the default error of Der sket en fejl. This validation should not be seen by users, but acts as a safety net for unforseen errors.

All fields can be given the required prop, which will append the yup.required() rule to that field's validation schema. Any empty fields that are required will block formik.onSubmit from being called, and display the error message 'Obligatorisk felt' as assistive text to the field.

Salesforce Form

The <SalesforceForm /> is the primary form used on TDC.dk. This form is built upon the <StandardContactForm />, and provides off-the-shelf validation and integration with our Salesforce Integration Middleware for LEAD and CASE forms.

Props

The salesforceForm has the following props:

export interface ISalesforceForm extends IContactFormProps {
    formType: FormType
    environment: Environment
    formData: ICaseForm | ILeadForm
    fields: [
        {
            salesforcemapping?: string
        } & InputField,
    ]
}
  • formType prop can be CASE or LEAD, defines if this is a Case form or a Lead form.
  • environment prop can be PROD or DEV, sets up to send the cases to the Salesforce production or development endpoints.
  • formData prop defines all the data needed by Salesforce in addition to the fields and user-supplied values. Find the details in Salesforce Definitions section below.
  • fields prop refers to input fields. Example: text, cvr, address etc.
  • salesforcemapping is an optional prop, but is required for the following types of fields:
    • CHECKBOX
    • CHECKBOXGROUP
    • RADIO
    • TEXT
  • Salesforce also requires a sourceUrl, though this is provided on submission as window.location.host + window.location.pathname.
interface IBaseSalesforceFormData {
    Recordtypeid?: string
    Origin: string //Origin is called LeadSource on LeadForm
}
export interface ICaseForm extends IBaseSalesforceFormData {
    Type__c: string
    Sub_Type__c: string
    Subject: string
}
export interface ILeadForm extends IBaseSalesforceFormData {
    Lead_Type__c: string
    DemandBase_Information__c?: string
}

Salesforce Definitions

CASE:

field-namefield-rulesSalesforce RequirementsBusiness Requirements
SubjectText(255)Optional
DescriptionText Area(32000)Optional✔(when given)
RecordtypeidId(similar to text)Optional
Type__cPicklist
Sub_Type__cPicklistOptional
SuppliedNameText(255)Optional✔(when given)
SuppliedPhonePhoneOptional✔(when given)
SuppliedEmailEmailOptional✔(when given)
CVR_number__cText(255)Optional
Web_Account_Name__cText(50)Optional✔(when CVR is given)
Web_Account_Address__cText Area(255)Optional✔(when CVR is given)
Web_Account_Number__cText(15)Optional✔(when CVR is given)
Web_Invoice_Number__cText(15)Optional✔(when CVR is given)
OriginPicklistOptional
Web_P_Number__cText(255)OptionalOptional

ONE+ CONFIGURATOR LEAD:

field-namefield-rulesSalesforce RequirementsBusiness Requirements
LeadSourcePicklist
CompanyText(255)✔(when CVR is given)
Lead_Type__cPicklist
FirstNameText(40)✔(when given)
LastNameText(80)✔(when given)
Web_Email__cEmailOptional✔(when given)
EmailEmailOptional✔(when given)
Web_CVR__cLong Text(255)✔(when CVR is given)
PhonePhoneOptional✔(when given)
DescriptionText Area(32000)Optional✔(when given)
RecordtypeidId(similar to text)Optional
Product_of_Interest__cMulti PicklistOptional✔(when given)
Source_URL__cText(1000)Optional
Product_Information__cLong Text Area(32000)OptionalOptional

VERTIC LEAD:

field-namefield-rulesSalesforce RequirementsBusiness Requirements
LeadSourcePicklist
CompanyText(255)✔(when CVR is given)
Lead_Type__cPicklist
FirstNameText(40)✔(when given)
LastNameText(80)✔(when given)
Web_Email__cEmailOptional✔(when given)
EmailEmailOptional✔(when given)
Web_CVR__cLong Text(255)✔(when CVR is given)
PhonePhoneOptional✔(when given)
DescriptionText Area(32000)Optional✔(when given)
RecordtypeidId(similar to text)Optional
Product_of_Interest__cMulti PicklistOptional✔(when given)
Source_URL__cText(1000)Optional
DemandBase_Information__cLong Text Area(32000)OptionalOptional

Salesforce Picklist values

CASE:

Type__c:      Billing | Inquiry
Sub_Type__c:  Inquiry | Standard Inquiry
Origin:       Web - Open Pages

Vertic LEAD:

Lead_Type__c: Digital Demand Engine
LeadSource:   Web - Open Pages
Product_of_Interest__c: One+| Mobil| Internet

One+ Configurator LEAD:

Lead_Type__c: One+ Configurator
LeadSource:   Web - Open Pages
Product_of_Interest__c: One+
Product_Information__c: Its a generic field that can take any string. Max length 32000 characters.
This field contains the user choices from the One+ configurator.

FeedbackDialog

The <FeedbackDialog /> is the standalone component that can be use in conjunction with the StandardContantForm or the SaleforceForm. It take props of ISubmissionState.

Salesforce mappings

Known salesforce fields that are mapped by using the salesforcemapping parameter | field-name | field-rules | Salesforce Requirements | Business Requirements | | --------------------------- | --------------------- | :---------------------: | :-------------------: | | Web_Address__c | Text Area(255) | Optional | ✔(when the field is given) |

1.23.5

3 months ago

1.23.4

3 months ago

1.23.3

3 months ago

1.23.2

3 months ago

1.23.0

3 months ago

1.23.1

3 months ago

1.22.7

4 months ago

1.22.6

4 months ago

1.21.4

10 months ago

1.22.0

9 months ago

1.22.3

9 months ago

1.22.4

9 months ago

1.22.1

9 months ago

1.22.2

9 months ago

1.22.5

6 months ago

1.21.3

11 months ago

1.21.2

11 months ago

1.21.1

1 year ago

1.21.0

1 year ago

1.20.1

1 year ago

1.20.2

1 year ago

1.18.1

1 year ago

1.18.0

1 year ago

1.16.4

2 years ago

1.19.0

1 year ago

1.17.2

2 years ago

1.17.1

2 years ago

1.17.0

2 years ago

1.17.5

2 years ago

1.17.4

2 years ago

1.17.3

2 years ago

1.20.0

1 year ago

1.16.3

2 years ago

1.16.2

2 years ago

1.16.1

2 years ago

1.16.0

2 years ago

1.15.3

2 years ago

1.14.2

2 years ago

1.15.0

2 years ago

1.15.2

2 years ago

1.15.1

2 years ago

1.13.2

2 years ago

1.13.1

2 years ago

1.13.0

2 years ago

1.12.1

2 years ago

1.12.0

2 years ago

1.11.0

2 years ago

1.9.0

2 years ago

1.10.0

2 years ago

1.5.5

2 years ago

1.8.0

2 years ago

1.7.1

2 years ago

1.6.2

2 years ago

1.7.0

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.6

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.1

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.2.2

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.0-alpha.12

3 years ago

1.0.0-alpha.11

3 years ago

1.0.0-alpha.10

3 years ago

1.0.0-alpha.9

3 years ago

1.0.0-alpha.8

3 years ago

1.0.0-alpha.7

3 years ago

1.0.0-alpha.6

3 years ago

1.0.0-alpha.5

3 years ago

1.0.0-alpha.4

3 years ago

1.0.0-alpha.3

3 years ago

1.0.0-alpha.2

3 years ago