Skip to content

Commit

Permalink
Merge pull request #5 from openimis/develop
Browse files Browse the repository at this point in the history
v1.3
  • Loading branch information
edarchis authored Oct 28, 2021
2 parents 6a5de3b + 74286c4 commit d9b710d
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 122 deletions.
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "all",
"printWidth": 120,
"quoteProps": "preserve",
"arrowParens": "always"
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openimis/fe-payer",
"version": "1.2.1",
"version": "1.3.0",
"license": "AGPL-3.0-only",
"description": "openIMIS Frontend Payment module",
"repository": "openimis/openimis-fe-payer_js",
Expand All @@ -13,12 +13,13 @@
"scripts": {
"build": "rollup -c",
"prepare": "yarn run build",
"start": "rollup -c -w"
"start": "rollup -c -w",
"format": "prettier src -w"
},
"peerDependency": {
"react-intl": "^5.8.1"
},
"devDependencies": {
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.6",
"@babel/plugin-proposal-class-properties": "^7.8.3",
Expand All @@ -30,13 +31,14 @@
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-json": "^4.0.3",
"@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-url": "^5.0.0",
"moment": "^2.25.3",
"prettier": "^2.4.1",
"prop-types": "^15.7.2",
"react-autosuggest": "^10.0.2",
"react-router-dom": "^5.2.0",
"redux": "^4.0.5",
"redux-api-middleware": "^3.2.1",
"@rollup/plugin-url": "^5.0.0",
"rollup": "^2.10.0"
},
"files": [
Expand Down
27 changes: 15 additions & 12 deletions src/actions.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import {
baseApiUrl, graphql, formatQuery, formatPageQuery, formatPageQueryWithCount,
formatMutation, decodeId, openBlob, formatJsonField
baseApiUrl,
graphql,
formatQuery,
formatPageQuery,
formatPageQueryWithCount,
formatMutation,
decodeId,
openBlob,
formatJsonField,
} from "@openimis/fe-core";
import _ from "lodash";
import _uuid from "lodash-uuid";

export function fetchPayers(mm, hf, str, prev) {
export function fetchPayers(mm, hf, str, prev) {
var filters = [];
if (!!hf) {
filters.push(`healthFacility_Uuid: "${hf.uuid}"`)
filters.push(`healthFacility_Uuid: "${hf.uuid}"`);
}
if (!!str) {
filters.push(`str: "${str}"`)
filters.push(`str: "${str}"`);
}
if (_.isEqual(filters, prev)) {
return (dispatch) => { }
return (dispatch) => {};
}
const payload = formatPageQuery(
"payers",
filters,
mm.getRef("payer.PayerPicker.projection")
);
return graphql(payload, 'PAYER_PAYERS', filters);
const payload = formatPageQuery("payers", filters, mm.getRef("payer.PayerPicker.projection"));
return graphql(payload, "PAYER_PAYERS", filters);
}
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import reducer from "./reducer";

const DEFAULT_CONFIG = {
"translations": [{ key: "en", messages: messages_en }],
"reducers": [{ key: 'payer', reducer }],
"refs" : [
"reducers": [{ key: "payer", reducer }],
"refs": [
{ key: "payer.PayerPicker", ref: PayerPicker },
{ key: "payer.PayerPicker.projection", ref: ["id", "uuid", "name"] }
]
}
{ key: "payer.PayerPicker.projection", ref: ["id", "uuid", "name"] },
],
};

export const PayerModule = (cfg) => {
return { ...DEFAULT_CONFIG, ...cfg };
}
};
132 changes: 70 additions & 62 deletions src/pickers/PayerPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,94 @@ import React, { Component, Fragment } from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import { withTheme, withStyles } from "@material-ui/core/styles";
import { injectIntl } from 'react-intl';
import { injectIntl } from "react-intl";
import _debounce from "lodash/debounce";
import _ from "lodash";
import { fetchPayers } from "../actions";
import { formatMessage, AutoSuggestion, ProgressOrError, withModulesManager } from "@openimis/fe-core";

const styles = theme => ({
label: {
color: theme.palette.primary.main
}
const styles = (theme) => ({
label: {
color: theme.palette.primary.main,
},
});

class PayerPicker extends Component {
constructor(props) {
super(props);
this.selectThreshold = props.modulesManager.getConf("fe-payer", "PayerPicker.selectThreshold", 10);
}
constructor(props) {
super(props);
this.selectThreshold = props.modulesManager.getConf("fe-payer", "PayerPicker.selectThreshold", 10);
}

formatSuggestion = p => !p ? "" : `${p.name || ""}`;
formatSuggestion = (p) => (!p ? "" : `${p.name || ""}`);

onSuggestionSelected = v => this.props.onChange(v, this.formatSuggestion(v));
onSuggestionSelected = (v) => this.props.onChange(v, this.formatSuggestion(v));

getSuggestions = (str) => !!str &&
str.length >= this.props.modulesManager.getConf("fe-payer", "payersMinCharLookup", 2) &&
this.props.fetchPayers(
this.props.modulesManager,
this.props.userHealthFacilityFullPath,
str,
this.props.fetchedPayers
)
getSuggestions = (str) =>
!!str &&
str.length >= this.props.modulesManager.getConf("fe-payer", "payersMinCharLookup", 2) &&
this.props.fetchPayers(
this.props.modulesManager,
this.props.userHealthFacilityFullPath,
str,
this.props.fetchedPayers,
);

debouncedGetSuggestion = _.debounce(
this.getSuggestions,
this.props.modulesManager.getConf("fe-payer", "debounceTime", 800)
)
debouncedGetSuggestion = _.debounce(
this.getSuggestions,
this.props.modulesManager.getConf("fe-payer", "debounceTime", 800),
);

render() {
const {
intl, value,
reset, readOnly = false, required = false,
payers, fetchingPayers, errorPayers,
withNull = false, nullLabel = null,
withLabel = true, label,
} = this.props;
return (
<Fragment>
<ProgressOrError progress={fetchingPayers} error={errorPayers} />
{!fetchingPayers && !errorPayers && (
<AutoSuggestion
module="payer"
items={payers}
label={!!withLabel && (label || formatMessage(intl, "payer", "PayerPicker.label"))}
getSuggestions={this.debouncedGetSuggestion}
renderSuggestion={a => <span>{this.formatSuggestion(a)}</span>}
getSuggestionValue={this.formatSuggestion}
onSuggestionSelected={this.onSuggestionSelected}
value={value}
reset={reset}
readOnly={readOnly}
required={required}
selectThreshold={this.selectThreshold}
withNull={withNull}
nullLabel={nullLabel || formatMessage(intl, "payer", "payer.PayerPicker.null")}
/>
)}
</Fragment>
)
}
render() {
const {
intl,
value,
reset,
readOnly = false,
required = false,
payers,
fetchingPayers,
errorPayers,
withNull = false,
nullLabel = null,
withLabel = true,
label,
} = this.props;
return (
<Fragment>
<ProgressOrError progress={fetchingPayers} error={errorPayers} />
{!fetchingPayers && !errorPayers && (
<AutoSuggestion
module="payer"
items={payers}
label={!!withLabel && (label || formatMessage(intl, "payer", "PayerPicker.label"))}
getSuggestions={this.debouncedGetSuggestion}
renderSuggestion={(a) => <span>{this.formatSuggestion(a)}</span>}
getSuggestionValue={this.formatSuggestion}
onSuggestionSelected={this.onSuggestionSelected}
value={value}
reset={reset}
readOnly={readOnly}
required={required}
selectThreshold={this.selectThreshold}
withNull={withNull}
nullLabel={nullLabel || formatMessage(intl, "payer", "payer.PayerPicker.null")}
/>
)}
</Fragment>
);
}
}

const mapStateToProps = state => ({
userHealthFacilityFullPath: !!state.loc ? state.loc.userHealthFacilityFullPath : null,
payers: state.payer.payers,
fetchedPayers: state.payer.fetchedPayers,
const mapStateToProps = (state) => ({
userHealthFacilityFullPath: !!state.loc ? state.loc.userHealthFacilityFullPath : null,
payers: state.payer.payers,
fetchedPayers: state.payer.fetchedPayers,
});

const mapDispatchToProps = dispatch => {
return bindActionCreators({ fetchPayers }, dispatch);
const mapDispatchToProps = (dispatch) => {
return bindActionCreators({ fetchPayers }, dispatch);
};

export default withModulesManager(
connect(mapStateToProps, mapDispatchToProps)(injectIntl(withTheme(withStyles(styles)(PayerPicker))))
connect(mapStateToProps, mapDispatchToProps)(injectIntl(withTheme(withStyles(styles)(PayerPicker)))),
);
75 changes: 40 additions & 35 deletions src/reducer.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
import {
parseData, dispatchMutationReq, dispatchMutationResp, dispatchMutationErr,
pageInfo, formatServerError, formatGraphQLError
} from '@openimis/fe-core';
parseData,
dispatchMutationReq,
dispatchMutationResp,
dispatchMutationErr,
pageInfo,
formatServerError,
formatGraphQLError,
} from "@openimis/fe-core";

function reducer(
state = {
fetchingPayers: false,
state = {
fetchingPayers: false,
fetchedPayers: null,
errorPayers: null,
payers: null,
},
action,
) {
switch (action.type) {
case "PAYER_PAYERS_REQ":
return {
...state,
fetchingPayers: true,
fetchedPayers: null,
errorPayers: null,
payers: null,
},
action,
) {
switch (action.type) {
case 'PAYER_PAYERS_REQ':
return {
...state,
fetchingPayers: true,
fetchedPayers: null,
payers: null,
errorPayers: null,
};
case 'PAYER_PAYERS_RESP':
return {
...state,
fetchingPayers: false,
fetchedPayers: action.meta,
payers: parseData(action.payload.data.payers),
errorPayers: formatGraphQLError(action.payload)
};
case 'PAYER_PAYERS_ERR':
return {
...state,
fetchingPayers: null,
errorPayers: formatServerError(action.payload)
};
default:
return state;
}
errorPayers: null,
};
case "PAYER_PAYERS_RESP":
return {
...state,
fetchingPayers: false,
fetchedPayers: action.meta,
payers: parseData(action.payload.data.payers),
errorPayers: formatGraphQLError(action.payload),
};
case "PAYER_PAYERS_ERR":
return {
...state,
fetchingPayers: null,
errorPayers: formatServerError(action.payload),
};
default:
return state;
}
}

export default reducer;
6 changes: 3 additions & 3 deletions src/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"payer.PayerPicker.label": "Payer",
"payer.PayerPicker.null": "Any"
}
"payer.PayerPicker.label": "Payer",
"payer.PayerPicker.null": "Any"
}

0 comments on commit d9b710d

Please sign in to comment.