Skip to content

Commit 3cd4039

Browse files
committed
ui: add error message when password incorrect
1 parent 518ac88 commit 3cd4039

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/app/claim/[id]/ClientPage.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default function ClientPage() {
2020
const [error, setError] = useState<string | undefined>();
2121
const [effectivePassword, setEffectivePassword] = useState<string | undefined>(undefined);
2222
const [askPassword, setAskPassword] = useState(false);
23+
const [passwordError, setPasswordError] = useState(false);
2324
type DownUrl = { url: string; expiresAt?: string };
2425
const [downUrls, setDownUrls] = useState<Record<string, DownUrl>>({});
2526
const [updating, setUpdating] = useState(false);
@@ -61,6 +62,8 @@ export default function ClientPage() {
6162
if (e instanceof HttpError && (e.status === 401 || e.status === 403)) {
6263
// Need or wrong password → open modal
6364
setAskPassword(true);
65+
// If we already tried with a password, mark error to display feedback
66+
setPasswordError(!!effectivePassword);
6467
} else {
6568
const msg = e instanceof Error ? e.message : '加载失败';
6669
setError(msg);
@@ -129,8 +132,10 @@ export default function ClientPage() {
129132
const updated = await Api.patchClaim(id, { status: newStatus, password: effectivePassword || undefined });
130133
setClaim(updated);
131134
} catch (e: unknown) {
132-
if (e instanceof HttpError && e.status === 403) setAskPassword(true);
133-
else setError(e instanceof Error ? e.message : '更新失败');
135+
if (e instanceof HttpError && e.status === 403) {
136+
setAskPassword(true);
137+
setPasswordError(!!effectivePassword);
138+
} else setError(e instanceof Error ? e.message : '更新失败');
134139
} finally {
135140
setUpdating(false);
136141
}
@@ -155,8 +160,10 @@ export default function ClientPage() {
155160
setClaimPassword(id, pwd);
156161
setEffectivePassword(pwd);
157162
setAskPassword(false);
163+
setPasswordError(false);
158164
}}
159-
onCancel={() => setAskPassword(false)}
165+
onCancel={() => { setAskPassword(false); setPasswordError(false); }}
166+
error={passwordError}
160167
/>
161168
</div>
162169
</div>
@@ -300,7 +307,7 @@ export default function ClientPage() {
300307
);
301308
}
302309

303-
function PasswordPrompt({ onSubmit, onCancel }: { onSubmit: (pwd: string) => void; onCancel: () => void }) {
310+
function PasswordPrompt({ onSubmit, onCancel, error }: { onSubmit: (pwd: string) => void; onCancel: () => void; error?: boolean }) {
304311
const [v, setV] = useState('');
305312
const { t } = useI18n();
306313
return (
@@ -312,6 +319,7 @@ function PasswordPrompt({ onSubmit, onCancel }: { onSubmit: (pwd: string) => voi
312319
}}
313320
className="space-y-3"
314321
>
322+
{error && <div className="text-sm text-red-600">{t('passwordWrong')}</div>}
315323
<input autoFocus type="password" value={v} onChange={(e) => setV(e.target.value)} className="w-full rounded border px-3 py-2 bg-transparent" placeholder={t('enterPassword')} />
316324
<div className="flex justify-end gap-2">
317325
<button type="button" className="px-3 py-1.5 rounded border" onClick={onCancel}>{t('cancel')}</button>

src/lib/i18n.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const dict: Record<Lang, Record<string, string>> = {
6464
claimIdNote: "此 ID 类似密码,请妥善保管,不要分享。",
6565
copy: "复制",
6666
enterPassword: "请输入访问密码",
67+
passwordWrong: "密码错误,请重试",
6768
cancel: "取消",
6869
confirm: "确认",
6970
},
@@ -118,6 +119,7 @@ const dict: Record<Lang, Record<string, string>> = {
118119
claimIdNote: "Treat this ID like a password. Keep it private.",
119120
copy: "Copy",
120121
enterPassword: "Enter password",
122+
passwordWrong: "Incorrect password. Please try again.",
121123
cancel: "Cancel",
122124
confirm: "Confirm",
123125
},
@@ -172,6 +174,7 @@ const dict: Record<Lang, Record<string, string>> = {
172174
claimIdNote: "Behandeln Sie diese ID wie ein Passwort. Nicht teilen.",
173175
copy: "Kopieren",
174176
enterPassword: "Passwort eingeben",
177+
passwordWrong: "Falsches Passwort. Bitte erneut versuchen.",
175178
cancel: "Abbrechen",
176179
confirm: "Bestätigen",
177180
},
@@ -226,6 +229,7 @@ const dict: Record<Lang, Record<string, string>> = {
226229
claimIdNote: "Considérez cet ID comme un mot de passe. Ne le partagez pas.",
227230
copy: "Copier",
228231
enterPassword: "Saisir le mot de passe",
232+
passwordWrong: "Mot de passe incorrect. Veuillez réessayer.",
229233
cancel: "Annuler",
230234
confirm: "Confirmer",
231235
},
@@ -280,6 +284,7 @@ const dict: Record<Lang, Record<string, string>> = {
280284
claimIdNote: "Tratta questo ID come una password. Mantienilo privato.",
281285
copy: "Copia",
282286
enterPassword: "Inserisci la password",
287+
passwordWrong: "Password errata. Riprova.",
283288
cancel: "Annulla",
284289
confirm: "Conferma",
285290
},

0 commit comments

Comments
 (0)