CRUD icon indicating copy to clipboard operation
CRUD copied to clipboard

[v7] Remove noty dependency in favor of a sweetalert2 fork - streamline notifications in core

Open pxpm opened this issue 1 year ago • 3 comments

In https://github.com/Laravel-Backpack/community-forum/discussions/1090 we were trying to address the fact that it's not possible to change the backpack core notifications. If you as a developer would prefer to use swal instead of noty of the other way around there isn't a single file (where notifications are triggered) that you didn't had to change to cater your needs.

Doing a little research on the issue I've uncovered some more things that highlight the fact that notifications in Backpack are a little bit all over the place and are not very consistent. You have the ability to trigger a noty from php Alert:: but not a sweetalert for eg.

Regarding the dependencies this issue intends to remove noty and sweetalert (v1) in favor of adding sweertalert2 (or a fork of it because of the russian issue). We now use a deprecated beta version of noty and a deprecated version of sweetalert (v1) soo yeah.

We should look at this as the opportunity to make backpack core notifications "easily" configurable for the 90% use cases. the 10% should still have the ability to create a blade file with their own notifications and use the same api to trigger them.

pxpm avatar Jul 22 '24 15:07 pxpm

I second this suggestion. In theory most of the functionality is easy enough to handle merging this all into one blade file, or perhaps 2 files - one to update all the alerts from JavaScript and local storage into a workable array, and then another to actually display the alerts. Once this is being done, I assume we should allow users to add more info than just type and text?

Has anyone started working on this, maybe I can try to look at this one day until someone else is able to come along?

zachweix avatar Sep 05 '24 17:09 zachweix

Hey @zachweix thanks for the input 🙏

We haven't started working on this, no. Actually we talked about this a few days ago, and I know @tabacitu had been doing some research about this subject.

I think it wouldn't be wise to start working on this just now, until we are certain of what, and how this issue will be addressed. Be assured that when we decide how to proceed we will update this issue, and maybe then if you want to give it a shot, I'd say to go ahead 👍 thanks for helping out.

Cheers

pxpm avatar Sep 06 '24 12:09 pxpm

Sounds good, thanks. It took me a while to figure out how to make a notification like Noty in sweetalert2, so I just want to put it here for posterity (partially for my sake 🙂)

const Toast = Swal.mixin({
  toast: true,
  position: "top-end",
  showConfirmButton: false,
  timer: 3000,
  timerProgressBar: true,
  didOpen: (toast) => {
    toast.onmouseenter = Swal.stopTimer;
    toast.onmouseleave = Swal.resumeTimer;
  }
});
Toast.fire({
  icon: "success",
  title: "Signed in successfully"
});

zachweix avatar Sep 06 '24 13:09 zachweix

I'd love to have notifications all cleaned up, but:

  • I wouldn't add MORE dependency to SweetAlert2, after what happened I'm a little scared they might introduce other things, to be honest - even security problems;
  • I don't know a library we can use to trigger both bubble notifications and alerts;
  • if we are to work on this, I'd rather we do a complete solution - a JS+PHP API to trigger notifications, alerts, modals, offcanvas - both normal ones and Livewire ones; I worked a bit on this months ago but never finished 😔

In short, I think the "quick fix" of using SweetAlert2 instead of Noty... isn't a step in the right direction. And steps in the right right direction... are in limbo right now, because it's a lot of work.

That's why this didn't make the cut in v7. But hopefully we'll be able to finish this by v8, it's a cleanup I'd really like.

tabacitu avatar Jul 01 '25 06:07 tabacitu

I hear you, but one thing that can be done is moving most of the logic for the Noty notifications into one file, this way if someone wants to replace Noty with their own library (or for when you're ready to), it is all consolidated into one location. If you're interested, I am willing to work on that consolidation effort, all while still keeping it with Noty

zachweix avatar Jul 01 '25 14:07 zachweix