diff --git a/src/@open-adm/pages/configuracao/frete/index.tsx b/src/@open-adm/pages/configuracao/frete/index.tsx index a9e27b4..a6c78c7 100644 --- a/src/@open-adm/pages/configuracao/frete/index.tsx +++ b/src/@open-adm/pages/configuracao/frete/index.tsx @@ -3,11 +3,14 @@ import { initialValues, schema } from "./config" import { useApiConfiguracaoDeFrete } from "./use-api-configuracao-de-frete"; import { useEffect } from "react"; import { Form } from "src/@open-adm/components/form"; -import { Grid } from "@mui/material"; +import { Checkbox, FormControlLabel, Grid } from "@mui/material"; import { InputCustom } from "src/@open-adm/components/input"; +import { useNavigateApp } from "src/@open-adm/hooks/use-navigate-app"; +import { IConfiguracaoDeFrete } from "src/@open-adm/types/configuracao-de-frete"; export function ConfiguracaoDeFrete() { - const form = useFormikAdapter({ + const { navigate } = useNavigateApp(); + const form = useFormikAdapter({ initialValues, validationSchema: schema, onSubmit: submit @@ -16,21 +19,17 @@ export function ConfiguracaoDeFrete() { const { get, create } = useApiConfiguracaoDeFrete(); async function init() { - try { - const response = await get(); - if (response) { - form.setValue(response); - } - } catch (error) { - + const response = await get(); + if (response) { + form.setValue(response); } + } async function submit(values: any) { - try { - await create(values); - } catch (error) { - + const response = await create(values); + if (response) { + navigate("/home") } } @@ -108,7 +107,7 @@ export function ConfiguracaoDeFrete() { + + + + + + + form.setValue({ + cobrarCpf: e.target.checked + })} /> + } + /> + + + form.setValue({ + cobrarCnpj: e.target.checked + })} /> + } + /> + + + form.setValue({ + inativo: e.target.checked + })} /> + } + /> + ); diff --git a/src/@open-adm/pages/configuracao/frete/use-api-configuracao-de-frete.tsx b/src/@open-adm/pages/configuracao/frete/use-api-configuracao-de-frete.tsx index 22a4400..821b9b6 100644 --- a/src/@open-adm/pages/configuracao/frete/use-api-configuracao-de-frete.tsx +++ b/src/@open-adm/pages/configuracao/frete/use-api-configuracao-de-frete.tsx @@ -4,19 +4,20 @@ import { IConfiguracaoDeFrete, IConfiguracaoDeFreteCreate } from "src/@open-adm/ export function useApiConfiguracaoDeFrete() { const apiCreate = useNewApi({ method: 'POST', - url: 'configuracao-de-frete' + url: 'configuracao-de-frete/create-or-update' }); const apiGet = useNewApi({ method: 'GET', - url: 'configuracao-de-frete', + url: 'configuracao-de-frete/get', notAlert: true, notLoading: true }); async function create(body: IConfiguracaoDeFreteCreate): Promise { return await apiCreate.fecth({ - body + body, + message: "Registro atualizado com sucesso!" }); } diff --git a/src/@open-adm/pages/configuracao/mercado-pago/api-mercado-pago.tsx b/src/@open-adm/pages/configuracao/mercado-pago/api-mercado-pago.tsx index ff1566c..1037743 100644 --- a/src/@open-adm/pages/configuracao/mercado-pago/api-mercado-pago.tsx +++ b/src/@open-adm/pages/configuracao/mercado-pago/api-mercado-pago.tsx @@ -5,19 +5,20 @@ export function apiMercadoPago() { const created = useNewApi({ method: "POST", - url: "pagamento/configuracao-pagamento-mercado-pago/create-or-update", + url: "configuracao-de-pagamento/create-or-update", }) const get = useNewApi({ method: "GET", - url: "pagamento/configuracao-pagamento-mercado-pago/get", + url: "configuracao-de-pagamento/get", notAlert: true, }) async function cretarOrUpdate(config: Partial) : Promise { return created.fecth({ - body: config + body: config, + message: 'Registro editado com sucesso!' }); } diff --git a/src/@open-adm/pages/configuracao/mercado-pago/index.tsx b/src/@open-adm/pages/configuracao/mercado-pago/index.tsx index 5165682..0ea0b89 100644 --- a/src/@open-adm/pages/configuracao/mercado-pago/index.tsx +++ b/src/@open-adm/pages/configuracao/mercado-pago/index.tsx @@ -17,12 +17,9 @@ export function MercadoPago() { }); async function init() { - try { - const response = await getConfig(); - if (response) { - form.setValue(response); - } - } catch (error) { + const response = await getConfig(); + if (response) { + form.setValue(response); } } diff --git a/src/@open-adm/types/configuracao-de-frete.ts b/src/@open-adm/types/configuracao-de-frete.ts index 2983545..f646df1 100644 --- a/src/@open-adm/types/configuracao-de-frete.ts +++ b/src/@open-adm/types/configuracao-de-frete.ts @@ -1,13 +1,14 @@ export interface IConfiguracaoDeFrete { id: string, - dataDeCriacao: string, - dataDeAtualizacao: string, - numero: number, cepOrigem: string, alturaEmbalagem: string, larguraEmbalagem: string, comprimentoEmbalagem: string, - peso?: number + chaveApi: string, + peso?: number, + cobrarCpf?: boolean, + cobrarCnpj?: boolean, + inativo?: boolean } export interface IConfiguracaoDeFreteCreate { @@ -15,5 +16,9 @@ export interface IConfiguracaoDeFreteCreate { alturaEmbalagem: string, larguraEmbalagem: string, comprimentoEmbalagem: string, - peso?: number + chaveApi: string, + peso?: number, + cobrarCpf?: boolean, + cobrarCnpj?: boolean, + inativo?: boolean } \ No newline at end of file