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.
 
 

110 regels
3.1 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. export function getDeletedRecordWithRefList(referenceList, updatedList){
  10. return referenceList.filter(x => !updatedList.includes(x)) ;
  11. }
  12. export function getIdList(input){
  13. const output = input.map(function (obj) {
  14. return obj.id;
  15. });
  16. return output;
  17. }
  18. export function getObjectById(list, id){
  19. const obj = list.find((element) => {
  20. return element.id === id;
  21. });
  22. return obj === undefined || Object.keys(obj).length <= 0? null : obj
  23. }
  24. export function removeObjectWithId(arr, id) {
  25. const arrCopy = Array.from(arr);
  26. const objWithIdIndex = arrCopy.findIndex((obj) => obj.id === id);
  27. arrCopy.splice(objWithIdIndex, 1);
  28. return arrCopy;
  29. }
  30. export function getDateString(queryDateArray) {
  31. return(
  32. queryDateArray[0]
  33. + "-" +
  34. queryDateArray[1]
  35. + "-" +
  36. queryDateArray[2]
  37. + " " +
  38. queryDateArray[3]
  39. + ":" +
  40. queryDateArray[4]
  41. + ":" +
  42. queryDateArray[5]
  43. )
  44. }
  45. // export const notifySaveSuccess = () => toast.success('Save success!', {
  46. // position: "bottom-right",
  47. // autoClose: 5000,
  48. // hideProgressBar: false,
  49. // closeOnClick: true,
  50. // pauseOnHover: true,
  51. // draggable: true,
  52. // progress: undefined,
  53. // theme: "light",
  54. // });
  55. export const notifyDeleteSuccess = () => toast.success('Delete Success!', {
  56. position: "bottom-right",
  57. autoClose: 5000,
  58. hideProgressBar: false,
  59. closeOnClick: true,
  60. pauseOnHover: true,
  61. draggable: true,
  62. progress: undefined,
  63. theme: "light",
  64. });
  65. export function prettyJson(json){
  66. console.log(json);
  67. console.log(JSON.stringify(json, null, 2));
  68. return (
  69. <div>{JSON.stringify(json, null, 2)}</div>
  70. );
  71. }
  72. export function GeneralConfirmWindow({
  73. isWindowOpen,
  74. title,
  75. content,
  76. onNormalClose,
  77. onConfirmClose}){
  78. return (
  79. <Dialog
  80. open={isWindowOpen}
  81. onClose={onNormalClose}
  82. aria-labelledby="alert-dialog-title"
  83. aria-describedby="alert-dialog-description"
  84. >
  85. <DialogTitle id="alert-dialog-title">
  86. {title}
  87. </DialogTitle>
  88. <DialogContent>
  89. <DialogContentText id="alert-dialog-description">
  90. {content}
  91. </DialogContentText>
  92. </DialogContent>
  93. <DialogActions>
  94. <Button onClick={onNormalClose}>Cancel</Button>
  95. <Button onClick={onConfirmClose} autoFocus>
  96. Confirm
  97. </Button>
  98. </DialogActions>
  99. </Dialog>
  100. )
  101. }