Fixes/overall (#67)

* Update: remove autofocus
* Update: Breadcrumbs functionality
* Update: removed validation for attributes
* Update: Field name
* Update: warehouse setup breadcrumbs
* Update: Inventory setup breadcrumbs
* Added: delete button to nested table

Co-authored-by: Llewellyn Dsouza <lledsouza2209@gmail.com>
This commit is contained in:
bluestreamlds
2022-02-27 17:29:25 +05:30
committed by GitHub
parent 72f7297355
commit b3d7b0344a
4 changed files with 78 additions and 83 deletions

View File

@@ -29,6 +29,7 @@ import { getColorOfLocationType } from 'utils/nestedTableTools';
import { toTitleCase } from 'utils/nestedTableTools';
import WarehouseLocationsActions from 'redux/WarehouseLocationsRedux';
import { getAPIslugOfLocationType } from 'utils/nestedTableTools';
import { API } from 'constant';
function NestedDataTable({ data, selected, setSelected, populateChildren }) {
const dispatch = useDispatch();
@@ -137,6 +138,35 @@ function NestedDataTable({ data, selected, setSelected, populateChildren }) {
<Grid item xs>
{data.specs}
</Grid>
<Grid item xs={1}>
<MDButton
size="small"
variant="contained"
color="error"
sx={{
textTransform: 'capitalize',
minWidth: '45px',
minHeight: '28px',
marginLeft: '5px',
marginRight: '20px',
boxShadow: 'none',
fontWeight: '500',
padding: '0 6'
}}
onClick={() => {
dispatch(
WarehouseLocationsActions.deleteLocationRequest({
loader: 'location-request',
slug: API.LOCATION_DELETE,
method: 'post',
data: { type: data.location, id: data.id }
})
);
}}
>
DELETE
</MDButton>
</Grid>
</Grid>
</Grid>
{open && children ? (

View File

@@ -12,5 +12,6 @@ export default {
ADD_NEW_LEVEL: '/level',
ADD_NEW_SUBLEVEL: '/sublevel',
ADD_PRODUCT: '/item/',
ADD_INVENTORY: '/inventory'
ADD_INVENTORY: '/inventory',
LOCATION_DELETE: '/dashboard/delete-location'
};

View File

@@ -11,7 +11,8 @@ const { Types, Creators } = createActions({
locationSuccess: ['data'],
locationFailure: ['error'],
addLocationRequest: ['payload'],
editLocationRequest: ['payload']
editLocationRequest: ['payload'],
deleteLocationRequest: ['payload']
});
export const WarehouseLocationsTypes = Types;
@@ -53,7 +54,7 @@ const mapResponseToNestedTable = (stateData, childData) => {
location: childData.child.type,
parentId: childData.child.parentId
}));
} else {
} else if (!childData.deleted) {
// created
newChildren = childData?.childrenData.map((child) => ({
...child,
@@ -63,11 +64,15 @@ const mapResponseToNestedTable = (stateData, childData) => {
}));
}
const idsInNewChildren = newChildren.map((st) => st.id);
if (childData.deleted) {
return stateData.filter((x) => x.id !== childData?.deleted?.id);
} else {
const idsInNewChildren = newChildren.map((st) => st.id);
const newState = stateData.filter((st) => !idsInNewChildren.includes(st.id));
const newState = stateData.filter((st) => !idsInNewChildren.includes(st.id));
return [...newState, ...newChildren];
return [...newState, ...newChildren];
}
};
export const onLocationSuccess = (state, { data }) => {
@@ -96,86 +101,18 @@ export const onEditLocationRequest = (state, { payload }) =>
error: getErrorValue(state?.error, payload?.loader)
});
export const onDeleteLocationRequest = (state, { payload }) =>
state.merge({
fetching: _.uniq([...state.fetching, payload?.loader]),
error: getErrorValue(state?.error, payload?.loader)
});
/* ------------- Hookup Reducers To Types ------------- */
export const WarehouseLocationsReducer = createReducer(INITIAL_STATE, {
[Types.LOCATION_REQUEST]: onLocationRequest,
[Types.LOCATION_SUCCESS]: onLocationSuccess,
[Types.LOCATION_FAILURE]: onLocationFailure,
[Types.ADD_LOCATION_REQUEST]: onAddLocationRequest,
[Types.EDIT_LOCATION_REQUEST]: onEditLocationRequest
[Types.EDIT_LOCATION_REQUEST]: onEditLocationRequest,
[Types.DELETE_LOCATION_REQUEST]: onDeleteLocationRequest
});
// const sampleState = [
// {
// parentId: '61cea720ccc4b530015164f0',
// id: 132,
// location: 'Zone',
// name: 'Zone 1',
// type: 'Type 1',
// specifications: 'something really long, idk'
// },
// {
// parentId: 132,
// id: 154,
// location: 'Area',
// name: 'Area 1',
// type: 'Type 1',
// specifications: 'something really long, idk'
// },
// {
// parentId: 154,
// id: 254,
// location: 'Row',
// name: 'Row 2',
// type: 'Type 2',
// specifications: 'something really long, idk'
// },
// {
// parentId: 154,
// id: 233,
// location: 'Row',
// name: 'Row 2',
// type: 'Type 2',
// specifications: 'something really long, idk'
// },
// {
// parentId: 233,
// id: 254,
// location: 'Bay',
// name: 'Bay 2',
// type: 'Type 2',
// specifications: 'something really long, idk'
// },
// {
// parentId: 233,
// id: 954,
// location: 'Bay',
// name: 'Bay 2',
// type: 'Type 2',
// specifications: 'something really long, idk'
// },
// {
// parentId: 954,
// id: 4687,
// location: 'Level',
// name: 'Level 2',
// type: 'Type 2',
// specifications: 'something really long, idk'
// },
// {
// parentId: 954,
// id: 1264,
// location: 'Level',
// name: 'Level 2',
// type: 'Type 2',
// specifications: 'something really long, idk'
// },
// {
// parentId: 132,
// id: 133,
// location: 'Area',
// name: 'Area 1',
// type: 'Type 1',
// specifications: 'something really long, idk'
// }
// ];

View File

@@ -62,6 +62,32 @@ export function* onAddRequestLocation({ payload }) {
}
}
export function* onDeleteRequestLocation({ payload }) {
const response = yield call(
ApiServices[payload?.method],
AuthorizedAPI,
payload?.slug,
payload?.data
);
LOGGER.log('delete response', response.data);
if (response?.status === 200) {
yield put(
WarehouseLocationsActions.locationSuccess({
loader: payload?.loader,
childData: { deleted: true, ...response?.data?.data }
})
);
} else {
payload.onFailedLocation(response.data.error);
yield put(
WarehouseLocationsActions.locationFailure({
loader: payload?.loader,
error: response?.data
})
);
}
}
export function* onEditRequestLocation({ payload }) {
const response = yield call(
ApiServices[payload?.method],
@@ -95,5 +121,6 @@ export function* onEditRequestLocation({ payload }) {
export default [
takeEvery(WarehouseLocationsTypes.LOCATION_REQUEST, onRequestLocation),
takeEvery(WarehouseLocationsTypes.ADD_LOCATION_REQUEST, onAddRequestLocation),
takeEvery(WarehouseLocationsTypes.EDIT_LOCATION_REQUEST, onEditRequestLocation)
takeEvery(WarehouseLocationsTypes.EDIT_LOCATION_REQUEST, onEditRequestLocation),
takeEvery(WarehouseLocationsTypes.DELETE_LOCATION_REQUEST, onDeleteRequestLocation)
];