Permalink
Browse files

UNSTABLE VERSION with a lot of a shit code.

  • Loading branch information...
danbilokha committed Jan 12, 2018
1 parent 6fa4989 commit 83b2ecf0d2294c75931b3bf15e5c4305e3ac1ede
@@ -8,6 +8,7 @@ import CabinetHome from './home/Home';
import CabinetInfo from './info/Info';
import CabinetBookshelf from './bookshelf/Bookshelf';
import CabinetAddBook from './addBook/AddBook';
import BookDeal from './bookDeal/BookDeal';
let Cabinet = () =>
<div className='container cabinet'>
@@ -17,6 +18,7 @@ let Cabinet = () =>
<Route exact path='/cabinet/info' component={CabinetInfo} />
<Route exact path='/cabinet/my-bookshelf' component={CabinetBookshelf} />
<Route exact path='/cabinet/add-book' component={CabinetAddBook} />
<Route exact path='/cabinet/deals' component={BookDeal} />
<Route path='/cabinet/' component={CabinetHome} />
</Switch>
</div>
@@ -0,0 +1,101 @@
import {fetchingBookDealData, fetchingBookDealChange} from './bookDeal.actions';
import {ResolveButtons} from './resolveButtons/ResolveButtons';
import React, {PureComponent} from 'react';
import {connect} from 'react-redux';
import {Link} from 'react-router-dom';
class BookRequest extends PureComponent {
constructor(props) {
super(props);
this.onClickControlButton = this.onClickControlButton.bind(this);
}
componentDidMount() {
this.props.getAllDeals();
}
onClickControlButton({target}) {
console.log(target);
let method = target.data-method;
let dealStatus = target.data-dealStatus;
console.log(method, dealStatus);
}
render() {
console.log(this.props);
const deals = this.props.dealData;
if(!deals.length) {
return (
<div> Loading ... </div>
)
}
return (
<div className='deals'>
{
deals.map((deal, index) => {
return (
<div className='deals__deal' key={index}>
<div className='dials__deal_book'>
<Link to={`/book/${deal.bookId}`}>
Dealing book
</Link>
</div>
<div className='deals__deal_status'>
Deal status: {deal.dealStatusName}
</div>
<div className='deals__time'>
<div className='deals__time_created'>
Deal created: {deal.createdOn}
</div>
<div className='deals__time_ended'>
Deal ended: {deal.endedOn}
</div>
<div className='deals__time_expired'>
Deal expired: {deal.expiredOn}
</div>
<div className='deals__time_modified'>
Deal last modified: {deal.modifiedOn}
</div>
</div>
<div className='deals__participants'>
<div className='deals__participants_acceptor'>
Acceptor: {deal.acceptorId}
</div>
<div className='deals__participants_donor'>
Donor: {deal.donorId}
</div>
</div>
<ResolveButtons
onClickControlButton={this.onClickControlButton}
isDonor={deal.isDonor}
dealStatus={deal.dealStatusId} />
</div>
)
})
}
</div>
)
}
}
const mapStateToProps = state => {
return {
dealData: state.bookDeal.bookDealData
}
}
const mapDispatchToProps = dispatch => {
return {
getAllDeals: () => dispatch(fetchingBookDealData()),
changeDeal: (dealData) => dispatch(fetchingBookDealChange(dealData))
}
}
export default BookRequest = connect(mapStateToProps, mapDispatchToProps)(BookRequest);
@@ -0,0 +1,46 @@
export const FETCHING_BOOK_DEAL_DATA = 'FETCHING_BOOK_DEAL_DATA';
export const FETCHING_BOOK_DEAL_DATA_SUCCESS = 'FETCHING_BOOK_DEAL_DATA_SUCCESS';
export const FETCHING_BOOK_DEAL_DATA_FAILURE = 'FETCHING_BOOK_DEAL_DATA_FAILURE';
export const FETCHING_BOOK_DEAL_CHANGE = 'FETCHING_BOOK_DEAL_CHANGE';
export const FETCHING_BOOK_DEAL_CHANGE_SUCCESS = 'FETCHING_BOOK_DEAL_CHANGE_SUCCESS';
export const FETCHING_BOOK_DEAL_CHANGE_FAILURE = 'FETCHING_BOOK_DEAL_CHANGE_FAILURE';
export const fetchingBookDealData = () => {
return {
type: FETCHING_BOOK_DEAL_DATA,
}
}
export const fetchingBookDealDataSuccess = (payload) => {
return {
type: FETCHING_BOOK_DEAL_DATA_SUCCESS,
payload,
}
}
export const fetchingBookDealDataFailure = () => {
return {
type: FETCHING_BOOK_DEAL_DATA_FAILURE
}
}
export const fetchingBookDealChange = (payload) => {
return {
type: FETCHING_BOOK_DEAL_CHANGE,
payload
}
}
export const fetchingBookDealChangeSuccess = (payload) => {
return {
type: FETCHING_BOOK_DEAL_CHANGE_SUCCESS,
payload,
}
}
export const fetchingBookDealChangeFailure = () => {
return {
type: FETCHING_BOOK_DEAL_CHANGE_FAILURE
}
}
@@ -0,0 +1,61 @@
import * as actions from './bookDeal.actions';
const initState = {
bookDealData: [],
dealIdToChange: null,
}
const bookDealReducer = (state = initState, action) => {
switch(action.type) {
case actions.FETCHING_BOOK_DEAL_DATA: {
return {
...state,
bookDealData: [],
dealIdToChange: null,
}
}
case actions.FETCHING_BOOK_DEAL_DATA_SUCCESS: {
return {
...state,
bookDealData: [
...action.payload
],
dealIdToChange: null,
}
}
case actions.FETCHING_BOOK_DEAL_DATA_FAILURE:
return {
...state,
bookDealData: [],
dealIdToChange: null,
}
case actions.FETCHING_BOOK_DEAL_CHANGE: {
return {
...state,
dealIdToChange: action.payload
}
}
case actions.FETCHING_BOOK_DEAL_CHANGE_SUCCESS: {
return {
...state,
dealIdToChange: null,
}
}
case actions.FETCHING_BOOK_DEAL_CHANGE_FAILURE:
return {
...state,
dealIdToChange: null,
}
default:
return state;
}
}
export default bookDealReducer;
@@ -0,0 +1,59 @@
import {put,
take,
call,
fork} from 'redux-saga/effects';
import {FETCHING_BOOK_DEAL_DATA,
FETCHING_BOOK_DEAL_CHANGE,
fetchingBookDealDataSuccess,
fetchingBookDealDataFailure,
fetchingBookDealChangeSuccess,
fetchingBookDealChangeFailure} from './bookDeal.actions';
// Global action
import {
isFetching,
isntFetching } from '../../../../services/store/globalState/global.actions';
// API
import {getDealData, changeDealStatus} from '../../../../services/Api';
export default function* watchUserDeal() {
const userDealData = yield fork(watchUserDealData);
const userChangeDeal = yield fork(watchUserChangeDeal);
}
function* watchUserDealData() {
while(true) {
yield take(FETCHING_BOOK_DEAL_DATA);
yield call(fetchUserDeal,
getDealData,
null,
fetchingBookDealDataSuccess,
fetchingBookDealDataFailure);
}
}
function* watchUserChangeDeal() {
while(true) {
const dealChangeData = yield take(FETCHING_BOOK_DEAL_CHANGE);
yield call(fetchUserDeal,
changeDealStatus,
dealChangeData.payload,
fetchingBookDealChangeSuccess,
fetchingBookDealChangeFailure);
}
}
function* fetchUserDeal(api, userData, onSuccess, onFailure) {
try {
// Show, that we start to fetching books
yield put(isFetching());
// Fetching the books
const response = yield call(api(userData));
yield put(onSuccess(response));
} catch(err) {
yield put(onFailure());
} finally {
yield put(isntFetching());
}
}
@@ -0,0 +1,54 @@
import React from 'react';
const ResolveButtons = ({onClickControlButton, isDonor, dealStatus}) => {
let button1Text;
let button2Text;
let callingMethod1;
let callingMethod2;
if(isDonor) {
switch(dealStatus) {
case 1:
button1Text = 'Aprove';
callingMethod1 = 'ApproveDeal';
button2Text = 'Decline';
callingMethod2 = 'DeclineDeal';
break;
case 3:
button1Text = 'Close';
callingMethod1 = 'CloseDeal';
button2Text = 'Decline';
callingMethod2 = 'DeclineDeal';
break;
}
} else {
if(dealStatus === 2) {
button1Text = 'Book recieved';
callingMethod1 = 'BookRecieved';
button2Text = 'Decline';
callingMethod2 = 'DeclineDeal';
}
}
return (
<div className='deals__control'>
<button
onClick={onClickControlButton}
data-method={`${callingMethod1}`}
data-dealStatus={`${dealStatus}`}>
{button1Text}
</button>
<button
onClick={onClickControlButton}
data-method={`${callingMethod2}`}
data-dealStatus={`${dealStatus}`}>
{button2Text}
</button>
</div>
)
}
export {ResolveButtons};
@@ -5,7 +5,8 @@ const link = [
"Home",
"Info",
"My bookshelf",
"Add Book"
"Add Book",
"Deals"
]
const Nav = () => (
View
@@ -125,3 +125,17 @@ export function getBookShelfBooks() {
}
}
export function getDealData() {
return function() {
return apiAuthPostFetch("PersonalCabinet/GetAllMyDeals")
.then(response => response);
}
}
export function changeDealStatus(dealId, dealAction) {
return function() {
return apiAuthPostFetch(`PersonalCabinet/${dealAction}`);
}
}
@@ -11,6 +11,7 @@ import BookShelf from '../../containers/page/cabinet/bookshelf/bookshelf.reducer
import OrderBook from '../../containers/page/book/orderBook/orderBook.reducer';
import Book from '../../containers/page/book/book.reducer';
import BookAddComment from '../../containers/page/book/bookAddComment/bookAddComment.reducer';
import bookDeal from '../../containers/page/cabinet/bookDeal/bookDeal.reducer';
//import UserInfo from '../../containers/page/cabinet/info/info.reducer';
export default combineReducers({
@@ -25,5 +26,6 @@ export default combineReducers({
OrderBook,
Book,
BookAddComment,
bookDeal,
//UserInfo
});
Oops, something went wrong.

0 comments on commit 83b2ecf

Please sign in to comment.