Skip to content

Add a field to the lead form (end-to-end)

Goal: add a new field — we’ll use occupation (the buyer’s job, a free-text field) — to the broker “New Deal” form, and have it travel all the way to Dynamics 365. Read Broker submits a lead first if the flow isn’t fresh.

New Deal form ──▶ NewDealFormInterface ──▶ POST /api/broker/leads
(frontend) │
SubmitLeadRequest (validate) ──▶ SubmitNewLead (forward)
(backend) │
SubmitNewLeadRequest (validate) ──▶ SubmitNewLeadRequestMapper
(crms-middleware) │ occupation ⟶ <dynamics field>
Azure Logic App ──▶ Dynamics 365

You edit three request classes, one mapper, and the form — and you touch i18n. Below, per repo.

Repo frontend, app apps/orascom-broker-app. Edit exactly these:

  • src/definitions/interfaces/inputs/new-deal.ts two interfaces
  • src/pages/new-deal/new-deal.tsx form + payload
  • public/locales/en/translation.json labels
  • public/locales/ar/translation.json labels (partial stub — add here too)
  1. new-deal.ts — add the field to both interfaces:

    // NewDealInputInterface (Formik value shape — camelCase)
    occupation?: string;
    // NewDealFormInterface (API request body — snake_case, the backend's field name)
    occupation?: string;

    For a single word like occupation the two names match. For a multi-word field they diverge — the Formik interface stays camelCase (jobTitle) while the request interface uses snake_case (job_title) — and you map between them in submitHandler.

  2. new-deal.tsx — four edits inside NewDeal():

    • initialValues (~line 378): occupation: ''
    • Add a <Field> block inside <Form> (copy the “First name” block, ~397–414), with a <label>{t('occupation')}</label> and <ErrorMessage name="occupation" />.
    • schema (Yup, ~206): add a rule if needed, e.g. occupation: yup.string() (required fields also gate the submit button via !isValid).
    • submitHandler mappedData (~247–293): map it into the body — occupation: values.occupation (guard it like budget/phone_2 if it can be empty).
  3. i18n — add occupation (label + placeholder + any validation message) to both en/translation.json and ar/translation.json. Arabic is a partial stub, so if you skip it the label renders in English even in Arabic mode.

  1. Lint + type-check the frontend: yarn nx lint orascom-broker-app and tsc -p apps/orascom-broker-app/tsconfig.app.json --noEmit (plain tsc --noEmit checks nothing in this Nx app).
  2. Backend: add/adjust a Feature test under tests/Feature/Api/Broker/… (happy + validation + auth-failure), run php artisan test.
  3. Manually: run the broker app (yarn start:broker, port 4201), submit a lead with the new field, and confirm the value reaches the CRM. If you can’t see it land in Dynamics, that’s the Logic App / field-name contract — go back to the CRM team.
  4. Contracts: update backend/docs/openapi.yaml and crms-middleware/docs/portals-openapi.yml.