Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
90ef303
feat: pirania home page
luandro Dec 29, 2019
71c3f56
feat: added pirania voucher list
luandro Dec 29, 2019
204953c
feat: collapsable Box component
luandro Dec 30, 2019
a79e151
fix: textAlign typo on metrics
luandro Dec 30, 2019
3cf63a6
fix: moved getting data pirania/list com[ponent
luandro Dec 30, 2019
4bd3ed7
fix: added Pirania to config
luandro Dec 30, 2019
838de00
fix: linting list component
luandro Dec 30, 2019
64f2bc2
fix: no loading text and minor fixes
luandro Dec 30, 2019
213516b
feat: added translations to List box title
luandro Dec 30, 2019
a9318e3
feat: added create voucher page
luandro Dec 30, 2019
35d1f46
feat: pirania create member and visitor vouchers
luandro Dec 31, 2019
716f34f
fix: pirania page cleanup and linting
luandro Dec 31, 2019
fba42c9
fix: editorconfig aligned with eslint rules
luandro Dec 31, 2019
834b3a0
fix: button separtion on admin
luandro Dec 31, 2019
0340d39
fix: added style css file back
luandro Dec 31, 2019
385beb9
chore: linting
luandro Dec 31, 2019
949c79c
fix: admin english I18n entries
luandro Dec 31, 2019
5a3902b
fix: changed menu name to english default
luandro Dec 31, 2019
272cb41
fix: added show error notification on .catch
luandro Dec 31, 2019
a9a2221
feat: added renew member vouchers UI page
luandro Dec 31, 2019
fe4290f
chore: basic cleanup based on code review
luandro Jan 1, 2020
70f6033
feat: dynamic active visitors and members on admin and home pages
luandro Jan 1, 2020
d131054
fix: correct daysleft for members
luandro Jan 1, 2020
7ae91c3
fix: dates using payday instead of daysleft and minor fixes
luandro Jan 3, 2020
b173876
feat: added renew members
luandro Jan 3, 2020
0935516
feat: showing vouchers when creating visitor vouchers
luandro Jan 3, 2020
95fc08b
fix: reducer to new simpler format for listing vouchers
luandro Jan 3, 2020
36a856c
fix: better list vouchers UI
luandro Jan 4, 2020
3a2aaaa
feat: added Pirania status, enable and disable
luandro Jan 4, 2020
20de097
feat: added edit governance info page to pirania
luandro Jan 4, 2020
b1b3d44
chore: linting, css and cleanup
luandro Jan 4, 2020
45488dc
feat: added edit captive portal content page
luandro Jan 4, 2020
005fe0e
feat: added remove voucher
luandro Jan 5, 2020
6f2b38b
fix: create and renew vouchers with correct dates and formats
luandro Jan 5, 2020
ee2b9d2
fix: reload governance and active_vouchers after remove and write
luandro Jan 5, 2020
6b96398
chore: added goback button to create page
luandro Jan 5, 2020
e59a2b4
fix: fix translations on Input and linting
luandro Jan 6, 2020
49ebd1e
feat: added pirania translations with pt-br
luandro Jan 6, 2020
2c8ecdf
fix: build script
luandro Jan 7, 2020
4541c68
build(rxjs): update import and build script
gmarcos87 Jan 7, 2020
57cf063
Merge branch 'pirania' of https://github.com/libremesh/lime-app into …
luandro Jan 7, 2020
4ca24c3
chore: portuguese translations
luandro Jan 7, 2020
8c52c39
chore: plularize i18n, lint and parametize initial value
luandro Jan 7, 2020
76b0f55
Merge branch 'develop' of https://github.com/libremesh/lime-app into …
luandro Feb 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/lime-plugin-pirania/src/PiraniaPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ export const Pirania = ({
<Create
goBack={() => setPage(0)}
daysLeft={daysLeft}
date={payday}
/>
)}
{page === 3 && (
<Renew
goBack={() => setPage(0)}
daysLeft={daysLeft}
renewDate={payday}
/>
)}
</div>
Expand Down
12 changes: 6 additions & 6 deletions plugins/lime-plugin-pirania/src/pages/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import I18n from 'i18n-js';

const Admin = ({ visitors, members, list, create, renew, download, daysLeft }) => (
<div>
<Box title={I18n.t('Next month')}>
<Box title={I18n.t('Current month')}>
<div class="info">
<span>
<b>{I18n.t('Members')}: </b>
Expand All @@ -24,7 +24,7 @@ const Admin = ({ visitors, members, list, create, renew, download, daysLeft }) =
{I18n.t('Show all vouchers')}
</button>
</Box>
<Box title={I18n.t('Last month')}>
{/* <Box title={I18n.t('Last month')}>
<div class="info">
<span>
<b>{I18n.t('Members')}: </b>
Expand All @@ -40,7 +40,7 @@ const Admin = ({ visitors, members, list, create, renew, download, daysLeft }) =
<button class="button green block" onClick={download}>
{I18n.t('Download CSV')}
</button>
</Box>
</Box> */}
{/* WIP: Node election */}
{/* <Box title={I18n.t('Admins elegidos')}>
<div class="info">
Expand All @@ -50,9 +50,9 @@ const Admin = ({ visitors, members, list, create, renew, download, daysLeft }) =
<br />
</div>
<button
style={{ marginTop: 15 }}
class="button green block"
onClick={elect}
style={{ marginTop: 15 }}
class="button green block"
onClick={elect}
>
{I18n.t('Elegir')}
</button>
Expand Down
9 changes: 7 additions & 2 deletions plugins/lime-plugin-pirania/src/pages/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ import Loading from '../../../../src/components/loading';
import daysFromNow from '../../../../src/utils/daysFromNow';
import makeid from '../../../../src/utils/makeid';

function Create({ goBack, createMemberVoucher, createVisitorVoucher, daysLeft, createVoucher, loading }) {
function Create({ goBack, createMemberVoucher, createVisitorVoucher, daysLeft, createVoucher, loading, date }) {
const [voucherQuantity, setVoucherQuantity] = useState(1);
const [daysQuantity, setDaysQuantity] = useState(1);
const [note, setNote] = useState('marcos android');
const [confirm, setConfirm] = useState(false);
const [member, setMember] = useState(false);
const splitDate = date.split('/');
const day = parseInt(splitDate[0]);
const month = parseInt(splitDate[1] - 1);
const year = parseInt(splitDate[2]);
const epoc = new Date(year, month, day + 1).valueOf();

function handleInput(e, input) {
setVoucherQuantity;
Expand All @@ -38,7 +43,7 @@ function Create({ goBack, createMemberVoucher, createVisitorVoucher, daysLeft, c
return createMemberVoucher({
secret: makeid(8),
note,
epoc: daysFromNow(daysLeft + 1)
epoc
});
}
function addVisitor() {
Expand Down
48 changes: 30 additions & 18 deletions plugins/lime-plugin-pirania/src/pages/renew.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { h } from 'preact';
import { useEffect, useState } from 'preact/hooks';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { getVoucherList } from '../piraniaActions';
import { vouchers, loading } from '../piraniaSelectors';
import { getVoucherList, renewVouchers } from '../piraniaActions';
import { vouchers, loading, renewed } from '../piraniaSelectors';
import Loading from '../../../../src/components/loading';
import { Box } from '../../../../src/components/box';
import { Select } from '../../../../src/components/select';
import { mergeTypes } from './list';

import I18n from 'i18n-js';

function RenewContent ({ vouchers, handleCheck, selected }) {
function RenewContent({ vouchers, handleCheck, selected }) {
let flatList = {
member: {},
visitor: {},
Expand All @@ -31,17 +31,25 @@ function RenewContent ({ vouchers, handleCheck, selected }) {
));
}

function renewVouchers () {

/* TODO */
}

function Renew ({ goBack, loading, vouchers, getVoucherList }) {
const [ selected, setSelected ] = useState([]);
function handleCheck (e) {
function Renew({ goBack, loading, vouchers, getVoucherList, daysLeft, renewDate, renewVouchers, renewed }) {
const [selected, setSelected] = useState([]);
function handleCheck(e) {
const newList = selected.filter(i => i !== e.target.value);
setSelected(newList);
}
function handleRenew() {
const splitDate = renewDate.split('/');
const day = parseInt(splitDate[0]);
const month = parseInt(splitDate[1]);
const year = parseInt(splitDate[2]);
console.log(day + 1, month, year);
const epoc = new Date(year, month, day + 1).valueOf();
console.log('epoc', epoc);
renewVouchers({
date: epoc,
vouchers: selected
});
}
useEffect(() => {
getVoucherList();
return () => { };
Expand All @@ -52,24 +60,26 @@ function Renew ({ goBack, loading, vouchers, getVoucherList }) {
.map(v => v.voucher);
setSelected(firstSelected);
}
console.log('renewed', renewed);
return (
<div>
<Box title={I18n.t('Renew')}>
<Box title={daysLeft + ' ' + I18n.t('days left')}>
{!loading && vouchers
? <RenewContent
vouchers={vouchers}
handleCheck={handleCheck}
selected={selected}
/>
/>
: <Loading />
}
</Box>
<div>
<button class="button green block button-one" onClick={renewVouchers}>
{I18n.t('Renovar')}
<h4>{I18n.t('Renew vouchers until')} {renewDate}</h4>
<button class="button green block button-one" disabled={loading} onClick={handleRenew}>
{I18n.t('Renew')}
</button>
<button class="button green block" onClick={goBack}>
{I18n.t('Cancelar')}
{I18n.t('Cancel')}
</button>
</div>
</div>
Expand All @@ -78,10 +88,12 @@ function Renew ({ goBack, loading, vouchers, getVoucherList }) {

export const mapStateToProps = state => ({
loading: loading(state),
vouchers: vouchers(state)
vouchers: vouchers(state),
renewed: renewed(state)
});

export const mapDispatchToProps = dispatch => ({
getVoucherList: bindActionCreators(getVoucherList, dispatch)
getVoucherList: bindActionCreators(getVoucherList, dispatch),
renewVouchers: bindActionCreators(renewVouchers, dispatch)
});
export default connect(mapStateToProps, mapDispatchToProps)(Renew);
9 changes: 7 additions & 2 deletions plugins/lime-plugin-pirania/src/piraniaActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
LOAD_GOVERNANCE,
LOAD_VOUCHERS,
CREATE_MEMBER_VOUCHER,
CREATE_VISITOR_VOUCHER
// RENEW_MEMBER_VOUCHERS,
CREATE_VISITOR_VOUCHER,
RENEW_MEMBER_VOUCHERS
// DELETE_VOUCHER
} from './piraniaConstants';

Expand All @@ -29,3 +29,8 @@ export const createVisitorVoucher = (payload) => ({
type: CREATE_VISITOR_VOUCHER,
payload
});

export const renewVouchers = (payload) => ({
type: RENEW_MEMBER_VOUCHERS,
payload
});
1 change: 1 addition & 0 deletions plugins/lime-plugin-pirania/src/piraniaApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export const getGovernance = (api, sid) => api.call(sid, 'pirania-app', 'show_go
export const getVoucherList = (api, sid) => api.call(sid, 'pirania', 'list_vouchers', {});
export const addMemberVoucher = (api, sid, input) => api.call(sid, 'pirania', 'add_member_voucher', input);
export const addVisitorVoucher = (api, sid, input) => api.call(sid, 'pirania', 'add_visitor_voucher', input);
export const runRenewVouchers = (api, sid, input) => api.call(sid, 'pirania', 'renew_many_vouchers', input);
24 changes: 21 additions & 3 deletions plugins/lime-plugin-pirania/src/piraniaEpics.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { getActiveVouchers, getGovernance, getVoucherList, addMemberVoucher, addVisitorVoucher } from './piraniaApi';
import { getActiveVouchers, getGovernance, getVoucherList, addMemberVoucher, addVisitorVoucher, runRenewVouchers } from './piraniaApi';
import {
LOAD_ACTIVE_VOUCHERS, LOAD_ACTIVE_VOUCHERS_SUCCESS, LOAD_ACTIVE_VOUCHERS_ERROR,
LOAD_GOVERNANCE, LOAD_GOVERNANCE_SUCCESS, LOAD_GOVERNANCE_ERROR,
LOAD_VOUCHERS, LOAD_VOUCHERS_SUCCESS, LOAD_VOUCHERS_ERROR,
CREATE_MEMBER_VOUCHER, CREATE_MEMBER_VOUCHER_SUCCESS, CREATE_MEMBER_VOUCHER_ERROR,
CREATE_VISITOR_VOUCHER, CREATE_VISITOR_VOUCHER_SUCCESS, CREATE_VISITOR_VOUCHER_ERROR
CREATE_VISITOR_VOUCHER, CREATE_VISITOR_VOUCHER_SUCCESS, CREATE_VISITOR_VOUCHER_ERROR,
RENEW_MEMBER_VOUCHERS, RENEW_MEMBER_VOUCHERS_SUCCESS, RENEW_MEMBER_VOUCHERS_ERROR
} from './piraniaConstants';

import 'rxjs/add/operator/map';
Expand Down Expand Up @@ -104,5 +105,22 @@ const createVisitorVoucher = (action$, store, { wsAPI }) =>
{ type: 'NOTIFICATION', payload: { msg: 'Error' } }
]);

const renewVouchers = (action$, store, { wsAPI }) =>
action$
.ofType(RENEW_MEMBER_VOUCHERS)
.mergeMap(action => runRenewVouchers(wsAPI, store.value.admin.sid, action.payload))
.mergeMap(payload => {
if (payload.code) {
return [
{ type: RENEW_MEMBER_VOUCHERS_ERROR, payload },
{ type: 'NOTIFICATION', payload: { msg: payload.message } }
];
}
return [{ type: RENEW_MEMBER_VOUCHERS_SUCCESS, payload }];
})
.catch([
{ type: RENEW_MEMBER_VOUCHERS_ERROR },
{ type: 'NOTIFICATION', payload: { msg: 'Error' } }
]);

export default { loadActiveVouchers, loadGovernance, loadVoucherList, createMemberVoucher, createVisitorVoucher };
export default { loadActiveVouchers, loadGovernance, loadVoucherList, createMemberVoucher, createVisitorVoucher, renewVouchers };
8 changes: 7 additions & 1 deletion plugins/lime-plugin-pirania/src/piraniaReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
LOAD_GOVERNANCE, LOAD_GOVERNANCE_SUCCESS, LOAD_GOVERNANCE_ERROR,
LOAD_VOUCHERS, LOAD_VOUCHERS_SUCCESS, LOAD_VOUCHERS_ERROR,
CREATE_MEMBER_VOUCHER, CREATE_MEMBER_VOUCHER_SUCCESS, CREATE_MEMBER_VOUCHER_ERROR,
CREATE_VISITOR_VOUCHER, CREATE_VISITOR_VOUCHER_SUCCESS, CREATE_VISITOR_VOUCHER_ERROR
CREATE_VISITOR_VOUCHER, CREATE_VISITOR_VOUCHER_SUCCESS, CREATE_VISITOR_VOUCHER_ERROR,
RENEW_MEMBER_VOUCHERS, RENEW_MEMBER_VOUCHERS_SUCCESS, RENEW_MEMBER_VOUCHERS_ERROR
} from './piraniaConstants';

export const initialState = {
Expand All @@ -20,6 +21,7 @@ export const reducer = (state = initialState, { type, payload }) => {
case LOAD_VOUCHERS:
case CREATE_VISITOR_VOUCHER:
case CREATE_MEMBER_VOUCHER:
case RENEW_MEMBER_VOUCHERS:
return Object.assign({}, state, { loading: true });
case LOAD_ACTIVE_VOUCHERS_SUCCESS:
return Object.assign({}, state, { activeVouchers: payload.vouchers, loading: false });
Expand All @@ -39,6 +41,10 @@ export const reducer = (state = initialState, { type, payload }) => {
case CREATE_MEMBER_VOUCHER_ERROR:
case CREATE_VISITOR_VOUCHER_ERROR:
return Object.assign({}, state, { loading: false });
case RENEW_MEMBER_VOUCHERS_SUCCESS:
return Object.assign({}, state, { renewed: payload, loading: false });
case RENEW_MEMBER_VOUCHERS_ERROR:
return Object.assign({}, state, { loading: false });
default:
return state;
}
Expand Down
1 change: 1 addition & 0 deletions plugins/lime-plugin-pirania/src/piraniaSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export const governance = state => state.pirania.governance;
export const vouchers = state => state.pirania.vouchers;
export const loading = state => state.pirania.loading;
export const createVoucher = state => state.pirania.createVoucher;
export const renewed = state => state.pirania.renewed;