|
| 1 | +# Login Modal Implementation Plan |
| 2 | + |
| 3 | +> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. |
| 4 | +
|
| 5 | +**Goal:** Replace the two inline login buttons (Google + GitHub) in the Navbar with a single "Log In" button that opens a centered modal for the user to choose a login provider. |
| 6 | + |
| 7 | +**Architecture:** All changes are self-contained in `Navbar.tsx` — add a `useState` boolean for modal visibility, replace the two `<a>` login tags with one `<button>`, and append a modal overlay + card as a portal-free JSX sibling inside the `<nav>`. Translation keys for the new copy live in `messages/en.json` and `messages/zh.json`. |
| 8 | + |
| 9 | +**Tech Stack:** Next.js 14, TypeScript, Tailwind CSS, next-intl |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +### Task 1: Add translation keys |
| 14 | + |
| 15 | +**Files:** |
| 16 | +- Modify: `messages/en.json` |
| 17 | +- Modify: `messages/zh.json` |
| 18 | + |
| 19 | +**Step 1: Add keys to `messages/en.json`** |
| 20 | + |
| 21 | +Inside the `"Navbar"` object, add three keys: |
| 22 | + |
| 23 | +```json |
| 24 | +"login": "Log In", |
| 25 | +"loginTitle": "Welcome to MoltMarket", |
| 26 | +"loginSubtitle": "Choose a login method" |
| 27 | +``` |
| 28 | + |
| 29 | +After editing, the `"Navbar"` block should look like: |
| 30 | +```json |
| 31 | +"Navbar": { |
| 32 | + "home": "Home", |
| 33 | + "overview": "Overview", |
| 34 | + "tokenMarket": "Token Recycling Market", |
| 35 | + "logout": "Logout", |
| 36 | + "startEarning": "Start Earning", |
| 37 | + "login": "Log In", |
| 38 | + "loginTitle": "Welcome to MoltMarket", |
| 39 | + "loginSubtitle": "Choose a login method" |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +**Step 2: Add keys to `messages/zh.json`** |
| 44 | + |
| 45 | +Inside the `"Navbar"` object, add the same three keys in Chinese: |
| 46 | + |
| 47 | +```json |
| 48 | +"login": "登录", |
| 49 | +"loginTitle": "欢迎来到 MoltMarket", |
| 50 | +"loginSubtitle": "选择登录方式" |
| 51 | +``` |
| 52 | + |
| 53 | +**Step 3: Commit** |
| 54 | + |
| 55 | +```bash |
| 56 | +git add messages/en.json messages/zh.json |
| 57 | +git commit -m "feat: add login modal translation keys" |
| 58 | +``` |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +### Task 2: Rewrite the unauthenticated login section in Navbar |
| 63 | + |
| 64 | +**Files:** |
| 65 | +- Modify: `src/components/Navbar.tsx` |
| 66 | + |
| 67 | +**Step 1: Add `useState` import and modal state** |
| 68 | + |
| 69 | +At the top of the component function body (after the existing `const pathname = usePathname();` line), add: |
| 70 | + |
| 71 | +```tsx |
| 72 | +const [loginOpen, setLoginOpen] = useState(false); |
| 73 | +``` |
| 74 | + |
| 75 | +Also add `useState` to the React import at the top of the file: |
| 76 | + |
| 77 | +```tsx |
| 78 | +import { useState } from "react"; |
| 79 | +``` |
| 80 | + |
| 81 | +**Step 2: Replace the unauthenticated login JSX** |
| 82 | + |
| 83 | +Find the `else` branch of `{userName ? (...) : (...)}` — it currently renders a `<div className="flex items-center gap-2">` containing the Google `<a>` and GitHub `<a>` tags. |
| 84 | + |
| 85 | +Replace that entire `<div>` (lines 109–148 in the original file) with a single button: |
| 86 | + |
| 87 | +```tsx |
| 88 | +<button |
| 89 | + onClick={() => setLoginOpen(true)} |
| 90 | + className="font-inter text-[15px] font-semibold text-white rounded-lg px-4 py-2 bg-[var(--accent)] hover:opacity-90 transition-opacity cursor-pointer" |
| 91 | +> |
| 92 | + {t("login")} |
| 93 | +</button> |
| 94 | +``` |
| 95 | + |
| 96 | +**Step 3: Add the modal JSX** |
| 97 | + |
| 98 | +Immediately before the closing `</nav>` tag, add: |
| 99 | + |
| 100 | +```tsx |
| 101 | +{loginOpen && ( |
| 102 | + <> |
| 103 | + {/* Overlay */} |
| 104 | + <div |
| 105 | + className="fixed inset-0 z-[100] bg-black/50 backdrop-blur-sm" |
| 106 | + onClick={() => setLoginOpen(false)} |
| 107 | + /> |
| 108 | + {/* Modal card */} |
| 109 | + <div className="fixed inset-0 z-[101] flex items-center justify-center pointer-events-none"> |
| 110 | + <div className="pointer-events-auto w-[360px] bg-[var(--bg-primary)] rounded-2xl shadow-2xl p-8 flex flex-col gap-6"> |
| 111 | + {/* Header */} |
| 112 | + <div className="flex items-start justify-between"> |
| 113 | + <div> |
| 114 | + <h2 className="font-inter text-[20px] font-bold text-[var(--text-primary)]"> |
| 115 | + {t("loginTitle")} |
| 116 | + </h2> |
| 117 | + <p className="font-inter text-[14px] text-[var(--text-muted)] mt-1"> |
| 118 | + {t("loginSubtitle")} |
| 119 | + </p> |
| 120 | + </div> |
| 121 | + <button |
| 122 | + onClick={() => setLoginOpen(false)} |
| 123 | + className="text-[var(--text-muted)] hover:text-[var(--text-primary)] transition-colors text-[20px] leading-none cursor-pointer" |
| 124 | + > |
| 125 | + × |
| 126 | + </button> |
| 127 | + </div> |
| 128 | + |
| 129 | + {/* Login options */} |
| 130 | + <div className="flex flex-col gap-3"> |
| 131 | + {/* Google */} |
| 132 | + <a |
| 133 | + href="/api/auth/login?provider=google" |
| 134 | + className="flex items-center gap-3 font-inter text-[15px] font-medium text-[var(--text-primary)] rounded-xl px-4 py-3 border border-[var(--border-medium)] hover:bg-[var(--bg-tag)] transition-colors" |
| 135 | + > |
| 136 | + <svg className="w-5 h-5 shrink-0" viewBox="0 0 24 24"> |
| 137 | + <path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z" fill="#4285F4" /> |
| 138 | + <path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z" fill="#34A853" /> |
| 139 | + <path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l3.66-2.84z" fill="#FBBC05" /> |
| 140 | + <path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z" fill="#EA4335" /> |
| 141 | + </svg> |
| 142 | + Continue with Google |
| 143 | + </a> |
| 144 | + |
| 145 | + {/* GitHub */} |
| 146 | + <a |
| 147 | + href="/api/auth/login?provider=github" |
| 148 | + className="flex items-center gap-3 font-inter text-[15px] font-semibold text-white rounded-xl px-4 py-3 bg-[#24292e] hover:bg-[#1a1e22] transition-colors" |
| 149 | + > |
| 150 | + <svg className="w-5 h-5 shrink-0" fill="currentColor" viewBox="0 0 24 24"> |
| 151 | + <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" /> |
| 152 | + </svg> |
| 153 | + Continue with GitHub |
| 154 | + </a> |
| 155 | + </div> |
| 156 | + </div> |
| 157 | + </div> |
| 158 | + </> |
| 159 | +)} |
| 160 | +``` |
| 161 | + |
| 162 | +**Step 4: Verify the file compiles** |
| 163 | + |
| 164 | +```bash |
| 165 | +npx tsc --noEmit |
| 166 | +``` |
| 167 | + |
| 168 | +Expected: no errors |
| 169 | + |
| 170 | +**Step 5: Commit** |
| 171 | + |
| 172 | +```bash |
| 173 | +git add src/components/Navbar.tsx |
| 174 | +git commit -m "feat: replace login buttons with Log In modal in Navbar" |
| 175 | +``` |
| 176 | + |
| 177 | +--- |
| 178 | + |
| 179 | +### Task 3: Manual smoke test |
| 180 | + |
| 181 | +**Step 1: Start dev server** |
| 182 | + |
| 183 | +```bash |
| 184 | +npm run dev |
| 185 | +``` |
| 186 | + |
| 187 | +**Step 2: Verify checklist** |
| 188 | + |
| 189 | +- [ ] Navbar shows single "Log In" button when logged out |
| 190 | +- [ ] Clicking "Log In" opens the modal with Google and GitHub options |
| 191 | +- [ ] Clicking the overlay (outside the card) closes the modal |
| 192 | +- [ ] Clicking the × button closes the modal |
| 193 | +- [ ] Clicking "Continue with Google" redirects to `/api/auth/login?provider=google` |
| 194 | +- [ ] Clicking "Continue with GitHub" redirects to `/api/auth/login?provider=github` |
| 195 | +- [ ] Switching locale (EN ↔ 中文) shows correct translated text in modal title/subtitle |
| 196 | +- [ ] Logged-in state still shows username + Logout (unchanged) |
0 commit comments