# Setup Guide — Wallex Influencer Dashboard

A 15-minute setup to get the dashboard running with your Airtable base.

---

## Prerequisites

- A computer with Python 3 or Node.js installed (any modern version)
- An Airtable account (free tier is fine for <10 influencers)
- 15 minutes

---

## Step 1 — Create the Airtable base

1. Go to https://airtable.com and create a new **empty base** named `Wallex Influencer Tracker`.
2. Open [`AIRTABLE_SCHEMA.md`](./AIRTABLE_SCHEMA.md) side-by-side.
3. Create all 4 required tables (`Influencers`, `Campaigns`, `Deliverables`, `Payments`) with the exact field names and types listed.
   - Tip: field names are **case-sensitive** when the dashboard reads them via the API.
4. (Optional) Create the views suggested under `Deliverables`.

---

## Step 2 — Get your API credentials

1. **Personal Access Token (PAT):**
   - Visit https://airtable.com/create/tokens
   - Click **Create new token**
   - Name: `Wallex Dashboard`
   - Scopes: check `data.records:read`, `data.records:write`, `schema.bases:read`
   - Access: select your `Wallex Influencer Tracker` base only
   - Click **Create token** and copy it. **You won't see it again** — save it somewhere safe.

2. **Base ID:**
   - Visit https://airtable.com/api → click your base
   - The intro paragraph contains `The ID of this base is appXXXXXXXXXXXXXX` — copy it.

---

## Step 3 — Configure the dashboard

1. In the project folder, copy the example config:
   ```bash
   cp assets/js/config.example.js assets/js/config.js
   ```
2. Open `assets/js/config.js` and paste your token + base ID:
   ```js
   window.WALLEX_CONFIG = {
     airtable: {
       apiKey: "patXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXX",
       baseId: "appXXXXXXXXXXXXXX",
       tables: {
         influencers: "Influencers",
         campaigns:   "Campaigns",
         deliverables:"Deliverables",
         payments:    "Payments",
       },
     },
     useMockData: false,  // ← flip to true if Airtable isn't ready yet
   };
   ```
3. `assets/js/config.js` is gitignored — never commit your token.

---

## Step 4 — Run the dashboard locally

From the project root:

**Option A — Node (preferred):**
```bash
npx serve . -p 3000
```

**Option B — Python:**
```bash
python3 -m http.server 8080
```

Then open http://localhost:3000 (or :8080) in your browser.

---

## Step 5 — Add your first records

Open Airtable directly and add:
1. At least one **Campaign**
2. At least one **Influencer**
3. Then go back to the dashboard and use **Submit Deliverable** to log a post

The dashboard reads live from Airtable — refresh to see new data.

---

## Step 6 — (Later) Set up automated metrics fetching

The auto-fetcher pulls likes/views/comments nightly from platform APIs. It runs separately as a scheduled worker.

This is **phase 2** — once you've been using the manual dashboard for a couple of weeks and confirmed the workflow, follow [`AUTOFETCH.md`](./AUTOFETCH.md) (coming soon) to set up the Cloudflare Worker that updates metrics.

For each platform you want to auto-fetch from, you'll need:

| Platform | What you need |
|---|---|
| Instagram + Facebook | Meta developer app + influencer grants you access to their Business/Creator account |
| TikTok | TikTok for Developers app + influencer connects via OAuth |
| YouTube | YouTube Data API key (free, instant) + channel ID per influencer |
| X (Twitter) | API Basic tier — $200/mo. Skip unless you have budget. |
| Snapchat | No public API. Manual entry only. |

---

## Troubleshooting

**"Failed to load deliverables"**
→ Check `config.js`. The token may be wrong, expired, or missing a scope. Make sure the base is included in the token's access list.

**"Field X not found"**
→ Field names in Airtable must match the schema doc exactly, including capitalization.

**Dashboard works but no data shows**
→ Try setting `useMockData: true` in config to verify the UI works. Then go back to Airtable and check you have records in the right tables.

**CORS errors**
→ The Airtable API supports CORS by default. If you see CORS errors, you likely have a typo in `baseId` causing a 404.
