Merge pull request #32 from rede5/codex/fix-typeerror-in-login-flow
Fix catalog price formatting
This commit is contained in:
commit
a873d29160
2 changed files with 86 additions and 44 deletions
|
|
@ -31,6 +31,18 @@ const CatalogoProdutosList: React.FC<CatalogoProdutosListProps> = ({
|
||||||
onNextPage,
|
onNextPage,
|
||||||
onRowClick,
|
onRowClick,
|
||||||
}) => {
|
}) => {
|
||||||
|
const formatCurrency = (value: unknown) => {
|
||||||
|
if (value === null || value === undefined || value === "") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const numericValue =
|
||||||
|
typeof value === "number" ? value : Number(String(value));
|
||||||
|
if (Number.isNaN(numericValue)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return numericValue.toFixed(2);
|
||||||
|
};
|
||||||
|
|
||||||
const totalPages = Math.ceil(totalProdutos / pageSize);
|
const totalPages = Math.ceil(totalProdutos / pageSize);
|
||||||
const startItem = (currentPage - 1) * pageSize + 1;
|
const startItem = (currentPage - 1) * pageSize + 1;
|
||||||
const endItem = Math.min(currentPage * pageSize, totalProdutos);
|
const endItem = Math.min(currentPage * pageSize, totalProdutos);
|
||||||
|
|
@ -104,33 +116,35 @@ const CatalogoProdutosList: React.FC<CatalogoProdutosListProps> = ({
|
||||||
{
|
{
|
||||||
key: "preco-original",
|
key: "preco-original",
|
||||||
header: "Preço Original",
|
header: "Preço Original",
|
||||||
render: (produto: Models.Document) => (
|
render: (produto: Models.Document) => {
|
||||||
<div className="text-sm">
|
const valor = formatCurrency((produto as any)["preco-original"]);
|
||||||
{(produto as any)["preco-original"] ? (
|
return (
|
||||||
<span className="font-medium text-green-600">
|
<div className="text-sm">
|
||||||
R$ {(produto as any)["preco-original"].toFixed(2)}
|
{valor ? (
|
||||||
</span>
|
<span className="font-medium text-green-600">R$ {valor}</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-gray-400">N/A</span>
|
<span className="text-gray-400">N/A</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
),
|
);
|
||||||
|
},
|
||||||
width: "w-28",
|
width: "w-28",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "preco-atual",
|
key: "preco-atual",
|
||||||
header: "Preço Atual",
|
header: "Preço Atual",
|
||||||
render: (produto: Models.Document) => (
|
render: (produto: Models.Document) => {
|
||||||
<div className="text-sm">
|
const valor = formatCurrency((produto as any)["preco-atual"]);
|
||||||
{(produto as any)["preco-atual"] ? (
|
return (
|
||||||
<span className="font-medium text-blue-600">
|
<div className="text-sm">
|
||||||
R$ {(produto as any)["preco-atual"].toFixed(2)}
|
{valor ? (
|
||||||
</span>
|
<span className="font-medium text-blue-600">R$ {valor}</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-gray-400">N/A</span>
|
<span className="text-gray-400">N/A</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
),
|
);
|
||||||
|
},
|
||||||
width: "w-24",
|
width: "w-24",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -154,12 +168,14 @@ const CatalogoProdutosList: React.FC<CatalogoProdutosListProps> = ({
|
||||||
header: "Subst. Tributária",
|
header: "Subst. Tributária",
|
||||||
render: (produto: Models.Document) => {
|
render: (produto: Models.Document) => {
|
||||||
const produtoData = produto as any;
|
const produtoData = produto as any;
|
||||||
const valor = produtoData["valor-substituicao-tributaria"];
|
const valor = formatCurrency(
|
||||||
|
produtoData["valor-substituicao-tributaria"]
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<div className="text-sm">
|
<div className="text-sm">
|
||||||
{valor ? (
|
{valor ? (
|
||||||
<span className="font-medium text-purple-600">
|
<span className="font-medium text-purple-600">
|
||||||
R$ {valor.toFixed(2)}
|
R$ {valor}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-gray-400">N/A</span>
|
<span className="text-gray-400">N/A</span>
|
||||||
|
|
@ -174,12 +190,12 @@ const CatalogoProdutosList: React.FC<CatalogoProdutosListProps> = ({
|
||||||
header: "Preço NF",
|
header: "Preço NF",
|
||||||
render: (produto: Models.Document) => {
|
render: (produto: Models.Document) => {
|
||||||
const produtoData = produto as any;
|
const produtoData = produto as any;
|
||||||
const preco = produtoData["preco-nf"];
|
const preco = formatCurrency(produtoData["preco-nf"]);
|
||||||
return (
|
return (
|
||||||
<div className="text-sm">
|
<div className="text-sm">
|
||||||
{preco ? (
|
{preco ? (
|
||||||
<span className="font-medium text-indigo-600">
|
<span className="font-medium text-indigo-600">
|
||||||
R$ {preco.toFixed(2)}
|
R$ {preco}
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="text-gray-400">N/A</span>
|
<span className="text-gray-400">N/A</span>
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,18 @@ const CatalogoProdutosList: React.FC<CatalogoProdutosListProps> = ({
|
||||||
onNextPage,
|
onNextPage,
|
||||||
onRowClick,
|
onRowClick,
|
||||||
}) => {
|
}) => {
|
||||||
|
const formatCurrency = (value: unknown) => {
|
||||||
|
if (value === null || value === undefined || value === "") {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const numericValue =
|
||||||
|
typeof value === "number" ? value : Number(String(value));
|
||||||
|
if (Number.isNaN(numericValue)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return numericValue.toFixed(2);
|
||||||
|
};
|
||||||
|
|
||||||
const totalPages = Math.ceil(totalProdutos / pageSize);
|
const totalPages = Math.ceil(totalProdutos / pageSize);
|
||||||
const startItem = (currentPage - 1) * pageSize + 1;
|
const startItem = (currentPage - 1) * pageSize + 1;
|
||||||
const endItem = Math.min(currentPage * pageSize, totalProdutos);
|
const endItem = Math.min(currentPage * pageSize, totalProdutos);
|
||||||
|
|
@ -123,26 +135,40 @@ const CatalogoProdutosList: React.FC<CatalogoProdutosListProps> = ({
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap">
|
<td className="px-6 py-4 whitespace-nowrap">
|
||||||
<div className="text-sm">
|
{(() => {
|
||||||
{(produto as any)["preco-original"] ? (
|
const precoOriginal = formatCurrency(
|
||||||
<span className="font-medium text-green-600">
|
(produto as any)["preco-original"]
|
||||||
R$ {(produto as any)["preco-original"].toFixed(2)}
|
);
|
||||||
</span>
|
return (
|
||||||
) : (
|
<div className="text-sm">
|
||||||
<span className="text-gray-400">N/A</span>
|
{precoOriginal ? (
|
||||||
)}
|
<span className="font-medium text-green-600">
|
||||||
</div>
|
R$ {precoOriginal}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-gray-400">N/A</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap">
|
<td className="px-6 py-4 whitespace-nowrap">
|
||||||
<div className="text-sm">
|
{(() => {
|
||||||
{(produto as any)["preco-atual"] ? (
|
const precoAtual = formatCurrency(
|
||||||
<span className="font-medium text-blue-600">
|
(produto as any)["preco-atual"]
|
||||||
R$ {(produto as any)["preco-atual"].toFixed(2)}
|
);
|
||||||
</span>
|
return (
|
||||||
) : (
|
<div className="text-sm">
|
||||||
<span className="text-gray-400">N/A</span>
|
{precoAtual ? (
|
||||||
)}
|
<span className="font-medium text-blue-600">
|
||||||
</div>
|
R$ {precoAtual}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-gray-400">N/A</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})()}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap">
|
<td className="px-6 py-4 whitespace-nowrap">
|
||||||
<div className="text-sm">
|
<div className="text-sm">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue