...
const request = require('superagent-bluebird-promise')
...
export function addProduct(formData) {
return dispatch => {
dispatch({ type: PRODUCT_ADD_REQUEST })
if (formData.image) {
return request.post(`${API_ROOT_V1}/api/v1/products/add`)
.field('name', formData.name)
.field('price', formData.price)
.field('description', formData.description)
.field('providerId', formData.providerId)
.attach('image', formData.image, formData.image.name) // добавление картинки
.then(...) // здесь дальнейшая обработка в случае успеха
} else { // кейс, когда у товара нет картинки
return request.post(`${API_ROOT_V1}/api/v1/products/add`)
.send(formData)
.then(...)
}
}
}
...
// (обработчик сабмита формы)
this.props.addProduct({
name,
price,
description,
image: findDOMNode(this.refs.image).files[0], // (забираю картинку)
providerId: this.props.providerId,
})
...
// непосредственно кнопка загрузки файла в форме
<div className='form-group'>
<input
id='productImage'
type='file'
name='image'
placeholder='Image'
onChange={this.handleChange}
value={this.state.image}
data-field-name='image'
ref='image' />
<p>Load product image</p>
</div>
...
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
module.exports = {
devtool: 'cheap-module-source-map',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'production/public/'),
filename: 'bundle.js',
publicPath: '/',
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new ExtractTextPlugin({
filename: 'style.css',
disable: false,
allChunks: false, // true
})
],
module: {
rules: [
{
test: /\.js$/,
loaders: ['babel-loader'],
include: path.join(__dirname, 'src'),
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: ['css-loader', 'postcss-loader'],
publicPath: '/public',
}),
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: ['css-loader', 'postcss-loader', 'sass-loader'],
publicPath: '/public',
}),
},
....
module.exports = {
devtool: 'cheap-module-source-map',
entry: [
'./src/index'
],
output: {
path: path.join(__dirname, 'production/public/'),
filename: 'bundle.js',
publicPath: '/',
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}),
new ExtractTextPlugin('style.css', {
allChunks: false
})
],
module: {
loaders: [
{
test: /\.js$/,
loaders: ['babel'],
include: path.join(__dirname, 'src')
},
{
test: /\.scss$/,
include: path.join(__dirname, 'src'),
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader!sass-loader')
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
},
...
const ExtractTextPlugin = require('extract-text-webpack-plugin');
"autoload": {
"psr-4": {
"Appname\\": "src/"
}
}
src/
--Appname/
----Controller/
------IndexController.php
namespace Appname\Controller;
use Appname\Controller\IndexController as Control;
composer dump-autoload -o