Skip to content

Commit

Permalink
Worked on implementing jackpot add
Browse files Browse the repository at this point in the history
  • Loading branch information
godfredcs committed Jun 5, 2018
1 parent 50d3c33 commit 34cd176
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 92 deletions.
37 changes: 24 additions & 13 deletions src/actions/jackpotActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
GET_ALL_JACKPOTS_SUCCESS, GET_JACKPOTS_TODAY, GET_ALL_JACKPOTS_FAIL,
ADD_JACKPOT_FAIL, ADD_JACKPOT_SUCCESS,
GET_ALL_JACKPOTS_SUCCESS, GET_ALL_JACKPOTS_FAIL,
GET_JACKPOTS_TODAY_SUCCESS, GET_JACKPOTS_TODAY_FAIL,
GET_JACKPOTS_YESTERDAY_SUCCESS, GET_JACKPOTS_YESTERDAY_FAIL,
ADD_JACKPOT_SUCCESS, ADD_JACKPOT_FAIL, EDIT_JACKPOT_SUCCESS, EDIT_JACKPOT_FAIL,
SHOW_ADD_JACKPOT_MODAL, SHOW_EDIT_JACKPOT_MODAL, SHOW_DELETE_JACKPOT_MODAL,
} from './types';

Expand All @@ -27,7 +29,7 @@ export const getJackpotByDate = (from, to, today) => async dispatch => {

if (jackpots) {
if (today) {
dispatch({ type: GET_JACKPOTS_TODAY, payload: jackpots });
dispatch({ type: GET_JACKPOTS_TODAY_SUCCESS, payload: jackpots });
} else {
dispatch({ type: GET_ALL_JACKPOTS_SUCCESS, payload: jackpots });
}
Expand Down Expand Up @@ -60,30 +62,39 @@ export const showDeleteJackpotModal = value => {
};

// Action creator for adding jackpot transaction to the system.
export const addJackpot = (data, refresh, clear) => async dispatch => {
export const addJackpot = (data, refresh, clear, successNotification, errorNotification) => async dispatch => {
try {
let jackpot = await Jackpot.add(data);

if (jackpot) {
dispatch({ type: ADD_JACKPOT_SUCCESS });

if (refresh) {
refresh();
}
refresh && refresh();

if (clear) {
clear();
}
clear && clear();

successNotification && successNotification();
}

} catch (error) {
dispatch({ type: ADD_JACKPOT_FAIL });
errorNotification && errorNotification();
console.log(error);
}
};

// Action creator for editing jackpot transactions to the system.
export const editJackpot = (id, data, refresh) => async dispatch => {
try {
let jackpot = await Jackpot.update(id, data);

if (jackpot) {
dispatch({ type: EDIT_JACKPOT_SUCCESS });




refresh && refresh();
}
console.log('so you are trying to edit huh');
} catch(error) {
console.log(error);
}
};
19 changes: 10 additions & 9 deletions src/actions/types/jackpotActionTypes.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
export const GET_ALL_JACKPOTS_SUCCESS = 'get_all_jackpots_success';
export const GET_ALL_JACKPOTS_FAIL = 'get_all_jackpots_fail';

export const GET_JACKPOTS_TODAY = 'get_jackpots_today';

export const GET_JACKPOTS_YESTERDAY = 'get_jackpots_yesterday';
export const GET_JACKPOTS_TODAY_SUCCESS = 'get_jackpots_today_success';
export const GET_JACKPOTS_TODAY_FAIL = 'get_jackpots_today_fail';

export const GET_ALL_JACKPOTS_FAIL = 'get_all_jackpots_fail';

export const ADD_JACKPOT_SUCCESS = 'add_jackpot_success';
export const GET_JACKPOTS_YESTERDAY_SUCCESS = 'get_jackpots_yesterday_success';
export const GET_JACKPOTS_YESTERDAY_FAIL = 'get_jackpots_yesterday_fail';


export const ADD_JACKPOT_SUCCESS = 'add_jackpot_success';
export const ADD_JACKPOT_FAIL = 'add_jackpot_fail';

export const EDIT_JACKPOT_SUCCESS = 'edit_jackpot_success';

export const EDIT_JACKPOT_SUCCESS = 'edit_jackpot_success';
export const EDIT_JACKPOT_FAIL = 'edit_jackpot_fail';

export const DELETE_JACKPOT_SUCCESS = 'delete_jackpot_success';

export const DELETE_JACKPOT_SUCCESS = 'delete_jackpot_success';
export const DELETE_JACKPOT_FAIL = 'delete_jackpot_fail';


export const SHOW_ADD_JACKPOT_MODAL = 'show_add_jackpot_modal';

export const SHOW_EDIT_JACKPOT_MODAL = 'show_edit_jackpot_modal';

export const SHOW_DELETE_JACKPOT_MODAL = 'show_delete_jackpot_modal';



1 change: 1 addition & 0 deletions src/components/Table/CreditTransfer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CreditTransferTable extends React.Component {
isSuperAdmin = () => {
return this.props.user.role.name === 'super_admin';
};

_renderDate(value) {
let date = Moment(value);

Expand Down
4 changes: 2 additions & 2 deletions src/components/Table/Jackpot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CustomTable extends React.Component {

_renderTableData = () => {
let number = 0;
const { classes, tableData, updateSale } = this.props;
const { classes, tableData, editJackpot } = this.props;

return tableData.map((prop, key) => {
return (
Expand All @@ -43,7 +43,7 @@ class CustomTable extends React.Component {
{
this.isSuperAdmin() && (
<TableCell className={classes.tableCell}>
<Button style={ styles.updateButton } onClick={ updateSale }>Edit</Button>
<Button style={ styles.updateButton } onClick={ editJackpot }>Edit</Button>
<Button style={ styles.deleteButton }>Delete</Button>
</TableCell>
)
Expand Down
5 changes: 3 additions & 2 deletions src/reducers/jackpotReducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
GET_ALL_JACKPOTS_SUCCESS, GET_JACKPOTS_TODAY, GET_ALL_JACKPOTS_FAIL,
GET_ALL_JACKPOTS_SUCCESS, GET_ALL_JACKPOTS_FAIL,
GET_JACKPOTS_TODAY_SUCCESS,
ADD_JACKPOT_SUCCESS, ADD_JACKPOT_FAIL,
SHOW_ADD_JACKPOT_MODAL, SHOW_EDIT_JACKPOT_MODAL, SHOW_DELETE_JACKPOT_MODAL,
} from '../actions/types';
Expand All @@ -18,7 +19,7 @@ export default (state = INITIAL_STATE, action) => {
case GET_ALL_JACKPOTS_SUCCESS:
return { ...state, jackpots: action.payload };

case GET_JACKPOTS_TODAY:
case GET_JACKPOTS_TODAY_SUCCESS:
return { ...state, jackpots_today: action.payload };

case GET_ALL_JACKPOTS_FAIL:
Expand Down
18 changes: 15 additions & 3 deletions src/views/CreditTransfers/CreditTransfers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ class CreditTransfer extends Component {
}
}
};

// Check if the user is super admin.
isSuperAdmin = () => {
return this.props.user.role.name === 'super_admin';
};

tableHead = () => {
return this.isSuperAdmin()
? ['No.', 'Number', 'Amount', 'Date Added', 'Date Updated', '']
: ['No.', 'Number', 'Amount', 'Date Added', 'Date Updated']
};

render() {
return (
Expand Down Expand Up @@ -143,9 +154,9 @@ class CreditTransfer extends Component {
content={
<CreditTransferTable
tableHeaderColor="primary"
tableHead={['No.', 'Number', 'Amount', 'Date Added', 'Date Updated', '']}
tableHead={this.tableHead()}
tableData={this.props.credit_transfers}
editCreditTransfer={() => { this.setState({ openEditCreditTransferModal: true }) }}
editCreditTransfer={() => { this.setState({ openEditCreditTransferModal: true, notificationGroup: 'edit' }) }}
/>
}
/>
Expand Down Expand Up @@ -232,9 +243,10 @@ const styles = {
};

const mapStateToProps = state => {
const { user } = state.users;
const { credit_transfers, credit_transfer_to_edit } = state.creditTransfers;

return { credit_transfers, credit_transfer_to_edit };
return { user, credit_transfers, credit_transfer_to_edit };
};

export default connect(mapStateToProps, {
Expand Down
2 changes: 1 addition & 1 deletion src/views/Items/Items.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { getAllItems, addItem, showAddItemModal, showEditItemModal, showDeleteIt

class Items extends Component {
state = {
notificationGroup: '',
notificationGroup: 'add',
tr: false,
tc: false,
};
Expand Down
Loading

0 comments on commit 34cd176

Please sign in to comment.