Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure react project #36

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update json objects
Update json object
  • Loading branch information
ankitkanojia committed Sep 14, 2019
commit 8de87ec65853952670ed19f0d3e3b92781d27535
17 changes: 9 additions & 8 deletions src/pages/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class Home extends Component {
}

deleteDetails = (object) => {
console.log(object);
this.props.deleteDetails(object);
}

updateDetails = (object) => {
this.setState({
name: object.Name,
profession: object.Profession,
contactno: object.ContactNo,
name: object.name,
profession: object.profession,
contactno: object.contactno,
Id: object.Id,
isUpdate : true
});
}
Expand All @@ -41,6 +41,7 @@ class Home extends Component {

submitUpdateDetails = () => {
const userDetails = {
Id: this.state.Id,
name: this.state.name,
profession: this.state.profession,
contactno: this.state.contactno
Expand Down Expand Up @@ -75,9 +76,9 @@ class Home extends Component {
{this.props.dataCollection && this.props.dataCollection.map((data, index) => {
return (
<tr key={index}>
<td>{data.Name}</td>
<td>{data.Profession}</td>
<td>{data.ContactNo}</td>
<td>{data.name}</td>
<td>{data.profession}</td>
<td>{data.contactno}</td>
<td width="10%">
<button onClick={() => this.updateDetails(data)} type="button">EDIT</button>
</td>
Expand Down Expand Up @@ -105,7 +106,7 @@ class Home extends Component {
</td>
</tr>
<tr>
<td>ContactNo :</td>
<td>Contact No :</td>
<td>
<input onChange={this.hangleChangeEvent} value={this.state.contactno} type="text" name="contactno" />
</td>
Expand Down
16 changes: 8 additions & 8 deletions src/redux/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export const UPDATE_DETAILS = 'UPDATE_DETAILS';
export const DELETE_DETAILS = 'DELETE_DETAILS';

const staticData = [
{ "Id": 1, "Name": "Ankit Kanojia", "Profession": "Adept Coder", "ContactNo": "(+91)-9099673090" },
{ "Id": 2,"Name": "Dixita Kanojia", "Profession": "Developer", "ContactNo": "(+91)-9898989898" },
{ "Id": 3,"Name": "Rio Webs", "Profession": "Manger", "ContactNo": "(+91)-9898989898" }
{ "id": 1, "name": "Ankit Kanojia", "profession": "Adept Coder", "contactno": "(+91)-9099673090" },
{ "id": 2,"name": "Dixita Kanojia", "profession": "Developer", "contactno": "(+91)-9898989898" },
{ "id": 3,"name": "Rio Webs", "profession": "Manger", "contactno": "(+91)-9898989898" }
];

const initialState = {
Expand All @@ -25,13 +25,13 @@ const reducerCollection = (state = initialState, action) => {
case ADD_DETAILS:
return {
...state,
dataCollection: state.dataCollection.concat({ "Id": state.id +1 , "Name": action.payload.name, "Profession": action.payload.profession, "ContactNo": action.payload.contactno })
dataCollection: state.dataCollection.concat({ "id": state.id + 1 , "name": action.payload.name, "profession": action.payload.profession, "contactno": action.payload.contactno })
};
case UPDATE_DETAILS:
return {
...state,
dataCollection: state.dataCollection.map(item => item.Id === action.payload.Id ? action.payload : item)
};
return {
...state,
dataCollection: state.dataCollection.map((item) => item.id === action.payload.id ? action.payload : item)
};
case DELETE_DETAILS:
return {
...state,
Expand Down