Skip to content

Commit 4322a2d

Browse files
committed
Saga done
1 parent d5ac549 commit 4322a2d

File tree

7 files changed

+17
-36
lines changed

7 files changed

+17
-36
lines changed

db.json

+3-17
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,12 @@
1414
}
1515
],
1616
"contacts": [
17-
{
18-
"firstName": "danil",
19-
"lastName": "bohdan",
20-
"email": "[email protected]",
21-
"phone": "0979608233",
22-
"id": 13
23-
},
24-
{
25-
"firstName": "Kornienko",
26-
"lastName": "bohdan",
27-
"email": "[email protected]",
28-
"phone": "0979608233",
29-
"id": 14
30-
},
3117
{
3218
"firstName": "Kornienko",
33-
"lastName": "bohdan",
34-
"email": "bogdanburn123@gmail.com",
19+
"lastName": "sddasad",
20+
"email": "dsgmail.com",
3521
"phone": "0979608233",
36-
"id": 15
22+
"id": 1658163826630
3723
}
3824
],
3925
"profile": {

src/App.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function App({selectedContact}) {
1111
<h1 className='header-app'>Contact List</h1>
1212
<div className='main'>
1313
<ContactList
14+
1415

1516
/>
1617
<ContactForm

src/components/ContactForm/ContactForm.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function ContactForm({contactForEdit}){
3333
e.preventDefault();
3434

3535
if (!editContact.id){
36-
36+
editContact.id = Date.now()
3737
dispatch(createContactAction(editContact))
3838
}
3939
else {
@@ -46,7 +46,7 @@ function ContactForm({contactForEdit}){
4646

4747
const onContactDelete = () => {
4848

49-
dispatch(deleteContactAction(editContact))
49+
dispatch(deleteContactAction(editContact.id))
5050
}
5151

5252
// console.log(editContact);

src/components/ContactItem/ContactItem.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ function ContactItem(
55
{contact, onDelete, onEdit}
66
) {
77

8-
const onContactDelete = () => {
9-
// e.stopPropagation();
10-
onDelete(contact)
8+
const onContactDelete = (e) => {
9+
e.stopPropagation()
10+
11+
onDelete(contact.id)
1112
}
1213

1314

src/components/ContactList/ContactList.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ function ContactList(){
2020

2121

2222

23-
const onDelete = (contact) => {
24-
dispatch(deleteContactAction(contact));
23+
const onDelete = (id) => {;
24+
dispatch(deleteContactAction(id));
2525
};
2626

2727

src/sagas/contactsSagas.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ export function* updateContactSaga({payload}){
5656
export function* deleteContactSaga({payload}){
5757
yield put(deleteContactRequest())
5858
try {
59-
const deleteContact = yield contactService.delete(`/${payload.id}`, payload)
60-
.then(({data})=>data)
61-
yield put(deleteContactSuccsess(deleteContact))
59+
yield contactService.delete(`/${payload}`)
60+
yield put(deleteContactSuccsess(payload))
6261

6362
} catch (error) {
6463
yield put(deleteContactError(error))

src/store/reducers/Contactreducer.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function toContactReducer(state = initialState,{type, payload}) {
1616

1717
switch(type){
1818

19-
case ADD_NEW_CONTACT: return {...state, selectedContact:createEmptyContact()}
19+
case ADD_NEW_CONTACT: return {...state, selectedContact:createEmptyContact(),}
2020
case SELECT_CONTACT: return{...state, selectedContact:payload}
2121

2222
case ACTION_TYPES.DELETE_CONTACT_SUCCSESS: return {...state, contacts: state.contacts
@@ -26,7 +26,7 @@ export default function toContactReducer(state = initialState,{type, payload}) {
2626
case ACTION_TYPES.DELETE_CONTACT_REQUEST: return {...state, isFetching:true}
2727
case ACTION_TYPES.DELETE_CONTACT_ERROR: return {...state, error:payload, isFetching:true}
2828

29-
case ACTION_TYPES.POST_CONTACT_SUCCSESS: return {...state, contacts: [...state.contacts, payload], isFetching:true}
29+
case ACTION_TYPES.POST_CONTACT_SUCCSESS: return {...state, contacts: [...state.contacts,payload], isFetching:true}
3030
case ACTION_TYPES.POST_CONTACT_REQUEST:return {...state, isFetching:true}
3131
case ACTION_TYPES.POST_CONTACT_ERROR:return {...state, error:payload, isFetching:true}
3232

@@ -40,13 +40,7 @@ export default function toContactReducer(state = initialState,{type, payload}) {
4040
case ACTION_TYPES.GET_CONTACTS_REQUEST:return{...state, isFetching:true}
4141
case ACTION_TYPES.GET_CONTACTS_ERROR:return{...state, error:payload, isFetching:true}
4242

43-
// case GET_CONTACT: return {...state, contacts: payload, selectedContact:createEmptyContact()}
44-
// case DELETE_CONTACT: return {...state, contacts: state.contacts
45-
// .filter((contact)=> contact.id !==payload), selectedContact:createEmptyContact()}
46-
// case UPDATE_CONTACT: return {...state, contacts: state.contacts
47-
// .map((contact)=> contact.id !== payload.id ? contact : payload),
48-
// selectedContact:createEmptyContact()}
49-
// case CREATE_CONTACT: return{...state, contacts: [...state.contacts, payload]}
43+
5044

5145
default:return state
5246

0 commit comments

Comments
 (0)