From 1881826f4993a445a543ceb57c1b126a08c8ae8f Mon Sep 17 00:00:00 2001 From: Bruno Date: Sat, 26 Oct 2024 17:36:48 -0300 Subject: [PATCH] fix --- src/@open-adm/components/box/index.tsx | 10 + .../components/table-paginacao/footer.tsx | 108 ++++++++ .../components/table-paginacao/header.tsx | 70 +++++ .../components/table-paginacao/index.tsx | 250 ++++++++++++++++++ .../components/table-paginacao/table.tsx | 115 ++++++++ src/@open-adm/pages/banners/config.tsx | 14 +- src/@open-adm/pages/banners/index.tsx | 25 +- .../pages/estoque/categorias/config.tsx | 9 +- .../pages/estoque/categorias/index.tsx | 25 +- .../estoque/movimentacao-produto/config.tsx | 7 +- .../estoque/movimentacao-produto/index.tsx | 16 +- src/@open-adm/pages/estoque/peso/config.tsx | 9 +- .../pages/estoque/peso/form/index.tsx | 45 ++-- src/@open-adm/pages/estoque/peso/index.tsx | 25 +- .../pages/estoque/posicao-estoque/config.tsx | 6 +- .../pages/estoque/posicao-estoque/index.tsx | 16 +- .../pages/estoque/produto/config.tsx | 11 +- src/@open-adm/pages/estoque/produto/index.tsx | 26 +- .../pages/estoque/tamanho/config.tsx | 9 +- .../pages/estoque/tamanho/form/index.tsx | 50 ++-- src/@open-adm/pages/estoque/tamanho/index.tsx | 25 +- .../form/use-api-contas-a-receber.tsx | 8 +- .../financeiro/contas-a-receber/index.tsx | 31 ++- .../pages/lojas-parceiras/config.tsx | 13 +- src/@open-adm/pages/lojas-parceiras/index.tsx | 43 +-- src/@open-adm/pages/pedidos/config.tsx | 47 +++- src/@open-adm/pages/pedidos/index.tsx | 65 ++++- src/@open-adm/pages/vendas/cliente/config.tsx | 5 +- src/@open-adm/pages/vendas/cliente/index.tsx | 11 +- .../pages/vendas/tabela-de-preco/index.tsx | 33 +-- src/@open-adm/types/peso.ts | 1 + src/@open-adm/types/tamanho.ts | 1 + 32 files changed, 884 insertions(+), 245 deletions(-) create mode 100644 src/@open-adm/components/table-paginacao/footer.tsx create mode 100644 src/@open-adm/components/table-paginacao/header.tsx create mode 100644 src/@open-adm/components/table-paginacao/index.tsx create mode 100644 src/@open-adm/components/table-paginacao/table.tsx diff --git a/src/@open-adm/components/box/index.tsx b/src/@open-adm/components/box/index.tsx index b457285..b1a43c9 100644 --- a/src/@open-adm/components/box/index.tsx +++ b/src/@open-adm/components/box/index.tsx @@ -27,6 +27,10 @@ interface propsBoxApp { justifyContent?: justifyContent; flexDirection?: flexDirection; padding?: string; + height?: string; + marginBottom?: string; + maxHeight?: string; + overflowy?: string; } export function BoxApp(props: propsBoxApp) { @@ -41,6 +45,12 @@ export function BoxApp(props: propsBoxApp) { alignItems={props.alignItems} justifyContent={props.justifyContent} flexDirection={props.flexDirection} + height={props.height} + marginBottom={props.marginBottom} + maxHeight={props.maxHeight} + sx={{ + overflowY: props.overflowy as any + }} > {props.children} diff --git a/src/@open-adm/components/table-paginacao/footer.tsx b/src/@open-adm/components/table-paginacao/footer.tsx new file mode 100644 index 0000000..c017b57 --- /dev/null +++ b/src/@open-adm/components/table-paginacao/footer.tsx @@ -0,0 +1,108 @@ +import { Pagination, Typography } from '@mui/material'; +import { useLocalStorage } from 'src/hooks/useLocalStorage'; +import { BoxApp } from '../box'; +import { DropDown } from '../drop-down'; + +const opcoesDeQuantidadePorPagina = [ + { + id: 1, + label: '5', + }, + { + id: 2, + label: '10', + }, + { + id: 3, + label: '15', + }, + { + id: 4, + label: '20', + }, + { + id: 5, + label: '25', + }, + { + id: 6, + label: '30', + }, + { + id: 7, + label: '35', + }, + { + id: 8, + label: '40', + }, + { + id: 9, + label: '45', + }, + { + id: 10, + label: '50', + }, +]; + +interface propsFooterTable { + length: number; + totalDeRegistros: number; + quantidadePagina: number; + quantidadePorPagina: number; + pagina: number; + setPagina: (newPage: number) => void; + setQuantidadePorPagina: (newPage: number) => void; +} + +export function FooterTable(props: propsFooterTable) { + const { setItem } = useLocalStorage(); + + return ( + + + Registros por página: + x.label === props.quantidadePorPagina.toString(), + )} + onChange={(_, newValue) => { + const id = + typeof newValue === 'string' ? parseInt(newValue) : newValue; + const newV = opcoesDeQuantidadePorPagina.find( + (x) => x.id === id, + )?.label; + setItem( + 'quantidade-por-pagina', + newV?.toString() ?? '5', + ); + props.setQuantidadePorPagina(parseInt(newV ?? '5')); + }} + /> + {`Exibindo ${props.length} registros de ${props.totalDeRegistros}`} + + props.setPagina(newPage)} + /> + + ); +} \ No newline at end of file diff --git a/src/@open-adm/components/table-paginacao/header.tsx b/src/@open-adm/components/table-paginacao/header.tsx new file mode 100644 index 0000000..e58f0a3 --- /dev/null +++ b/src/@open-adm/components/table-paginacao/header.tsx @@ -0,0 +1,70 @@ +import { useNavigateApp } from '../../hooks/use-navigate-app'; +import { useState } from 'react'; +import { Button } from '@mui/material'; +import { InputCustom } from '../input'; +import { BoxApp } from '../box'; + +interface propsHeaderTable { + urlAdd?: string; + notBtnAdd?: boolean; + pesquisar: (search?: string) => void; +} + +export function HeaderTable(props: propsHeaderTable) { + const { navigate } = useNavigateApp(); + const [search, setSearch] = useState(''); + function handleBtnAdicionar() { + if (props.notBtnAdd || !props.urlAdd) { + return <>; + } + + return ( + + ); + } + + return ( + + {handleBtnAdicionar()} +
{ + e.preventDefault(); + if (props.pesquisar) { + props.pesquisar(search?.length === 0 ? undefined : search); + } + }} + > + { + setSearch(e); + if (e?.length === 0) { + props.pesquisar(undefined); + } + }} + fullWidth + /> + +
+ ); +} \ No newline at end of file diff --git a/src/@open-adm/components/table-paginacao/index.tsx b/src/@open-adm/components/table-paginacao/index.tsx new file mode 100644 index 0000000..5d1ce7c --- /dev/null +++ b/src/@open-adm/components/table-paginacao/index.tsx @@ -0,0 +1,250 @@ +import { ReactNode, useEffect, useState } from 'react'; +import { useLocalStorage } from 'src/hooks/useLocalStorage'; +import { TypeMethod, useNewApi } from 'src/@open-adm/hooks/use-new-api'; +import { ISortingTable, TablePaginacao } from './table'; +import { BoxApp } from '../box'; +import { FooterTable } from './footer'; +import { HeaderTable } from './header'; +import { Card, CircularProgress, Divider, IconButton, Tooltip, Typography } from '@mui/material'; +import { GridColDef, GridRenderCellParams } from '@mui/x-data-grid'; +import IconifyIcon from 'src/@core/components/icon'; +import { useApi } from 'src/@open-adm/hooks/use-api'; +import { useModal } from '../modal/modal'; +import { useNavigateApp } from 'src/@open-adm/hooks/use-navigate-app'; +import { formatDate } from 'src/@open-adm/utils/convert-date'; + +interface tableProps { + columns: any[]; + url: string; + checkboxSelection?: boolean; + urlDelete?: string; + urlAdd?: string; + urlView?: string; + urlEdit?: string; + notShowHeader?: boolean; + notBtnAdd?: boolean; + initialField?: string; + refreshPai?: any; + filtroComplementar?: any; + nomeColunaAcoes?: string; + desabilitarColunaAcoes?: boolean; + metodo?: TypeMethod; + childrenHeader?: ReactNode; +} + +export function TableIndex(props: tableProps) { + const { getItem } = useLocalStorage(); + const { deleteApi } = useApi(); + const { navigate } = useNavigateApp(); + const modal = useModal(); + const [totalDeRegistros, setTotalDeRegistros] = useState(0); + const [pagina, setPagina] = useState(1); + const [loading, setLoading] = useState(true); + const [quantidadePorPagina, setQuantidadePorPagina] = useState( + parseInt(getItem('quantidade-por-pagina') ?? '5'), + ); + const [sorting, setSorting] = useState({ + field: 'dataDeAtualizacao', + sort: 'desc', + }); + const [quantidadePagina, setQuantidadePagina] = useState(0); + const [rows, setRows] = useState([]); + const { fecth } = useNewApi({ + method: props.metodo ?? 'POST', + url: props.url, + notAlert: true, + notLoading: true, + }); + + const body = { + skip: pagina, + take: + typeof quantidadePorPagina === 'string' + ? parseInt(quantidadePorPagina) + : quantidadePorPagina, + orderBy: sorting.field, + asc: sorting.sort === 'asc', + ...props.filtroComplementar, + }; + + async function refresh(searchP?: string) { + setLoading(true); + const response = await fecth({ + body: { ...body, search: searchP }, + }); + if (response?.values?.length > 0) { + setRows(response.values); + setTotalDeRegistros(response.totalDeRegistros); + setQuantidadePagina(response.totalPaginas); + } else { + if (rows?.length > 0) { + setRows([]); + } + } + setLoading(false); + } + + function excluir(id: string) { + try { + modal.show({ + async confirmed() { + modal.close(); + await deleteApi(`${props.urlDelete}?id=${id}`) + await refresh(); + }, + }) + } catch (error) { + + } + } + + function optionsColumns(): GridColDef[] { + return [ + { + flex: 0.175, + minWidth: 140, + field: 'dataDeCriacao', + headerName: 'Data de cadastro', + renderCell: (params: any) => formatDate(params?.dataDeCriacao), + sortable: true, + }, + { + flex: 0.175, + minWidth: 140, + field: 'action', + headerName: 'Ações', + renderCell: (params: any) => { + return ( + <> + {props.urlView && + + navigate(`${props.urlView}/${params.id}`)} + > + + + + } + {props.urlEdit && + + navigate(`${props.urlEdit}/${params.id}`)} + > + + + + } + {props.urlDelete && + + excluir(params.id)} + > + + + + } + + + ) + } + }, + ] + } + + function defaultColuns(): GridColDef[] { + let columns: GridColDef[] = []; + + columns.push( + { + field: 'numero', + headerName: 'Número', + flex: 0.100, + minWidth: 80, + renderCell: (params: any) => ( + + #{params.numero} + + ), + sortable: true, + }, + ) + + return columns; + } + + useEffect(() => { + refresh(); + }, [ + pagina, + quantidadePorPagina, + sorting, + props.refreshPai, + ]); + + return ( + + {props.childrenHeader && + <>{props.childrenHeader} + } + {!props.notShowHeader && ( + + )} + + {loading ? ( + + Carregando ... + + + ) : ( + <> + + + )} + + + + + ); +} \ No newline at end of file diff --git a/src/@open-adm/components/table-paginacao/table.tsx b/src/@open-adm/components/table-paginacao/table.tsx new file mode 100644 index 0000000..99b5e3e --- /dev/null +++ b/src/@open-adm/components/table-paginacao/table.tsx @@ -0,0 +1,115 @@ +import Table from '@mui/material/Table'; +import TableBody from '@mui/material/TableBody'; +import TableCell from '@mui/material/TableCell'; +import TableContainer from '@mui/material/TableContainer'; +import TableHead from '@mui/material/TableHead'; +import TableRow from '@mui/material/TableRow'; +import TableSortLabel from '@mui/material/TableSortLabel'; +import { keyframes } from '@mui/system'; + +export const opacityAnimation = keyframes` + from { opacity: 0; } + to { opacity: 1; } +`; + +export type ISort = 'asc' | 'desc'; + +export interface ISortingTable { + field: string; + sort: ISort; +} + +interface propsTable { + columns: any[]; + rows: any[]; + sorting?: ISortingTable; + setSorting?: (sorting: ISortingTable) => void; + minWidth?: number; + stickyHeader?: boolean; + maxHeigth?: number | string; + marginTop?: string; +} + +export function TablePaginacao(props: propsTable) { + return ( + + + + + {props.columns.map((column, index) => ( + + {column.headerName} + {column.sortable ? ( + { + if (props.setSorting) { + props.setSorting({ + field: column.field, + sort: + props?.sorting?.sort === 'asc' + ? 'desc' + : 'asc', + }); + } + }} + > + <> + + ) : undefined} + + ))} + + + + {props.rows.map((row, index) => ( + + {props.columns.map((column, index) => ( + + {column.renderCell && !column?.pesquisar ? ( + column.renderCell(row) + ) : ( + row[column.field] + )} + + ))} + + ))} + +
+
+ ); +} \ No newline at end of file diff --git a/src/@open-adm/pages/banners/config.tsx b/src/@open-adm/pages/banners/config.tsx index 9ec5b96..e855d34 100644 --- a/src/@open-adm/pages/banners/config.tsx +++ b/src/@open-adm/pages/banners/config.tsx @@ -9,22 +9,24 @@ export function useConfig() { minWidth: 200, field: 'foto', headerName: 'Foto', - renderCell: (params: GridRenderCellParams) => ( + renderCell: (params: any) => ( - ) + ), + sortable: true, }, { flex: 0.200, minWidth: 200, field: 'ativo', headerName: 'Ativo', - renderCell: (params: GridRenderCellParams) => ( - - ) + renderCell: (params: any) => ( + + ), + sortable: true, } ] diff --git a/src/@open-adm/pages/banners/index.tsx b/src/@open-adm/pages/banners/index.tsx index aed7da5..c6dc2b2 100644 --- a/src/@open-adm/pages/banners/index.tsx +++ b/src/@open-adm/pages/banners/index.tsx @@ -1,25 +1,18 @@ -import Table from "src/@open-adm/components/table"; import { useConfig } from "./config"; +import { TableIndex } from "src/@open-adm/components/table-paginacao"; export function Banners() { const config = useConfig(); return ( - <> - - + ) } \ No newline at end of file diff --git a/src/@open-adm/pages/estoque/categorias/config.tsx b/src/@open-adm/pages/estoque/categorias/config.tsx index 7d43f1b..94abfe5 100644 --- a/src/@open-adm/pages/estoque/categorias/config.tsx +++ b/src/@open-adm/pages/estoque/categorias/config.tsx @@ -1,5 +1,5 @@ import { Box } from "@mui/material" -import { GridColDef, GridRenderCellParams } from "@mui/x-data-grid" +import { GridColDef } from "@mui/x-data-grid" import * as yup from 'yup'; export const columns: GridColDef[] = [ @@ -8,10 +8,10 @@ export const columns: GridColDef[] = [ minWidth: 200, field: 'foto', headerName: 'Foto', - renderCell: (params: GridRenderCellParams) => ( + renderCell: (params: any) => ( ) @@ -20,7 +20,8 @@ export const columns: GridColDef[] = [ flex: 0.200, minWidth: 200, field: 'descricao', - headerName: 'Descricao' + headerName: 'Descricao', + sortable: true, } ] diff --git a/src/@open-adm/pages/estoque/categorias/index.tsx b/src/@open-adm/pages/estoque/categorias/index.tsx index dce3956..82e1d03 100644 --- a/src/@open-adm/pages/estoque/categorias/index.tsx +++ b/src/@open-adm/pages/estoque/categorias/index.tsx @@ -1,23 +1,16 @@ -import Table from "src/@open-adm/components/table"; import { columns } from './config' +import { TableIndex } from "src/@open-adm/components/table-paginacao"; export function Categorias() { return ( - <> -
- + ) } \ No newline at end of file diff --git a/src/@open-adm/pages/estoque/movimentacao-produto/config.tsx b/src/@open-adm/pages/estoque/movimentacao-produto/config.tsx index 27e00d0..f4db3b9 100644 --- a/src/@open-adm/pages/estoque/movimentacao-produto/config.tsx +++ b/src/@open-adm/pages/estoque/movimentacao-produto/config.tsx @@ -32,15 +32,16 @@ export const columns: GridColDef[] = [ flex: 0.200, minWidth: 200, field: 'quantidadeMovimentada', - headerName: 'Quantidade movimentadao' + headerName: 'Quantidade movimentadao', + sortable: true, }, { flex: 0.200, minWidth: 200, field: 'tipoMovimentacaoDeProduto', headerName: 'Tipo Movimentação', - renderCell: (params: GridRenderCellParams) => { - const status = tipoMovimentacaoDeProduto[params.row.tipoMovimentacaoDeProduto] + renderCell: (params: any) => { + const status = tipoMovimentacaoDeProduto[params.tipoMovimentacaoDeProduto] return ( -
- + ) } \ No newline at end of file diff --git a/src/@open-adm/pages/estoque/peso/config.tsx b/src/@open-adm/pages/estoque/peso/config.tsx index e4e5426..eba06c0 100644 --- a/src/@open-adm/pages/estoque/peso/config.tsx +++ b/src/@open-adm/pages/estoque/peso/config.tsx @@ -6,7 +6,14 @@ export const columns: GridColDef[] = [ flex: 0.200, minWidth: 200, field: 'descricao', - headerName: 'Descricao' + headerName: 'Descrição', + sortable: true, + }, + { + flex: 0.200, + minWidth: 200, + field: 'pesoReal', + headerName: 'Peso real' } ] diff --git a/src/@open-adm/pages/estoque/peso/form/index.tsx b/src/@open-adm/pages/estoque/peso/form/index.tsx index 7203b2d..cffbd11 100644 --- a/src/@open-adm/pages/estoque/peso/form/index.tsx +++ b/src/@open-adm/pages/estoque/peso/form/index.tsx @@ -11,6 +11,8 @@ import { useFormik } from 'formik'; import { defaultValues, schema } from "../config"; import { useRouter as useRouterQuery } from 'next/router' import { IPeso } from "src/@open-adm/types/peso"; +import { useFormikAdapter } from "src/@open-adm/adapters/formik-adapter"; +import { InputCustom } from "src/@open-adm/components/input"; export function FormPeso(props: IForm) { @@ -21,10 +23,10 @@ export function FormPeso(props: IForm) { const { query } = useRouterQuery(); const title = props.action === 'create' ? 'Adicionar novo peso' : props.action === 'update' ? 'Editar peso' : 'Visualizar peso' - const formik = useFormik({ + const formik = useFormikAdapter({ initialValues: defaultValues, validationSchema: schema, - onSubmit: (values) => onSubmit(values), + onSubmit: onSubmit, }); async function init() { @@ -32,7 +34,7 @@ export function FormPeso(props: IForm) { if (props.action !== 'create') { const response = await get(`pesos/get-peso?id=${query.id}`); if (response) { - formik.setValues(response); + formik.setValue(response); } } } catch (error) { @@ -44,20 +46,19 @@ export function FormPeso(props: IForm) { init(); }, []) - async function onSubmit(values: any) { + async function onSubmit() { try { if (props.action === "update") { await put('pesos/update', { - descricao: values.descricao, - id: query.id + ...formik.values } as IPeso) } if (props.action === 'create') { await post('pesos/create', { - descricao: values.descricao + ...formik.values } as IPeso) } router.replace('/estoque/peso') @@ -70,25 +71,37 @@ export function FormPeso(props: IForm) {
- + + + diff --git a/src/@open-adm/pages/estoque/peso/index.tsx b/src/@open-adm/pages/estoque/peso/index.tsx index 22c3d41..65de628 100644 --- a/src/@open-adm/pages/estoque/peso/index.tsx +++ b/src/@open-adm/pages/estoque/peso/index.tsx @@ -1,23 +1,16 @@ -import Table from "src/@open-adm/components/table"; import { columns } from './config' +import { TableIndex } from "src/@open-adm/components/table-paginacao"; export function Pesos() { return ( - <> -
- + ) } \ No newline at end of file diff --git a/src/@open-adm/pages/estoque/posicao-estoque/config.tsx b/src/@open-adm/pages/estoque/posicao-estoque/config.tsx index 23ee7fe..6d8810e 100644 --- a/src/@open-adm/pages/estoque/posicao-estoque/config.tsx +++ b/src/@open-adm/pages/estoque/posicao-estoque/config.tsx @@ -33,8 +33,8 @@ export const columns: GridColDef[] = [ minWidth: 200, field: 'quantidade', headerName: 'Posição do estoque', - renderCell: (params: GridRenderCellParams) => { - const status = quantidade[params.row.quantidade > 0 ? 1 : 0] + renderCell: (params: any) => { + const status = quantidade[params.quantidade > 0 ? 1 : 0] return ( ) diff --git a/src/@open-adm/pages/estoque/posicao-estoque/index.tsx b/src/@open-adm/pages/estoque/posicao-estoque/index.tsx index 2b6bfa6..27ac701 100644 --- a/src/@open-adm/pages/estoque/posicao-estoque/index.tsx +++ b/src/@open-adm/pages/estoque/posicao-estoque/index.tsx @@ -1,16 +1,12 @@ -import Table from "src/@open-adm/components/table"; import { columns } from "./config"; +import { TableIndex } from "src/@open-adm/components/table-paginacao"; export function EstoqueProduto() { return ( - <> -
- + ) } \ No newline at end of file diff --git a/src/@open-adm/pages/estoque/produto/config.tsx b/src/@open-adm/pages/estoque/produto/config.tsx index 70b44f4..62ac12e 100644 --- a/src/@open-adm/pages/estoque/produto/config.tsx +++ b/src/@open-adm/pages/estoque/produto/config.tsx @@ -1,5 +1,5 @@ -import { Box, Typography } from "@mui/material" -import { GridColDef, GridRenderCellParams } from "@mui/x-data-grid" +import { Box } from "@mui/material" +import { GridColDef } from "@mui/x-data-grid" import { ICreateProdutoDto, IProduto } from "src/@open-adm/types/produto"; import { IItensTabelaDePreco, ITabelaDePreco } from "src/@open-adm/types/tabela-de-preco"; import * as yup from 'yup'; @@ -10,11 +10,11 @@ export const columns: GridColDef[] = [ minWidth: 200, field: 'foto', headerName: 'Foto', - renderCell: (params: GridRenderCellParams) => ( + renderCell: (params: any) => ( ) @@ -23,7 +23,8 @@ export const columns: GridColDef[] = [ flex: 0.200, minWidth: 200, field: 'descricao', - headerName: 'Descricao' + headerName: 'Descricao', + sortable: true, }, { flex: 0.200, diff --git a/src/@open-adm/pages/estoque/produto/index.tsx b/src/@open-adm/pages/estoque/produto/index.tsx index b9386de..37fb592 100644 --- a/src/@open-adm/pages/estoque/produto/index.tsx +++ b/src/@open-adm/pages/estoque/produto/index.tsx @@ -1,23 +1,15 @@ -import Table from "src/@open-adm/components/table"; import { columns } from './config' +import { TableIndex } from "src/@open-adm/components/table-paginacao"; export function Produtos() { - return ( - <> -
- + ) } \ No newline at end of file diff --git a/src/@open-adm/pages/estoque/tamanho/config.tsx b/src/@open-adm/pages/estoque/tamanho/config.tsx index e4e5426..3faa366 100644 --- a/src/@open-adm/pages/estoque/tamanho/config.tsx +++ b/src/@open-adm/pages/estoque/tamanho/config.tsx @@ -6,7 +6,14 @@ export const columns: GridColDef[] = [ flex: 0.200, minWidth: 200, field: 'descricao', - headerName: 'Descricao' + headerName: 'Descricao', + sortable: true, + }, + { + flex: 0.200, + minWidth: 200, + field: 'pesoReal', + headerName: 'Peso real' } ] diff --git a/src/@open-adm/pages/estoque/tamanho/form/index.tsx b/src/@open-adm/pages/estoque/tamanho/form/index.tsx index 8aa11d9..204ecb1 100644 --- a/src/@open-adm/pages/estoque/tamanho/form/index.tsx +++ b/src/@open-adm/pages/estoque/tamanho/form/index.tsx @@ -11,6 +11,8 @@ import { useFormik } from 'formik'; import { defaultValues, schema } from "../config"; import { useRouter as useRouterQuery } from 'next/router' import { ITamanho } from "src/@open-adm/types/tamanho"; +import { useFormikAdapter } from "src/@open-adm/adapters/formik-adapter"; +import { InputCustom } from "src/@open-adm/components/input"; export function FormTamanho(props: IForm) { @@ -21,10 +23,10 @@ export function FormTamanho(props: IForm) { const { query } = useRouterQuery(); const title = props.action === 'create' ? 'Adicionar novo tamanho' : props.action === 'update' ? 'Editar tamanho' : 'Visualizar tamanho' - const formik = useFormik({ + const formik = useFormikAdapter({ initialValues: defaultValues, validationSchema: schema, - onSubmit: (values, helpers) => onSubmit(values), + onSubmit: onSubmit, }); async function init() { @@ -32,7 +34,7 @@ export function FormTamanho(props: IForm) { if (props.action !== 'create') { const response = await get(`tamanhos/get-tamanho?id=${query.id}`); if (response) { - formik.setValues(response); + formik.setValue(response); } } } catch (error) { @@ -44,21 +46,16 @@ export function FormTamanho(props: IForm) { init(); }, []) - async function onSubmit(values: any) { + async function onSubmit() { try { if (props.action === "update") { - await put('tamanhos/update', { - descricao: values.descricao, - id: query.id - } as ITamanho) + await put('tamanhos/update', formik.values) } if (props.action === 'create') { - await post('tamanhos/create', { - descricao: values.descricao - } as ITamanho) + await post('tamanhos/create', formik.values) } router.replace('/estoque/tamanho') } catch (error) { @@ -70,26 +67,37 @@ export function FormTamanho(props: IForm) { - + + + diff --git a/src/@open-adm/pages/estoque/tamanho/index.tsx b/src/@open-adm/pages/estoque/tamanho/index.tsx index 04f9de0..dcb3beb 100644 --- a/src/@open-adm/pages/estoque/tamanho/index.tsx +++ b/src/@open-adm/pages/estoque/tamanho/index.tsx @@ -1,23 +1,16 @@ -import Table from "src/@open-adm/components/table"; import { columns } from './config' +import { TableIndex } from "src/@open-adm/components/table-paginacao"; export function Tamanhos() { return ( - <> -
- + ) } \ No newline at end of file diff --git a/src/@open-adm/pages/financeiro/contas-a-receber/form/use-api-contas-a-receber.tsx b/src/@open-adm/pages/financeiro/contas-a-receber/form/use-api-contas-a-receber.tsx index a964fe5..b02ec18 100644 --- a/src/@open-adm/pages/financeiro/contas-a-receber/form/use-api-contas-a-receber.tsx +++ b/src/@open-adm/pages/financeiro/contas-a-receber/form/use-api-contas-a-receber.tsx @@ -4,25 +4,25 @@ import { IFaturaContasAReceber, IPagarFaturaAReceber } from "src/@open-adm/types export function useContasAReceber() { const apiFaturasPorPedido = useNewApi({ method: 'GET', - url: 'fatura-contas-a-receber/pedido?pedidoId=', + url: 'fatura/pedido?pedidoId=', notAlert: true }); const apiGet = useNewApi({ method: 'GET', - url: 'fatura-contas-a-receber/get-by-id?id=', + url: 'fatura/get-by-id?id=', notAlert: true }); const apiPagarFatura = useNewApi({ method: 'PUT', - url: 'fatura-contas-a-receber/pagar', + url: 'fatura/pagar', notAlert: true }); const apiEdit = useNewApi({ method: 'PUT', - url: 'fatura-contas-a-receber/edit' + url: 'fatura/edit' }); async function faturasDoPedido(pedidoId: string, statusFatura?: number): Promise { diff --git a/src/@open-adm/pages/financeiro/contas-a-receber/index.tsx b/src/@open-adm/pages/financeiro/contas-a-receber/index.tsx index a752712..73be7c8 100644 --- a/src/@open-adm/pages/financeiro/contas-a-receber/index.tsx +++ b/src/@open-adm/pages/financeiro/contas-a-receber/index.tsx @@ -3,6 +3,7 @@ import { formatMoney } from "src/@open-adm/utils/format-money"; import { StatusObj } from "../../pedidos/config"; import CustomChip, { StatusApp } from 'src/@open-adm/components/chip' import { formatDate } from "src/@open-adm/utils/convert-date"; +import { TableIndex } from "src/@open-adm/components/table-paginacao"; export const statusFatura: StatusObj = { 0: { title: 'Pendente', color: 'warning' }, @@ -13,47 +14,49 @@ export function ContasAReceberPaginacao() { return ( <> -
formatMoney(params.row.valor) + renderCell: (params: any) => formatMoney(params.valor), + sortable: true, }, { flex: 0.175, minWidth: 140, field: 'status', headerName: 'Status', - renderCell: (params) => { - const status = statusFatura[params.row.status] + renderCell: (params: any) => { + const status = statusFatura[params.status] return ( ) - } + }, + sortable: true, }, { flex: 0.200, field: 'vencimento', headerName: 'Vencimento', - renderCell: (params) => formatDate(params.row.dataDeVencimento) + renderCell: (params: any) => formatDate(params.dataDeVencimento), + sortable: true, }, ]} - title="Faturas contas a receber" - url="fatura-contas-a-receber/paginacao" - // add - // routeAdd="banners/create" - view - routeView="contas-a-receber/view" - edit - routeEdit="contas-a-receber/edit" + url="fatura/paginacao" + urlView="contas-a-receber/view" + urlEdit="contas-a-receber/edit" + filtroComplementar={{ + tipo: 1 + }} /> ) diff --git a/src/@open-adm/pages/lojas-parceiras/config.tsx b/src/@open-adm/pages/lojas-parceiras/config.tsx index 6d9da07..2fb8e20 100644 --- a/src/@open-adm/pages/lojas-parceiras/config.tsx +++ b/src/@open-adm/pages/lojas-parceiras/config.tsx @@ -11,10 +11,10 @@ export const columns: GridColDef[] = [ minWidth: 200, field: 'foto', headerName: 'Foto', - renderCell: (params: GridRenderCellParams) => ( + renderCell: (params: any) => ( ) @@ -23,22 +23,23 @@ export const columns: GridColDef[] = [ flex: 0.200, minWidth: 200, field: 'nome', - headerName: 'Nome' + headerName: 'Nome', + sortable: true, }, { flex: 0.200, minWidth: 200, field: 'contato', headerName: 'Contato', - renderCell: (params: GridRenderCellParams) => ( + renderCell: (params: any) => ( - {maskPhone(params.row.contato)} + {maskPhone(params.contato)} ) } ]; -export const defaultValues : ILojasParceiras = { +export const defaultValues: ILojasParceiras = { nome: "", id: "", dataDeCriacao: "", diff --git a/src/@open-adm/pages/lojas-parceiras/index.tsx b/src/@open-adm/pages/lojas-parceiras/index.tsx index 1878afe..ec572f8 100644 --- a/src/@open-adm/pages/lojas-parceiras/index.tsx +++ b/src/@open-adm/pages/lojas-parceiras/index.tsx @@ -1,23 +1,32 @@ -import Table from "src/@open-adm/components/table"; import { columns } from './config' +import { TableIndex } from "src/@open-adm/components/table-paginacao"; export function LojasParceirasPaginacao() { - return ( - <> -
- + ) + // return ( + // <> + //
+ // + // ) } \ No newline at end of file diff --git a/src/@open-adm/pages/pedidos/config.tsx b/src/@open-adm/pages/pedidos/config.tsx index 45e5a27..8d8c2ab 100644 --- a/src/@open-adm/pages/pedidos/config.tsx +++ b/src/@open-adm/pages/pedidos/config.tsx @@ -1,12 +1,32 @@ import { IconButton, Tooltip } from '@mui/material' -import { GridColDef, GridRenderCellParams } from '@mui/x-data-grid' +import { GridColDef } from '@mui/x-data-grid' import IconifyIcon from 'src/@core/components/icon' import { ThemeColor } from 'src/@core/layouts/types' import { StatusApp } from 'src/@open-adm/components/chip' import { useNavigateApp } from 'src/@open-adm/hooks/use-navigate-app' +import { useNewApi } from 'src/@open-adm/hooks/use-new-api' +import { generatePdfFromBase64 } from 'src/@open-adm/utils/download-pdf' export function useConfig() { const { navigate } = useNavigateApp(); + + async function downloadPedido(id: string) { + const api = useNewApi({ + method: 'GET', + url: 'pedidos/download-pedido?pedidoId=' + }); + const pdfBase64 = await api.fecth({ urlParams: `${id}` }); + if (pdfBase64?.pdf) { + const pdf = await generatePdfFromBase64(pdfBase64.pdf); + const link = document.createElement('a'); + link.href = pdf; + link.download = `${id}.pdf`; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + } + } + const columns: GridColDef[] = [ { flex: 0.200, @@ -19,8 +39,9 @@ export function useConfig() { width: 10, field: 'status', headerName: 'Status', - renderCell: (params: GridRenderCellParams) => { - const status = statusPedido[params.row.statusPedido] + sortable: true, + renderCell: (params: any) => { + const status = statusPedido[params.statusPedido] return ( { return ( - navigate(`/pedidos/modificar-status-pedido/${params.row.id}`)}> + navigate(`/pedidos/modificar-status-pedido/${params.id}`)}> @@ -45,6 +66,24 @@ export function useConfig() { ) } + }, + { + field: 'status3', + headerName: 'PDF', + align: 'center', + renderCell: (params: any) => { + return ( + + downloadPedido(params.id)} + > + + + + ) + } } ] diff --git a/src/@open-adm/pages/pedidos/index.tsx b/src/@open-adm/pages/pedidos/index.tsx index dc39563..8948d85 100644 --- a/src/@open-adm/pages/pedidos/index.tsx +++ b/src/@open-adm/pages/pedidos/index.tsx @@ -1,20 +1,65 @@ -import Table from "src/@open-adm/components/table"; +import { useState } from "react"; import { useConfig } from "./config"; +import { TableIndex } from "src/@open-adm/components/table-paginacao"; +import { RadioApp } from "src/@open-adm/components/radio"; export function Pedidos() { - + const [status, setStatus] = useState(0) const config = useConfig(); - + function filtro() { + return ( + { + if (typeof value === 'number') { + setStatus(value) + } else { + setStatus(parseInt(value)) + } + }} + /> + ) + } return ( -
0 ? status - 1 : undefined + }} + refreshPai={status} /> ) } \ No newline at end of file diff --git a/src/@open-adm/pages/vendas/cliente/config.tsx b/src/@open-adm/pages/vendas/cliente/config.tsx index af6a7c8..72e346d 100644 --- a/src/@open-adm/pages/vendas/cliente/config.tsx +++ b/src/@open-adm/pages/vendas/cliente/config.tsx @@ -6,19 +6,20 @@ export const columns = [ minWidth: 200, field: 'nome', headerName: 'Nome', + sortable: true, }, { flex: 0.200, minWidth: 200, field: 'telefone', headerName: 'Telefone', - renderCell: (params: any) => maskPhone(params.row?.telefone) + renderCell: (params: any) => maskPhone(params?.telefone) }, { flex: 0.200, minWidth: 200, field: 'cpf', headerName: 'CPF/CNPJ', - renderCell: (params: any) => params.row?.cpf ? maskCPF(params.row.cpf) : maskCNPJ(params.row?.cnpj) + renderCell: (params: any) => params?.cpf ? maskCPF(params.cpf) : maskCNPJ(params?.cnpj) }, ] \ No newline at end of file diff --git a/src/@open-adm/pages/vendas/cliente/index.tsx b/src/@open-adm/pages/vendas/cliente/index.tsx index ab55033..c1de85a 100644 --- a/src/@open-adm/pages/vendas/cliente/index.tsx +++ b/src/@open-adm/pages/vendas/cliente/index.tsx @@ -1,16 +1,13 @@ -import Table from "src/@open-adm/components/table"; import { columns } from "./config"; +import { TableIndex } from "src/@open-adm/components/table-paginacao"; export function ClientePaginacao() { return ( -
) } \ No newline at end of file diff --git a/src/@open-adm/pages/vendas/tabela-de-preco/index.tsx b/src/@open-adm/pages/vendas/tabela-de-preco/index.tsx index dab01f6..9dceb9f 100644 --- a/src/@open-adm/pages/vendas/tabela-de-preco/index.tsx +++ b/src/@open-adm/pages/vendas/tabela-de-preco/index.tsx @@ -1,21 +1,22 @@ import { Checkbox } from "@mui/material"; -import { GridColDef, GridRenderCellParams } from "@mui/x-data-grid"; -import Table from "src/@open-adm/components/table"; +import { GridColDef } from "@mui/x-data-grid"; +import { TableIndex } from "src/@open-adm/components/table-paginacao"; const columns: GridColDef[] = [ { flex: 0.200, minWidth: 200, field: 'descricao', - headerName: 'Descricao' + headerName: 'Descricao', + sortable: true, }, { flex: 0.200, minWidth: 200, field: 'ativaEcommerce', headerName: 'Ativa', - renderCell: (params: GridRenderCellParams) => ( - + renderCell: (params: any) => ( + ) } ] @@ -23,20 +24,12 @@ const columns: GridColDef[] = [ export function TabelaDePrecoIndex() { return ( - <> -
- + ) } \ No newline at end of file diff --git a/src/@open-adm/types/peso.ts b/src/@open-adm/types/peso.ts index daabde5..8fba71f 100644 --- a/src/@open-adm/types/peso.ts +++ b/src/@open-adm/types/peso.ts @@ -2,4 +2,5 @@ import { IBase } from "./base"; export interface IPeso extends IBase { descricao: string; + pesoReal?: number } \ No newline at end of file diff --git a/src/@open-adm/types/tamanho.ts b/src/@open-adm/types/tamanho.ts index ad82d91..1417bed 100644 --- a/src/@open-adm/types/tamanho.ts +++ b/src/@open-adm/types/tamanho.ts @@ -2,4 +2,5 @@ import { IBase } from "./base"; export interface ITamanho extends IBase { descricao: string + pesoReal?: number } \ No newline at end of file