pelagia-portal/App/components/po/project-code-field.tsx
Claude (auto-fix) 4ed27d668b
All checks were successful
PR checks / checks (pull_request) Successful in 51s
PR checks / integration (pull_request) Successful in 29s
feat(po): Project Code dropdown on PO forms
Replace the free-text Project Code input with a native <select> carrying a
fixed list of project codes (Petronet LNG Cochin, COMACOE Trombay, Haldia
Reach, Haldia MMT, COMACOE Mandvi) plus an empty "— none —" option, across
all three PO forms (new / edit / manager-edit).

- Add a shared PROJECT_CODES constant in lib/validations/po.ts as the single
  source of truth.
- Add a reusable <ProjectCodeField> (mirrors <DeliveryLocationField>): plain
  HTML select keeping name="projectCode" so the server actions are unchanged.
- The field stays optional; projectCode remains a nullable free-text snapshot
  (no schema/migration, no validation tightening) so legacy/imported values
  are not rejected. On edit, a current value not in the list is preserved as a
  leading "(current)" option so it is never silently dropped.
- Add unit tests for the new field.

Fixes #124

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 13:35:59 +05:30

34 lines
1.2 KiB
TypeScript

/**
* Project Code dropdown (issue #124) — a native <select name="projectCode">
* carrying the fixed `PROJECT_CODES` list plus an empty "— none —" option
* (the field stays optional). Plain HTML so it works with the forms' native
* FormData submission (no client state needed), matching DeliveryLocationField.
*
* `current` is the PO's existing project code; if it isn't one of the fixed
* options (legacy / imported / a since-removed code) it is preserved as a
* leading "(current)" option so an edit never silently drops it.
*/
import { PROJECT_CODES } from "@/lib/validations/po";
export function ProjectCodeField({
current,
className,
}: {
current?: string | null;
className?: string;
}) {
const cur = (current ?? "").trim();
const currentMissing = cur.length > 0 && !(PROJECT_CODES as readonly string[]).includes(cur);
return (
<select name="projectCode" defaultValue={cur} className={className}>
<option value=""> none </option>
{currentMissing && <option value={cur}>{cur} (current)</option>}
{PROJECT_CODES.map((code) => (
<option key={code} value={code}>
{code}
</option>
))}
</select>
);
}