# MAMS front end (React) Replacement front end for the ColdFusion app `OmanTCS_STG`. The ColdFusion backend is unchanged; this app calls the same `backend/core/controller.cfc` endpoint. ## Develop ``` npm install npm run dev # http://127.0.0.1:5173/mams/ , proxies /OmanTCS_stg to VITE_BACKEND_ORIGIN npm run typecheck ``` Copy `.env.example` to `.env` to change `VITE_API_BASE` (default `/OmanTCS_stg`) or the dev proxy target. ## How modules are built Lists, search, view pages and Excel export are generic: they are driven by what the backend says per module (`getGridStructure`, search metadata, field metadata from `getConfig`). Only the **form layout** (section and field order) comes from the legacy pages: ``` node scripts/gen-layouts.mjs [path/to/legacy/frontend/entities] # writes src/features/forms/generated-layouts.json ``` Run it again if a legacy page changes. `src/features/forms/layouts.ts` merges that file with the backend metadata, hand-written layouts (Users, Trucks) win, and owner / governorate-state-city pickers are wired automatically. A required dropdown the new UI has no data source for disables Save on that form (with a notice). Menu: `FLEET_TRACKING_SERVICES` is hidden (`HIDDEN_ENTITIES` in `src/layout/nav.ts`); the old home-page dashboards live under the "Dashboard" menu (`src/features/dashboard`). ## Run the production build on your PC (backend stays on 192.168.6.46) ``` npm start # builds, then serves http://127.0.0.1:4173/mams/ with the backend proxied ``` ## Environments | Environment | Command | Frontend | Backend | |---|---|---|---| | Local | `npm run dev` | http://localhost:5173/mams/ | proxied to `VITE_BACKEND_ORIGIN` (default 192.168.6.46, `/OmanTCS_stg`) | | Staging | `npm run build:staging` (or `dev:staging`, `start:staging`) | `/mams/` on the staging IIS host, files from `dist-staging/` | http://192.168.6.46/OmanTCS_stg (same host) | | Production | `npm run build` | https://mamsv2.nafith.om, files from `dist/` | https://mamsbe.nafith.om through the `/api` forward (see `deploy/apache-mamsv2.conf`) | Each one reads its own env file: `.env` (local overrides), `.env.staging`, `.env.production`. ### Deploy to staging 1. `npm run build:staging` 2. Copy the contents of `dist-staging/` to `C:inetpubwwwrootmams` on 192.168.6.46 (next to `OmanTCS_stg`); the app is then at `http://192.168.6.46/mams/`. 3. IIS needs the **URL Rewrite** module for `web.config` (it is copied into the build). ## Deploy to a server (IIS, same host as the backend) The app must be served from the **same host** as the backend (session cookies, no CORS). 1. `npm run build` 2. Copy the contents of `dist/` (not the folder itself) to `C:\inetpub\wwwroot\mams\` on the server that hosts `OmanTCS_stg` (192.168.6.46). The app is then at `http:///mams/`. 3. The server needs the IIS **URL Rewrite** module for `web.config` (SPA fallback to `/mams/index.html`). Do not copy `node_modules`, `src` or `package.json` to the server. Built for the `/mams/` path. To serve under another path, build with `VITE_BASE=/other/ npm run build` and edit the rewrite target in `public/web.config`.