Skip to content

✨(preview) provide feedback to the user when they request access - #382

Open
magopian wants to merge 5 commits into
mainfrom
customize-FilePreview-request-access-button
Open

magopian wants to merge 5 commits into
mainfrom
customize-FilePreview-request-access-button

Conversation

@magopian

@magopian magopian commented Nov 11, 2026 •

Copy link
Copy Markdown

Fixes #377

Purpose

This gives feedback to the user when they request (or have already requested) access to an item.

Add a requestAccessState prop "not-requested" | "sent" | "already-requested" to FilePreview and NoAccessPreview.

As soon as the state changes from "not-requested", the button is disabled.

It might make sense to add a error <error message> variant to the requestAccessState type, to give feedback on error to the user. As a reminder, toasts are not an option as they're displayed behind the backdrop, and as such as unreadable.
If there's such a error, the button might be displayed as disabled a error button.

Edit: Robin proposed the following

RL 2026-11-13 at 16 08 25@2x

@magopian

magopian commented Nov 23, 2026 •

Copy link
Copy Markdown
Author

@robin-lecomte after a quick chat with @lterm this morning, i'll implement the error messages in toasts instead, unless you think this is a bad idea?

Capture d’écran 2026-11-23 à 11 55 14

This commit gives feedback to the user when they request (or have
already requested) access to an item.

Add a `requestAccessState` prop `"not-requested" | "sent" |
"already-requested"` to `FilePreview` and `NoAccessPreview`.

As soon as the state changes from "not-requested", the button is
disabled.
@magopian
magopian force-pushed the customize-FilePreview-request-access-button branch from 8d1c712 to 874f2b1 Compare November 23, 2026 10:55

@PanchoutNathan PanchoutNathan left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the PR! The feature is useful, but I'm requesting changes before merging: the current API causes several problems as soon as an app wires it in the natural way (try → "sent", catch → "error"). I reproduced each case locally with stories.

1. The error is passed as a state, but it is an event

The error toast is fired by a useEffect watching requestAccessState (NoAccessPreview.tsx L45-52). Consequences:

  • A 2nd failure shows nothing. The state is already "error", React does not re-render, so no new toast. The user thinks the request went through.
  • Double submit. The button stays clickable while the request is pending, so a double-click on a slow network sends two requests.
  • The toast comes back by itself. After a failure, moving to another file and back to the folder remounts the component, and the toast shows again with no new request.

Proposal: onRequestAccess returns a Promise. The ui-kit locks the button while it is pending and shows the toast in the catch, on every failure. "error" is removed from the states.

// FilePreview.tsx
onRequestAccess?: (file: FilePreviewType) => Promise<void>;

// NoAccessPreview.tsx
const [isSending, setIsSending] = useState(false);
const state = file.requestAccessState ?? "not-requested";
const isLocked =
  isSending || state === "sent" || state === "already-requested";

const handleRequestAccess = async () => {
  if (isLocked || !onRequestAccess) return;
  setIsSending(true);
  try {
    await onRequestAccess(file);
  } catch {
    toast(
      t("components.filePreview.folderAccessDenied.requestError"),
      VariantType.ERROR,
    );
  } finally {
    setIsSending(false);
  }
};

2. One single state for the whole carousel

requestAccessState is a FilePreview prop, while access denial is per file (isFolderAccessDenied in types.ts). With two denied folders in files, if I request access to the first one and move to the second, the second shows "Request sent" with a disabled button: I can't request access, even though no request was made.

Proposal: move the status onto the file, next to isFolderAccessDenied, and remove the FilePreview prop. We also need a key per file. Otherwise React keeps the same NoAccessPreview instance from one denied folder to the next, and the local isSending state carries over.

// types.ts
export type RequestAccessState = "not-requested" | "sent" | "already-requested";

export interface FilePreviewType {
  // ...
  isFolderAccessDenied?: boolean;
  /** Access request status, only used when `isFolderAccessDenied` is true. */
  requestAccessState?: RequestAccessState;
}
// FilePreview.tsx, renderViewer
<NoAccessPreview key={currentFile.id} file={currentFile} /* ... */ />

On the app side, the wiring becomes:

const handleRequestAccess = async (file: FilePreviewType) => {
  await api.requestAccess(file.id); // if it rejects, the ui-kit shows the toast
  setFiles((prev) =>
    prev.map((f) =>
      f.id === file.id ? { ...f, requestAccessState: "sent" } : f,
    ),
  );
};

3. RequestAccessState is not exported by the package

src/index.ts lists its type exports one by one, so the export * in preview/index.ts is not enough. An app writing import { type RequestAccessState } from "@gouvfr-lasuite/ui-components" gets TS2305, and will end up copying the union.

// src/index.ts
export type {
  FilePreviewType,
  PreviewControlsProps,
  RequestAccessState,
  VolumeBarProps,
} from "./components/preview";

4. The JSDoc contradicts the behaviour

The onRequestAccess JSDoc says "The consuming app handles the access request and its feedback", but the ui-kit already shows the error toast. An app that follows the JSDoc shows its own toast, and the user sees two toasts for a single error. With the proposal from point 1, the ui-kit owns the toast, and the JSDoc should say so:

/**
 * Sends the access request for `file`. Return a promise: while it is pending
 * the button is locked, and if it rejects the preview shows an error toast.
 * Do not show your own error toast. On success, set the file's
 * `requestAccessState` to "sent".
 */
onRequestAccess?: (file: FilePreviewType) => Promise<void>;

To update accordingly

  • add stories and e2e tests
  • Stories: there is currently no error case. A story with an onRequestAccess that rejects would help.
  • E2E tests: two failures in a row show two toasts, a double-click calls onRequestAccess only once, and navigating between two denied folders keeps independent statuses.

Optional — button layout (@robin-lecomte , what do you think?)

Depending on the language, the buttons can wrap onto two lines. Robin, is that fine for you, or would you rather keep them on a single line?

This is following @PanchoutNathan's review.

`onRequestAccess` now returns `Promise<void>`.
`NoAccessPreview` owns the async lifecycle and locks the button while
the request is in flight to prevent double-submits.

The error toast is shown in its own catch block on every failure: one
toast per failure.

This fixes three bugs with the old "error" state approach:
- a second failure showed no toast (state didn't change, no re-render)
- double-clicking sent two requests
- remounting an errored component re-fired the stale toast
This is following @PanchoutNathan's review.

Each `FilePreviewType` now carries its own optional
`requestAccessState`: `"sent" | "already-requested"`.
`"not-requested"` was removed as it's redundant with no
`requestAccessState` (undefined).
The FilePreview-level prop is removed.

This fixes the carousel bug: with a single prop shared across all
files, requesting access to one denied folder disabled the button on
every other denied folder in the same preview.

`key={currentFile.id}` is added to `NoAccessPreview` so local
`isSending` state resets on navigation rather than carrying over between
folders.
This is following @PanchoutNathan's review.

Apps importing it from `@gouvfr-lasuite/ui-components` got TS2305
because `src/index.ts` lists type exports one by one and the type was
missing from the list.
This is following @PanchoutNathan's review

- JSDoc on `onRequestAccess` now states the ui-kit owns the error toast
and instructs callers to set `requestAccessState: "sent"` on success
- `FilePreviewType` table in the story meta documents
`requestAccessState`
- `FilePreviewProps` table and argTypes reflect the `Promise<void>`
signature
@magopian
magopian force-pushed the customize-FilePreview-request-access-button branch from 6a6e1f6 to d1762b6 Compare November 23, 2026 15:25

This branch has not been deployed

No deployments
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.

Allow to customize the state of the button in the FilePreview, and its text

2 participants