FPSMS-frontend
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

153 satır
4.2 KiB

  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. }).fire({
  20. icon: "success",
  21. title: title,
  22. });
  23. };
  24. export const popup = (options: SweetAlertOptions) => {
  25. Swal.fire(options);
  26. };
  27. export const successDialog = (title: SweetAlertTitle, t: Transaction) => {
  28. return Swal.fire({
  29. icon: "success",
  30. title: title,
  31. confirmButtonText: t("Confirm"),
  32. showConfirmButton: true,
  33. });
  34. };
  35. export const successDialogWithContent = (title: SweetAlertTitle, html: SweetAlertHtml, t: Transaction) => {
  36. return Swal.fire({
  37. icon: "success",
  38. title: title,
  39. html: html,
  40. confirmButtonText: t("Confirm"),
  41. showConfirmButton: true,
  42. });
  43. };
  44. export const errorDialog = (title: SweetAlertTitle, t: Transaction) => {
  45. return Swal.fire({
  46. icon: "error",
  47. title: title,
  48. confirmButtonText: t("Confirm"),
  49. showConfirmButton: true,
  50. });
  51. };
  52. export const errorDialogWithContent = (title: SweetAlertTitle, html: SweetAlertHtml, t: Transaction) => {
  53. return Swal.fire({
  54. icon: "error",
  55. title: title,
  56. html: html,
  57. confirmButtonText: t("Confirm"),
  58. showConfirmButton: true,
  59. });
  60. };
  61. export const warningDialog = (title: SweetAlertTitle, t: Transaction) => {
  62. return Swal.fire({
  63. icon: "warning",
  64. title: title,
  65. confirmButtonText: t("Confirm"),
  66. showConfirmButton: true,
  67. });
  68. };
  69. export const submitDialog = async (
  70. confirmAction: () => void,
  71. t: Transaction,
  72. { ...props } = {
  73. title: t("Do you want to submit?") as SweetAlertTitle,
  74. confirmButtonText: t("Submit") as SweetAlertConfirmButtonText,
  75. }
  76. ) => {
  77. // console.log(props)
  78. // const { t } = useTranslation("common")
  79. const result = await Swal.fire({
  80. icon: "question",
  81. title: props?.title,
  82. cancelButtonText: t("Cancel"),
  83. confirmButtonText: props?.confirmButtonText,
  84. showCancelButton: true,
  85. showConfirmButton: true,
  86. customClass: {
  87. container: "swal-container-class", // Add a custom class to the Swal.fire container element
  88. popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
  89. },
  90. });
  91. if (result.isConfirmed) {
  92. confirmAction();
  93. }
  94. };
  95. export const submitDialogWithWarning = async (
  96. confirmAction: () => void,
  97. t: Transaction,
  98. { ...props } = {
  99. title: t("Do you want to submit?") as SweetAlertTitle,
  100. html: t("Warning!") as SweetAlertHtml,
  101. confirmButtonText: t("Submit") as SweetAlertConfirmButtonText,
  102. }
  103. ) => {
  104. // console.log(props)
  105. // const { t } = useTranslation("common")
  106. const result = await Swal.fire({
  107. icon: "warning",
  108. title: props?.title,
  109. html: props?.html,
  110. cancelButtonText: t("Cancel"),
  111. confirmButtonText: props?.confirmButtonText,
  112. showCancelButton: true,
  113. showConfirmButton: true,
  114. customClass: {
  115. container: "swal-container-class", // Add a custom class to the Swal.fire container element
  116. popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
  117. },
  118. });
  119. if (result.isConfirmed) {
  120. confirmAction();
  121. }
  122. };
  123. export const deleteDialog = async (confirmAction: () => void, t: Transaction) => {
  124. // const { t } = useTranslation("common")
  125. const result = await Swal.fire({
  126. icon: "question",
  127. title: t("Do you want to delete?"),
  128. cancelButtonText: t("Cancel"),
  129. confirmButtonText: t("Delete"),
  130. showCancelButton: true,
  131. showConfirmButton: true,
  132. customClass: {
  133. container: "swal-container-class", // Add a custom class to the Swal.fire container element
  134. popup: "swal-popup-class", // Add a custom class to the Swal.fire popup element
  135. },
  136. });
  137. if (result.isConfirmed) {
  138. confirmAction();
  139. }
  140. };