Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: A way to detect when the user manually closes the Portal #219

Open
cauli opened this issue Nov 7, 2024 · 3 comments
Open

Suggestion: A way to detect when the user manually closes the Portal #219

cauli opened this issue Nov 7, 2024 · 3 comments
Assignees

Comments

@cauli
Copy link

cauli commented Nov 7, 2024

Slack logo #triage-eng-support thread

version: Flatfile "Platform"
lib: @flatfile/react

Overview

In my specific use-case, it matters if the user has closed the Portal (via the X button), or of it was closed programatically via closePortal() when using const { openPortal, closePortal } = useFlatfile()

But currently no event is emitted when the user closes the Portal, or when the Space is unmounted.

What did I try?

The only way of detecting this is through FlatfileProvider config

<FlatfileProvider config={{
   closeSpace: {
      // operation: not provided on purpose
      onClose() {
         // this will trigger when the user clicks the "X" close button,
         // but not when the portal is closed programatically
      }
   }
>
   {children}
</FlatfileProvider>

but the ergonomics of this is not ideal, because I need to React to that event from inside the provider, not from outside.

What about useFlatfile({onClose})?

useFlatfile({
   onClose() {
     // detects when the portal is closed for any reason, 
     // but doesn't provide a reason.
   }
)

This is insufficient, because I want to detect if it was closed by clicking the "X" (more like a "onCancel" event)

My workarounds

  • Wrapped useFlatfile with my own hook, that stores the state of the Portal, and emits triggers useMyCustomFlatfile({ onCancel() { /* this is triggered when it's closed without a job:outcome-acknowledged */ } })
  • Emitted a custom event on closeSpace: { onClose () { } }, that can be detected elsewhere in the application
@Arsik36
Copy link

Arsik36 commented Nov 8, 2024

Hey Cauli, would you be able to test with const { open } = useFlatfile(); and see if that makes any difference for you?

@cauli
Copy link
Author

cauli commented Nov 8, 2024

Hey @Arsik36.

const { open } = useFlatfile(); only allows me to know if the Portal is open or not, it doesn't solve the issue of being able to detect a cancellation (manual closure of the Portal by clicking on the "X")

It's definitely possible to create a workaround component that uses:

  1. open,
  2. useFlatfile({ onClose })
  3. And an event listener for job:outcome-acknowledged

It just ends up being a lot of code for what would be trivial to do on Flatfile's end (emit an event when closing the space)

@Arsik36
Copy link

Arsik36 commented Dec 12, 2024

Ah, you're right! We'll accept this as a feature request. Thank you for the suggestion!

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

No branches or pull requests

3 participants