Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECMS-3076 #4

Open
wants to merge 1 commit into
base: contactus
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 138 additions & 3 deletions src/components/ContactForm/ContactForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useState, useMemo } from "react";
import React, { useState, useEffect, useMemo } from "react";
import {
Form,
FormContent,
FormInput,
Typography,
FormContentProps,
useForm
} from "@asicsdigital/adi-blocks-core";

import { useContactForm } from "../../hooks";
Expand Down Expand Up @@ -38,10 +39,144 @@ export function ContactForm(props: ContactFormProps) {
subject: "",
};

const { watch } = useForm(contactFormDefaults);

useEffect(() => {
const subscription = watch((currentDatabject, data) => {
if(data.name === 'subject' && data.type === 'change' ) {
if(currentDatabject.subject === 'Order Status') {
console.log('The Value', currentDatabject);
}
}
}
)
return () => subscription.unsubscribe()
}, [watch])


const handleCaptchaTokenChange = (token: string | null) => {
setCaptchaToken(token);
};

const inp : FormInput[] = [
{
"control": "select",
"options": {
"label": "Select Subject",
"name": "subject",
"required": true,
"placeholder": "Select Subject",
"choices": [
{
"label": "Product Questions",
"value": "Product Questions"
},
{
"label": "Warranty & Defective Items",
"value": "Warranty & Defective Items"
},
{
"label": "Order Status",
"value": "Order Status"
},
{
"label": "Returns",
"value": "Returns"
},
{
"label": "My Account",
"value": "My Account"
},
{
"label": "Remove from Mailing List",
"value": "Remove from Mailing List"
},
{
"label": "Team Sales",
"value": "Team Sales"
},
{
"label": "Charity Donations & Sponsorships",
"value": "Charity Donations & Sponsorships"
}
],
"fullWidth": true,
"requiredMessage": "This field is required."
}
},
{
"control": "textField",
"options": {
"label": "Name",
"name": "suppliedname",
"placeholder": "",
"type": "text",
"multiline": false,
"required": true,
"helperText": "",
"fullWidth": true,
"requiredMessage": "This field is required."
}
},
{
"control": "textField",
"options": {
"label": "Email Address (If you placed an order, please use the email address associated with your order)",
"name": "suppliedemail",
"placeholder": "",
"type": "email",
"multiline": false,
"required": true,
"helperText": "",
"fullWidth": true,
"requiredMessage": "This field is required."
}
},
{
"control": "textField",
"options": {
"label": "Order Number (If applicable)",
"name": "ordernumber",
"placeholder": "",
"type": "text",
"multiline": false,
"required": false,
"helperText": "",
"fullWidth": true,
"requiredMessage": "This field is required."
}
},
{
"control": "textField",
"options": {
"label": "Phone Number",
"name": "suppliedphone",
"placeholder": "",
"type": "tel",
"multiline": false,
"required": true,
"helperText": "",
"fullWidth": true,
"requiredMessage": "This field is required."
}
},
{
"control": "textField",
"options": {
"label": "Message",
"name": "description",
"placeholder": "",
"type": "text",
"multiline": true,
"required": true,
"helperText": "",
"fullWidth": true,
"requiredMessage": "This field is required."
}
}
];


// Modify the button props to include a disabled state based on captcha validation
const modifiedButtonProps: FormContentProps["buttons"] = useMemo(
() => ({
Expand All @@ -57,15 +192,15 @@ export function ContactForm(props: ContactFormProps) {
<Form>
<FormContent
defaultValues={contactFormDefaults}
inputs={inputs}
inputs={inp}
// onError={onError}
onSubmit={onSubmit}
/>
<Recaptcha onChange={handleCaptchaTokenChange} />
<Typography paragraph>{message}</Typography>
<FormContent
defaultValues={contactFormDefaults}
inputs={inputs.slice(inputs.length)}
inputs={inp.slice(inp.length)}
buttons={modifiedButtonProps}
// onError={onError}
onSubmit={onSubmit}
Expand Down