From 1e1f496fd2c48722eb14d39bbd5e485ecd6fc52d Mon Sep 17 00:00:00 2001 From: Suzane Duarte Date: Sun, 2 Jul 2023 13:45:07 -0300 Subject: [PATCH 01/16] #150 feat: adicionando modal de upload de XLS Co-authored-by: PabloGJBS --- .../equipment-register-modal/index.tsx | 20 +++++++- .../equipment-upload-modal/index.tsx | 49 +++++++++++++++++++ src/components/modal/index.tsx | 9 +++- src/pages/equipments/EquipmentsControl.tsx | 14 ++++-- 4 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 src/components/equipment-upload-modal/index.tsx diff --git a/src/components/equipment-register-modal/index.tsx b/src/components/equipment-register-modal/index.tsx index fcdb54e9..91b80149 100644 --- a/src/components/equipment-register-modal/index.tsx +++ b/src/components/equipment-register-modal/index.tsx @@ -1,10 +1,12 @@ -import { Flex } from '@chakra-ui/react'; +import { MdUpload } from 'react-icons/md'; +import { Button, Flex } from '@chakra-ui/react'; import EquipmentForm from '../equipment-form'; import { Modal } from '../modal'; type EquipmentRegisterModalProps = { isOpen: boolean; onClose(): void; + onUploadOpen(): void; refreshRequest: boolean; setRefreshRequest: React.Dispatch>; }; @@ -14,13 +16,29 @@ export function EquipmentRegisterModal({ onClose, refreshRequest, setRefreshRequest, + onUploadOpen, }: EquipmentRegisterModalProps) { + const onClickUploadXLS = () => { + onClose(); + onUploadOpen(); + }; return ( } + variant="outline" + borderColor="orange" + color="orange" + onClick={onClickUploadXLS} + > + Adicionar Arquivo XLS + + } > >; +}; + +export function EquipmentsUploadModal({ + isOpen, + onClose, + refreshRequest, + setRefreshRequest, +}: EquipmentsUploadModalProps) { + return ( + + + + Upload XLS + + + + + + + + + ); +} diff --git a/src/components/modal/index.tsx b/src/components/modal/index.tsx index e8f7427e..3711f862 100644 --- a/src/components/modal/index.tsx +++ b/src/components/modal/index.tsx @@ -9,6 +9,7 @@ Quaisquer erros ou bugs nesta implementação são de nossa responsabilidade. */ import { + Flex, Heading, Modal as ModalContainer, ModalBody, @@ -22,9 +23,10 @@ import React from 'react'; export interface ModalProps extends ChakraModalProps { title: string; + headerButton?: React.ReactNode; } -export function Modal({ children, title, ...props }: ModalProps) { +export function Modal({ children, title, headerButton, ...props }: ModalProps) { return ( @@ -34,10 +36,13 @@ export function Modal({ children, title, ...props }: ModalProps) { backdropFilter="blur(8px)" > - + {title} + + {headerButton} + diff --git a/src/pages/equipments/EquipmentsControl.tsx b/src/pages/equipments/EquipmentsControl.tsx index be18b7e3..bd068c44 100644 --- a/src/pages/equipments/EquipmentsControl.tsx +++ b/src/pages/equipments/EquipmentsControl.tsx @@ -30,6 +30,7 @@ import { ControlledSelect } from '@/components/form-fields/controlled-select'; import { STATUS, TIPOS_EQUIPAMENTO, Workstation } from '@/constants/equipment'; import { Datepicker } from '@/components/form-fields/date'; import { Input } from '@/components/form-fields/input'; +import { EquipmentsUploadModal } from '@/components/equipment-upload-modal'; interface ISelectOption { label: string; @@ -145,9 +146,9 @@ function EquipmentTable() { const { isOpen, onClose, onOpen } = useDisclosure(); const { - isOpen: isRegisterOpen, - onClose: onRegisterClose, - onOpen: onRegisterOpen, + isOpen: isUploadOpen, + onClose: onUploadClose, + onOpen: onUploadOpen, } = useDisclosure(); const { @@ -456,6 +457,7 @@ function EquipmentTable() { isOpen={isOpen} refreshRequest={refreshRequest} setRefreshRequest={setRefreshRequest} + onUploadOpen={onUploadOpen} /> + ); From c70f1d13537de540f56691a4960c0ebdcd6baa10 Mon Sep 17 00:00:00 2001 From: PabloGJBS Date: Sun, 2 Jul 2023 14:55:58 -0300 Subject: [PATCH 02/16] #150 feat: envio de arquivo ta show Co-authored-by: suzaneduarte --- package.json | 5 +- .../equipment-upload-modal/index.tsx | 143 +++++++++++++++++- 2 files changed, 139 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 90b0628f..217e6375 100755 --- a/package.json +++ b/package.json @@ -50,7 +50,8 @@ "react-render-if-visible": "^2.1.1", "react-router-dom": "^6.6.1", "react-toastify": "^9.1.2", - "sass": "^1.57.1" + "sass": "^1.57.1", + "xlsx": "^0.18.5" }, "devDependencies": { "@testing-library/jest-dom": "^5.16.5", @@ -84,4 +85,4 @@ "vitest": "^0.26.3", "zlib": "^1.0.5" } -} \ No newline at end of file +} diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index fcc37766..23e409cb 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -1,6 +1,9 @@ -import { Button, Flex, Text } from '@chakra-ui/react'; -import EquipmentForm from '../equipment-form'; +import { Button, Flex, Icon, Text } from '@chakra-ui/react'; import { Modal } from '../modal'; +import React, { useState } from "react"; +import * as XLSX from "xlsx"; +// import {AiFillFileAdd} from '@chakra-ui/icons'; +import { AiFillFileAdd } from 'react-icons/ai'; type EquipmentsUploadModalProps = { isOpen: boolean; @@ -9,12 +12,123 @@ type EquipmentsUploadModalProps = { setRefreshRequest: React.Dispatch>; }; -export function EquipmentsUploadModal({ +export const EquipmentsUploadModal = ({ isOpen, onClose, refreshRequest, setRefreshRequest, -}: EquipmentsUploadModalProps) { +}: EquipmentsUploadModalProps) => { + const [file, setFile] = useState(null); + + const handleFileChange = (e: React.ChangeEvent) => { + const selectedFile = e.target.files?.[0] || null; + setFile(selectedFile); + }; + + const handleUpload = () => { + if (file) { + const reader = new FileReader(); + reader.onload = (e) => { + const data = new Uint8Array(e.target?.result as ArrayBuffer); + const workbook = XLSX.read(data, { type: "array" }); + const sheetName = workbook.SheetNames[0]; + const worksheet = workbook.Sheets[sheetName]; + const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); + + const formattedData = formatData(jsonData as any [][]); + // Agora você pode utilizar os dados (formattedData) para cadastrar no banco de dados, exibir em uma tabela, etc. + console.log(formattedData); + }; + reader.readAsArrayBuffer(file); + } + }; + + const formatData = (jsonData: any[][]) => { + const formattedData: any[] = []; + + // Percorre cada linha da planilha + for (let i = 1; i < jsonData.length; i++) { + const row = jsonData[i]; + const formattedRow: any = {}; + + // Validação dos campos obrigatórios + const tipoEquipamento = row[0]; + const marca = row[1]; + const modelo = row[2]; + const numeroTombamento = row[3]; + const numeroSerie = row[4]; + const numeroNotaFiscal = row[5]; + const tipoAquisicao = row[6]; + const estadoEquipamento = row[7]; + const anoAquisicao = row[8]; + const dataAquisicao = row[9]; + + if ( + !tipoEquipamento || + !marca || + !modelo || + !numeroTombamento || + !numeroSerie || + !numeroNotaFiscal || + !tipoAquisicao || + !estadoEquipamento || + !anoAquisicao || + !dataAquisicao + ) { + // Pular linha se algum dos campos obrigatórios estiver faltando + continue; + } + + formattedRow.tipoEquipamento = tipoEquipamento; + formattedRow.marca = marca; + formattedRow.modelo = modelo; + formattedRow.numeroTombamento = numeroTombamento; + formattedRow.numeroSerie = numeroSerie; + formattedRow.numeroNotaFiscal = numeroNotaFiscal; + formattedRow.tipoAquisicao = tipoAquisicao; + formattedRow.estadoEquipamento = estadoEquipamento; + formattedRow.anoAquisicao = anoAquisicao; + formattedRow.dataAquisicao = dataAquisicao; + + // Campos adicionais para tipos específicos de equipamento + if (tipoEquipamento === "CPU") { + const qtdMemoriaRAM = row[10]; + const tipoArmazenamento = row[11]; + const qntArmazenamento = row[12]; + const processador = row[13]; + + formattedRow.qtdMemoriaRAM = qtdMemoriaRAM; + formattedRow.tipoArmazenamento = tipoArmazenamento; + formattedRow.qntArmazenamento = qntArmazenamento; + formattedRow.processador = processador; + } else if (tipoEquipamento === "Estabilizador") { + const potencia = row[10]; + + formattedRow.potencia = potencia; + } else if (tipoEquipamento === "Monitor") { + const tipoMonitor = row[10]; + const tamanhoMonitor = row[11]; + + formattedRow.tipoMonitor = tipoMonitor; + formattedRow.tamanhoMonitor = tamanhoMonitor; + } else if (tipoEquipamento === "Nobreak") { + const potencia = row[10]; + + formattedRow.potencia = potencia; + } + + // Campo opcional + const descricao = row[14]; + if (descricao) { + formattedRow.descricao = descricao; + } + + formattedData.push(formattedRow); + } + + return formattedData; + }; + return ( + onDrop={(e) => e.preventDefault()} + onDragOver={(e) => e.preventDefault()} + onDragLeave={(e) => e.preventDefault()} + > + + + Arraste um arquivo XLS + + + + Adicione um arquivo do seu computador + + + + - + ); -} + +}; From f318c7379c488a84687d97c81f55602c251d8e6d Mon Sep 17 00:00:00 2001 From: Suzane Duarte Date: Sun, 2 Jul 2023 15:42:24 -0300 Subject: [PATCH 03/16] #150 feat: estilizando componente de upload de arquivos --- .../equipment-upload-modal/index.tsx | 135 ++++++++++++------ 1 file changed, 94 insertions(+), 41 deletions(-) diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index 23e409cb..70110a77 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -1,9 +1,9 @@ import { Button, Flex, Icon, Text } from '@chakra-ui/react'; -import { Modal } from '../modal'; -import React, { useState } from "react"; -import * as XLSX from "xlsx"; -// import {AiFillFileAdd} from '@chakra-ui/icons'; import { AiFillFileAdd } from 'react-icons/ai'; +import { MdAttachFile } from 'react-icons/md'; +import React, { useRef, useState } from 'react'; +import * as XLSX from 'xlsx'; +import { Modal } from '../modal'; type EquipmentsUploadModalProps = { isOpen: boolean; @@ -12,42 +12,51 @@ type EquipmentsUploadModalProps = { setRefreshRequest: React.Dispatch>; }; -export const EquipmentsUploadModal = ({ +export function EquipmentsUploadModal({ isOpen, onClose, refreshRequest, setRefreshRequest, -}: EquipmentsUploadModalProps) => { +}: EquipmentsUploadModalProps) { + const fileInputRef = useRef(null); const [file, setFile] = useState(null); + const [isHovering, setIsHovering] = useState(false); const handleFileChange = (e: React.ChangeEvent) => { const selectedFile = e.target.files?.[0] || null; setFile(selectedFile); }; - const handleUpload = () => { - if (file) { - const reader = new FileReader(); - reader.onload = (e) => { - const data = new Uint8Array(e.target?.result as ArrayBuffer); - const workbook = XLSX.read(data, { type: "array" }); - const sheetName = workbook.SheetNames[0]; - const worksheet = workbook.Sheets[sheetName]; - const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); + const onDropFile = (e: React.DragEvent) => { + e.preventDefault(); - const formattedData = formatData(jsonData as any [][]); - // Agora você pode utilizar os dados (formattedData) para cadastrar no banco de dados, exibir em uma tabela, etc. - console.log(formattedData); - }; - reader.readAsArrayBuffer(file); + const file = e.dataTransfer.files?.[0]; + + if (fileInputRef.current) { + fileInputRef.current.files = e.dataTransfer.files; } + + setFile(file); + setIsHovering(false); + }; + + const onDragOver = (e: React.DragEvent) => { + e.preventDefault(); + + setIsHovering(false); + }; + + const onDragStart = (e: React.DragEvent) => { + e.preventDefault(); + + setIsHovering(true); }; const formatData = (jsonData: any[][]) => { const formattedData: any[] = []; // Percorre cada linha da planilha - for (let i = 1; i < jsonData.length; i++) { + for (let i = 1; i < jsonData.length; i += 1) { const row = jsonData[i]; const formattedRow: any = {}; @@ -76,6 +85,7 @@ export const EquipmentsUploadModal = ({ !dataAquisicao ) { // Pular linha se algum dos campos obrigatórios estiver faltando + // eslint-disable-next-line no-continue continue; } @@ -91,7 +101,7 @@ export const EquipmentsUploadModal = ({ formattedRow.dataAquisicao = dataAquisicao; // Campos adicionais para tipos específicos de equipamento - if (tipoEquipamento === "CPU") { + if (tipoEquipamento === 'CPU') { const qtdMemoriaRAM = row[10]; const tipoArmazenamento = row[11]; const qntArmazenamento = row[12]; @@ -101,17 +111,17 @@ export const EquipmentsUploadModal = ({ formattedRow.tipoArmazenamento = tipoArmazenamento; formattedRow.qntArmazenamento = qntArmazenamento; formattedRow.processador = processador; - } else if (tipoEquipamento === "Estabilizador") { + } else if (tipoEquipamento === 'Estabilizador') { const potencia = row[10]; formattedRow.potencia = potencia; - } else if (tipoEquipamento === "Monitor") { + } else if (tipoEquipamento === 'Monitor') { const tipoMonitor = row[10]; const tamanhoMonitor = row[11]; formattedRow.tipoMonitor = tipoMonitor; formattedRow.tamanhoMonitor = tamanhoMonitor; - } else if (tipoEquipamento === "Nobreak") { + } else if (tipoEquipamento === 'Nobreak') { const potencia = row[10]; formattedRow.potencia = potencia; @@ -127,7 +137,23 @@ export const EquipmentsUploadModal = ({ } return formattedData; - }; + }; + + const handleUpload = () => { + if (file) { + const reader = new FileReader(); + reader.onload = (e) => { + const data = new Uint8Array(e.target?.result as ArrayBuffer); + const workbook = XLSX.read(data, { type: 'array' }); + const sheetName = workbook.SheetNames[0]; + const worksheet = workbook.Sheets[sheetName]; + const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); + + const formattedData = formatData(jsonData as any[][]); + }; + reader.readAsArrayBuffer(file); + } + }; return ( e.preventDefault()} - onDragOver={(e) => e.preventDefault()} - onDragLeave={(e) => e.preventDefault()} + borderColor={isHovering ? 'blue' : 'black'} + backgroundColor={isHovering ? 'blue.100' : 'unset'} + onDrop={onDropFile} + onDragOver={onDragStart} + onDragLeave={onDragOver} + flexDirection="column" + alignItems="center" + justifyContent="center" + gap={4} > - - - Arraste um arquivo XLS - + {file ? ( + <> + + + {file.name} + + + ) : ( + <> + + + Arraste um arquivo XLS + + + )} - - Adicione um arquivo do seu computador - - - + + Adicione um arquivo do seu computador + @@ -174,5 +228,4 @@ export const EquipmentsUploadModal = ({ ); - -}; +} From 6db80a993215aa5ff7d9b0c869379ff04202f328 Mon Sep 17 00:00:00 2001 From: Suzane Duarte Date: Sun, 2 Jul 2023 13:45:07 -0300 Subject: [PATCH 04/16] 150 feat: adicionando modal de upload de XLS Co-authored-by: PabloGJBS --- .../equipment-register-modal/index.tsx | 20 +++++++- .../equipment-upload-modal/index.tsx | 49 +++++++++++++++++++ src/components/modal/index.tsx | 9 +++- src/pages/equipments/EquipmentsControl.tsx | 10 ++++ 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/components/equipment-upload-modal/index.tsx diff --git a/src/components/equipment-register-modal/index.tsx b/src/components/equipment-register-modal/index.tsx index fcdb54e9..91b80149 100644 --- a/src/components/equipment-register-modal/index.tsx +++ b/src/components/equipment-register-modal/index.tsx @@ -1,10 +1,12 @@ -import { Flex } from '@chakra-ui/react'; +import { MdUpload } from 'react-icons/md'; +import { Button, Flex } from '@chakra-ui/react'; import EquipmentForm from '../equipment-form'; import { Modal } from '../modal'; type EquipmentRegisterModalProps = { isOpen: boolean; onClose(): void; + onUploadOpen(): void; refreshRequest: boolean; setRefreshRequest: React.Dispatch>; }; @@ -14,13 +16,29 @@ export function EquipmentRegisterModal({ onClose, refreshRequest, setRefreshRequest, + onUploadOpen, }: EquipmentRegisterModalProps) { + const onClickUploadXLS = () => { + onClose(); + onUploadOpen(); + }; return ( } + variant="outline" + borderColor="orange" + color="orange" + onClick={onClickUploadXLS} + > + Adicionar Arquivo XLS + + } > >; +}; + +export function EquipmentsUploadModal({ + isOpen, + onClose, + refreshRequest, + setRefreshRequest, +}: EquipmentsUploadModalProps) { + return ( + + + + Upload XLS + + + + + + + + + ); +} diff --git a/src/components/modal/index.tsx b/src/components/modal/index.tsx index e8f7427e..3711f862 100644 --- a/src/components/modal/index.tsx +++ b/src/components/modal/index.tsx @@ -9,6 +9,7 @@ Quaisquer erros ou bugs nesta implementação são de nossa responsabilidade. */ import { + Flex, Heading, Modal as ModalContainer, ModalBody, @@ -22,9 +23,10 @@ import React from 'react'; export interface ModalProps extends ChakraModalProps { title: string; + headerButton?: React.ReactNode; } -export function Modal({ children, title, ...props }: ModalProps) { +export function Modal({ children, title, headerButton, ...props }: ModalProps) { return ( @@ -34,10 +36,13 @@ export function Modal({ children, title, ...props }: ModalProps) { backdropFilter="blur(8px)" > - + {title} + + {headerButton} + diff --git a/src/pages/equipments/EquipmentsControl.tsx b/src/pages/equipments/EquipmentsControl.tsx index 984b2ae2..b3324f5f 100644 --- a/src/pages/equipments/EquipmentsControl.tsx +++ b/src/pages/equipments/EquipmentsControl.tsx @@ -35,6 +35,7 @@ import { MovementRegisterModal } from '@/components/movement-register-modal'; import { TermModal } from '@/components/term-modal'; import { movement } from '../movements/MovementControl'; import { NewControlledSelect } from '@/components/form-fields/new-controlled-select'; +import { EquipmentsUploadModal } from '@/components/equipment-upload-modal'; interface ISelectOption { label: string; @@ -166,6 +167,9 @@ function EquipmentTable() { isOpen: isOpenRegister, onClose: onCloseRegister, onOpen: onOpenRegister, + isOpen: isUploadOpen, + onClose: onUploadClose, + onOpen: onUploadOpen, } = useDisclosure(); const { @@ -524,6 +528,7 @@ function EquipmentTable() { isOpen={isOpen} refreshRequest={refreshRequest} setRefreshRequest={setRefreshRequest} + onUploadOpen={onUploadOpen} /> From e00ec8d4da5a589d1508847eecaf1e2cd2f92e1a Mon Sep 17 00:00:00 2001 From: PabloGJBS Date: Sun, 2 Jul 2023 14:55:58 -0300 Subject: [PATCH 05/16] #150 feat: envio de arquivo ta show Co-authored-by: suzaneduarte --- package.json | 3 +- .../equipment-upload-modal/index.tsx | 143 +++++++++++++++++- 2 files changed, 138 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index a428a340..d741bc6f 100755 --- a/package.json +++ b/package.json @@ -52,7 +52,8 @@ "react-render-if-visible": "^2.1.1", "react-router-dom": "^6.6.1", "react-toastify": "^9.1.2", - "sass": "^1.57.1" + "sass": "^1.57.1", + "xlsx": "^0.18.5" }, "devDependencies": { "@testing-library/jest-dom": "^5.16.5", diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index fcc37766..23e409cb 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -1,6 +1,9 @@ -import { Button, Flex, Text } from '@chakra-ui/react'; -import EquipmentForm from '../equipment-form'; +import { Button, Flex, Icon, Text } from '@chakra-ui/react'; import { Modal } from '../modal'; +import React, { useState } from "react"; +import * as XLSX from "xlsx"; +// import {AiFillFileAdd} from '@chakra-ui/icons'; +import { AiFillFileAdd } from 'react-icons/ai'; type EquipmentsUploadModalProps = { isOpen: boolean; @@ -9,12 +12,123 @@ type EquipmentsUploadModalProps = { setRefreshRequest: React.Dispatch>; }; -export function EquipmentsUploadModal({ +export const EquipmentsUploadModal = ({ isOpen, onClose, refreshRequest, setRefreshRequest, -}: EquipmentsUploadModalProps) { +}: EquipmentsUploadModalProps) => { + const [file, setFile] = useState(null); + + const handleFileChange = (e: React.ChangeEvent) => { + const selectedFile = e.target.files?.[0] || null; + setFile(selectedFile); + }; + + const handleUpload = () => { + if (file) { + const reader = new FileReader(); + reader.onload = (e) => { + const data = new Uint8Array(e.target?.result as ArrayBuffer); + const workbook = XLSX.read(data, { type: "array" }); + const sheetName = workbook.SheetNames[0]; + const worksheet = workbook.Sheets[sheetName]; + const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); + + const formattedData = formatData(jsonData as any [][]); + // Agora você pode utilizar os dados (formattedData) para cadastrar no banco de dados, exibir em uma tabela, etc. + console.log(formattedData); + }; + reader.readAsArrayBuffer(file); + } + }; + + const formatData = (jsonData: any[][]) => { + const formattedData: any[] = []; + + // Percorre cada linha da planilha + for (let i = 1; i < jsonData.length; i++) { + const row = jsonData[i]; + const formattedRow: any = {}; + + // Validação dos campos obrigatórios + const tipoEquipamento = row[0]; + const marca = row[1]; + const modelo = row[2]; + const numeroTombamento = row[3]; + const numeroSerie = row[4]; + const numeroNotaFiscal = row[5]; + const tipoAquisicao = row[6]; + const estadoEquipamento = row[7]; + const anoAquisicao = row[8]; + const dataAquisicao = row[9]; + + if ( + !tipoEquipamento || + !marca || + !modelo || + !numeroTombamento || + !numeroSerie || + !numeroNotaFiscal || + !tipoAquisicao || + !estadoEquipamento || + !anoAquisicao || + !dataAquisicao + ) { + // Pular linha se algum dos campos obrigatórios estiver faltando + continue; + } + + formattedRow.tipoEquipamento = tipoEquipamento; + formattedRow.marca = marca; + formattedRow.modelo = modelo; + formattedRow.numeroTombamento = numeroTombamento; + formattedRow.numeroSerie = numeroSerie; + formattedRow.numeroNotaFiscal = numeroNotaFiscal; + formattedRow.tipoAquisicao = tipoAquisicao; + formattedRow.estadoEquipamento = estadoEquipamento; + formattedRow.anoAquisicao = anoAquisicao; + formattedRow.dataAquisicao = dataAquisicao; + + // Campos adicionais para tipos específicos de equipamento + if (tipoEquipamento === "CPU") { + const qtdMemoriaRAM = row[10]; + const tipoArmazenamento = row[11]; + const qntArmazenamento = row[12]; + const processador = row[13]; + + formattedRow.qtdMemoriaRAM = qtdMemoriaRAM; + formattedRow.tipoArmazenamento = tipoArmazenamento; + formattedRow.qntArmazenamento = qntArmazenamento; + formattedRow.processador = processador; + } else if (tipoEquipamento === "Estabilizador") { + const potencia = row[10]; + + formattedRow.potencia = potencia; + } else if (tipoEquipamento === "Monitor") { + const tipoMonitor = row[10]; + const tamanhoMonitor = row[11]; + + formattedRow.tipoMonitor = tipoMonitor; + formattedRow.tamanhoMonitor = tamanhoMonitor; + } else if (tipoEquipamento === "Nobreak") { + const potencia = row[10]; + + formattedRow.potencia = potencia; + } + + // Campo opcional + const descricao = row[14]; + if (descricao) { + formattedRow.descricao = descricao; + } + + formattedData.push(formattedRow); + } + + return formattedData; + }; + return ( + onDrop={(e) => e.preventDefault()} + onDragOver={(e) => e.preventDefault()} + onDragLeave={(e) => e.preventDefault()} + > + + + Arraste um arquivo XLS + + + + Adicione um arquivo do seu computador + + + + - + ); -} + +}; From 72e810bf62da35908d52dd1199c320e768da277b Mon Sep 17 00:00:00 2001 From: Suzane Duarte Date: Sun, 2 Jul 2023 15:42:24 -0300 Subject: [PATCH 06/16] #150 feat: estilizando componente de upload de arquivos --- .../equipment-upload-modal/index.tsx | 135 ++++++++++++------ 1 file changed, 94 insertions(+), 41 deletions(-) diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index 23e409cb..70110a77 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -1,9 +1,9 @@ import { Button, Flex, Icon, Text } from '@chakra-ui/react'; -import { Modal } from '../modal'; -import React, { useState } from "react"; -import * as XLSX from "xlsx"; -// import {AiFillFileAdd} from '@chakra-ui/icons'; import { AiFillFileAdd } from 'react-icons/ai'; +import { MdAttachFile } from 'react-icons/md'; +import React, { useRef, useState } from 'react'; +import * as XLSX from 'xlsx'; +import { Modal } from '../modal'; type EquipmentsUploadModalProps = { isOpen: boolean; @@ -12,42 +12,51 @@ type EquipmentsUploadModalProps = { setRefreshRequest: React.Dispatch>; }; -export const EquipmentsUploadModal = ({ +export function EquipmentsUploadModal({ isOpen, onClose, refreshRequest, setRefreshRequest, -}: EquipmentsUploadModalProps) => { +}: EquipmentsUploadModalProps) { + const fileInputRef = useRef(null); const [file, setFile] = useState(null); + const [isHovering, setIsHovering] = useState(false); const handleFileChange = (e: React.ChangeEvent) => { const selectedFile = e.target.files?.[0] || null; setFile(selectedFile); }; - const handleUpload = () => { - if (file) { - const reader = new FileReader(); - reader.onload = (e) => { - const data = new Uint8Array(e.target?.result as ArrayBuffer); - const workbook = XLSX.read(data, { type: "array" }); - const sheetName = workbook.SheetNames[0]; - const worksheet = workbook.Sheets[sheetName]; - const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); + const onDropFile = (e: React.DragEvent) => { + e.preventDefault(); - const formattedData = formatData(jsonData as any [][]); - // Agora você pode utilizar os dados (formattedData) para cadastrar no banco de dados, exibir em uma tabela, etc. - console.log(formattedData); - }; - reader.readAsArrayBuffer(file); + const file = e.dataTransfer.files?.[0]; + + if (fileInputRef.current) { + fileInputRef.current.files = e.dataTransfer.files; } + + setFile(file); + setIsHovering(false); + }; + + const onDragOver = (e: React.DragEvent) => { + e.preventDefault(); + + setIsHovering(false); + }; + + const onDragStart = (e: React.DragEvent) => { + e.preventDefault(); + + setIsHovering(true); }; const formatData = (jsonData: any[][]) => { const formattedData: any[] = []; // Percorre cada linha da planilha - for (let i = 1; i < jsonData.length; i++) { + for (let i = 1; i < jsonData.length; i += 1) { const row = jsonData[i]; const formattedRow: any = {}; @@ -76,6 +85,7 @@ export const EquipmentsUploadModal = ({ !dataAquisicao ) { // Pular linha se algum dos campos obrigatórios estiver faltando + // eslint-disable-next-line no-continue continue; } @@ -91,7 +101,7 @@ export const EquipmentsUploadModal = ({ formattedRow.dataAquisicao = dataAquisicao; // Campos adicionais para tipos específicos de equipamento - if (tipoEquipamento === "CPU") { + if (tipoEquipamento === 'CPU') { const qtdMemoriaRAM = row[10]; const tipoArmazenamento = row[11]; const qntArmazenamento = row[12]; @@ -101,17 +111,17 @@ export const EquipmentsUploadModal = ({ formattedRow.tipoArmazenamento = tipoArmazenamento; formattedRow.qntArmazenamento = qntArmazenamento; formattedRow.processador = processador; - } else if (tipoEquipamento === "Estabilizador") { + } else if (tipoEquipamento === 'Estabilizador') { const potencia = row[10]; formattedRow.potencia = potencia; - } else if (tipoEquipamento === "Monitor") { + } else if (tipoEquipamento === 'Monitor') { const tipoMonitor = row[10]; const tamanhoMonitor = row[11]; formattedRow.tipoMonitor = tipoMonitor; formattedRow.tamanhoMonitor = tamanhoMonitor; - } else if (tipoEquipamento === "Nobreak") { + } else if (tipoEquipamento === 'Nobreak') { const potencia = row[10]; formattedRow.potencia = potencia; @@ -127,7 +137,23 @@ export const EquipmentsUploadModal = ({ } return formattedData; - }; + }; + + const handleUpload = () => { + if (file) { + const reader = new FileReader(); + reader.onload = (e) => { + const data = new Uint8Array(e.target?.result as ArrayBuffer); + const workbook = XLSX.read(data, { type: 'array' }); + const sheetName = workbook.SheetNames[0]; + const worksheet = workbook.Sheets[sheetName]; + const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); + + const formattedData = formatData(jsonData as any[][]); + }; + reader.readAsArrayBuffer(file); + } + }; return ( e.preventDefault()} - onDragOver={(e) => e.preventDefault()} - onDragLeave={(e) => e.preventDefault()} + borderColor={isHovering ? 'blue' : 'black'} + backgroundColor={isHovering ? 'blue.100' : 'unset'} + onDrop={onDropFile} + onDragOver={onDragStart} + onDragLeave={onDragOver} + flexDirection="column" + alignItems="center" + justifyContent="center" + gap={4} > - - - Arraste um arquivo XLS - + {file ? ( + <> + + + {file.name} + + + ) : ( + <> + + + Arraste um arquivo XLS + + + )} - - Adicione um arquivo do seu computador - - - + + Adicione um arquivo do seu computador + @@ -174,5 +228,4 @@ export const EquipmentsUploadModal = ({ ); - -}; +} From 403ba90d0bb38c9bde1349606c462f470db30573 Mon Sep 17 00:00:00 2001 From: DafneM Date: Sun, 2 Jul 2023 20:57:45 -0300 Subject: [PATCH 07/16] 150 feat: altera nomes dos atributos json e implementa cadastro Co-authored-by: PabloGJBS --- .../equipment-upload-modal/index.tsx | 86 +++++++++++-------- src/pages/equipments/EquipmentsControl.tsx | 1 + 2 files changed, 52 insertions(+), 35 deletions(-) diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index 70110a77..c0f6b5c1 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -3,7 +3,9 @@ import { AiFillFileAdd } from 'react-icons/ai'; import { MdAttachFile } from 'react-icons/md'; import React, { useRef, useState } from 'react'; import * as XLSX from 'xlsx'; +import { api } from '@/config/lib/axios'; import { Modal } from '../modal'; +import { parse, format } from 'date-fns'; type EquipmentsUploadModalProps = { isOpen: boolean; @@ -66,11 +68,9 @@ export function EquipmentsUploadModal({ const modelo = row[2]; const numeroTombamento = row[3]; const numeroSerie = row[4]; - const numeroNotaFiscal = row[5]; - const tipoAquisicao = row[6]; - const estadoEquipamento = row[7]; - const anoAquisicao = row[8]; - const dataAquisicao = row[9]; + const tipoAquisicao = row[5]; + const estadoEquipamento = row[6]; + const dataAquisicao = row[7]; if ( !tipoEquipamento || @@ -78,10 +78,8 @@ export function EquipmentsUploadModal({ !modelo || !numeroTombamento || !numeroSerie || - !numeroNotaFiscal || !tipoAquisicao || !estadoEquipamento || - !anoAquisicao || !dataAquisicao ) { // Pular linha se algum dos campos obrigatórios estiver faltando @@ -89,46 +87,50 @@ export function EquipmentsUploadModal({ continue; } - formattedRow.tipoEquipamento = tipoEquipamento; - formattedRow.marca = marca; - formattedRow.modelo = modelo; - formattedRow.numeroTombamento = numeroTombamento; - formattedRow.numeroSerie = numeroSerie; - formattedRow.numeroNotaFiscal = numeroNotaFiscal; - formattedRow.tipoAquisicao = tipoAquisicao; - formattedRow.estadoEquipamento = estadoEquipamento; - formattedRow.anoAquisicao = anoAquisicao; - formattedRow.dataAquisicao = dataAquisicao; + formattedRow.type = tipoEquipamento; + formattedRow.brandName = marca; + formattedRow.model = modelo; + formattedRow.tippingNumber = numeroTombamento.toString(); + formattedRow.serialNumber = numeroSerie; + formattedRow.acquisitionName = tipoAquisicao; + formattedRow.estado = + estadoEquipamento.charAt(0).toUpperCase() + estadoEquipamento.slice(1); + // formattedRow.acquisitionDate = dataAquisicao; + + // Converte a string de data em um objeto Date + const data = new Date(1900, 0, dataAquisicao - 1); + const data2 = format(data, 'dd/MM/yyyy'); + formattedRow.acquisitionDate = parse(data2, 'dd/MM/yyyy', new Date()); // Campos adicionais para tipos específicos de equipamento if (tipoEquipamento === 'CPU') { - const qtdMemoriaRAM = row[10]; - const tipoArmazenamento = row[11]; - const qntArmazenamento = row[12]; - const processador = row[13]; - - formattedRow.qtdMemoriaRAM = qtdMemoriaRAM; - formattedRow.tipoArmazenamento = tipoArmazenamento; - formattedRow.qntArmazenamento = qntArmazenamento; - formattedRow.processador = processador; + const qtdMemoriaRAM = row[8]; + const tipoArmazenamento = row[9]; + const qntArmazenamento = row[10]; + const processador = row[11]; + + formattedRow.ram_size = qtdMemoriaRAM.toString(); + formattedRow.storageType = tipoArmazenamento; + formattedRow.storageAmount = qntArmazenamento.toString(); + formattedRow.processor = processador; } else if (tipoEquipamento === 'Estabilizador') { - const potencia = row[10]; + const potencia = row[8]; - formattedRow.potencia = potencia; + formattedRow.power = potencia; } else if (tipoEquipamento === 'Monitor') { - const tipoMonitor = row[10]; - const tamanhoMonitor = row[11]; + const tipoMonitor = row[8]; + const tamanhoMonitor = row[9]; - formattedRow.tipoMonitor = tipoMonitor; - formattedRow.tamanhoMonitor = tamanhoMonitor; + formattedRow.screenType = tipoMonitor; + formattedRow.screenSize = tamanhoMonitor; } else if (tipoEquipamento === 'Nobreak') { - const potencia = row[10]; + const potencia = row[8]; - formattedRow.potencia = potencia; + formattedRow.power = potencia; } // Campo opcional - const descricao = row[14]; + const descricao = row[12]; if (descricao) { formattedRow.descricao = descricao; } @@ -150,6 +152,20 @@ export function EquipmentsUploadModal({ const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); const formattedData = formatData(jsonData as any[][]); + + formattedData.forEach((item) => { + console.log(item); + api + .post('equipment/createEquipment', item) + .then((response) => { + // Lógica de tratamento da resposta da requisição + console.log(response.data); + }) + .catch((error) => { + // Lógica de tratamento de erro + console.error(error); + }); + }); }; reader.readAsArrayBuffer(file); } diff --git a/src/pages/equipments/EquipmentsControl.tsx b/src/pages/equipments/EquipmentsControl.tsx index b3324f5f..656dce70 100644 --- a/src/pages/equipments/EquipmentsControl.tsx +++ b/src/pages/equipments/EquipmentsControl.tsx @@ -560,6 +560,7 @@ function EquipmentTable() { selectedMoviment={selectedMovement} refreshRequest={refreshRequest} setRefreshRequest={setRefreshRequest} + /> Date: Sun, 2 Jul 2023 22:47:51 -0300 Subject: [PATCH 08/16] 150 fix: corrige cadastro de equipamentos --- .../equipment-upload-modal/index.tsx | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index c0f6b5c1..619f2189 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -3,9 +3,10 @@ import { AiFillFileAdd } from 'react-icons/ai'; import { MdAttachFile } from 'react-icons/md'; import React, { useRef, useState } from 'react'; import * as XLSX from 'xlsx'; +import { parse, format } from 'date-fns'; import { api } from '@/config/lib/axios'; import { Modal } from '../modal'; -import { parse, format } from 'date-fns'; +import { toast } from '@/utils/toast'; type EquipmentsUploadModalProps = { isOpen: boolean; @@ -89,7 +90,7 @@ export function EquipmentsUploadModal({ formattedRow.type = tipoEquipamento; formattedRow.brandName = marca; - formattedRow.model = modelo; + formattedRow.model = modelo.toString(); formattedRow.tippingNumber = numeroTombamento.toString(); formattedRow.serialNumber = numeroSerie; formattedRow.acquisitionName = tipoAquisicao; @@ -102,6 +103,7 @@ export function EquipmentsUploadModal({ const data2 = format(data, 'dd/MM/yyyy'); formattedRow.acquisitionDate = parse(data2, 'dd/MM/yyyy', new Date()); + console.log(tipoEquipamento); // Campos adicionais para tipos específicos de equipamento if (tipoEquipamento === 'CPU') { const qtdMemoriaRAM = row[8]; @@ -114,25 +116,25 @@ export function EquipmentsUploadModal({ formattedRow.storageAmount = qntArmazenamento.toString(); formattedRow.processor = processador; } else if (tipoEquipamento === 'Estabilizador') { - const potencia = row[8]; + const potencia = row[12]; formattedRow.power = potencia; } else if (tipoEquipamento === 'Monitor') { - const tipoMonitor = row[8]; - const tamanhoMonitor = row[9]; + const tipoMonitor = row[13]; + const tamanhoMonitor = row[14]; formattedRow.screenType = tipoMonitor; formattedRow.screenSize = tamanhoMonitor; } else if (tipoEquipamento === 'Nobreak') { - const potencia = row[8]; + const potencia = row[12]; formattedRow.power = potencia; } // Campo opcional - const descricao = row[12]; + const descricao = row[15]; if (descricao) { - formattedRow.descricao = descricao; + formattedRow.description = descricao; } formattedData.push(formattedRow); @@ -150,6 +152,7 @@ export function EquipmentsUploadModal({ const sheetName = workbook.SheetNames[0]; const worksheet = workbook.Sheets[sheetName]; const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); + let erro = 0; const formattedData = formatData(jsonData as any[][]); @@ -158,14 +161,25 @@ export function EquipmentsUploadModal({ api .post('equipment/createEquipment', item) .then((response) => { - // Lógica de tratamento da resposta da requisição - console.log(response.data); + if (response.status === 200) { + setRefreshRequest(!refreshRequest); + onClose(); + erro = 0; + } + erro = 1; }) .catch((error) => { - // Lógica de tratamento de erro + erro = 1; console.error(error); }); }); + if (erro === 1) { + toast.error( + 'Sua importação não foi bem sucedida! Verifique se os campos estão preenchidos corretamente.' + ); + } else { + toast.success('Equipamentos cadastrados com sucesso', 'Sucesso'); + } }; reader.readAsArrayBuffer(file); } @@ -238,7 +252,7 @@ export function EquipmentsUploadModal({ - + From 8d5b9cfcc57b841dd341342ca0451f6d1b652860 Mon Sep 17 00:00:00 2001 From: PabloGJBS Date: Mon, 3 Jul 2023 17:40:25 -0300 Subject: [PATCH 09/16] #150 feat: adicionando toasts de erro Co-authored-by: suzaneduarte --- .../equipment-upload-modal/index.tsx | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index 619f2189..470cab85 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -162,6 +162,7 @@ export function EquipmentsUploadModal({ .post('equipment/createEquipment', item) .then((response) => { if (response.status === 200) { + toast.success('Equipamentos cadastrados com sucesso', 'Sucesso'); setRefreshRequest(!refreshRequest); onClose(); erro = 0; @@ -169,17 +170,33 @@ export function EquipmentsUploadModal({ erro = 1; }) .catch((error) => { + if ( + error.response.data.error === + 'Tippingnumber nao pode ser igual ao de um equipamento ja cadastrado.' + ) { + toast.error( + 'Já existe um equipamento cadastrado com este número de tombamento. Cadastre um equipamento com número de tombamento diferente.', + 'Erro' + ); + } + if ( + error.response.data.error === + 'Tipo de equipamento não encontrado.' + ) { + toast.error( + 'Tipo do equipamento não encontrado por favor verifique se foi digitado corretamente', + 'Erro' + ); + } erro = 1; console.error(error); }); }); if (erro === 1) { toast.error( - 'Sua importação não foi bem sucedida! Verifique se os campos estão preenchidos corretamente.' + 'Sua importação não foi bem sucedida! Verifique se os campos estão preenchidos corretamente.', 'Erro' ); - } else { - toast.success('Equipamentos cadastrados com sucesso', 'Sucesso'); - } + } }; reader.readAsArrayBuffer(file); } From b2b474cbc2cf70e5b6f168a84edb1188eda760d3 Mon Sep 17 00:00:00 2001 From: Suzane Duarte Date: Mon, 3 Jul 2023 23:31:18 -0300 Subject: [PATCH 10/16] =?UTF-8?q?#150=20fix:=20corre=C3=A7=C3=A3o=20de=20e?= =?UTF-8?q?rros=20no=20c=C3=B3digo=20Co-authored-by:=20PabloGJBS=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/equipment-upload-modal/index.tsx | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index c5745c8d..ea487ed4 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -58,12 +58,10 @@ export function EquipmentsUploadModal({ const formatData = (jsonData: any[][]) => { const formattedData: any[] = []; - // Percorre cada linha da planilha for (let i = 1; i < jsonData.length; i += 1) { const row = jsonData[i]; const formattedRow: any = {}; - // Validação dos campos obrigatórios const tipoEquipamento = row[0]; const marca = row[1]; const modelo = row[2]; @@ -83,7 +81,6 @@ export function EquipmentsUploadModal({ !estadoEquipamento || !dataAquisicao ) { - // Pular linha se algum dos campos obrigatórios estiver faltando // eslint-disable-next-line no-continue continue; } @@ -96,15 +93,11 @@ export function EquipmentsUploadModal({ formattedRow.acquisitionName = tipoAquisicao; formattedRow.estado = estadoEquipamento.charAt(0).toUpperCase() + estadoEquipamento.slice(1); - // formattedRow.acquisitionDate = dataAquisicao; - // Converte a string de data em um objeto Date const data = new Date(1900, 0, dataAquisicao - 1); const data2 = format(data, 'dd/MM/yyyy'); formattedRow.acquisitionDate = parse(data2, 'dd/MM/yyyy', new Date()); - console.log(tipoEquipamento); - // Campos adicionais para tipos específicos de equipamento if (tipoEquipamento === 'CPU') { const qtdMemoriaRAM = row[8]; const tipoArmazenamento = row[9]; @@ -157,7 +150,6 @@ export function EquipmentsUploadModal({ const formattedData = formatData(jsonData as any[][]); formattedData.forEach((item) => { - console.log(item); api .post('equipment/createEquipment', item) .then((response) => { From cbbf18e0c8bbdd78611d060f83bfb0917ee62565 Mon Sep 17 00:00:00 2001 From: Suzane Duarte Date: Tue, 4 Jul 2023 07:56:18 -0300 Subject: [PATCH 11/16] =?UTF-8?q?#150=20fix:=20arrumando=20sobreposi=C3=A7?= =?UTF-8?q?=C3=A3o=20de=20modais=20Co-authored-by:=20PabloGJBS=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/equipments/EquipmentsControl.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pages/equipments/EquipmentsControl.tsx b/src/pages/equipments/EquipmentsControl.tsx index 656dce70..716ac4cd 100644 --- a/src/pages/equipments/EquipmentsControl.tsx +++ b/src/pages/equipments/EquipmentsControl.tsx @@ -167,6 +167,9 @@ function EquipmentTable() { isOpen: isOpenRegister, onClose: onCloseRegister, onOpen: onOpenRegister, + } = useDisclosure(); + + const { isOpen: isUploadOpen, onClose: onUploadClose, onOpen: onUploadOpen, From 26ee15e6cca8e2fb0c9e097dac73412f6db904bb Mon Sep 17 00:00:00 2001 From: PabloGJBS Date: Tue, 4 Jul 2023 13:59:26 -0300 Subject: [PATCH 12/16] #150 fix: Corrigindo os erros de code smell Co-authored-by: suzaneduarte --- .../equipment-upload-modal/index.tsx | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index ea487ed4..68164aa6 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -26,7 +26,7 @@ export function EquipmentsUploadModal({ const [isHovering, setIsHovering] = useState(false); const handleFileChange = (e: React.ChangeEvent) => { - const selectedFile = e.target.files?.[0] || null; + const selectedFile = e.target.files?.[0] ?? null; setFile(selectedFile); }; @@ -108,7 +108,7 @@ export function EquipmentsUploadModal({ formattedRow.storageType = tipoArmazenamento; formattedRow.storageAmount = qntArmazenamento.toString(); formattedRow.processor = processador; - } else if (tipoEquipamento === 'Estabilizador') { + } else if (tipoEquipamento === 'Estabilizador' || tipoEquipamento === 'Nobreak') { const potencia = row[12]; formattedRow.power = potencia; @@ -118,12 +118,7 @@ export function EquipmentsUploadModal({ formattedRow.screenType = tipoMonitor; formattedRow.screenSize = tamanhoMonitor; - } else if (tipoEquipamento === 'Nobreak') { - const potencia = row[12]; - - formattedRow.power = potencia; - } - + } // Campo opcional const descricao = row[15]; if (descricao) { @@ -162,7 +157,12 @@ export function EquipmentsUploadModal({ onClose(); erro = 0; } - erro = 1; + else{ + toast.error( + 'Sua importação não foi bem sucedida! Verifique se os campos estão preenchidos corretamente.', + 'Erro' + ); + } }) .catch((error) => { if ( @@ -187,12 +187,6 @@ export function EquipmentsUploadModal({ console.error(error); }); }); - if (erro === 1) { - toast.error( - 'Sua importação não foi bem sucedida! Verifique se os campos estão preenchidos corretamente.', - 'Erro' - ); - } }; reader.readAsArrayBuffer(file); } From 011a7b1a766fc56d5035f47d51b2782838fd7fea Mon Sep 17 00:00:00 2001 From: Suzane Duarte Date: Tue, 4 Jul 2023 16:34:33 -0300 Subject: [PATCH 13/16] #150 fix: corrigindo erros do yarn lint Co-authored-by: PabloGJBS --- src/components/equipment-upload-modal/index.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index 68164aa6..216e6544 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -108,7 +108,10 @@ export function EquipmentsUploadModal({ formattedRow.storageType = tipoArmazenamento; formattedRow.storageAmount = qntArmazenamento.toString(); formattedRow.processor = processador; - } else if (tipoEquipamento === 'Estabilizador' || tipoEquipamento === 'Nobreak') { + } else if ( + tipoEquipamento === 'Estabilizador' || + tipoEquipamento === 'Nobreak' + ) { const potencia = row[12]; formattedRow.power = potencia; @@ -118,7 +121,7 @@ export function EquipmentsUploadModal({ formattedRow.screenType = tipoMonitor; formattedRow.screenSize = tamanhoMonitor; - } + } // Campo opcional const descricao = row[15]; if (descricao) { @@ -156,8 +159,7 @@ export function EquipmentsUploadModal({ setRefreshRequest(!refreshRequest); onClose(); erro = 0; - } - else{ + } else { toast.error( 'Sua importação não foi bem sucedida! Verifique se os campos estão preenchidos corretamente.', 'Erro' From ae74612ecb6dd59bd33b74b14b785ea92faf642e Mon Sep 17 00:00:00 2001 From: PabloGJBS Date: Tue, 4 Jul 2023 21:12:08 -0300 Subject: [PATCH 14/16] #150 fix: add erro pro caso da planilha vazia Co-authored-by: suzaneduarte --- src/components/equipment-upload-modal/index.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index 216e6544..2a61b7ed 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -144,7 +144,10 @@ export function EquipmentsUploadModal({ const worksheet = workbook.Sheets[sheetName]; const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); let erro = 0; - + + if(jsonData.length >= 1){ + toast.error('Planilha sem nenhum equipamento por favor verificar o arquivo','Erro') + } const formattedData = formatData(jsonData as any[][]); formattedData.forEach((item) => { @@ -158,7 +161,6 @@ export function EquipmentsUploadModal({ ); setRefreshRequest(!refreshRequest); onClose(); - erro = 0; } else { toast.error( 'Sua importação não foi bem sucedida! Verifique se os campos estão preenchidos corretamente.', @@ -185,7 +187,6 @@ export function EquipmentsUploadModal({ 'Erro' ); } - erro = 1; console.error(error); }); }); From 891ca9346d4649540e927253a249ea48a538f0a2 Mon Sep 17 00:00:00 2001 From: Suzane Duarte Date: Tue, 4 Jul 2023 21:36:48 -0300 Subject: [PATCH 15/16] =?UTF-8?q?#150=20fix:=20arrumando=20condi=C3=A7?= =?UTF-8?q?=C3=A3o=20e=20erros=20do=20lint=20Co-authored-by:=20PabloGJBS?= =?UTF-8?q?=20= 1){ - toast.error('Planilha sem nenhum equipamento por favor verificar o arquivo','Erro') + + if (jsonData.length <= 1) { + toast.error( + 'Planilha sem nenhum equipamento, favor verificar o arquivo', + 'Erro' + ); } const formattedData = formatData(jsonData as any[][]); From be50a16ef37791b8dd2d381a7ee5f419d64b3e98 Mon Sep 17 00:00:00 2001 From: Suzane Duarte Date: Tue, 4 Jul 2023 21:59:59 -0300 Subject: [PATCH 16/16] =?UTF-8?q?#150=20fix:=20corrigindo=20erro=20de=20co?= =?UTF-8?q?ndi=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/equipment-upload-modal/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/equipment-upload-modal/index.tsx b/src/components/equipment-upload-modal/index.tsx index 41cb1e8a..8aaceaf1 100644 --- a/src/components/equipment-upload-modal/index.tsx +++ b/src/components/equipment-upload-modal/index.tsx @@ -144,13 +144,14 @@ export function EquipmentsUploadModal({ const worksheet = workbook.Sheets[sheetName]; const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); - if (jsonData.length <= 1) { + const formattedData = formatData(jsonData as any[][]); + + if (formattedData.length <= 1) { toast.error( 'Planilha sem nenhum equipamento, favor verificar o arquivo', 'Erro' ); } - const formattedData = formatData(jsonData as any[][]); formattedData.forEach((item) => { api