FPSMS-frontend
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

CustomAlerts.tsx 4.9 KiB

před 10 měsíci
před 11 měsíci
před 11 měsíci
před 5 měsíci
před 11 měsíci
před 11 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 5 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 10 měsíci
před 11 měsíci
před 10 měsíci
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. import Swal, { SweetAlertOptions } from "sweetalert2";
  2. import "./sweetalert2.css";
  3. import { TFunction } from "i18next";
  4. export type SweetAlertTitle = string | HTMLElement | JQuery | undefined;
  5. export type SweetAlertHtml = string | HTMLElement | JQuery | undefined;
  6. export type SweetAlertConfirmButtonText = string | undefined;
  7. type Transaction = TFunction<["translation", ...string[]], undefined>;
  8. export const msg = (title: SweetAlertTitle) => {
  9. Swal.mixin({
  10. toast: true,
  11. position: "bottom-end",
  12. showConfirmButton: false,
  13. timer: 3000,
  14. timerProgressBar: true,
  15. didOpen: (toast) => {
  16. toast.onmouseenter = Swal.stopTimer;
  17. toast.onmouseleave = Swal.resumeTimer;
  18. },
  19. customClass: {
  20. container: 'swal2-custom-zindex',
  21. },
  22. }).fire({
  23. icon: "success",
  24. title: title,
  25. });
  26. };
  27. export const msgError = (title: SweetAlertTitle) => {
  28. Swal.mixin({
  29. toast: true,
  30. position: "bottom-end",
  31. showConfirmButton: false,
  32. timer: 3000,
  33. timerProgressBar: true,
  34. didOpen: (toast) => {
  35. toast.onmouseenter = Swal.stopTimer;
  36. toast.onmouseleave = Swal.resumeTimer;
  37. },
  38. customClass: {
  39. container: 'swal2-custom-zindex',
  40. },
  41. }).fire({
  42. icon: "error",
  43. title: title,
  44. });
  45. };
  46. export const popup = (options: SweetAlertOptions) => {
  47. Swal.fire(options);
  48. };
  49. export const successDialog = async (
  50. title: SweetAlertTitle,
  51. t: Transaction,
  52. confirmAction?: () => void,
  53. ) => {
  54. const result = await Swal.fire({
  55. icon: "success",
  56. title: title,
  57. confirmButtonText: t("Confirm"),
  58. showConfirmButton: true,
  59. });
  60. if (result.isConfirmed && confirmAction) {
  61. confirmAction();
  62. }
  63. };
  64. export const successDialogWithContent = (
  65. title: SweetAlertTitle,
  66. html: SweetAlertHtml,
  67. t: Transaction,
  68. ) => {
  69. return Swal.fire({
  70. icon: "success",
  71. title: title,
  72. html: html,
  73. confirmButtonText: t("Confirm"),
  74. showConfirmButton: true,
  75. });
  76. };
  77. export const errorDialog = (title: SweetAlertTitle, t: Transaction) => {
  78. return Swal.fire({
  79. icon: "error",
  80. title: title,
  81. confirmButtonText: t("Confirm"),
  82. showConfirmButton: true,
  83. });
  84. };
  85. export const errorDialogWithContent = (
  86. title: SweetAlertTitle,
  87. html: SweetAlertHtml,
  88. t: Transaction,
  89. ) => {
  90. return Swal.fire({
  91. icon: "error",
  92. title: title,
  93. html: html,
  94. confirmButtonText: t("Confirm"),
  95. showConfirmButton: true,
  96. });
  97. };
  98. export const warningDialog = (title: SweetAlertTitle, t: Transaction) => {
  99. return Swal.fire({
  100. icon: "warning",
  101. title: title,
  102. confirmButtonText: t("Confirm"),
  103. showConfirmButton: true,
  104. });
  105. };
  106. export const submitDialog = async (
  107. confirmAction: () => void,
  108. t: Transaction,
  109. { ...props } = {
  110. title: t("Do you want to submit?") as SweetAlertTitle,
  111. confirmButtonText: t("Submit") as SweetAlertConfirmButtonText,
  112. },
  113. ) => {
  114. // console.log(props)
  115. // const { t } = useTranslation("common")
  116. const result = await Swal.fire({
  117. icon: "question",
  118. title: props?.title,
  119. cancelButtonText: t("Cancel"),
  120. confirmButtonText: props?.confirmButtonText,
  121. showCancelButton: true,
  122. showConfirmButton: true,
  123. customClass: {
  124. container: "swal-container-class", // Add a custom class to the Swal.fire container element
  125. popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
  126. },
  127. });
  128. if (result.isConfirmed) {
  129. confirmAction();
  130. }
  131. };
  132. export const submitDialogWithWarning = async (
  133. confirmAction: () => void,
  134. t: Transaction,
  135. { ...props } = {
  136. title: t("Do you want to submit?") as SweetAlertTitle,
  137. html: t("Warning!") as SweetAlertHtml,
  138. confirmButtonText: t("Submit") as SweetAlertConfirmButtonText,
  139. // cancelButtonText: t("Cancel") as SweetAlertConfirmButtonText,
  140. },
  141. ) => {
  142. // console.log(props)
  143. // const { t } = useTranslation("common")
  144. const result = await Swal.fire({
  145. icon: "warning",
  146. title: props?.title,
  147. html: props?.html,
  148. cancelButtonText: t("Cancel"),
  149. confirmButtonText: props?.confirmButtonText,
  150. showCancelButton: true,
  151. showConfirmButton: true,
  152. customClass: {
  153. container: "swal-container-class", // Add a custom class to the Swal.fire container element
  154. popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
  155. },
  156. });
  157. if (result.isConfirmed) {
  158. confirmAction();
  159. }
  160. };
  161. export const deleteDialog = async (
  162. confirmAction: () => void,
  163. t: Transaction,
  164. ) => {
  165. // const { t } = useTranslation("common")
  166. const result = await Swal.fire({
  167. icon: "question",
  168. title: t("Do you want to delete?"),
  169. cancelButtonText: t("Cancel"),
  170. confirmButtonText: t("Delete"),
  171. showCancelButton: true,
  172. showConfirmButton: true,
  173. customClass: {
  174. container: "swal-container-class", // Add a custom class to the Swal.fire container element
  175. popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
  176. },
  177. });
  178. if (result.isConfirmed) {
  179. confirmAction();
  180. }
  181. };