Skip to content

Commit

Permalink
corrijo mensajes y guardados
Browse files Browse the repository at this point in the history
  • Loading branch information
mpvaldez committed Jun 4, 2024
1 parent 3ac4d46 commit efbf188
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 145 deletions.
12 changes: 5 additions & 7 deletions src/components/CRUD/caja/CU.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ClipLoader } from 'react-spinners';
import get from 'lodash/get';
import { useDispatch } from 'react-redux';
import { cajasActions } from '@/redux/actions/cajas';
import { toastr } from "react-redux-toastr";

import { cajas } from '@/utility/options/taxones';
import Spinner from '@/components/spinner';
Expand Down Expand Up @@ -64,12 +63,11 @@ const CU = ({ selected, onClose }) => {
await dispatch(cajasActions.send({
...values,
id: get(selected, 'id', null)
})).then(() => {
toastr.success('¡Listo! Guardado con éxito');
});
if (onClose) {
onClose(false);
}
})).then((response) => {
if (200 <= response.status < 300 && onClose) {
onClose(false);
}
})
} catch (error) {
console.error(error);
} finally {
Expand Down
20 changes: 8 additions & 12 deletions src/components/CRUD/cliente/CU.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as Yup from 'yup';
import { ClipLoader } from 'react-spinners';
import get from 'lodash/get';
import { useDispatch } from 'react-redux';
import { toastr } from "react-redux-toastr";

import { clientesActions } from '@/redux/actions/clientes';
import Spinner from '@/components/spinner';
Expand Down Expand Up @@ -50,11 +49,10 @@ const CU = ({ selected, onClose }) => {
razon_social: get(selected, 'perfil.razon_social', '') || '',
tipo_documento: get(selected, 'perfil.tipo_documento', ''),
numero_documento: get(selected, 'perfil.numero_documento', ''),
fecha_nacimiento: get(selected, 'perfil.fecha_nacimiento', ''),
es_extranjero: get(selected, 'perfil.es_extranjero', false),
mail: get(selected, 'perfil.mail', ''),
telefono: get(selected, 'perfil.telefono', ''),
domicilio_provincia: get(selected, 'perfil.domicilio.provincia', ''),
domicilio_provincia: get(selected, 'perfil.domicilio.provincia', null),
domicilio_localidad: get(selected, 'perfil.domicilio.localidad', ''),
domicilio_calle: get(selected, 'perfil.domicilio.calle', ''),
domicilio_numero: get(selected, 'perfil.domicilio.numero', ''),
Expand All @@ -65,11 +63,10 @@ const CU = ({ selected, onClose }) => {
razon_social: Yup.string(),
tipo_documento: Yup.string().required(empty),
numero_documento: Yup.number().required(empty),
fecha_nacimiento: Yup.date(),
es_extranjero: Yup.boolean(),
mail: Yup.string().email("Email invalido").required(empty),
mail: Yup.string().email("Email invalido").nullable(),
telefono: Yup.string(),
domicilio_provincia: Yup.string(),
domicilio_provincia: Yup.string().nullable(),
domicilio_localidad: Yup.string(),
domicilio_calle: Yup.string(),
domicilio_numero: Yup.string(),
Expand All @@ -81,12 +78,11 @@ const CU = ({ selected, onClose }) => {
await dispatch(clientesActions.send({
...values,
id: get(selected, 'id', null)
})).then(() => {
toastr.success('¡Listo! Guardado con éxito');
});
if (onClose) {
onClose(false);
}
})).then((response) => {
if (200 <= response.status < 300 && onClose) {
onClose(false);
}
})
} catch (error) {
console.error(error);
} finally {
Expand Down
12 changes: 5 additions & 7 deletions src/components/CRUD/gasto/CU.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ClipLoader } from 'react-spinners';
import get from 'lodash/get';
import { useDispatch } from 'react-redux';
import { gastosActions } from '@/redux/actions/gastos';
import { toastr } from "react-redux-toastr";

import Spinner from '@/components/spinner';
import { useTitulos } from '@/utility/hooks';
Expand Down Expand Up @@ -58,12 +57,11 @@ const CU = ({ selected, onClose }) => {
await dispatch(gastosActions.send({
...values,
id: get(selected, 'id', null)
})).then(() => {
toastr.success('¡Listo! Guardado con éxito');
});
if (onClose) {
onClose(false);
}
})).then((response) => {
if (200 <= response.status < 300 && onClose) {
onClose(false);
}
})
} catch (error) {
console.error(error);
} finally {
Expand Down
13 changes: 6 additions & 7 deletions src/components/CRUD/ingreso/CU.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ClipLoader } from 'react-spinners';
import get from 'lodash/get';
import { useDispatch } from 'react-redux';
import { ingresosActions } from '@/redux/actions/ingresos';
import { toastr } from "react-redux-toastr";


import Spinner from '@/components/spinner';
import { useTitulos } from '@/utility/hooks';
Expand Down Expand Up @@ -58,12 +58,11 @@ const CU = ({ selected, onClose }) => {
await dispatch(ingresosActions.send({
...values,
id: get(selected, 'id', null)
})).then(() => {
toastr.success('¡Listo! Guardado con éxito');
});
if (onClose) {
onClose(false);
}
})).then((response) => {
if (200 <= response.status < 300 && onClose) {
onClose(false);
}
})
} catch (error) {
console.error(error);
} finally {
Expand Down
18 changes: 7 additions & 11 deletions src/components/CRUD/proveedor/CU.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as Yup from 'yup';
import { ClipLoader } from 'react-spinners';
import get from 'lodash/get';
import { useDispatch } from 'react-redux';
import { toastr } from "react-redux-toastr";

import { proveedoresActions } from '@/redux/actions/proveedores';
import Spinner from '@/components/spinner';
Expand Down Expand Up @@ -50,11 +49,10 @@ const CU = ({ selected, onClose }) => {
razon_social: get(selected, 'perfil.razon_social', '') || '',
tipo_documento: get(selected, 'perfil.tipo_documento', ''),
numero_documento: get(selected, 'perfil.numero_documento', ''),
fecha_nacimiento: get(selected, 'perfil.fecha_nacimiento', ''),
es_extranjero: get(selected, 'perfil.es_extranjero', false),
mail: get(selected, 'perfil.mail', ''),
telefono: get(selected, 'perfil.telefono', ''),
provincia: get(selected, 'perfil.domicilio.provincia', ''),
provincia: get(selected, 'perfil.domicilio.provincia', null),
localidad: get(selected, 'perfil.domicilio.localidad', ''),
calle: get(selected, 'perfil.domicilio.calle', ''),
numero: get(selected, 'perfil.domicilio.numero', ''),
Expand All @@ -65,11 +63,10 @@ const CU = ({ selected, onClose }) => {
razon_social: Yup.string(),
tipo_documento: Yup.string().required(empty),
numero_documento: Yup.number().required(empty),
fecha_nacimiento: Yup.date().nullable(),
es_extranjero: Yup.boolean(),
mail: Yup.string().email("Email invalido").nullable(),
telefono: Yup.string(),
provincia: Yup.string(),
provincia: Yup.string().nullable(),
localidad: Yup.string(),
calle: Yup.string(),
numero: Yup.string(),
Expand All @@ -81,12 +78,11 @@ const CU = ({ selected, onClose }) => {
await dispatch(proveedoresActions.send({
...values,
id: get(selected, 'id', null)
})).then(() => {
toastr.success('¡Listo! Guardado con éxito');
});
if (onClose) {
onClose(false);
}
})).then((response) => {
if (200 <= response.status < 300 && onClose) {
onClose(false);
}
})
} catch (error) {
console.error(error);
} finally {
Expand Down
12 changes: 5 additions & 7 deletions src/components/CRUD/proyecto/CU.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ClipLoader } from 'react-spinners';
import get from 'lodash/get';
import { useDispatch } from 'react-redux';
import { proyectosActions } from '@/redux/actions/proyectos';
import { toastr } from "react-redux-toastr";


const CU = ({ selected, onClose }) => {
Expand All @@ -28,12 +27,11 @@ const CU = ({ selected, onClose }) => {
await dispatch(proyectosActions.send({
...values,
id: get(selected, 'id', null)
})).then(() => {
toastr.success('¡Listo! Guardado con éxito');
});
if (onClose) {
onClose(false);
}
})).then((response) => {
if (200 <= response.status < 300 && onClose) {
onClose(false);
}
})
} catch (error) {
console.error(error);
} finally {
Expand Down
12 changes: 5 additions & 7 deletions src/components/CRUD/titulo/CU.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ClipLoader } from 'react-spinners';
import get from 'lodash/get';
import { useDispatch } from 'react-redux';
import { titulosActions } from '@/redux/actions/titulos';
import { toastr } from "react-redux-toastr";
import { naturalezas } from './_options';

import Spinner from '@/components/spinner';
Expand Down Expand Up @@ -49,12 +48,11 @@ const CU = ({ selected, onClose }) => {
await dispatch(titulosActions.send({
...values,
id: get(selected, 'id', null)
})).then(() => {
toastr.success('¡Listo! Guardado con éxito');
});
if (onClose) {
onClose(false);
}
})).then((response) => {
if (200 <= response.status < 300 && onClose) {
onClose(false);
}
})
} catch (error) {
console.error(error);
} finally {
Expand Down
7 changes: 0 additions & 7 deletions src/redux/actions/cajas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ const send = (values) => async (dispatch) => {

if (values.id) {
response = await Service.put(apiEndpoint + values.id + '/', payload);
await dispatch(get_all());
return;
} else {
response = await Service.post(apiEndpoint, payload);
}
Expand All @@ -64,11 +62,6 @@ const send = (values) => async (dispatch) => {
type: 'POST_CAJA',
payload: response.data
});
response.result = 'success'
} else {
response = {
result: 'error'
}
}


Expand Down
44 changes: 7 additions & 37 deletions src/redux/actions/clientes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const select = client => ({
payload: client
});

const get_all = (force=false) => async (dispatch) => {
const get_all = () => async (dispatch) => {

const response = await Service.get(apiEndpoint);
if (response) {
Expand All @@ -39,28 +39,7 @@ const get_all = (force=false) => async (dispatch) => {
type: 'GET_CLIENTES',
payload: clientes
});

}
};

const get_client = (id) => async (dispatch) => {
const response = await Service.get(apiEndpoint + id);
if (response && response.data) {
const cliente = {
...response.data,
full_name: response.data.perfil.nombre
}

dispatch({
type: 'GET_CLIENTE',
payload: cliente
});

dispatch(select(cliente));
}

return response.data;

};

const send = (values) => async (dispatch) => {
Expand All @@ -73,7 +52,7 @@ const send = (values) => async (dispatch) => {
razon_social: values.razon_social,
tipo_documento: values.tipo_documento,
numero_documento: values.numero_documento,
fecha_nacimiento: values.fecha_nacimiento ? values.fecha_nacimiento : null,
fecha_nacimiento: null,
es_extranjero: values.es_extranjero,
mail: values.mail,
telefono: values.telefono,
Expand All @@ -90,25 +69,17 @@ const send = (values) => async (dispatch) => {

if (values.id) {
response = await Service.put(apiEndpoint + values.id + '/', payload);
await dispatch(get_all());
return;
}
} else {
response = await Service.post(apiEndpoint, payload);
}

response = await Service.post(apiEndpoint, payload);
if (response) {
await dispatch(get_all(true));
await dispatch(get_all());
await dispatch({
type: 'POST_CLIENTE',
payload: response.data
});
response.result = 'success'
} else {
response = {
result: 'error'
}
}


return response
};

Expand All @@ -121,7 +92,7 @@ const send_bulk = (values) => async (dispatch) => {
razon_social: x.razon_social,
tipo_documento: x.tipo_documento,
numero_documento: x.numero_documento,
fecha_nacimiento: x.fecha_nacimiento ? x.fecha_nacimiento : null,
fecha_nacimiento: null,
es_extranjero: x.es_extranjero,
mail: x.mail,
telefono: x.telefono,
Expand Down Expand Up @@ -151,7 +122,6 @@ const send_bulk = (values) => async (dispatch) => {

export const clientesActions = {
get_all,
get_client,
send,
send_bulk,
search,
Expand Down
7 changes: 0 additions & 7 deletions src/redux/actions/gastos/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ const send = (values) => async (dispatch) => {

if (values.id) {
response = await Service.put(apiEndpoint + values.id + '/', payload);
await dispatch(get_all());
return;
} else {
response = await Service.post(apiEndpoint, payload);
}
Expand All @@ -54,11 +52,6 @@ const send = (values) => async (dispatch) => {
type: 'POST_GASTO',
payload: response.data
});
response.result = 'success'
} else {
response = {
result: 'error'
}
}


Expand Down
7 changes: 0 additions & 7 deletions src/redux/actions/ingresos/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ const send = (values) => async (dispatch) => {

if (values.id) {
response = await Service.put(apiEndpoint + values.id + '/', payload);
await dispatch(get_all());
return;
} else {
response = await Service.post(apiEndpoint, payload);
}
Expand All @@ -56,11 +54,6 @@ const send = (values) => async (dispatch) => {
type: 'POST_INGRESO',
payload: response.data
});
response.result = 'success'
} else {
response = {
result: 'error'
}
}


Expand Down
Loading

0 comments on commit efbf188

Please sign in to comment.