From 8da5791b7c995d9c5dc46f0ffac7bb5c0a3936e4 Mon Sep 17 00:00:00 2001 From: "cyril.tsui" Date: Mon, 17 Mar 2025 18:43:47 +0800 Subject: [PATCH] copy CustomAlerts --- src/components/Swal/CustomAlerts.js | 107 ++++++++++++++++++++++++++-- src/components/Swal/sweetalert2.css | 7 ++ 2 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 src/components/Swal/sweetalert2.css diff --git a/src/components/Swal/CustomAlerts.js b/src/components/Swal/CustomAlerts.js index 9839ffe..ea96112 100644 --- a/src/components/Swal/CustomAlerts.js +++ b/src/components/Swal/CustomAlerts.js @@ -1,4 +1,5 @@ import Swal from "sweetalert2"; +import "./sweetalert2.css" export const msg = (text) => { Swal.mixin({ @@ -16,6 +17,106 @@ export const msg = (text) => { 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({ @@ -33,8 +134,4 @@ export const deleteDialog = async (confirmAction, t) => { if (result.isConfirmed) { confirmAction(); } -} - -export const popup = (text) => { - Swal.fire(text); -}; +} \ No newline at end of file diff --git a/src/components/Swal/sweetalert2.css b/src/components/Swal/sweetalert2.css new file mode 100644 index 0000000..4825796 --- /dev/null +++ b/src/components/Swal/sweetalert2.css @@ -0,0 +1,7 @@ +.swal-container-class { + z-index: 9999; /* Adjust the z-index value as needed */ + } + +.swal-popup-class { +z-index: 10000; /* Adjust the z-index value as needed */ +} \ No newline at end of file