Advertisement
bruno83

BACKUP - old group document edit

Jan 19th, 2025
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*import { ArrowLeftOutlined } from '@ant-design/icons';
  2. import { pdf } from '@react-pdf/renderer';
  3. import { Button, Card } from 'antd';
  4. import React, { useEffect, useMemo, useState } from 'react';
  5. import { useTranslation } from 'react-i18next';
  6. import { useDispatch, useSelector } from 'react-redux';
  7. import { Link, useParams } from 'react-router-dom';
  8. import withLoadStatus from '../../../components/common/withLoadStatus';
  9. import DocumentExport from '../../../components/DocumentExport';
  10. import DocumentForm from '../../../components/forms/DocumentForm';
  11. import useExportToFiles from '../../../hooks/useExportToFiles';
  12. import { getFiles } from '../../../store/file/fileActions';
  13. import { selectFiles } from '../../../store/file/fileSlice';
  14. import {
  15.   getGroupDocuments,
  16.   updateGroupDocument,
  17.   getNotesForDocumentImport,
  18.   getDocumentLocationDetails,
  19. } from '../../../store/group/groupActions';
  20. import { selectGroupDocuments, selectGroupNotes } from '../../../store/group/groupSlice';
  21. import { selectUser } from '../../../store/user/userSlice';
  22.  
  23. const Edit = ({ isLoading }) => {
  24.   const { assetId, documentId } = useParams();
  25.   const { t } = useTranslation();
  26.   const groupDocuments = useSelector(selectGroupDocuments);
  27.   const currentUser = useSelector(selectUser);
  28.   const groupNotes = useSelector(selectGroupNotes);
  29.   const { exportDocument } = useExportToFiles(assetId);
  30.   const files = useSelector(selectFiles);
  31.   const dispatch = useDispatch();
  32.   const [hasChanges, setHasChanges] = useState(false);
  33.   const [locationDetails, setLocationDetails] = useState(null);
  34.  
  35.   useEffect(() => {
  36.     dispatch(getFiles({ parentId: assetId, skipParams: true }));
  37.     dispatch(getNotesForDocumentImport(assetId));
  38.     dispatch(getGroupDocuments(assetId));
  39.  
  40.     const fetchLocationDetails = async () => {
  41.       try {
  42.         const response = await dispatch(getDocumentLocationDetails(assetId)).unwrap(); // Dohvaćanje detalja o lokaciji
  43.         setLocationDetails(response.locationDetails || {}); // Čuvanje detalja o lokaciji
  44.       } catch (error) {
  45.         console.error('Greška prilikom preuzimanja lokacijskih detalja:', error);
  46.         setLocationDetails({ name: 'Unknown Location', image_url: null }); // Fallback vrednost
  47.       }
  48.     };
  49.  
  50.     fetchLocationDetails();
  51.   }, [assetId, dispatch]);
  52.  
  53.   const specificDocument = useMemo(() => {
  54.     return groupDocuments.find((document) => document.id === parseInt(documentId));
  55.   }, [groupDocuments, documentId]);
  56.  
  57.   const translations = {
  58.     updatedBy: t('note.audit.updatedBy'),
  59.   };
  60.  
  61.   const handleExportNote = async () => {
  62.     const element = (
  63.       <DocumentExport
  64.         document={specificDocument}
  65.         tenant={currentUser.tenant}
  66.         translations={translations}
  67.         locationDetails={locationDetails}
  68.       />
  69.     );
  70.     const pdfBlob = await pdf(element).toBlob();
  71.  
  72.     const url = URL.createObjectURL(pdfBlob);
  73.     window.open(url, '_blank');
  74.  
  75.     exportDocument(specificDocument, pdfBlob, files);
  76.   };
  77.  
  78.   return (
  79.     <Card
  80.       title={
  81.         <div className='flex items-center justify-between'>
  82.           <div className='flex flex-row gap-3'>
  83.             <Link to={-1}>
  84.               <ArrowLeftOutlined />
  85.             </Link>
  86.             {t('document.edit.title')}
  87.           </div>
  88.           <Button
  89.             type='primary'
  90.             htmlType='button'
  91.             loading={isLoading}
  92.             onClick={handleExportNote}
  93.             disabled={hasChanges}
  94.           >
  95.             {t('button.exportDocument')}
  96.           </Button>
  97.         </div>
  98.       }
  99.     >
  100.  
  101.       {locationDetails?.name && (
  102.         <div style={{ marginBottom: '16px', color: '#6c757d', fontSize: '12px' }}>
  103.           <p>{`${t('document.audit.location')}: ${locationDetails.name}`}</p>
  104.           {locationDetails.image_url && (
  105.             <img
  106.               src={locationDetails.image_url}
  107.               alt='Location'
  108.               style={{ width: '100px', height: 'auto', marginTop: '8px' }}
  109.             />
  110.           )}
  111.         </div>
  112.       )}
  113.       <DocumentForm
  114.         parentId={assetId}
  115.         contextId={documentId}
  116.         document={specificDocument?.content}
  117.         isEditing={true}
  118.         updateAction={updateGroupDocument}
  119.         contextNotes={groupNotes || []}
  120.         getContextNotes={getNotesForDocumentImport}
  121.         hasChanges={hasChanges}
  122.         setHasChanges={setHasChanges}
  123.         fetchDocuments={getGroupDocuments}
  124.       />
  125.     </Card>
  126.   );
  127. };
  128.  
  129. export default withLoadStatus(Edit); */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement