Skip to content

Commit

Permalink
feature criar pedido pelo admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunobento1990 committed Dec 28, 2024
1 parent 7666f1c commit c170180
Show file tree
Hide file tree
Showing 15 changed files with 427 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/@open-adm/adapters/formik-adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function useFormikAdapter<T = any>(props: propsUseFormikAdapter) {
onSubmit: props.onSubmit,
});

function setValue(value: any) {
function setValue(value: Partial<T>) {
formik.setValues({
...formik.values,
...value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { useNewApi } from "src/@open-adm/hooks/use-new-api";
import { IAtualizarStatusPedido, IPedido } from "src/@open-adm/types/pedido";
import { useNewApi } from "../hooks/use-new-api";
import { IAtualizarStatusPedido, IPedido, IPedidoCreate } from "../types/pedido";

export function useApiPedido() {
const apiCreateAdm = useNewApi({
method: 'POST',
url: 'pedidos-adm/create'
})

const apiGet = useNewApi({
method: 'GET',
url: 'pedidos/get?pedidoId=',
Expand All @@ -22,7 +27,12 @@ export function useApiPedido() {
return await apiAtualizarStatus.fecth({ body })
}

async function criarPedido(body: IPedidoCreate): Promise<any> {
return await apiCreateAdm.fecth({ body })
}

return {
criarPedido,
get,
atualizarStatus
}
Expand Down
18 changes: 18 additions & 0 deletions src/@open-adm/api/UseApiTabelaDePreco.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useNewApi } from '../hooks/use-new-api'
import { ITabelaDePreco } from 'src/@open-adm/types/tabela-de-preco'

export function useApiTabelaDePreco() {
const apiTabelaDePrecoPadraoEcommerce = useNewApi({
method: 'GET',
url: 'tabelas-de-precos/get-tabela-ativa',
notAlert: true
})

async function tabelaDePrecoEcommerce(): Promise<ITabelaDePreco | undefined> {
return await apiTabelaDePrecoPadraoEcommerce.fecth()
}

return {
tabelaDePrecoEcommerce
}
}
3 changes: 2 additions & 1 deletion src/@open-adm/components/divider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ interface propsDividerApp {
chip?: string;
marginTop?: string;
marginBotton?: string;
color?: "primary" | "secondary" | "error" | "info" | "success" | "warning";
}

export function DividerApp(props: propsDividerApp) {
if (props.chip) {
return (
<Divider sx={{ marginTop: props.marginTop ?? '10px', marginBottom: props.marginBotton }}>
<Chip label={props.chip} size="small" />
<Chip color={props.color} label={props.chip} size="small" />
</Divider>
)
}
Expand Down
11 changes: 10 additions & 1 deletion src/@open-adm/components/drop-down-scroll/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,19 @@ export function DropDownScroll(props: propsDropDownScroll) {
search
}
});
if (newItems) {
if (Array.isArray(newItems)) {
setOptions(newItems);
if (props.retornarObjetoCompleto) {
setOpcoesOriginais(newItems);
}
}

if (Array.isArray(newItems?.values)) {
setOptions(newItems?.values);
if (props.retornarObjetoCompleto) {
setOpcoesOriginais(newItems?.values);
}
}
}

function getLabel(value: any) {
Expand Down Expand Up @@ -95,6 +102,8 @@ export function DropDownScroll(props: propsDropDownScroll) {
<Autocomplete
open={open}
id={props.id}
loadingText='Carregando...'
noOptionsText='Sem registros'
disabled={props.readonly}
size='small'
value={
Expand Down
6 changes: 3 additions & 3 deletions src/@open-adm/components/table-paginacao/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ export function TablePaginacao(props: propsTable) {
}s linear alternate`,
}}
>
{props.columns.map((column, index) => (
{props.columns.map((column, i) => (
<TableCell
align={column.align}
key={index}
key={i}
width={column.width}
>
{column.renderCell && !column?.pesquisar ? (
column.renderCell(row)
column.renderCell(row, index)
) : (
row[column.field]
)}
Expand Down
68 changes: 68 additions & 0 deletions src/@open-adm/pages/pedidos/create/config.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { IconButton } from "@mui/material";
import IconifyIcon from "src/@core/components/icon";
import { YupAdapter } from "src/@open-adm/adapters/yup-adapter";
import { IItemPedidoCreate, IPedidoCreate } from "src/@open-adm/types/pedido";
import { formatMoney } from "src/@open-adm/utils/format-money";
import { listaIcones } from "src/configs/listaIcones";

export const initialValues: IPedidoCreate = {
usuarioId: "",
usuario: undefined!,
itens: [],
tabelaDePrecoId: "",
tabelaDePreco: undefined!
}

export const schema = new YupAdapter()
.string('usuarioId')
.string('tabelaDePrecoId', 'Selecione a tabela de preço')
.build();

interface propsConfig {
remove: (index: number) => void;
}

export function config(props: propsConfig) {
const coluns = [
{
field: 'descricao',
headerName: 'Descricao',
renderCell: (item: IItemPedidoCreate) => item.produto?.descricao
},
{
field: 'peso',
headerName: 'Peso',
renderCell: (item: IItemPedidoCreate) => item.peso?.descricao
},
{
field: 'tamanho',
headerName: 'Tamanho',
renderCell: (item: IItemPedidoCreate) => item.tamanho?.descricao
},
{
field: 'quantidade',
headerName: 'Qtd',
renderCell: (item: IItemPedidoCreate) => item.quantidade
},
{
field: 'valorUnitario',
headerName: 'Vlr',
renderCell: (item: IItemPedidoCreate) => formatMoney(item.valorUnitario)
},
{
field: 'excluir',
headerName: 'Excluir',
renderCell: (_: any, i: number) => {
return (
<IconButton>
<IconifyIcon icon={listaIcones.delete} onClick={() => props.remove(i)} />
</IconButton>
)
}
},
]

return {
coluns
}
}
Loading

0 comments on commit c170180

Please sign in to comment.