Files
halobestie-clone/requirement/flow_mitra.md
Ramadhan Sjamsani 9696eadeaf Mitra §A: pre-home (S3a/S3b/AccountInactive) + design system + Bestie Home
- Port halo_tokens + halo_theme + HaloButton to mitra_app (rose palette,
  Bricolage display, Poppins body, JetBrainsMono).
- Build S3a Input WhatsApp (figma-bestie BestieS3 first half) with
  +62 chip, leading-zero/62 normalization, allow '+' in input.
- Build S3b OTP verification (6-digit, 60s resend timer, attempts hint,
  Focus(canRequestFocus:false) for maestro inputText compat) with full
  error branching (CODE_MISMATCH, OTP_EXPIRED, OTP_USED, ATTEMPTS_EXCEEDED,
  WRONG_FLOW, ACCOUNT_INACTIVE).
- Add AccountInactive terminal screen for is_active=false mitras.
- Typed MitraAuthError with Indonesian-first localized messages +
  retryAfterSeconds passthrough.
- Rebuild home_screen.dart to match figma BestieHome (greeting + status
  card + Ganti Status CTA + Pengingat + 2-tile dark grid).
- Backend: POST /internal/_test/seed-mitra (idempotent) and
  PATCH /internal/mitras/:id (display_name update).
- Control center: inline Edit Nama on mitras row + expandable inline log
  table under clicked mitra (vs old below-table panel).
- 5 maestro flows ts-mitra-A-01/03/04/05/06 covering invalid input, happy
  path, account inactive, phone-format normalization, and the back-to-S3a
  regression. All green.

Plan + memory documented in:
- requirement/phase4-mitra-prehome-plan.md
- requirement/flow_mitra.md / flow_mitra.mermaid.md §A

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-19 22:01:28 +08:00

68 lines
3.4 KiB
Markdown

# Application Flow for Mitra App
We are defining mitra flow along with the app referenced on the claude design
## A. Pre-Home (auth)
The mitra app has no Google/Apple login — phone OTP only. All limits live on the
backend (see `backend/src/services/otp.service.js` + `config.service.js`); the
app must surface them clearly so a stuck mitra knows what to do.
### A1. Boot — token gate
1. App boot → check stored refresh token
1. Valid session → go straight to Home (skip auth)
2. No / expired refresh → go to Login screen
### A2. S3a · Input WhatsApp
1. Show phone number field (E.164, hint `+628xxxxxxxxxx`)
2. "Kirim OTP" submit → `POST /api/mitra/auth/otp/request`
3. Error responses:
1. `PHONE_INVALID` (422) → inline field error "Format nomor salah"
2. `OTP_COOLDOWN` (429) → snackbar "Tunggu N detik sebelum minta kode baru" using `retry_after_seconds`
3. `OTP_RATE_LIMIT_PHONE` (429) → popup "Terlalu banyak permintaan untuk nomor ini. Coba lagi dalam N menit" (use `retry_after_seconds`)
4. `OTP_RATE_LIMIT_IP` (429) → popup "Terlalu banyak permintaan dari jaringan ini. Coba lagi nanti / hubungi admin"
4. Success → push OTP screen with `otp_request_id` + masked phone
### A3. S3b · OTP verification (6-digit)
1. Show 6 digit fields + masked phone reminder
2. Auto-submit when 6 digits entered → `POST /api/mitra/auth/otp/verify`
3. Show "Tersisa N percobaan" hint when attempts have been used (compute from local counter; backend doesn't expose it)
4. Show "Kirim ulang kode" button — disabled until 60s cooldown elapses, with countdown timer
5. Error responses:
1. `CODE_INVALID` (422) → inline "Kode harus 6 digit angka"
2. `CODE_MISMATCH` (401) → clear fields, inline "Kode salah · tersisa N percobaan", focus first digit
3. `OTP_ATTEMPTS_EXCEEDED` (429) → blocked popup "Terlalu banyak percobaan" with CTAs: "Minta kode baru" (back to Login) / "Hubungi admin"
4. `OTP_EXPIRED` (410) → popup "Kode kadaluarsa" → CTA "Minta kode baru" (back to Login pre-filled)
5. `OTP_USED` (409) → same as `OTP_EXPIRED` (treat as terminal — user must request a new code)
6. `WRONG_FLOW` (400) → popup "Kode ini bukan untuk akun mitra. Pastikan kamu pakai app yang benar"
7. `ACCOUNT_INACTIVE` (403) — comes from verify endpoint after a valid code, before token issuance → full-screen "Akun belum aktif" state with admin contact CTAs (WhatsApp / Telegram). No retry.
6. Success → store tokens → push Home
### A4. Resend OTP (from S3b)
1. From S3b → tap "Kirim ulang kode" (only enabled after 60s)
2. Hits same `POST /api/mitra/auth/otp/request` → new `otp_request_id` replaces old
3. Resets the local attempts counter to 0
4. Same error scenarios as A2 (cooldown / rate-limit) apply
## B. Home onwards
mitra app flow:
1. Home screen
2. Undangan CTA -> Show Undangan · pending invitations
3. Perpanjang CTA -> Show Undangan · Perpanjang Curhat
4. Profil CTA -> show Bestie Profile · profil
2. Status Offline?
1. Status offline -> Show Bestie Home · OFFLINE
2. Status online -> Show Bestie Home · standby & status. Goto next step
3. incoming chat request:
1. New chat -> Show Popup · incoming Curhat Baru
2. Extend chat -> Show Popup · incoming Perpanjang
4. Accept chat request?
1. Reject -> Close dialog and Go to hoome screen
2. Accept -> Show Bestie Chat Room · sesi aktif
5. Session end -> Bestie Chat · durasi habis