fix(console): reset date picker to today when cleared to prevent 400 error#8741
Open
OfekDanny wants to merge 1 commit intologto-io:masterfrom
Open
fix(console): reset date picker to today when cleared to prevent 400 error#8741OfekDanny wants to merge 1 commit intologto-io:masterfrom
OfekDanny wants to merge 1 commit intologto-io:masterfrom
Conversation
…error When the native date input's clear button is clicked, event.target.value becomes an empty string. Passing that directly into the SWR key produces `api/dashboard/users/active?date=`, which fails koaGuard validation (regex rejects empty string) with a 400 guard.invalid_input error, crashing the Dashboard page. Fall back to today's date so the query remains valid and the page recovers gracefully without a request error. Fixes logto-io#8491
COMPARE TO
|
| Name | Diff |
|---|---|
| packages/console/src/pages/Dashboard/index.tsx | 📈 +36 Bytes |
Contributor
|
Codex Review: Didn't find any major issues. Keep it up! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Author
|
The CI failure in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #8491.
When the user clicks the Clear button on the native `` in the Dashboard's "Daily Active Users" section, `event.target.value` becomes `""`. That empty string is passed directly into the SWR key:
```
api/dashboard/users/active?date=
```
The backend `koaGuard` validates `date` with `string().regex(dateRegEx).optional()`. `.optional()` allows `undefined` but not an empty string, so it returns a `400 guard.invalid_input` error and the Dashboard crashes. Additionally, clicking the Retry button re-triggers the broken request and forces a session logout.
Root cause
```ts
// packages/console/src/pages/Dashboard/index.tsx
const handleDateChange: ChangeEventHandler = (event) => {
setDate(event.target.value); // "" when cleared → invalid API param
};
```
Fix
Fall back to today's date when the input value is empty:
```ts
const handleDateChange: ChangeEventHandler = (event) => {
setDate(event.target.value || format(Date.now(), 'yyyy-MM-dd'));
};
```
`format` is already imported from `date-fns` and used in the `useState` initializer on the same line above, so no new dependencies are introduced.
Behaviour after fix