Skip to content

Commit

Permalink
iniciado meio de pagamento e frete
Browse files Browse the repository at this point in the history
  • Loading branch information
Brunobento1990 committed Oct 21, 2024
1 parent a339146 commit fc3e5b7
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 31 deletions.
76 changes: 62 additions & 14 deletions src/@open-adm/pages/configuracao/frete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IConfiguracaoDeFrete>({
initialValues,
validationSchema: schema,
onSubmit: submit
Expand All @@ -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")
}
}

Expand Down Expand Up @@ -108,7 +107,7 @@ export function ConfiguracaoDeFrete() {
<Grid item xs={12} sm={6}>
<InputCustom
fullWidth
label='Peso (kg)'
label='Peso (gr)'
name='peso'
id='peso'
value={form.values.peso}
Expand All @@ -117,6 +116,55 @@ export function ConfiguracaoDeFrete() {
type="number"
/>
</Grid>
<Grid item xs={12} sm={6}>
<InputCustom
fullWidth
label='Chave api'
name='chaveApi'
id='chaveApi'
value={form.values.chaveApi}
onBlur={form.onBlur}
onChange={form.onChange}
/>
</Grid>
</Grid>
<Grid container spacing={6}>
<Grid item xs={12} sm={4}>
<FormControlLabel
label='Cobrar de CPF'
control={
<Checkbox
checked={form.values.cobrarCpf ?? false}
onChange={e => form.setValue({
cobrarCpf: e.target.checked
})} />
}
/>
</Grid>
<Grid item xs={12} sm={4}>
<FormControlLabel
label='Cobrar de CNPJ'
control={
<Checkbox
checked={form.values.cobrarCnpj ?? false}
onChange={e => form.setValue({
cobrarCnpj: e.target.checked
})} />
}
/>
</Grid>
<Grid item xs={12} sm={4}>
<FormControlLabel
label='Inativar'
control={
<Checkbox
checked={form.values.inativo ?? false}
onChange={e => form.setValue({
inativo: e.target.checked
})} />
}
/>
</Grid>
</Grid>
</Form>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IConfiguracaoDeFrete | undefined> {
return await apiCreate.fecth<IConfiguracaoDeFrete>({
body
body,
message: "Registro atualizado com sucesso!"
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IConfiguracaoPagamentoMercadoPago>)
: Promise<IConfiguracaoPagamentoMercadoPago | undefined> {
return created.fecth<IConfiguracaoPagamentoMercadoPago>({
body: config
body: config,
message: 'Registro editado com sucesso!'
});
}

Expand Down
9 changes: 3 additions & 6 deletions src/@open-adm/pages/configuracao/mercado-pago/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
15 changes: 10 additions & 5 deletions src/@open-adm/types/configuracao-de-frete.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
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 {
cepOrigem: string,
alturaEmbalagem: string,
larguraEmbalagem: string,
comprimentoEmbalagem: string,
peso?: number
chaveApi: string,
peso?: number,
cobrarCpf?: boolean,
cobrarCnpj?: boolean,
inativo?: boolean
}

0 comments on commit fc3e5b7

Please sign in to comment.