[javascript] file upload

Viewer

copydownloadembedprintName: file upload
  1. import React, {useState, useEffect, useContext} from 'react';
  2. import {useHistory} from 'react-router-dom';
  3. import {
  4.     Box,
  5.     Input,
  6.     Form,
  7.     layouts,
  8.     Text,
  9.     Table,
  10.     Popover,
  11.     Link,
  12.     MenuList
  13. } from "@tidbits/react-tidbits";
  14. import DateComponent from '../../../SharedComponents/DateComponent/dateComponent';
  15. import Notes from "../../../SharedComponents/NotesComponent/notesComponent.jsx";
  16. import MultipleFileUpload from "../../../SharedComponents/FileComponent/multipleFileUpload";
  17.  
  18. import axios from "axios";
  19. import moment from "moment";
  20. import ModalsPDF from "../../../SharedComponents/VisaModalComponent/modal";
  21.  
  22. import {loggedInDetails} from "../../../../Context/loggedInDetailsContext";
  23. import {GridContext} from '../../../../Context/gridContext';
  24. import {SAMFormContext} from './SAMFormContext';
  25.  
  26. const SAMFormAdditionalDetailsTab = (props) => {
  27.  
  28.     const history = useHistory();
  29.     const {loggedInUser, samAdminMode, appleCsrfToken, setToken} = useContext(loggedInDetails);
  30.     const {
  31.         spinnerVal, setSpinnerVal, searchValue, gridData, setgridData, bannerMessage,
  32.         variant, setBannerVariant, setBannerMessage, gridApiState, globalGridSearch
  33.     } = useContext(GridContext);
  34.     const {formData, setFormData, metaData} = useContext(SAMFormContext);
  35.  
  36.     const [files, setFiles] = useState([]);
  37.     const [files2, setFiles2] = useState([]);
  38.     const [filesData, setFilesData] = useState([]);
  39.  
  40.  
  41.     let temp;
  42.     /**************************************
  43.      *  File Upload
  44.      **************************************/
  45.     const uploadFile = (arr) => {
  46.         temp = [...files];
  47.         // testFile = files2;
  48.  
  49.         if(files.length + arr.length > 3){
  50.             alert("Maximum of 3 Files can be uploaded.");
  51.             // childRef.current.refResetFileData()
  52.         }else{
  53.  
  54.             if(arr != null && arr!= undefined && arr.length !=0) {
  55.                 for(let i=0; i<arr.length; i++){
  56.                     temp.push(arr[i]);
  57.                     // testFile.push(arr[i]);
  58.                 }
  59.             }
  60.             setFiles(temp);
  61.         }
  62.     }
  63.  
  64.     function removeFiles(file, index) {
  65.  
  66.         axios.post(`/deletedAttachements`)
  67.         .then((response) => {
  68.             let filesAfterFilter = '';
  69.             let flag = 0;
  70.     
  71.             filesAfterFilter = files.filter((val, i) => {
  72.                 if(val.name == file && i == index){
  73.                     flag = 1;
  74.                 }else{
  75.                     flag=0;
  76.                 }
  77.     
  78.                 if(flag == 1){
  79.                     return false;
  80.                 }else{
  81.                     return true;
  82.                 }
  83.                 });
  84.     
  85.                 setFiles(filesAfterFilter);
  86.         });
  87.         
  88.         
  89.     }
  90.  
  91.  
  92.     return (
  93.         <div className="detailed-info-tab">
  94.             <div className="row-item">
  95.                 <Form.Label>
  96.                     * Software Proposal? <span className="info-icon" />
  97.                     <Input.TextArea
  98.                         height="60px"
  99.                         value={formData.samAdditionalsEntity && formData.samAdditionalsEntity[0].softwarePurpose}
  100.                         onChange={() => {}}
  101.                         placeholder="Enter purpose" />
  102.                 </Form.Label>
  103.             </div>
  104.             <div className="row-item grid-container">
  105.                 <div className="grid-item col-3">
  106.                     <Form.Label>
  107.                         * Location
  108.                         <div className="form-value">
  109.                             <Input.DropdownSelect
  110.                                 selectedValuePlaceholder="Select"
  111.                                 onChange={() => {}}
  112.                                 value={formData.samReqLocDetailsEntity && formData.samReqLocDetailsEntity.locationId}
  113.                             >
  114.                                 {metaData.locations && metaData.locations.map(location => {
  115.                                     return (
  116.                                         <option key={location.metadatatype} value={location.metadatatype}>
  117.                                             {location.metadatatypesubname}
  118.                                         </option>
  119.                                     )
  120.                                 })}
  121.                             </Input.DropdownSelect>
  122.                         </div>
  123.                     </Form.Label>
  124.                 </div>
  125.             </div>
  126.  
  127.             <div className="row-item grid-container">
  128.                 <div className="grid-item col-3">
  129.                     <Form.Label>
  130.                         * Reason for Request
  131.                         <div className="form-value">
  132.                             <Input.DropdownSelect
  133.                                 selectedValuePlaceholder="Select"
  134.                                 onChange={() => {}}
  135.                                 value={formData.samAdditionalsEntity && formData.samAdditionalsEntity[0].reasonForReq}
  136.                             >
  137.                                 {metaData.reasonForRequest && metaData.reasonForRequest.map(reason => {
  138.                                     return (
  139.                                         <option key={reason.metadatatype} value={reason.metadatatype}>
  140.                                             {reason.metadatatypesubname}
  141.                                         </option>
  142.                                     )
  143.                                 })}
  144.                             </Input.DropdownSelect>
  145.                         </div>
  146.                     </Form.Label>
  147.                 </div>
  148.             </div>
  149.             <div>
  150.                 <Form.Label className="alternatives-evaluated">
  151.                     <input type="checkbox" onChange={() => {}}/> Alternatives Evaluated
  152.                     {/*<span className="checkmark"></span>*/}
  153.                 </Form.Label>
  154.             </div>
  155.             <div className="row-item grid-container">
  156.                 <div className="grid-item col-3">
  157.                     <Form.Label>
  158.                          
  159.                         <div className="form-value">
  160.                             <Input.DropdownSelect
  161.                                 value="108"
  162.                                 // selectedValuePlaceholder={Object.keys(vendorName).length === 0 ? 'Select Vendor Name' : vendorName.vendorName}
  163.                                 selectedValuePlaceholder="Select"
  164.                                 onChange={function(){}} //setVendorNameChange
  165.                                 typeahead
  166.                                 // value={vendorName}
  167.                             >
  168.                                 <option key="ADOBE XD 1" value="97">ADOBE XD 1</option>
  169.                                 <option key="ADOBE XD 2" value="97">ADOBE XD 2</option>
  170.                                 <option key="ADOBE XD 3" value="97">ADOBE XD 3</option>
  171.                                 <option key="ADOBE XD 4" value="97">ADOBE XD 4</option>
  172.                             </Input.DropdownSelect>
  173.                         </div>
  174.                     </Form.Label>
  175.                 </div>
  176.                 <div className="grid-item col-3">
  177.                     <Form.Label>
  178.                         * Product Title
  179.                         <div className="form-value">
  180.                             <Input.DropdownSelect
  181.                                 value="97"
  182.                                 // selectedValuePlaceholder={Object.keys(vendorName).length === 0 ? 'Select Vendor Name' : vendorName.vendorName}
  183.                                 selectedValuePlaceholder="Select"
  184.                                 onChange={function(){}} //setVendorNameChange
  185.                                 // value={vendorName}
  186.                             >
  187.                                 <option key="ADOBE XD 1" value="97">ADOBE XD 1</option>
  188.                                 <option key="ADOBE XD 2" value="97">ADOBE XD 2</option>
  189.                                 <option key="ADOBE XD 3" value="97">ADOBE XD 3</option>
  190.                                 <option key="ADOBE XD 4" value="97">ADOBE XD 4</option>
  191.                             </Input.DropdownSelect>
  192.                         </div>
  193.                     </Form.Label>
  194.                 </div>
  195.  
  196.             </div>
  197.             <div className="row-item grid-container">
  198.                 <div className="grid-item col-3">
  199.                     <Form.Label>
  200.                         * Approximate / estimated spend
  201.                         <div className="form-value">
  202.                             <Input.DropdownSelect
  203.                                 selectedValuePlaceholder="Select"
  204.                                 onChange={() => {}}
  205.                                 value={formData.samAdditionalsEntity && formData.samAdditionalsEntity[0].approxOrEstSpend}
  206.                             >
  207.                                 {metaData.appxEstimatedSpend && metaData.appxEstimatedSpend.map(spend => {
  208.                                     return (
  209.                                         <option key={spend.metadatatype} value={spend.metadatatype}>
  210.                                             {spend.metadatatypesubname}
  211.                                         </option>
  212.                                     )
  213.                                 })}
  214.                             </Input.DropdownSelect>
  215.                         </div>
  216.                     </Form.Label>
  217.                 </div>
  218.             </div>
  219.             <div className="row-item">
  220.                 <MultipleFileUpload files={files2} setFiles={setFiles2} clbk={uploadFile} showFiles={false}/>
  221.             </div>
  222.  
  223.             {files != undefined && files != null &&  files.length != 0 &&
  224.                 <layouts.EvenGrid cols={[1,2]} pt="10px" style={{textAlign:'left'}}>
  225.                     <Box><text> </text></Box>
  226.                     <Box style={{marginLeft: "32px"}}>
  227.                         <layouts.EvenGrid cols={[1]} pt="10px" style={{ marginTop: "1%", textAlign:'left'}}>
  228.                             <Box>
  229.                                 {files != undefined && files.length != null && files.map((val,key) => {
  230.                                         return (
  231.                                             <>           
  232.                                             {/* // <Text style={{color:'#0070C9', paddingTop: '5px', textDecoration:'underline'}} onClick={() => {download(val.filename, val.genevaKey)}}>{val.fileName == null ? requestedForId+'_'+index+'.pdf' : val.fileName}</Text> */}
  233.                                             <Text key={key} style={{color:'#333333', paddingTop: '5px', display: 'flex'}}>
  234.                                                 {val.name}
  235.                                                     <span style={{marginLeft:'5px', cursor:'pointer'}} onClick={()=>removeFiles(val.name, key)}><img style={{width:"20px"}} src={require('../../../../image/clear.svg')} /></span>
  236.                                             </Text>
  237.                                                     
  238.                                             </>
  239.                                         )
  240.                                     })}
  241.                             </Box>
  242.                         </layouts.EvenGrid>
  243.                     </Box>
  244.                 </layouts.EvenGrid>
  245.             }
  246.  
  247.             {(files == undefined || files == null ||  files.length == 0) &&
  248.                     <layouts.EvenGrid cols={[1,2]} pt="10px" style={{textAlign:'left'}}>
  249.                              <Box><text> </text></Box>
  250.                         <Box style={{marginLeft: "32px"}}>
  251.                             <layouts.EvenGrid cols={[1]} pt="10px" style={{ marginTop: "1%", textAlign:'left'}}>
  252.                                 {filesData != null && filesData.length !=0 && filesData != undefined && 
  253.                                    
  254.                                     <Box>
  255.                                          {/* <Text> Attachments:</Text> */}
  256.                                         {filesData.map((val,index) => {
  257.  
  258.                                             let filename = val.filename;
  259.                                             let visaRequestId = val.visaRequestId;
  260.                                             filename = (filename === null || filename === undefined) ? visaRequestId + "_RFE_" + index+1 : filename;
  261.                                             let finalFilename = filename.endsWith('.pdf') ? filename : filename + '.pdf';
  262.                                              return(
  263.                                                  <>
  264.  
  265.                                                 <ModalsPDF
  266.                                                 isAttachment = {true}
  267.                                                 labelName="View"
  268.                                                 headerName="View"
  269.                                                 gkey={val.genevaKey}
  270.                                                 fname={finalFilename}
  271.                                                 backGround="#A1BD90">{({hide, show})=>
  272.                                                     <span style={{color: '#037A9E', cursor: 'pointer', fontFamily: 'Helvetica Neue',
  273.                                                     fontSize: '15px'}} onClick={() => {
  274.                                                     show();
  275.                                                     }
  276.                                                     }>
  277.                                                         <span style={{display:'flex', paddingTop:'4px'}}>{val.filename}</span>
  278.                                                         
  279.                                                     </span>
  280.                                                 }
  281.                                                 </ModalsPDF>
  282.                                                 </>
  283.                                             )
  284.                                     })}
  285.                                         </Box>
  286.                                 }
  287.                                 
  288.                              
  289.                             </layouts.EvenGrid>
  290.                         </Box>
  291.                         </layouts.EvenGrid>
  292.                         }
  293.             <div className="row-item">
  294.                 <Form.Label>
  295.                     Why do you need this software and how will it be used?
  296.                     <Input.TextArea
  297.                         height="60px"
  298.                         value={formData.samAdditionalsEntity && formData.samAdditionalsEntity[0].softwareNeeds}
  299.                         onChange={(e) => {}}
  300.                         placeholder="Enter software need" />
  301.                 </Form.Label>
  302.             </div>
  303.             <div className="row-item">
  304.                 <Form.Label>
  305.                     How was the product and quantity determined?
  306.                     <Input.TextArea
  307.                         height="60px"
  308.                         value={formData.samAdditionalsEntity && formData.samAdditionalsEntity[0].howProdQtyDetermined}
  309.                         onChange={(e) => {}}
  310.                         placeholder="Enter software need" />
  311.  
  312.                 </Form.Label>
  313.             </div>
  314.             <div className="row-item">
  315.                 <Form.Label>
  316.                     What is the long-term (2-5 year) strategy for this software?
  317.                     <Input.TextArea
  318.                         height="60px"
  319.                         value={formData.samAdditionalsEntity && formData.samAdditionalsEntity[0].howProdQtyDetermined}
  320.                         onChange={(e) => {}}
  321.                         placeholder="Enter software need" />
  322.                 </Form.Label>
  323.             </div>
  324.             <div className="row-item">
  325.                 <Form.Label>
  326.                     What are the factors driving the decision?
  327.                     <Input.TextArea
  328.                         height="60px"
  329.                         value={formData.samAdditionalsEntity && formData.samAdditionalsEntity[0].howProdQtyDetermined}
  330.                         onChange={(e) => {}}
  331.                         placeholder="Enter software need" />
  332.                 </Form.Label>
  333.             </div>
  334.             <div className="section-header">Notes:</div>
  335.             <div className="row-item grid-container">
  336.                 <div className="grid-item col-3">
  337.                     <Form.Label>
  338.                         Show:
  339.                         <div className="form-value">
  340.                             <Input.DropdownSelect
  341.                                 selectedValuePlaceholder="Select"
  342.                                 onChange={() => {}}
  343.                                 value={134}
  344.                             >
  345.                                 {metaData.commentsType && metaData.commentsType.map(commentsType => {
  346.                                     return (
  347.                                         <option key={commentsType.metadatatype} value={commentsType.metadatatype}>
  348.                                             {commentsType.metadatatypesubname}
  349.                                         </option>
  350.                                     )
  351.                                 })}
  352.                             </Input.DropdownSelect>
  353.                         </div>
  354.                     </Form.Label>
  355.                 </div>
  356.             </div>
  357.             <div className="row-item">
  358.                 <div className="form-value">
  359.                     <Notes
  360.                         style={{fontSize: '13px', marginTop: '6px'}}
  361.                         NotesData={[]}
  362.                         onChange={() => {}}
  363.                         // tabIndex="23"
  364.                         moduleName="budgetproposal"/>
  365.                 </div>
  366.             </div>
  367.         </div>
  368.     );
  369. };
  370.  
  371. export default SAMFormAdditionalDetailsTab;

Editor

You can edit this paste and save as new:


File Description
  • file upload
  • Paste Code
  • 10 Aug-2022
  • 17.7 Kb
You can Share it: