|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import Swal from "sweetalert2";
- import "./sweetalert2.css";
-
- export const msg = (text) => {
- Swal.mixin({
- toast: true,
- position: "bottom-end",
- showConfirmButton: false,
- timer: 3000,
- timerProgressBar: true,
- didOpen: (toast) => {
- toast.onmouseenter = Swal.stopTimer;
- toast.onmouseleave = Swal.resumeTimer;
- },
- }).fire({
- icon: "Success",
- title: text,
- });
- };
-
- export const popup = (text) => {
- Swal.fire(text);
- };
-
- export const successDialog = (text, t) => {
- return Swal.fire({
- icon: "success",
- title: text,
- confirmButtonText: t("Confirm"),
- showConfirmButton: true,
- });
- };
-
- export const successDialogWithContent = (title, text, t) => {
- return Swal.fire({
- icon: "success",
- title: title,
- html: text,
- confirmButtonText: t("Confirm"),
- showConfirmButton: true,
- });
- };
-
- export const errorDialog = (text, t) => {
- return Swal.fire({
- icon: "error",
- title: text,
- confirmButtonText: t("Confirm"),
- showConfirmButton: true,
- });
- };
-
- export const errorDialogWithContent = (title, text, t) => {
- return Swal.fire({
- icon: "error",
- title: title,
- html: text,
- confirmButtonText: t("Confirm"),
- showConfirmButton: true,
- });
- };
-
- export const warningDialog = (text, t) => {
- return Swal.fire({
- icon: "warning",
- title: text,
- confirmButtonText: t("Confirm"),
- showConfirmButton: true,
- });
- };
-
- export const submitDialog = async (
- confirmAction,
- t,
- { ...props } = {
- title: t("Do you want to submit?"),
- confirmButtonText: t("Submit"),
- }
- ) => {
- // console.log(props)
- // const { t } = useTranslation("common")
- const result = await Swal.fire({
- icon: "question",
- title: props?.title,
- cancelButtonText: t("Cancel"),
- confirmButtonText: props?.confirmButtonText,
- showCancelButton: true,
- showConfirmButton: true,
- customClass: {
- container: "swal-container-class", // Add a custom class to the Swal.fire container element
- popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
- },
- });
- if (result.isConfirmed) {
- confirmAction();
- }
- };
-
- export const submitDialogWithWarning = async (
- confirmAction,
- t,
- { ...props } = {
- title: t("Do you want to submit?"),
- text: t("Warning!"),
- confirmButtonText: t("Submit"),
- }
- ) => {
- // console.log(props)
- // const { t } = useTranslation("common")
- const result = await Swal.fire({
- icon: "warning",
- title: props?.title,
- html: props?.text,
- cancelButtonText: t("Cancel"),
- confirmButtonText: props?.confirmButtonText,
- showCancelButton: true,
- showConfirmButton: true,
- customClass: {
- container: "swal-container-class", // Add a custom class to the Swal.fire container element
- popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
- },
- });
- if (result.isConfirmed) {
- confirmAction();
- }
- };
-
- export const deleteDialog = async (confirmAction, t) => {
- // const { t } = useTranslation("common")
- const result = await Swal.fire({
- icon: "question",
- title: t("Do you want to delete?"),
- cancelButtonText: t("Cancel"),
- confirmButtonText: t("Delete"),
- showCancelButton: true,
- showConfirmButton: true,
- customClass: {
- container: "swal-container-class", // Add a custom class to the Swal.fire container element
- popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
- },
- });
- if (result.isConfirmed) {
- confirmAction();
- }
- };
|