Skip to content

fix: 修复兑换码额度删除全部数值时强制为0的问题 - #6686

Closed
lihu-001 wants to merge 1 commit into
QuantumNous:mainfrom
lihu-001:redemption_code_del
Closed

lihu-001 wants to merge 1 commit into
QuantumNous:mainfrom
lihu-001:redemption_code_del

Conversation

@lihu-001

@lihu-001 lihu-001 commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • 修复兑换码额度数值删除全部数字后强制显示0的问题

📝 变更描述 / Description

  • 删除最后一位数字后,输入框现在会保持为空,不再强制显示 0。
  • 空输入在表单状态中使用 NaN 表示,并由 Zod 在提交时进行校验。

🚀 变更类型 / Type of change

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 Issues 与 PRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

已支持删除后为空
image

Summary by CodeRabbit

  • Bug Fixes
    • Improved redemption loading so rejected requests are handled gracefully.
    • Updated quota input behavior to preserve empty and invalid values instead of converting them to zero.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The redemption drawer now suppresses rejected redemption fetch errors. Successful loads still reset form defaults. The quota input preserves empty and invalid numeric states by rendering NaN as empty and passing valueAsNumber directly.

Changes

Redemption drawer behavior

Layer / File(s) Summary
Drawer loading and quota handling
web/src/features/redemption-codes/components/redemptions-mutate-drawer.tsx
The Redemption import is type-only. Rejected fetches are caught without propagation. Successful fetches reset the form. The quota input preserves empty and NaN values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • QuantumNous/new-api issue 6681: Directly covers preserving empty and NaN quota input values.
  • QuantumNous/new-api issue 6455: Also addresses preserving cleared numeric input values.
  • QuantumNous/new-api issue 6680: Relates to quota input precision and empty-value handling.

Possibly related PRs

Poem

A rabbit taps the quota field,
No empty value is forced to zero.
Fetch errors rest beneath the burrow,
While good defaults return in flow.
Type-only imports softly land—
Hop, hop, the drawer is grand!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main fix: preventing the redemption-code quota input from being forced to 0 when all digits are deleted.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Warning

⚠️ This pull request shows signs of AI-generated slop (defensive_cruft, ai_padded_prose). It has been flagged by CodeRabbit slop detection and should be reviewed carefully.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@web/src/features/redemption-codes/components/redemptions-mutate-drawer.tsx`:
- Around line 94-100: Update the redemption load flow around getRedemption so
Save is disabled until the fresh data load succeeds, including when
result.success is false or the request rejects. Track the update-load state,
call handleServerError and show the localized t(ERROR_MESSAGES.LOAD_FAILED)
toast on load failure, and narrow the catch to only the request rejection so
transformRedemptionToFormDefaults or form.reset errors remain visible.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e51d524c-9a4c-4479-b7b2-e6c77dce7b3b

📥 Commits

Reviewing files that changed from the base of the PR and between d6b5ce9 and e0043f9.

📒 Files selected for processing (1)
  • web/src/features/redemption-codes/components/redemptions-mutate-drawer.tsx

Comment on lines +94 to +100
getRedemption(currentRow.id)
.then((result) => {
if (result.success && result.data) {
form.reset(transformRedemptionToFormDefaults(result.data))
}
})
.catch(() => undefined)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

# Expect: failed update loads set an error state and cannot submit stale form data.
rg -n -C 8 \
  'getRedemption|handleServerError|toast\.error|isSubmitting|handleSubmit|currentRow' \
  web/src/features/redemption-codes --glob '*.{ts,tsx}'

Repository: QuantumNous/new-api

Length of output: 44265


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "== api.ts =="
cat -n web/src/features/redemption-codes/api.ts | sed -n '1,90p'

echo "== common error-server helper =="
rg -n -C 6 "handleServerError" web/src --glob '*.{ts,tsx}' | sed -n '1,160p'

echo "== toast/error usage around mutations =="
rg -n -C 5 "toast\.error|ERROR_MESSAGES\.(UPDATE_FAILED|CREATE_FAILED|DELETE_FAILED|UPDATE_INVALID_FAILED)" web/src/features/redemption-codes --glob '*.{ts,tsx}'

echo "== drawer outline =="
ast-grep outline web/src/features/redemption-codes/components/redemptions-mutate-drawer.tsx --view compact || true

echo "== drawer relevant sections =="
cat -n web/src/features/redemption-codes/components/redemptions-mutate-drawer.tsx | sed -n '75,105p;105,155p;334,342p'

echo "== behavioral probe for current load failure behavior =="
python3 - <<'PY'
from pathlib import Path
text = Path('web/src/features/redemption-codes/components/redemptions-mutate-drawer.tsx').read_text()
checks = {
    "load_has_error_state": "loadRedemptionFailed" in text or "isLoadFailed" in text or "loadError" in text or "loading" in text,
    "load_catch_returns_undefined": "catch(() => undefined)" in text or ".catch(e => null)" in text,
    "handleServerError_imported": "handleServerError" in text,
    "toast_error_imported": "toast" in text and ".error(" in text,
    "save_disabled_only_by_submitting": "disabled={isSubmitting}" in text,
    "onSubmit_has_result_success_branch_update": "if (result.success)" in text[text.find("const onSubmit"): text.find("const handleSubmit")],
}
for k, v in checks.items():
    print(f"{k}={v}")
PY

Repository: QuantumNous/new-api

Length of output: 12281


Do not leave the update form usable after a failed load.

getRedemption(currentRow.id) can reject, and result.success === false also skips form.reset. Both paths keep the existing form state while Save remains enabled, so updating with the current currentRow.id can send stale values.

Track the update-load state. Disable Save until the fresh load succeeds. On failure, call handleServerError and show the localized error toast with t(ERROR_MESSAGES.LOAD_FAILED). Keep the catch narrow so transformRedemptionToFormDefaults or form.reset errors are not hidden.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@web/src/features/redemption-codes/components/redemptions-mutate-drawer.tsx`
around lines 94 - 100, Update the redemption load flow around getRedemption so
Save is disabled until the fresh data load succeeds, including when
result.success is false or the request rejects. Track the update-load state,
call handleServerError and show the localized t(ERROR_MESSAGES.LOAD_FAILED)
toast on load failure, and narrow the catch to only the request rejection so
transformRedemptionToFormDefaults or form.reset errors remain visible.

Source: Coding guidelines

@lihu-001

lihu-001 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

关联的bug编号写错了,应该是 #6681

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants