Skip to content

Commit

Permalink
Merge pull request #49 from fga-eps-mds/210-arrumarR1.1
Browse files Browse the repository at this point in the history
210 arrumar Release 2
  • Loading branch information
mibasFerraz authored Dec 14, 2023
2 parents 57d16ff + 8a61516 commit 3636926
Show file tree
Hide file tree
Showing 21 changed files with 760 additions and 175 deletions.
Binary file modified public/Log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>PrintGO</title>
<title>PrintGo</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
Binary file modified public/logo--.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export async function login(email, password) {
};

try {
const response = await api.post('/user/login', data);
return response.data.token;
const response = await api.post('/user/login', data);
return {type: 'success', token: response.data.token };

Check warning on line 11 in src/api/api.js

View check run for this annotation

Codecov / codecov/patch

src/api/api.js#L10-L11

Added lines #L10 - L11 were not covered by tests
} catch (error) {
console.error('Erro ao fazer login:', error);
return {type: 'error', error};
Expand Down
134 changes: 53 additions & 81 deletions src/components/forms/EditPatternForm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { yupResolver } from "@hookform/resolvers/yup";
import React, { useEffect } from "react";
import { useForm } from "react-hook-form";
import { Link, useNavigate, useParams } from 'react-router-dom';
import "../../style/components/printerPatternForm.css";
import elipse6 from "../../assets/elipse6.svg";
import { getRegisterPrinterSchema } from "../utils/YupSchema";
import { getRegisterPatternSchema } from "../utils/YupSchema";
import { editPadrao } from "../../services/printerService";
import { toast } from "react-toastify";

const fieldLabels = {
tipo: "Tipo",
Expand All @@ -13,140 +16,109 @@ const fieldLabels = {
modeloImpressora: "Modelo da impressora",
numeroSerie: "Número de série",
versaoFirmware: "Versão do Firmware",
tempoAtivo: "Tempo ativo do sistema",
tempoAtivoSistema: "Tempo ativo do sistema",
totalDigitalizacoes: "Total de digitalizações",
totalCopiasPB: "Total de cópias P&B",
totalCopiasColorido: "Total de cópias coloridas",
totalImpressoesPB: "Total de impressões P&B",
totalImpressoesColorido: "Total de impressoões coloridas",
totalCopiasColoridas: "Total de cópias coloridas",
totalImpressoesPb: "Total de impressões P&B",
totalImpressoesColoridas: "Total de impressões coloridas",
totalGeral: "Total geral",
enderecoIP: "Endereço IP",
enderecoIp: "Endereço IP",
},
};


const testObject = {
tipo: "teste",
marca: "Marcateste",
modelo: "Modeloteste",
snmp: {
modeloImpressora: "Modelo da impressora",
numeroSerie: "Número de série",
versaoFirmware: "Versão do Firmware",
tempoAtivo: "Tempo ativo do sistema",
totalDigitalizacoes: "Total de digitalizações",
totalCopiasPB: "Total de cópias P&B",
totalCopiasColorido: "Total de cópias coloridas",
totalImpressoesPB: "Total de impressões P&B",
totalImpressoesColorido: "Total de impressoões coloridas",
totalGeral: "Total geral",
enderecoIP: "Endereço IP",
},
};


export default function EditPatternForm() {
const registerPrinterSchema = getRegisterPrinterSchema(fieldLabels);

const { padrao } = useParams();

const pattern = JSON.parse(atob(padrao));
console.log(pattern);

const navigate = useNavigate();
const registerPrinterSchema = getRegisterPatternSchema(fieldLabels);

const {
register,
handleSubmit,
setValue,
formState: { errors, isValid },
reset,
formState: { errors, isSubmitting },
} = useForm({
resolver: yupResolver(registerPrinterSchema),
mode: "onChange",
mode: "onSubmit",
});

const onSubmit = async (data) => {
console.log(data);

reset();

const response = await editPadrao(data);
if (response.type === "success") {
toast.success("Padrão editado com sucesso!");
setTimeout(() => {
navigate("/padroescadastrados");

Check warning on line 57 in src/components/forms/EditPatternForm.js

View check run for this annotation

Codecov / codecov/patch

src/components/forms/EditPatternForm.js#L57

Added line #L57 was not covered by tests
}, 1000);
} else {
toast.error("Erro ao editar o padrão!");

Check warning on line 60 in src/components/forms/EditPatternForm.js

View check run for this annotation

Codecov / codecov/patch

src/components/forms/EditPatternForm.js#L59-L60

Added lines #L59 - L60 were not covered by tests
}

};

useEffect(() => {
Object.entries(testObject).forEach(([key, value]) => {
Object.entries(pattern).forEach(([key, value]) => {
setValue(key, value);
});
}, [setValue]);

return (
<div id="printer-pattern-signup-card">
<div id="printer-pattern-signup-card" data-testid="printer-pattern-signup-card">
<h2 id="printer-pattern-form-header">Edição de padrão de impressora</h2>
<form onSubmit={handleSubmit(onSubmit)}>
<div id="printer-pattern-input-group">
<div id="printer-pattern-input-box">
<div id="printer-pattern-fields">
{["tipo", "marca", "modelo"].map((field) => (
<div id="printer-pattern-input-line" key={field.id}>
{Object.entries(fieldLabels).filter(([key]) => key !== "snmp").map(([key, label]) => (
<div id="printer-pattern-input-line" key={key}>
<label>
{fieldLabels[field]}
{label}
<span>*</span>
</label>
<input
{...register(field)}
placeholder={`Digite ${fieldLabels[field].toLowerCase()}`}
{...register(key)}
placeholder={`Digite ${label.toLowerCase()}`}
/>
<span>{errors[field]?.message}</span>
<span>{errors[key]?.message}</span>
</div>
))}
</div>

{/* SNMP Fields */}
<div id="printer-pattern-snmp-fields">
<label htmlFor="snmp">SNMP</label>
{Object.keys(fieldLabels.snmp).map((subField) => (
<div id="snmp-fields-input-line" key={`sub-${subField.id}`}>
{Object.entries(fieldLabels.snmp).map(([key, label]) => (
<div id="snmp-fields-input-line" key={key}>
<label>
{fieldLabels.snmp[subField]}
{label}
<span>*</span>
</label>
{[
"modeloImpressora",
"numeroSerie",
"versaoFirmware",
"tempoAtivo",
"totalDigitalizacoes",
"totalCopiasPB",
"totalCopiasColorido",
"totalImpressoesPB",
"totalImpressoesColorido",
"totalGeral",
"enderecoIP",
].includes(subField) ? (
<input
{...register(`snmp.${subField}`)}
//style={{ width: '200px' }} // Adjust the width as needed
placeholder="Código OID"
/>
) : (
<input
{...register(`snmp.${subField}`)}
style={{ width: "200px" }} // Adjust the width as needed
placeholder={`Digite ${fieldLabels.snmp[
subField
].toLowerCase()}`}
/>
)}
<span>{errors[`snmp.${subField}`]?.message}</span>
<input
{...register(key)}
placeholder="Código OID"
/>
<span>{errors[key]?.message}</span>
</div>
))}
</div>
</div>
</div>
<div id="printer-pattern-buttons">
<button
className="printer-pattern-form-button"
type="button"
id="cancelar-bnt"
>
EXCLUIR
<button className="printer-pattern-form-button" type="button" id="cancelar-bnt">
<Link to="/padroescadastrados">
CANCELAR
</Link>
</button>
<button
className="printer-pattern-form-button"
type="submit"
id="registrar-bnt"
disabled={!isValid}
disabled={isSubmitting}
>
SALVAR
</button>
Expand Down
7 changes: 3 additions & 4 deletions src/components/forms/EditPrinterForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const fieldLabels = {
export default function EditPrinterForm() {

const { printer } = useParams();
console.log(printer);

const navigate = useNavigate();
const printerObject = JSON.parse(atob(printer));
Expand Down Expand Up @@ -132,23 +131,23 @@ export default function EditPrinterForm() {
<span>*</span>
</label>
{key === "padrao_id" ? (
<select {...register(key)} onChange={(e) => setPadrao(e.target.value)}>
<select {...register(key)} onChange={(e) => setPadrao(e.target.value)} data-testid="padrao-select">
{padroes.map(option => (
<option key={option.id} value={option.id} >
{option.tipo}, {option.marca}, {option.modelo}
</option>
))}
</select>
) : key === "unidadePai" ? (
<select onChange={handleWorkstationChange}>
<select onChange={handleWorkstationChange} data-testid="unidadePai-select">
{unidadeList.map(option => (
<option key={option.id} value={option.id}>
{option.name}
</option>
))}
</select>
) : key === "unidadeId" ? (
<select {...register(key)} onChange={(e) => setUnidade(e.target.value)}>
<select {...register(key)} onChange={(e) => setUnidade(e.target.value)} data-testid="unidadeFilha-select">
{unidadesFilha.map(option => (
<option key={option.id} value={option.id}>
{option.name}
Expand Down
13 changes: 9 additions & 4 deletions src/components/forms/PrinterPatternForm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { yupResolver } from "@hookform/resolvers/yup";
import React from "react";
import { useForm } from "react-hook-form";
import { Link } from 'react-router-dom';
import "../../style/components/printerPatternForm.css";
import elipse6 from "../../assets/elipse6.svg";
import { getRegisterPrinterSchema } from "../utils/YupSchema";
import { getRegisterPatternSchema } from "../utils/YupSchema";
import { ReloadIcon } from "@radix-ui/react-icons";
import { createPadraoImpressora } from "../../services/printerService";
import { toast } from "react-toastify";
Expand All @@ -29,7 +30,7 @@ const fieldLabels = {


export default function PrinterPatternForm() {
const registerPrinterSchema = getRegisterPrinterSchema(fieldLabels);
const registerPrinterSchema = getRegisterPatternSchema(fieldLabels);
const {
register,
handleSubmit,
Expand Down Expand Up @@ -92,8 +93,12 @@ export default function PrinterPatternForm() {
</div>
</div>
<div id="printer-pattern-buttons">
<button className="printer-pattern-form-button" type="button" id="cancelar-bnt">CANCELAR</button>
<button className="form-button" type="submit" id="registrar-bnt" disabled={!isValid || isSubmitting}>
<button className="printer-pattern-form-button" type="button" id="cancelar-bnt">
<Link to="/">
CANCELAR
</Link>
</button>
<button className="printer-pattern-form-button" type="submit" id="registrar-bnt" disabled={!isValid || isSubmitting}>
{isSubmitting && (
<ReloadIcon id="animate-spin"/>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/navbar/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ const Navbar = () => {
</div>
);
};
export default Navbar;
export default Navbar;
4 changes: 2 additions & 2 deletions src/components/utils/YupSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getPrinterSchema = (printerFieldLabels) => {
};


export const getRegisterPrinterSchema = (fieldLabels) => {
export const getRegisterPatternSchema = (fieldLabels) => {

return yup.object().shape({
tipo: yup.string().required(`${fieldLabels.tipo} é obrigatório`),
Expand Down Expand Up @@ -85,4 +85,4 @@ export const getEditUserSchema = (userFiledLabels) => {
isAdmin: yup.boolean(),
isLocadora: yup.boolean(),
});
};
};
18 changes: 11 additions & 7 deletions src/pages/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ export default function Login() {
e.preventDefault();

try {
const token = await login(email, password);

localStorage.setItem("jwt", token);
navigate("/");

const response = await login(email, password);

if (response.type === 'success') {
localStorage.setItem("jwt", response.token);
navigate("/");
} else {
console.error(response.error);
setLoginError("E-mail ou senha incorreto.");
}

} catch (error) {
console.error(error);
setLoginError("E-mail ou senha incorreto.");

setLoginError("Não foi possível fazer o login");
}
};

Expand Down
32 changes: 32 additions & 0 deletions src/services/printerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,35 @@ export const createPadraoImpressora = async (printerPattern) => {
return { type: 'error', error };
}
};

export const editPadrao = async (pattern) => {
try {
const data = {
tipo: pattern.tipo,
marca: pattern.marca,
modelo: pattern.modelo,
modeloImpressora: pattern.modeloImpressora,
numeroSerie: pattern.numeroSerie,
versaoFirmware: pattern.versaoFirmware,
tempoAtivoSistema: pattern.tempoAtivoSistema,
totalDigitalizacoes: pattern.totalDigitalizacoes,
totalCopiasPB: pattern.totalCopiasPB,
totalCopiasColoridas: pattern.totalCopiasColoridas,
totalImpressoesPb: pattern.totalImpressoesPb,
totalImpressoesColoridas: pattern.totalImpressoesColoridas,
totalGeral: pattern.totalGeral,
enderecoIp: pattern.enderecoIp,
}

const response = await api.patch(`/printer/padrao/${pattern.id}`, data);

if (response.status !== 200) {
return { type: 'error', data: response.data };
}

return { type: 'success', data: response.data };

} catch (error) {
return { type: 'error', error };
}
}
Loading

0 comments on commit 3636926

Please sign in to comment.