diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..0dc119f --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "trailingComma": "all", + "printWidth": 120, + "quoteProps": "preserve", + "arrowParens": "always" +} diff --git a/package.json b/package.json index e9675e9..782ebd7 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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": [ diff --git a/src/actions.js b/src/actions.js index d1b413c..b2b195d 100644 --- a/src/actions.js +++ b/src/actions.js @@ -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); } diff --git a/src/index.js b/src/index.js index 3ef553a..33d5c27 100644 --- a/src/index.js +++ b/src/index.js @@ -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 }; -} \ No newline at end of file +}; diff --git a/src/pickers/PayerPicker.js b/src/pickers/PayerPicker.js index 0d17856..2d8d24b 100644 --- a/src/pickers/PayerPicker.js +++ b/src/pickers/PayerPicker.js @@ -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 ( - - - {!fetchingPayers && !errorPayers && ( - {this.formatSuggestion(a)}} - 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")} - /> - )} - - ) - } + render() { + const { + intl, + value, + reset, + readOnly = false, + required = false, + payers, + fetchingPayers, + errorPayers, + withNull = false, + nullLabel = null, + withLabel = true, + label, + } = this.props; + return ( + + + {!fetchingPayers && !errorPayers && ( + {this.formatSuggestion(a)}} + 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")} + /> + )} + + ); + } } -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)))), ); diff --git a/src/reducer.js b/src/reducer.js index 58012e8..757315a 100644 --- a/src/reducer.js +++ b/src/reducer.js @@ -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; diff --git a/src/translations/en.json b/src/translations/en.json index 44ffd81..f6f1bc6 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -1,4 +1,4 @@ { - "payer.PayerPicker.label": "Payer", - "payer.PayerPicker.null": "Any" -} \ No newline at end of file + "payer.PayerPicker.label": "Payer", + "payer.PayerPicker.null": "Any" +}