Commit 8abe90bf authored by Remy Huet's avatar Remy Huet

Change axios header and add create method

parent dbea25a2
Pipeline #30928 passed with stage
in 54 seconds
......@@ -4,21 +4,31 @@ import env from '../env';
/* eslint-enable import/no-unresolved */
export function fetchCategories(token) {
axios.defaults.headers.common = {
Authorization: `Bearer ${token}`,
};
return {
type: 'FETCH_CATEGORIES',
payload: axios.get(`${env.api_uri}/api/v1/categories`),
payload: axios.get(`${env.api_uri}/api/v1/categories`,
{
headers: { Authorization: `Bearer ${token}` },
}),
};
}
export function deleteCategory(token, id) {
axios.defaults.headers.common = {
Authorization: `Bearer ${token}`,
};
return {
type: 'DELETE_CATEGORY',
payload: axios.delete(`${env.api_uri}/api/v1/categories/${id}`),
payload: axios.delete(`${env.api_uri}/api/v1/categories/${id}`,
{
headers: { Authorization: `Bearer ${token}` },
}),
};
}
export function createCategory(token, data) {
return {
type: 'CREATE_CATEGORY',
payload: axios.post(`${env.api_uri}/api/v1/categories`, data,
{
headers: { Authorization: `Bearer ${token}` },
}),
};
}
......@@ -6,11 +6,11 @@ import { Link } from 'react-router-dom';
import { Confirm, Header, Button } from 'semantic-ui-react';
import CategoryForm from '../../forms/Category';
import { createCategory } from '../../actions/categoriesActions';
function CategoryCreate({ dispatch }) {
function CategoryCreate({ dispatch, userToken }) {
const handleFormSubmit = (values) => {
// Todo
dispatch({ type: 'Category', payload: values });
dispatch(createCategory(userToken, values));
};
return (
......@@ -26,6 +26,9 @@ function CategoryCreate({ dispatch }) {
CategoryCreate.propTypes = {
dispatch: PropTypes.func.isRequired,
userToken: PropTypes.string.isRequired,
};
export default connect()(CategoryCreate);
export default connect(store => ({
userToken: store.user.token,
}))(CategoryCreate);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment