|
| 1 | +import { Grid } from "@mui/material"; |
| 2 | +import CippFormComponent from "../CippComponents/CippFormComponent"; |
| 3 | + |
| 4 | +export const CustomerForm = (props) => { |
| 5 | + const { formControl } = props; |
| 6 | + |
| 7 | + const fields = [ |
| 8 | + { name: "Domain", label: "Domain", type: "textField", required: true }, |
| 9 | + { name: "CompanyName", label: "Company Name", type: "textField", required: true }, |
| 10 | + { name: "FirstName", label: "First Name", type: "textField", required: true }, |
| 11 | + { name: "LastName", label: "Last Name", type: "textField", required: true }, |
| 12 | + { name: "Email", label: "Email", type: "email", required: true }, |
| 13 | + { name: "PhoneNumber", label: "Phone Number", type: "textField", required: true }, |
| 14 | + { name: "Country", label: "Country", type: "textField", required: true }, |
| 15 | + { name: "City", label: "City", type: "textField", required: true }, |
| 16 | + { name: "State", label: "State", type: "textField", required: true }, |
| 17 | + { name: "AddressLine1", label: "Address Line 1", type: "textField", required: true }, |
| 18 | + { name: "AddressLine2", label: "Address Line 2", type: "textField", required: false }, |
| 19 | + { name: "PostalCode", label: "Postal Code", type: "textField", required: true }, |
| 20 | + ]; |
| 21 | + |
| 22 | + const transformPayload = (formData) => { |
| 23 | + const payload = { |
| 24 | + enableGDAPByDefault: false, |
| 25 | + Id: null, |
| 26 | + CommerceId: null, |
| 27 | + CompanyProfile: { |
| 28 | + TenantId: null, |
| 29 | + Domain: formData.Domain, |
| 30 | + CompanyName: formData.CompanyName, |
| 31 | + Attributes: { ObjectType: "CustomerCompanyProfile" }, |
| 32 | + }, |
| 33 | + BillingProfile: { |
| 34 | + Id: null, |
| 35 | + FirstName: formData.FirstName, |
| 36 | + LastName: formData.LastName, |
| 37 | + Email: formData.Email, |
| 38 | + Culture: "EN-US", |
| 39 | + Language: "En", |
| 40 | + CompanyName: formData.CompanyName, |
| 41 | + DefaultAddress: { |
| 42 | + Country: formData.Country, |
| 43 | + Region: null, |
| 44 | + City: formData.City, |
| 45 | + State: formData.State, |
| 46 | + AddressLine1: formData.AddressLine1, |
| 47 | + AddressLine2: formData.AddressLine2, |
| 48 | + PostalCode: formData.PostalCode, |
| 49 | + FirstName: formData.FirstName, |
| 50 | + LastName: formData.LastName, |
| 51 | + PhoneNumber: formData.PhoneNumber, |
| 52 | + }, |
| 53 | + Attributes: { ObjectType: "CustomerBillingProfile" }, |
| 54 | + }, |
| 55 | + RelationshipToPartner: "none", |
| 56 | + AllowDelegatedAccess: null, |
| 57 | + UserCredentials: null, |
| 58 | + CustomDomains: null, |
| 59 | + Attributes: { ObjectType: "Customer" }, |
| 60 | + }; |
| 61 | + |
| 62 | + if (formData.ResellerType === "Tier2" && associatedPartnerId) { |
| 63 | + payload.AssociatedPartnerId = associatedPartnerId; |
| 64 | + } |
| 65 | + |
| 66 | + return payload; |
| 67 | + }; |
| 68 | + |
| 69 | + return ( |
| 70 | + <Grid container spacing={3}> |
| 71 | + {fields.map((field, index) => ( |
| 72 | + <Grid item xs={12} md={6} key={index}> |
| 73 | + <CippFormComponent |
| 74 | + type={field.type} |
| 75 | + label={field.label} |
| 76 | + name={field.name} |
| 77 | + required={field.required} |
| 78 | + formControl={formControl} // Use shared formControl |
| 79 | + fullWidth |
| 80 | + /> |
| 81 | + </Grid> |
| 82 | + ))} |
| 83 | + </Grid> |
| 84 | + ); |
| 85 | +}; |
0 commit comments