summaryrefslogtreecommitdiffstats
path: root/front/odiparpack/app/components/Tables
diff options
context:
space:
mode:
authorgabrhr <[email protected]>2022-05-30 20:08:04 -0500
committergabrhr <[email protected]>2022-05-30 20:08:04 -0500
commit32fb17de8f78317b165b6f269a8bab2d4e852d0d (patch)
tree2de1643fcda13cc5c9c0f28ffcb7a7211d9e2922 /front/odiparpack/app/components/Tables
parent9c396976bb42a9d41407358ce1a1d37242230f21 (diff)
downloadDP1_project-32fb17de8f78317b165b6f269a8bab2d4e852d0d.tar.gz
DP1_project-32fb17de8f78317b165b6f269a8bab2d4e852d0d.tar.bz2
DP1_project-32fb17de8f78317b165b6f269a8bab2d4e852d0d.zip
Fix axios and add new
- FIX logica de añadiir (ok) - FIX axios y dispatch fuera de un componente (ok) - Cambiar las notificaciones
Diffstat (limited to 'front/odiparpack/app/components/Tables')
-rw-r--r--front/odiparpack/app/components/Tables/CrudTableForm.js36
-rw-r--r--front/odiparpack/app/components/Tables/tableParts/Form.js4
-rw-r--r--front/odiparpack/app/components/Tables/tableParts/MainTableForm.js4
-rw-r--r--front/odiparpack/app/components/Tables/tableParts/RowReadOnly.js17
4 files changed, 51 insertions, 10 deletions
diff --git a/front/odiparpack/app/components/Tables/CrudTableForm.js b/front/odiparpack/app/components/Tables/CrudTableForm.js
index 219fcd2..0ba5264 100644
--- a/front/odiparpack/app/components/Tables/CrudTableForm.js
+++ b/front/odiparpack/app/components/Tables/CrudTableForm.js
@@ -5,15 +5,39 @@ import MainTableForm from './tableParts/MainTableForm';
import FloatingPanel from './../Panel/FloatingPanel';
class CrudTableForm extends React.Component {
- componentDidMount() {
- console.log("en el FORM",this.props.dataInit)
- this.props.fetchData(this.props.dataInit, this.props.branch);
+
+ componentDidUpdate(previousProps) {
+ if (previousProps.dataInit !== this.props.dataInit) {
+ //console.log("en el FORM",this.props.dataInit)
+ this.props.fetchData(this.props.dataInit, this.props.branch);
+ }
}
sendValues = (values) => {
setTimeout(() => {
this.props.submit(values, this.props.branch);
}, 500);
+ if (this.props.editingId === this.props.initValues.get('id')) {
+ this.props.dispatch(this.props.editRowAPI()).then((res) => {
+ if (res) {
+ console.log("EDIT RO ", res)
+ }
+ })
+ } else {
+ this.props.dispatch(this.props.addNewAPI()).then((res) => {
+ if (res) {
+ console.log("ADD NEW FORM ", res)
+ }
+ })
+ }
+
+ }
+
+ getTitle( ){
+ if (this.props.editingId === this.props.initValues.get(this.props.anchor[0].name)) {
+ return "Editar"
+ }
+ return "Añadir nuevo"
}
render() {
@@ -28,12 +52,13 @@ class CrudTableForm extends React.Component {
anchor,
children,
branch,
- initValues
+ initValues,
+ removeRowAPI
} = this.props;
return (
<div>
- <FloatingPanel openForm={openForm} branch={branch} closeForm={closeForm}>
+ <FloatingPanel openForm={openForm} branch={branch} closeForm={closeForm} title = {this.getTitle()}>
<Form onSubmit={this.sendValues} initValues={initValues} branch={branch}>
{children}
</Form>
@@ -46,6 +71,7 @@ class CrudTableForm extends React.Component {
editRow={editRow}
anchor={anchor}
branch={branch}
+ removeRowAPI={removeRowAPI}
/>
</div>
);
diff --git a/front/odiparpack/app/components/Tables/tableParts/Form.js b/front/odiparpack/app/components/Tables/tableParts/Form.js
index da66966..66188c7 100644
--- a/front/odiparpack/app/components/Tables/tableParts/Form.js
+++ b/front/odiparpack/app/components/Tables/tableParts/Form.js
@@ -31,14 +31,14 @@ class Form extends Component {
</section>
<div className={css.buttonArea}>
<Button variant="contained" color="secondary" type="submit" disabled={submitting}>
- Submit
+ Guardar
</Button>
<Button
type="button"
disabled={pristine || submitting}
onClick={reset}
>
- Reset
+ Limpiar
</Button>
</div>
</form>
diff --git a/front/odiparpack/app/components/Tables/tableParts/MainTableForm.js b/front/odiparpack/app/components/Tables/tableParts/MainTableForm.js
index 8869212..1437fa8 100644
--- a/front/odiparpack/app/components/Tables/tableParts/MainTableForm.js
+++ b/front/odiparpack/app/components/Tables/tableParts/MainTableForm.js
@@ -29,7 +29,8 @@ class MainTableForm extends React.Component {
editRow,
addNew,
anchor,
- branch
+ branch,
+ removeRowAPI
} = this.props;
const getItems = dataArray => dataArray.map(item => (
<RowReadOnly
@@ -39,6 +40,7 @@ class MainTableForm extends React.Component {
editRow={() => editRow(item, branch)}
anchor={anchor}
branch={branch}
+ removeRowAPI = {removeRowAPI}
/>
));
diff --git a/front/odiparpack/app/components/Tables/tableParts/RowReadOnly.js b/front/odiparpack/app/components/Tables/tableParts/RowReadOnly.js
index 2f4a519..d060d02 100644
--- a/front/odiparpack/app/components/Tables/tableParts/RowReadOnly.js
+++ b/front/odiparpack/app/components/Tables/tableParts/RowReadOnly.js
@@ -8,6 +8,7 @@ import EditIcon from '@material-ui/icons/BorderColor';
import { etiqueta } from 'ba-components/Odipar/common';
import { TableCell, IconButton, LinearProgress } from '@material-ui/core';
+import { connect } from 'react-redux';
const styles = theme => ({
button: {
@@ -23,10 +24,16 @@ class RowReadOnly extends React.Component {
item,
removeRow,
editRow,
- branch
+ branch,
+ removeRowAPI
} = this.props;
const eventDel = () => {
removeRow(item, branch);
+ this.props.dispatch(removeRowAPI()).then((res) => {
+ if (res) {
+ console.log("REMOVE READ ONLY ", res)
+ }
+ })
};
const eventEdit = () => {
editRow(item, branch);
@@ -86,5 +93,11 @@ RowReadOnly.propTypes = {
editRow: PropTypes.func.isRequired,
branch: PropTypes.string.isRequired,
};
+const mapDispatchToProps = dispatch => ({
+ dispatch
+});
-export default withStyles(styles)(RowReadOnly);
+const RowReadOnlyMapped = connect(
+ mapDispatchToProps
+)(RowReadOnly);
+export default withStyles(styles)(RowReadOnlyMapped);