Skip to content

Commit

Permalink
developing
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Mar 29, 2017
1 parent f5563c3 commit 6ae50e2
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ dist/

# IDE/Editor data
.idea/
/lib
23 changes: 11 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@
"private": true,
"version": "0.0.4",
"description": "react+mobx admin panel",
"files": [
"*.md",
"docs",
"lib",
"src"
],
"main": "lib/index",
"scripts": {
"clean": "rimraf dist/*",
"copy": "copyfiles -f ./src/index.html ./dist && copyfiles -u 1 \"./src/static/**\" ./dist",
"dist": "npm run clean && npm run copy && webpack --progress --bail --env dist -p",
"clean": "rimraf lib/*",
"copy": "copyfiles -u 1 \"./src/static/**\" ./lib",
"build": "set NODE_ENV=production && babel ./src -d lib --ignore '*.spec.js' && npm run copy",
"lint": "eslint ./src",
"posttest": "npm run lint",
"release:major": "npm version prerelease && git push --follow-tags && npm publish --tag beta",
"release:minor": "npm version prerelease && git push --follow-tags && npm publish --tag beta",
"release:patch": "npm version prerelease && git push --follow-tags && npm publish --tag beta",
"serve:dev": "webpack-dev-server --env dev",
"serve:dist": "webpack-dev-server --open --env dist -p --progress",
"start": "npm run serve:dev",
"test": "cross-env NODE_ENV=test karma start",
"test:watch": "cross-env NODE_ENV=test karma start --autoWatch=true --singleRun=false --reporters=mocha,coverage"
"test:watch": "cross-env NODE_ENV=test karma start --autoWatch=true --singleRun=false --reporters=mocha,coverage",
"example": "cd example && webpack-dev-server --hot --inline --config ./webpack.config.js"
},
"repository": "",
"keywords": [],
Expand Down Expand Up @@ -74,7 +78,6 @@
},
"dependencies": {
"cross-env": "^3.2.4",
"history": "^4.6.1",
"inflection": "^1.12.0",
"lodash.defaultsdeep": "^4.6.0",
"lodash.get": "^4.4.2",
Expand All @@ -83,13 +86,9 @@
"mobx": "^3.1.7",
"mobx-persist": "^0.3.1",
"mobx-react": "^4.1.3",
"mobx-react-devtools": "^4.2.11",
"mobx-react-form": "^1.21.0",
"react-dom": "^15.4.2",
"react-hot-loader": "^3.0.0-beta.6",
"react-router-dom": "^4.0.0",
"react-tap-event-plugin": "^2.0.1",
"redux": "^3.6.0",
"url-join": "^1.1.0",
"webpack": "^2.3.1"
}
Expand Down
9 changes: 5 additions & 4 deletions src/client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import authStore from './stores/auth'

let token = ''
function toQueryString(obj) {
var parts = [];
for (var i in obj) {
Expand All @@ -23,7 +22,6 @@ const clientFetch = (url, method, data) => {
if (method === 'POST' || method === 'PUT' || method === 'PATCH'){
headers.append('Content-Type', 'application/json')
}
const token = authStore.token
if (token) {
headers['Authorization'] = `Bearer ${token}`
}
Expand Down Expand Up @@ -72,5 +70,8 @@ export default {
get: clientGet,
fetch: clientFetch,
patch: clientPatch,
delete: clientDelete
delete: clientDelete,
setToken: function(newToken){
token = newToken
}
}
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './widgets'
export stores, {getStore, addStores, factory as storeFactory} from './stores'
export {config as URLConfig} from './url'
export client from './client'
6 changes: 4 additions & 2 deletions src/stores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ const allStores = { notificationStore }
export const getStore = function (name) {
return allStores[name + 'Store']
}
export const addStores = function(stores){
export function addStores(stores){
Object.assign(allStores, stores)
}

export default stores
export factory from './factory'

export default allStores
32 changes: 20 additions & 12 deletions src/widgets/detail/Create.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
import React, { Component, PropTypes } from 'react';
import mobx, { observable } from "mobx"
import { observer } from 'mobx-react'
import { Card, CardTitle } from 'material-ui/Card';
import inflection from 'inflection';
import Title from '../layout/Title';
import DefaultActions from './CreateActions';

class Create extends Component {
@observable record = {}

handleSubmit = (record) => {
const store = getStore(this.props.entityName)
store.create(record).then((data)=>{
store.create(record).then((data) => {

})
};

componentDidMount() {
this.record = this.props.record
}

componentWillReceiveProps(nextProps) {
if (nextProps.record !== this.props.record) {
this.record = this.props.record
}
}
render() {
const { actions = <DefaultActions />, children, isLoading, entityName, title } = this.props;
const basePath = this.getBasePath();
const { actions = <DefaultActions />, children, entityName, title } = this.props;
return (
<Card style={{ margin: '2em', opacity: isLoading ? 0.8 : 1 }}>
<Card style={{ margin: '2em' }}>
{actions && React.cloneElement(actions, {
basePath,
entityName,
record: this.record,
})}
<CardTitle title={<Title title={title} defaultTitle={`Create ${inflection.humanize(inflection.singularize(entityName))}`} />} />
{React.cloneElement(children, {
onSubmit: this.handleSubmit,
entityName,
basePath,
record: {},
record: this.record,
})}
</Card>
);
Expand All @@ -36,16 +47,13 @@ class Create extends Component {
Create.propTypes = {
actions: PropTypes.element,
children: PropTypes.element,
crudCreate: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired,
location: PropTypes.object.isRequired,
params: PropTypes.object.isRequired,
entityName: PropTypes.string.isRequired,
title: PropTypes.any,
record: PropTypes.object.isRequired,
};

Create.defaultProps = {
data: {},
record: {},
};

export default Create;

0 comments on commit 6ae50e2

Please sign in to comment.