generated from goitacademy/react-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2be8f4
commit accb903
Showing
12 changed files
with
209 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
|
||
import { selectFilterValue } from '../../redux/selectors'; | ||
import { setSearchFilterAction } from '../../redux/filter/filterSlice'; | ||
import { FilterContainer, Label, Input } from './Filter.styled'; | ||
|
||
export const Filter = () => { | ||
const { filter } = useSelector(selectFilterValue); | ||
const dispatch = useDispatch(); | ||
|
||
const filterChange = e => { | ||
dispatch(setSearchFilterAction(e.target.value)); | ||
}; | ||
|
||
return ( | ||
<FilterContainer> | ||
<Label> | ||
Find contact | ||
<Input | ||
type="text" | ||
name="search" | ||
placeholder="Search..." | ||
value={filter} | ||
onChange={filterChange} | ||
/> | ||
</Label> | ||
</FilterContainer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import styled from '@emotion/styled'; | ||
|
||
export const FilterContainer = styled.div` | ||
width: 400px; | ||
background-color: #7ad9f7; | ||
padding: 12px; | ||
border-radius: 8px; | ||
`; | ||
|
||
export const Label = styled.label` | ||
color: #000000; | ||
font-size: 20px; | ||
display: flex; | ||
align-items: center; | ||
gap: 20px; | ||
`; | ||
|
||
export const Input = styled.input` | ||
font-size: 18px; | ||
padding: 4px; | ||
margin-top: 4px; | ||
border-radius: 4px; | ||
border: 2px solid transparent; | ||
outline: transparent; | ||
&: focus { | ||
border-color: #e9af3d; | ||
} | ||
&: hover { | ||
border-color: #e9af3d; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,40 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
import axios from 'axios'; | ||
import Notiflix from 'notiflix'; | ||
|
||
axios.defaults.baseURL = 'https://658c671c859b3491d3f606a0.mockapi.io'; | ||
axios.defaults.baseURL = 'https://connections-api.herokuapp.com'; | ||
|
||
export const getAllContactsAction = createAsyncThunk( | ||
'contacts/getAllContacts', | ||
|
||
async (_, thunkApi) => { | ||
async (_, thunkAPI) => { | ||
try { | ||
const response = await axios.get('/contacts'); | ||
return response.data; | ||
} catch (error) { | ||
Notiflix.Notify.info('Something went wrong! Try again'); | ||
return thunkApi.rejectWithValue(error.message); | ||
return thunkAPI.rejectWithValue(error.message); | ||
} | ||
} | ||
); | ||
|
||
export const addContactAction = createAsyncThunk( | ||
'contacts/addContactPost', | ||
|
||
async (info, thunkApi) => { | ||
async (body, thunkAPI) => { | ||
try { | ||
const response = await axios.post('/contacts', info); | ||
const response = await axios.post('/contacts', body); | ||
return response.data; | ||
} catch (error) { | ||
Notiflix.Notify.info('Something went wrong! Try again later'); | ||
return thunkApi.rejectWithValue(error.message); | ||
return thunkAPI.rejectWithValue(error.message); | ||
} | ||
} | ||
); | ||
|
||
export const deleteContactAction = createAsyncThunk( | ||
'contacts/deleteContact', | ||
|
||
async (contactId, thunkApi) => { | ||
async (contactId, thunkAPI) => { | ||
try { | ||
const response = await axios.delete(`/contacts/${contactId}`); | ||
return response.data; | ||
} catch (error) { | ||
Notiflix.Notify.info('Something went wrong! Try again later'); | ||
return thunkApi.rejectWithValue(error.message); | ||
return thunkAPI.rejectWithValue(error.message); | ||
} | ||
} | ||
); |