# Gas Station Admin Approval — Frontend Guide

After **Submit Registration**, the owner can log in, but **do not** open the full owner dashboard until an admin approves the station.

Auth (JWT) and approval are separate:

| Layer | Meaning |
|--------|---------|
| JWT / login success | User is authenticated |
| `gasStation.isAdminApproved === true` | Station is approved → show owner dashboard |

---

## Fields to use

Every station payload from register / login / my-station includes:

| Field | Type | FE usage |
|--------|------|----------|
| `approvalStatus` | `"pending"` \| `"approved"` \| `"rejected"` | Exact state for copy / screens |
| `isAdminApproved` | `boolean` | Primary route gate (`true` only when approved) |
| `approvalNote` | `string \| null` | Optional message (esp. on reject) |

**Rule:**

```ts
const canOpenDashboard = gasStation?.isAdminApproved === true;
// same as: gasStation?.approvalStatus === "approved"
```

Legacy stations without `approvalStatus` are treated as approved by the API (`isAdminApproved: true`).

---

## Recommended routing

```
Register / Login success
        │
        ▼
  Save token (Bearer)
        │
        ▼
  Read gasStation from response
        │
        ├─ gasStation == null     → “Register your station” flow
        ├─ isAdminApproved true   → Owner dashboard (Stripe, etc.)
        ├─ approvalStatus pending → Waiting for approval screen
        └─ approvalStatus rejected → Rejected screen (+ approvalNote)
```

Do **not** send the user to the full dashboard only because login returned a token.

---

## APIs that return these fields

Base: `/api/v1/gas-stations`

| Method | Path | Auth | Notes |
|--------|------|------|--------|
| `POST` | `/register-with-account` | none | Creates station as **pending**; returns `token` + `gasStation` |
| `POST` | `/register` | Bearer | Creates station as **pending** |
| `POST` | `/account/login` or `/login` | none | Returns `token` + `gasStation` (or `null`) |
| `GET` | `/my-station` | Bearer | Refresh approval / Stripe status after login |

### Example — register / login / my-station station slice

```json
{
  "gasStation": {
    "id": "...",
    "name": "My Gas Station",
    "approvalStatus": "pending",
    "isAdminApproved": false,
    "approvalNote": null,
    "stripeStatus": "connect_required",
    "isStripeConnected": false
  }
}
```

After admin approves:

```json
{
  "approvalStatus": "approved",
  "isAdminApproved": true
}
```

After reject:

```json
{
  "approvalStatus": "rejected",
  "isAdminApproved": false,
  "approvalNote": "Incomplete documents"
}
```

Register success message (informational):  
`"Gas station registered successfully. Waiting for admin approval."`

---

## Screens to build

### 1. Waiting for approval (`pending`)

- Title: e.g. “Waiting for admin approval”
- Short copy: registration submitted; dashboard unlocks after approval
- Actions: optional **Refresh** → `GET /my-station`; **Logout**
- Hide: full dashboard, public station tools that assume live listing

### 2. Rejected (`rejected`)

- Show `approvalNote` if present
- CTA: contact support / re-register policy (product decision)
- Do not treat as approved

### 3. Dashboard (`approved`)

- Existing owner home (Stripe connect, update station, etc.)

---

## When to re-check approval

Call `GET /api/v1/gas-stations/my-station` when:

- App resumes / owner app opens
- User taps **Refresh** on the waiting screen
- Optionally poll every 30–60s while on the waiting screen (keep it light)

On each response, re-run the same `isAdminApproved` gate.

---

## Product notes

- Pending stations **do not** appear in public / map listings until approved (backend filter).
- Stripe connect can stay available or locked on waiting screen — product choice; approval gate is independent of Stripe.
- Admin approve/reject is on admin APIs (`POST /api/v1/admin/gas-stations/:id/approve|reject`); owner app only reads status.

---

## Quick checklist (FE)

- [ ] After register → waiting screen if `!isAdminApproved`
- [ ] After login → same gate (token alone is not enough)
- [ ] Persist `approvalStatus` / `isAdminApproved` with station in app state
- [ ] Waiting screen → Refresh via `my-station`
- [ ] Rejected UI reads `approvalNote`
- [ ] Dashboard only when `isAdminApproved === true`
