{"version":3,"file":"Attachments_list.BxHmoWsQ.js","sources":["../../src/pages/attachments/components/Attachments_list_ListItem.jsx","../../src/pages/attachments/components/Attachments_list.jsx"],"sourcesContent":["import { useState } from \"react\";\r\nimport { ListItem, ListItemButton, ListItemIcon, ListItemText } from \"@mui/material\";\r\nimport PropTypes from \"prop-types\";\r\n\r\nimport { useUserData } from \"src/context/userContext\";\r\nimport { useAttachmentsData } from \"src/context/AttachmentsContext\";\r\n\r\nimport {\r\n attachment_attachToKeikka,\r\n attachment_delete,\r\n} from \"src/components/attachments/AttachmentFunctions\";\r\nimport { CancelIcon, DeleteIcon } from \"src/components/icons/ActionIcons\";\r\nimport AreYouSureButton from \"src/components/buttons/AreYouSureButton/AreYouSureButton\";\r\nimport { AttachmentIcon, DeAttachIcon } from \"src/components/icons/NavIcons\";\r\nimport { PdfIcon } from \"src/components/icons/MediaIcons\";\r\n\r\nconst AttachmentListItem = ({ attachment, deAttachOnDelete = false, allowDelete = false }) => {\r\n const { token } = useUserData();\r\n const { setAttachmentList, setSelectedAttachment } = useAttachmentsData();\r\n const [loading, setLoading] = useState(false);\r\n\r\n const handleImageClick = () => setSelectedAttachment(attachment);\r\n\r\n const handleDeleteClick = async (e) => {\r\n e.stopPropagation();\r\n e.preventDefault();\r\n if (!deAttachOnDelete) return await handleDelete();\r\n else return await handleDeAttach();\r\n };\r\n\r\n const handleDeAttach = async () => {\r\n setLoading(true);\r\n const result = await attachment_attachToKeikka(attachment.attachmentId, null, token);\r\n console.log(result);\r\n setAttachmentList((prevList) =>\r\n prevList.filter((i) => i.attachmentId !== attachment.attachmentId)\r\n );\r\n setLoading(false);\r\n return true;\r\n };\r\n\r\n const handleDelete = async () => {\r\n setLoading(true);\r\n const result = await attachment_delete(attachment.attachmentId, token);\r\n if (result.ok === false && result.error !== \"BlobNotFound\") {\r\n setLoading(false);\r\n return false;\r\n }\r\n setAttachmentList((prevList) =>\r\n prevList.filter((i) => i.attachmentId !== attachment.attachmentId)\r\n );\r\n setLoading(false);\r\n return true;\r\n };\r\n\r\n return (\r\n \r\n \r\n \r\n {attachment.origFileName.endsWith(\".pdf\") ? : }\r\n \r\n \r\n \r\n {allowDelete && (\r\n ,\r\n CancelIcon: ,\r\n }}>\r\n {deAttachOnDelete ? : }\r\n \r\n )}\r\n \r\n );\r\n};\r\n\r\nexport default AttachmentListItem;\r\n\r\nAttachmentListItem.propTypes = {\r\n attachment: PropTypes.object,\r\n deAttachOnDelete: PropTypes.bool,\r\n allowDelete: PropTypes.bool,\r\n};\r\n","import { List, Typography } from \"@mui/material\";\r\n\r\nimport { useAttachmentsData } from \"src/context/AttachmentsContext\";\r\nimport AttachmentListItem from \"./Attachments_list_ListItem\";\r\nimport ProgressBar from \"src/components/layout/Progress/ProgressBar\";\r\nimport AttachmentViewerModal from \"src/components/AttachmentViewer/AttachmentViewerModal\";\r\nimport PropTypes from \"prop-types\";\r\n\r\nexport default function Attachments_list({\r\n deAttachOnDelete = false,\r\n openAttachmentOnClick = true,\r\n allowDelete = false,\r\n}) {\r\n const { isLoading, attachmentList, selectedAttachment, setSelectedAttachment } =\r\n useAttachmentsData();\r\n\r\n return (\r\n <>\r\n setSelectedAttachment(null)}\r\n attachmentId={selectedAttachment?.attachmentId}\r\n />\r\n \r\n {attachmentList?.length === 0 ? (\r\n <>\r\n \r\n Ei tiedostoja\r\n \r\n \r\n ) : (\r\n \r\n {attachmentList?.map((attachment) => (\r\n \r\n ))}\r\n \r\n )}\r\n \r\n \r\n \r\n );\r\n}\r\n\r\nAttachments_list.propTypes = {\r\n deAttachOnDelete: PropTypes.bool,\r\n openAttachmentOnClick: PropTypes.bool,\r\n allowDelete: PropTypes.bool,\r\n};\r\n"],"names":["AttachmentListItem","attachment","deAttachOnDelete","allowDelete","token","useUserData","setAttachmentList","setSelectedAttachment","useAttachmentsData","loading","setLoading","useState","handleDeAttach","async","result","attachment_attachToKeikka","attachmentId","console","log","prevList","filter","i","handleDelete","attachment_delete","ok","error","jsxs","ListItem","disablePadding","children","ListItemButton","onClick","handleImageClick","ListItemIcon","origFileName","endsWith","PdfIcon","jsx","AttachmentIcon","ListItemText","primary","secondary","fileComment","AreYouSureButton","component","e","stopPropagation","preventDefault","snackbarProps","title","failMessage","doneMessage","autoHideDuration","toolTipProps","placement","disabled","isLoading","askAreYouSure","dontAskId","dialogProps","content","acceptText","cancelText","ConfirmIcon","DeleteIcon","CancelIcon","color","DeAttachIcon","Attachments_list","openAttachmentOnClick","attachmentList","selectedAttachment","Fragment","AttachmentViewerModal","open","onClose","className","style","display","border","borderRadius","minWidth","length","Typography","variant","sx","padding","List","dense","width","map","ProgressBar","show","marginTop","propTypes","PropTypes","object","bool"],"mappings":"8UAgBA,MAAMA,EAAqBA,EAAGC,aAAYC,oBAAmB,EAAOC,eAAc,MAC1E,MAAAC,MAAEA,GAAUC,KACZC,kBAAEA,EAAAA,sBAAmBC,GAA0BC,KAC9CC,EAASC,GAAcC,EAAAA,UAAS,GAWjCC,EAAiBC,UACrBH,GAAW,GACX,MAAMI,QAAeC,EAA0Bd,EAAWe,aAAc,KAAMZ,GAMvE,OALPa,QAAQC,IAAIJ,GACOK,GAAAA,GACjBA,EAASC,QAAQC,GAAMA,EAAEL,eAAiBf,EAAWe,iBAEvDN,GAAW,IACJ,CAAA,EAGHY,EAAeT,UACnBH,GAAW,GACX,MAAMI,QAAeS,EAAkBtB,EAAWe,aAAcZ,GAChE,OAAkB,IAAdU,EAAOU,IAAiC,iBAAjBV,EAAOW,OAChCf,GAAW,IACJ,IAEUS,GAAAA,GACjBA,EAASC,QAAQC,GAAMA,EAAEL,eAAiBf,EAAWe,iBAEvDN,GAAW,IACJ,EAAA,EAIP,OAACgB,EAAAC,EAAuC,CAAAC,gBAAc,EACpDC,SAAA,CAACH,EAAAI,EAAA,CAAeC,QApCKC,IAAMzB,EAAsBN,GAqC/C4B,SAAA,GAACI,EAAA,CACEhC,SAAWiC,EAAAA,aAAaC,SAAS,UAAWC,EAAO,CAAA,GAAOC,EAAAC,EAAA,QA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