# TARGO Email Editor

Standalone email template editor microservice — React + Vite + [easy-email](https://github.com/zalify/easy-email)
(OSS WYSIWYG email builder, MJML-based).

Embedded as an iframe in the ops UI's `/campaigns/templates/:name` page.
Talks to the hub's `/campaigns/templates/*` REST endpoints for load/save.

## Architecture

```
ops UI (Vue) → iframe → editor.gigafibre.ca → REST → msg.gigafibre.ca (hub)
                                                       └─ writes .mjml + .html
                                                          to /opt/targo-hub/templates/
```

## URL params

- `?name=gift-email-fr` — which template to load (defaults to gift-email-fr)

## postMessage protocol (to parent window)

Emitted on save success:
```js
{ type: 'email-editor:saved', template: 'gift-email-fr', ts: 1700000000000 }
```

The parent ops UI listens via:
```js
window.addEventListener('message', (e) => {
  if (e.data.type === 'email-editor:saved') {
    // refresh preview / show toast
  }
})
```

## Local dev

```bash
npm install
npm run dev          # http://localhost:5173?name=gift-email-fr
```

Set `VITE_HUB_URL` env to point at a non-prod hub if needed.

## Build + deploy

```bash
docker compose build
docker compose up -d
```

Traefik auto-provisions HTTPS at `editor.gigafibre.ca` (Let's Encrypt via
the `letsencrypt` resolver shared with the rest of our stack).

## Known limitations (Phase 1)

- Existing MJML templates from the hub are NOT auto-imported into the
  easy-email JSON tree (no MJML → JSON parser in easy-email out of the box).
  The editor starts from an empty page. User rebuilds visually with the
  hub's compiled HTML as visual reference.
- TODO Phase 3: integrate an MJML → easy-email-JSON parser (likely fork or
  reverse-engineer JsonToMjml).
