Skip to content

fix(console): reset date picker to today when cleared to prevent 400 error#8741

Open
OfekDanny wants to merge 1 commit intologto-io:masterfrom
OfekDanny:fix/dashboard-date-clear-causes-400
Open

fix(console): reset date picker to today when cleared to prevent 400 error#8741
OfekDanny wants to merge 1 commit intologto-io:masterfrom
OfekDanny:fix/dashboard-date-clear-causes-400

Conversation

@OfekDanny
Copy link
Copy Markdown

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

Action Before After
Clear date picker 400 error, page crash Resets to today's data
Retry on error screen Session logout N/A — error no longer occurs
Set a specific date Works Works (unchanged)

…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
@github-actions
Copy link
Copy Markdown

COMPARE TO master

Total Size Diff 📈 +36 Bytes

Diff by File
Name Diff
packages/console/src/pages/Dashboard/index.tsx 📈 +36 Bytes

@wangsijie
Copy link
Copy Markdown
Contributor

@codex

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@OfekDanny
Copy link
Copy Markdown
Author

The CI failure in run-logto (experience, false) appears to be a pre-existing flaky test unrelated to this change — experience/password-policy.test.js timed out waiting for an alert element. Could you please re-run that job? Thanks!

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

Development

Successfully merging this pull request may close these issues.

bug(console): Dashboard date picker clear button causes invalid parameter error and crashes the page

2 participants