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

feat: added attachment field #428

Merged
merged 1 commit into from
Sep 8, 2023
Merged

feat: added attachment field #428

merged 1 commit into from
Sep 8, 2023

Conversation

Fredx87
Copy link
Contributor

@Fredx87 Fredx87 commented Sep 6, 2023

Description

This PR adds the management of attachments, using public APIs.

I tried to replicate the existing logic as closely as possible, I just changed a bit the error handling. In the existing implementation, there is a logic for displaying different error messages based on the response returned by the API. I tried to replicate the error cases, for example uploading a big file, but I wasn't able to trigger an error from the API, even with a fairly big attachment. I decided to implement a simple error handling for now, when we get an error either from the API or the client side upload, we just show a generic error message: There was an error uploading {fileName}. Please try again or upload another file.. We can eventually revisit in the future if we need more specific errors, but as I said it is not clear what are the possible failures.
Looking at the current implementation, it seems that the eventual error is displayed inline near the attachments. I decided instead to use a Garden notification

It seems that there was also a logic for preventing the form submission while an upload was in progress, but I wasn't able to replicate this behavior, so for simplicity, the form is always submitted even if there are some uploads in progress. In this case, the pending uploads are simply not saved on the ticket.

Screenshots

attachments-demo.mov

Checklist

  • 📗 all commit messages follow the conventional commits standard
  • ⬅️ changes are compatible with RTL direction
  • ♿ Changes to the UI are tested for accessibility and compliant with WCAG 2.1.
  • 📝 changes are tested in Chrome, Firefox, Safari and Edge
  • 📱 changes are responsive and tested in mobile
  • 👍 PR is approved by @zendesk/vikings

@Fredx87 Fredx87 requested a review from a team as a code owner September 6, 2023 09:52
field: Field;
}

async function fetchCsrfToken() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could turned this into a useCsrfToken reusable hook and memoize it so we only get it once independently of where it's used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure how the CSRF token works. Does it expire? For example, if the user opens a page and fetches the CSRF token, then it stays idle for 1 hour, and then he starts an upload, is the token still valid?

If the answer is yes, we can use a hook and memoize it. Otherwise, it is better to always fetch it before using it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is based on the session so in theory in your example it should still be valid as long as the session is alive.

Otherwise, it is better to always fetch it before using it.

My only concern is if we need several times, e.g. upload and form submission, it may lead to unnecessary calls.
Totally fine to address it later on as well 👍🏼

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we can safely fetch it once it is better to memoize it to avoid unnecessary calls, but let's revisit it later when we'll need to use it in another places


const { addToast } = useToast();

const notifyError = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the useCallback in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that the onDrop from react-dropzone needs the useCallback: https://react-dropzone.js.org/. Our onDrop is calling notifyError so it needs to be passed in the dependency array of it and memorized as well.

: file
)
);
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to memoize all of these?

Copy link
Contributor Author

@Fredx87 Fredx87 Sep 8, 2023

Choose a reason for hiding this comment

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

As above, all these functions are used by the onDrop callback and they need to be memorized as well

@Fredx87 Fredx87 merged commit 4ddaa95 into v4-alpha Sep 8, 2023
6 checks passed
@Fredx87 Fredx87 deleted the gianluca/attachments branch September 8, 2023 09:00
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