From 9c396976bb42a9d41407358ce1a1d37242230f21 Mon Sep 17 00:00:00 2001 From: gabrhr <73925454+gabrhr@users.noreply.github.com> Date: Fri, 27 May 2022 12:50:13 -0500 Subject: Add redux, dispatch and etiquetas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - estetica de etiquetas (ok) - add message, pedido Reducer - add dispatch en Componentes con connect - add api reducer que obtienen el JSON todo ok #TODO - FIX logica de añadiir - FIX axios y dispatch fuera de un componente --- front/odiparpack/app/utils/odipar/api.js | 113 +++++++++++++++++++++++++ front/odiparpack/app/utils/odipar/constants.js | 9 ++ front/odiparpack/app/utils/odipar/menu.js | 51 +++++++++++ 3 files changed, 173 insertions(+) create mode 100644 front/odiparpack/app/utils/odipar/api.js create mode 100644 front/odiparpack/app/utils/odipar/constants.js create mode 100644 front/odiparpack/app/utils/odipar/menu.js (limited to 'front/odiparpack/app/utils') diff --git a/front/odiparpack/app/utils/odipar/api.js b/front/odiparpack/app/utils/odipar/api.js new file mode 100644 index 0000000..ea5e617 --- /dev/null +++ b/front/odiparpack/app/utils/odipar/api.js @@ -0,0 +1,113 @@ +import Axios from 'axios' +import {apiUrl} from './constants'; +import qs from "query-string"; +import { openSuccessMessage, openErrorMessage } from 'ba-actions/message'; + +export function getHeaders() { + let session = getSession(); + return { + //Authorization: `Token ${(session && session.accessToken) || null}` + } +} + + +export function getSession() { + if (window && window.localStorage) { + return window.localStorage.getObject('session'); + } + + return null; +} + +export function saveSession(value) { + if (window && window.localStorage) { + return window.localStorage.saveObject('session', value); + } + + return null; +} + +export function apiReq(endPoint, data, method, headers, requestOptions = {}) { + return new Promise((res, rej) => { + + headers = { + ...headers + } + if (method === 'get' || method === 'delete') { + data = { + ...requestOptions, + params: data, + paramsSerializer: function (params) { + return qs.stringify(params, { arrayFormat: 'repeat' }) + }, + headers + } + } + + Axios[method](endPoint, data, { headers }).then((result) => { + let { data } = result; + console.log("aca en la promesa ps") + if (data.status === false) { + return rej(data); + } + + return res(data); + }).catch((err) => { + return rej(err); + }); + }) +} + +export function generateUrl(path) { + return apiUrl + path; +} + +export function apiPost(endPoint, data, headers = {}) { + return apiReq(generateUrl(endPoint), data, 'post', headers); +} + +export function apiDelete(endPoint, data, headers = {}) { + return apiReq(generateUrl(endPoint), data, 'delete', headers); +} + +export function apiGet(endPoint, data, headers = {}, requestOptions) { + return apiReq(generateUrl(endPoint), data, 'get', headers, requestOptions); +} + +export function apiPut(endPoint, data, headers = {}) { + return apiReq(generateUrl(endPoint), data, 'put', headers); +} + + +export function addMessageCurry(promise, dispatch, errorMsg = '', successMsg = '', showError = true) { + return new Promise( + (resolve, reject) => { + + promise + .then(response => { + + if (successMsg) { + console.log("mensajitooooo=?????") + dispatch( + openSuccessMessage(successMsg) + ) + } + + resolve(response) + }) + .catch( + err => { + if(showError) { + dispatch( + openErrorMessage(errorMsg || ((err.response && err.response.data.message) || 'Server encountered an error')) + ) + } + + reject(err) + } + ) + + } + ) + +} \ No newline at end of file diff --git a/front/odiparpack/app/utils/odipar/constants.js b/front/odiparpack/app/utils/odipar/constants.js new file mode 100644 index 0000000..73f3521 --- /dev/null +++ b/front/odiparpack/app/utils/odipar/constants.js @@ -0,0 +1,9 @@ +//export const apiUrl = `${config.api}api/v1/`; +export const apiUrl = 'http://localhost:8083/'; + +//mensaje +export function partial(fn, ...presetArgs) { + return function partiallyApplied(...laterArgs) { + return fn(...presetArgs, ...laterArgs); + }; +} \ No newline at end of file diff --git a/front/odiparpack/app/utils/odipar/menu.js b/front/odiparpack/app/utils/odipar/menu.js new file mode 100644 index 0000000..eca2600 --- /dev/null +++ b/front/odiparpack/app/utils/odipar/menu.js @@ -0,0 +1,51 @@ +module.exports = [ + { + key: 'seguimiento', + name: 'Seguimiento', + icon: 'near_me', + link: '/app/dashboard-v2', + child: [ ] + }, + { + key: 'pedidos', + name: 'Pedidos', + icon: 'inventory_2', + link: '/app/pedidos', + child: [ ] + }, + { + key: 'camiones', + name: 'Camiones', + icon: 'local_shipping', + link: '/app/layouts/grid', + child: [ ] + }, + { + key: 'almacenes', + name: 'Almacenes', + icon: 'warehouse', + link: '/app/tables/crud-table', + child: [ ] + }, + { + key: 'red_tramos', + name: 'Red de Tramos', + icon: 'location_on', + link: '/app/forms/reduxform', + child: [ ] + }, + { + key: 'otros', + name: 'Otros parámetros', + icon: 'settings', + link: '/app/ui/icons', + child: [ ] + }, + { + key: 'simulacion', + name: 'Simulación', + icon: 'fast_forward', + link: '/app/pages/calendar', + child: [ ] + } + ]; \ No newline at end of file -- cgit v1.2.3 From 32fb17de8f78317b165b6f269a8bab2d4e852d0d Mon Sep 17 00:00:00 2001 From: gabrhr <73925454+gabrhr@users.noreply.github.com> Date: Mon, 30 May 2022 20:08:04 -0500 Subject: Fix axios and add new MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FIX logica de añadiir (ok) - FIX axios y dispatch fuera de un componente (ok) - Cambiar las notificaciones --- front/odiparpack/app/utils/odipar/api.js | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'front/odiparpack/app/utils') diff --git a/front/odiparpack/app/utils/odipar/api.js b/front/odiparpack/app/utils/odipar/api.js index ea5e617..50c2beb 100644 --- a/front/odiparpack/app/utils/odipar/api.js +++ b/front/odiparpack/app/utils/odipar/api.js @@ -1,4 +1,4 @@ -import Axios from 'axios' +import axios from 'axios' import {apiUrl} from './constants'; import qs from "query-string"; import { openSuccessMessage, openErrorMessage } from 'ba-actions/message'; @@ -28,8 +28,7 @@ export function saveSession(value) { } export function apiReq(endPoint, data, method, headers, requestOptions = {}) { - return new Promise((res, rej) => { - + //console.log("apiReq - ANTES DE PROMESA") headers = { ...headers } @@ -44,18 +43,7 @@ export function apiReq(endPoint, data, method, headers, requestOptions = {}) { } } - Axios[method](endPoint, data, { headers }).then((result) => { - let { data } = result; - console.log("aca en la promesa ps") - if (data.status === false) { - return rej(data); - } - - return res(data); - }).catch((err) => { - return rej(err); - }); - }) + return axios[method](endPoint, data, { headers }) } export function generateUrl(path) { @@ -87,7 +75,7 @@ export function addMessageCurry(promise, dispatch, errorMsg = '', successMsg = ' .then(response => { if (successMsg) { - console.log("mensajitooooo=?????") + console.log("addMessageCurry -SUCCESS MSG") dispatch( openSuccessMessage(successMsg) ) -- cgit v1.2.3 From cbc7d7f7494508fda69e88c76702a878bebca0e2 Mon Sep 17 00:00:00 2001 From: gabrhr <73925454+gabrhr@users.noreply.github.com> Date: Tue, 31 May 2022 03:58:23 -0500 Subject: Add Almacenes - todo de almacenes, redux, pagina - mejoro form de pedido (etiqueta estado, RUC) #TODO - Ver combobox con API --- front/odiparpack/app/utils/odipar/menu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'front/odiparpack/app/utils') diff --git a/front/odiparpack/app/utils/odipar/menu.js b/front/odiparpack/app/utils/odipar/menu.js index eca2600..1b280b8 100644 --- a/front/odiparpack/app/utils/odipar/menu.js +++ b/front/odiparpack/app/utils/odipar/menu.js @@ -24,7 +24,7 @@ module.exports = [ key: 'almacenes', name: 'Almacenes', icon: 'warehouse', - link: '/app/tables/crud-table', + link: '/app/almacenes', child: [ ] }, { -- cgit v1.2.3