FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

146 lines
3.5 KiB

  1. import Swal from "sweetalert2";
  2. import "./sweetalert2.css";
  3. export const msg = (text) => {
  4. Swal.mixin({
  5. toast: true,
  6. position: "bottom-end",
  7. showConfirmButton: false,
  8. timer: 3000,
  9. timerProgressBar: true,
  10. didOpen: (toast) => {
  11. toast.onmouseenter = Swal.stopTimer;
  12. toast.onmouseleave = Swal.resumeTimer;
  13. },
  14. }).fire({
  15. icon: "Success",
  16. title: text,
  17. });
  18. };
  19. export const popup = (text) => {
  20. Swal.fire(text);
  21. };
  22. export const successDialog = (text, t) => {
  23. return Swal.fire({
  24. icon: "success",
  25. title: text,
  26. confirmButtonText: t("Confirm"),
  27. showConfirmButton: true,
  28. });
  29. };
  30. export const successDialogWithContent = (title, text, t) => {
  31. return Swal.fire({
  32. icon: "success",
  33. title: title,
  34. html: text,
  35. confirmButtonText: t("Confirm"),
  36. showConfirmButton: true,
  37. });
  38. };
  39. export const errorDialog = (text, t) => {
  40. return Swal.fire({
  41. icon: "error",
  42. title: text,
  43. confirmButtonText: t("Confirm"),
  44. showConfirmButton: true,
  45. });
  46. };
  47. export const errorDialogWithContent = (title, text, t) => {
  48. return Swal.fire({
  49. icon: "error",
  50. title: title,
  51. html: text,
  52. confirmButtonText: t("Confirm"),
  53. showConfirmButton: true,
  54. });
  55. };
  56. export const warningDialog = (text, t) => {
  57. return Swal.fire({
  58. icon: "warning",
  59. title: text,
  60. confirmButtonText: t("Confirm"),
  61. showConfirmButton: true,
  62. });
  63. };
  64. export const submitDialog = async (
  65. confirmAction,
  66. t,
  67. { ...props } = {
  68. title: t("Do you want to submit?"),
  69. confirmButtonText: t("Submit"),
  70. }
  71. ) => {
  72. // console.log(props)
  73. // const { t } = useTranslation("common")
  74. const result = await Swal.fire({
  75. icon: "question",
  76. title: props?.title,
  77. cancelButtonText: t("Cancel"),
  78. confirmButtonText: props?.confirmButtonText,
  79. showCancelButton: true,
  80. showConfirmButton: true,
  81. customClass: {
  82. container: "swal-container-class", // Add a custom class to the Swal.fire container element
  83. popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
  84. },
  85. });
  86. if (result.isConfirmed) {
  87. confirmAction();
  88. }
  89. };
  90. export const submitDialogWithWarning = async (
  91. confirmAction,
  92. t,
  93. { ...props } = {
  94. title: t("Do you want to submit?"),
  95. text: t("Warning!"),
  96. confirmButtonText: t("Submit"),
  97. }
  98. ) => {
  99. // console.log(props)
  100. // const { t } = useTranslation("common")
  101. const result = await Swal.fire({
  102. icon: "warning",
  103. title: props?.title,
  104. html: props?.text,
  105. cancelButtonText: t("Cancel"),
  106. confirmButtonText: props?.confirmButtonText,
  107. showCancelButton: true,
  108. showConfirmButton: true,
  109. customClass: {
  110. container: "swal-container-class", // Add a custom class to the Swal.fire container element
  111. popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
  112. },
  113. });
  114. if (result.isConfirmed) {
  115. confirmAction();
  116. }
  117. };
  118. export const deleteDialog = async (confirmAction, t) => {
  119. // const { t } = useTranslation("common")
  120. const result = await Swal.fire({
  121. icon: "question",
  122. title: t("Do you want to delete?"),
  123. cancelButtonText: t("Cancel"),
  124. confirmButtonText: t("Delete"),
  125. showCancelButton: true,
  126. showConfirmButton: true,
  127. customClass: {
  128. container: "swal-container-class", // Add a custom class to the Swal.fire container element
  129. popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
  130. },
  131. });
  132. if (result.isConfirmed) {
  133. confirmAction();
  134. }
  135. };