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.
 
 

255 line
6.9 KiB

  1. // import {toast} from "react-toastify";
  2. import DialogTitle from "@mui/material/DialogTitle";
  3. import DialogContent from "@mui/material/DialogContent";
  4. import DialogContentText from "@mui/material/DialogContentText";
  5. import DialogActions from "@mui/material/DialogActions";
  6. import { Button } from "@mui/material";
  7. import Dialog from "@mui/material/Dialog";
  8. import * as React from "react";
  9. import { toast } from "react-toastify";
  10. export function getDeletedRecordWithRefList(referenceList, updatedList) {
  11. return referenceList.filter(x => !updatedList.includes(x));
  12. }
  13. export function getIdList(input) {
  14. const output = input.map(function (obj) {
  15. return obj.id;
  16. });
  17. return output;
  18. }
  19. export function getObjectById(list, id) {
  20. const obj = list.find((element) => {
  21. return element.id === id;
  22. });
  23. return obj === undefined || Object.keys(obj).length <= 0 ? null : obj
  24. }
  25. export function getObjectByValue(list, valueName, value) {
  26. const obj = list.find((element) => {
  27. return element[valueName] === parseInt(value);
  28. });
  29. console.log(obj);
  30. return obj === undefined || Object.keys(obj).length <= 0 ? null : obj
  31. }
  32. export function removeObjectWithId(arr, id) {
  33. const arrCopy = Array.from(arr);
  34. const objWithIdIndex = arrCopy.findIndex((obj) => obj.id === id);
  35. arrCopy.splice(objWithIdIndex, 1);
  36. return arrCopy;
  37. }
  38. export function getComboValueByLabel(comboList, input) {
  39. for (let i = 0; i < comboList.length; i++) {
  40. if (comboList[i].label === input) {
  41. return comboList[i];
  42. }
  43. }
  44. return input === undefined ? null : input;
  45. }
  46. export function getDateString(queryDateArray) {
  47. return (
  48. queryDateArray[0]
  49. + "-" +
  50. queryDateArray[1]
  51. + "-" +
  52. queryDateArray[2]
  53. + " " +
  54. queryDateArray[3]
  55. + ":" +
  56. queryDateArray[4]
  57. + ":" +
  58. queryDateArray[5]
  59. )
  60. }
  61. export const notifySaveSuccess = () => {
  62. const userType = JSON.parse(localStorage.getItem("userData")).type
  63. toast.success(userType === "GLD" ? 'Save success!' : "儲存成功!", {
  64. position: "bottom-right",
  65. autoClose: 5000,
  66. hideProgressBar: false,
  67. closeOnClick: true,
  68. pauseOnHover: true,
  69. draggable: true,
  70. progress: undefined,
  71. theme: "light",
  72. })
  73. };
  74. export const notifyCreateSuccess = () => {
  75. const userType = JSON.parse(localStorage.getItem("userData")).type
  76. toast.success(userType === "GLD" ? 'Create success!' : "創建成功!", {
  77. position: "bottom-right",
  78. autoClose: 5000,
  79. hideProgressBar: false,
  80. closeOnClick: true,
  81. pauseOnHover: true,
  82. draggable: true,
  83. progress: undefined,
  84. theme: "light",
  85. })
  86. };
  87. export const notifyVerifySuccess = () => {
  88. const userType = JSON.parse(localStorage.getItem("userData")).type
  89. toast.success(userType === "GLD" ? 'Verify success!' : "驗證成功!", {
  90. position: "bottom-right",
  91. autoClose: 5000,
  92. hideProgressBar: false,
  93. closeOnClick: true,
  94. pauseOnHover: true,
  95. draggable: true,
  96. progress: undefined,
  97. theme: "light",
  98. })
  99. };
  100. export const notifyDeleteSuccess = () => {
  101. const userType = JSON.parse(localStorage.getItem("userData")).type
  102. toast.success(userType === "GLD" ? 'Delete success!' : "刪除成功!", {
  103. position: "bottom-right",
  104. autoClose: 5000,
  105. hideProgressBar: false,
  106. closeOnClick: true,
  107. pauseOnHover: true,
  108. draggable: true,
  109. progress: undefined,
  110. theme: "light",
  111. })
  112. };
  113. export const notifyLockSuccess = () => {
  114. toast.success('Lock success!', {
  115. position: "bottom-right",
  116. autoClose: 5000,
  117. hideProgressBar: false,
  118. closeOnClick: true,
  119. pauseOnHover: true,
  120. draggable: true,
  121. progress: undefined,
  122. theme: "light",
  123. })
  124. };
  125. export const notifyUnlockSuccess = () => {
  126. toast.success('Unlock success!', {
  127. position: "bottom-right",
  128. autoClose: 5000,
  129. hideProgressBar: false,
  130. closeOnClick: true,
  131. pauseOnHover: true,
  132. draggable: true,
  133. progress: undefined,
  134. theme: "light",
  135. })
  136. };
  137. export const notifyActiveSuccess = () => {
  138. toast.success('Active success!', {
  139. position: "bottom-right",
  140. autoClose: 5000,
  141. hideProgressBar: false,
  142. closeOnClick: true,
  143. pauseOnHover: true,
  144. draggable: true,
  145. progress: undefined,
  146. theme: "light",
  147. })
  148. };
  149. export const notifyDownloadSuccess = () => {
  150. const userType = JSON.parse(localStorage.getItem("userData")).type
  151. toast.success(userType === "GLD" ? 'Download success!' : "下載成功!", {
  152. position: "bottom-right",
  153. autoClose: 5000,
  154. hideProgressBar: false,
  155. closeOnClick: true,
  156. pauseOnHover: true,
  157. draggable: true,
  158. progress: undefined,
  159. theme: "light",
  160. })
  161. };
  162. export const notifyActionSuccess = (actionMsg) => {
  163. toast.success(`${actionMsg}`, {
  164. position: "bottom-right",
  165. autoClose: 5000,
  166. hideProgressBar: false,
  167. closeOnClick: true,
  168. pauseOnHover: true,
  169. draggable: true,
  170. progress: undefined,
  171. theme: "light",
  172. })
  173. };
  174. export const notifyActionError = (actionMsg) => {
  175. toast.error(`${actionMsg}`, {
  176. position: "bottom-right",
  177. autoClose: 5000,
  178. hideProgressBar: false,
  179. closeOnClick: true,
  180. pauseOnHover: true,
  181. draggable: true,
  182. progress: undefined,
  183. theme: "light",
  184. })
  185. };
  186. export const notifyActionWarning = (actionMsg) => {
  187. toast.warn(`${actionMsg}`, {
  188. position: "bottom-right",
  189. autoClose: 5000,
  190. hideProgressBar: false,
  191. closeOnClick: true,
  192. pauseOnHover: true,
  193. draggable: true,
  194. progress: undefined,
  195. theme: "light",
  196. })
  197. }
  198. export function prettyJson(json) {
  199. console.log(json);
  200. console.log(JSON.stringify(json, null, 2));
  201. return (
  202. <div>{JSON.stringify(json, null, 2)}</div>
  203. );
  204. }
  205. export function GeneralConfirmWindow({
  206. isWindowOpen,
  207. title,
  208. content,
  209. onNormalClose,
  210. onConfirmClose }) {
  211. return (
  212. <Dialog
  213. open={isWindowOpen}
  214. onClose={onNormalClose}
  215. aria-labelledby="alert-dialog-title"
  216. aria-describedby="alert-dialog-description"
  217. >
  218. <DialogTitle id="alert-dialog-title">
  219. {title}
  220. </DialogTitle>
  221. <DialogContent>
  222. <DialogContentText id="alert-dialog-description">
  223. {content}
  224. </DialogContentText>
  225. </DialogContent>
  226. <DialogActions>
  227. <Button onClick={onNormalClose}>Cancel</Button>
  228. <Button onClick={onConfirmClose} autoFocus>
  229. Confirm
  230. </Button>
  231. </DialogActions>
  232. </Dialog>
  233. )
  234. }