From 0a0efd70ab9a1432f83c1360f6abc363af9b5291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Fri, 29 Oct 2021 12:48:24 +0100 Subject: [PATCH 1/5] fix: change color according to notification settings --- .../src/components/inputs/cashbox/Cashbox.js | 22 +++++++++++++------ .../inputs/cashbox/Cashbox.styles.js | 5 ++--- .../inputs/formik/CashCassetteInput.js | 3 ++- .../src/pages/Maintenance/CashCassettes.js | 9 ++++++-- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js b/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js index 1fbd83cc..6cc6864e 100644 --- a/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js +++ b/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js @@ -21,10 +21,11 @@ const Cashbox = ({ labelClassName, applyColorVariant, applyFiatBalanceAlertsStyling, - omitInnerPercentage + omitInnerPercentage, + isLow }) => { - const classes = cashboxClasses({ percent, cashOut, applyColorVariant }) - const threshold = 51 + const classes = cashboxClasses({ percent, cashOut, applyColorVariant, isLow }) + const ltHalf = percent <= 51 const showCashBox = { [classes.fiatBalanceAlertCashbox]: applyFiatBalanceAlertsStyling, @@ -34,12 +35,12 @@ const Cashbox = ({ return (
- {!omitInnerPercentage && percent <= threshold && ( + {!omitInnerPercentage && ltHalf && ( {percent.toFixed(0)}% )}
- {!omitInnerPercentage && percent > threshold && ( + {!omitInnerPercentage && !ltHalf && ( {percent.toFixed(0)}% )}
@@ -115,15 +116,22 @@ const CashOut = ({ currency, notes, className, - editingMode = false + editingMode = false, + threshold }) => { const percent = (100 * notes) / capacity + const isLow = percent < threshold const classes = gridClasses() return ( <>
- +
{!editingMode && (
diff --git a/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.styles.js b/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.styles.js index cebc8b4f..5556af4c 100644 --- a/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.styles.js +++ b/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.styles.js @@ -11,10 +11,9 @@ const colors = { } } -const colorPicker = ({ percent, cashOut, applyColorVariant }) => { - if (applyColorVariant) return colors[cashOut ? 'cashOut' : 'cashIn'].full +const colorPicker = ({ cashOut, applyColorVariant, isLow }) => { return colors[cashOut ? 'cashOut' : 'cashIn'][ - percent >= 50 ? 'full' : 'empty' + applyColorVariant || !isLow ? 'full' : 'empty' ] } diff --git a/new-lamassu-admin/src/components/inputs/formik/CashCassetteInput.js b/new-lamassu-admin/src/components/inputs/formik/CashCassetteInput.js index 5002b0fb..80e82e77 100644 --- a/new-lamassu-admin/src/components/inputs/formik/CashCassetteInput.js +++ b/new-lamassu-admin/src/components/inputs/formik/CashCassetteInput.js @@ -15,7 +15,7 @@ const useStyles = makeStyles({ } }) -const CashCassetteInput = memo(({ decimalPlaces, ...props }) => { +const CashCassetteInput = memo(({ decimalPlaces, threshold, ...props }) => { const classes = useStyles() const { name, onChange, onBlur, value } = props.field const { touched, errors } = props.form @@ -27,6 +27,7 @@ const CashCassetteInput = memo(({ decimalPlaces, ...props }) => { className={classes.cashCassette} notes={notes} editingMode={true} + threshold={threshold} /> { const machines = R.path(['machines'])(data) ?? [] const config = R.path(['config'])(data) ?? {} + const fillingPercentageSettings = fromNamespace('notifications', config) const [setCassetteBills, { error }] = useMutation(SET_CASSETTE_BILLS, { refetchQueries: () => ['getData'] }) @@ -198,11 +199,13 @@ const CashCassettes = () => { denomination={getCashoutSettings(id)?.top} currency={{ code: fiatCurrency }} notes={value} + threshold={fillingPercentageSettings.fillingPercentageCassette1} /> ), input: CashCassetteInput, inputProps: { - decimalPlaces: 0 + decimalPlaces: 0, + threshold: fillingPercentageSettings.fillingPercentageCassette1 } }, { @@ -217,12 +220,14 @@ const CashCassettes = () => { denomination={getCashoutSettings(id)?.bottom} currency={{ code: fiatCurrency }} notes={value} + threshold={fillingPercentageSettings.fillingPercentageCassette2} /> ) }, input: CashCassetteInput, inputProps: { - decimalPlaces: 0 + decimalPlaces: 0, + threshold: fillingPercentageSettings.fillingPercentageCassette2 } }, { From a3a069f335c8e18413a264b36402489b5880e7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Fri, 29 Oct 2021 12:52:46 +0100 Subject: [PATCH 2/5] chore: remove dead code --- .../src/components/inputs/cashbox/Cashbox.js | 81 +------------------ 1 file changed, 1 insertion(+), 80 deletions(-) diff --git a/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js b/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js index 6cc6864e..f41ddf82 100644 --- a/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js +++ b/new-lamassu-admin/src/components/inputs/cashbox/Cashbox.js @@ -3,11 +3,8 @@ import classnames from 'classnames' import React from 'react' import Chip from 'src/components/Chip' -import { Link } from 'src/components/buttons' import { Info2, Label1, Label2 } from 'src/components/typography' -import TextInputFormik from '../base/TextInput' - import { cashboxStyles, gridStyles } from './Cashbox.styles' const cashboxClasses = makeStyles(cashboxStyles) @@ -72,44 +69,6 @@ const CashIn = ({ currency, notes, total }) => { ) } -const CashInFormik = ({ - capacity = 1000, - onEmpty, - field: { - value: { notes, deviceId } - }, - form: { setFieldValue } -}) => { - const classes = gridClasses() - - return ( - <> -
-
- -
-
-
- { - onEmpty({ - variables: { - deviceId, - action: 'emptyCashInBills' - } - }).then(() => setFieldValue('cashin.notes', 0)) - }} - className={classes.link} - color={'primary'}> - Empty - -
-
-
- - ) -} - const CashOut = ({ capacity = 500, denomination = 0, @@ -154,42 +113,4 @@ const CashOut = ({ ) } -const CashOutFormik = ({ capacity = 500, ...props }) => { - const { - name, - onChange, - onBlur, - value: { notes } - } = props.field - const { touched, errors } = props.form - - const error = !!(touched[name] && errors[name]) - - const percent = (100 * notes) / capacity - const classes = gridClasses() - - return ( - <> -
-
- -
-
-
- -
-
-
- - ) -} - -export { Cashbox, CashIn, CashInFormik, CashOut, CashOutFormik } +export { Cashbox, CashIn, CashOut } From 8240d4d8dcb13335b66aa0e9b2156c821439e3a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Fri, 5 Nov 2021 10:14:35 +0000 Subject: [PATCH 3/5] refactor: remove unnecessary variable --- .../pages/Machines/MachineComponents/Cassettes/Cassettes.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js b/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js index 1f881809..7f3737dc 100644 --- a/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js +++ b/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js @@ -57,11 +57,10 @@ const SET_CASSETTE_BILLS = gql` ` const CashCassettes = ({ machine, config, refetchData }) => { - const data = { machine, config } const classes = useStyles() - const cashout = data?.config && fromNamespace('cashOut')(data.config) - const locale = data?.config && fromNamespace('locale')(data.config) + const cashout = fromNamespace('cashOut')(config) + const locale = fromNamespace('locale')(config) const fiatCurrency = locale?.fiatCurrency const getCashoutSettings = deviceId => fromNamespace(deviceId)(cashout) From ac6046d74a2d79f7915e8d6f5fb00b143881c3d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Fri, 5 Nov 2021 10:15:21 +0000 Subject: [PATCH 4/5] fix: change cassette color in machine details --- .../pages/Machines/MachineComponents/Cassettes/Cassettes.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js b/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js index 7f3737dc..c5458149 100644 --- a/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js +++ b/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js @@ -61,6 +61,7 @@ const CashCassettes = ({ machine, config, refetchData }) => { const cashout = fromNamespace('cashOut')(config) const locale = fromNamespace('locale')(config) + const fillingPercentageSettings = fromNamespace('notifications', config) const fiatCurrency = locale?.fiatCurrency const getCashoutSettings = deviceId => fromNamespace(deviceId)(cashout) @@ -92,6 +93,7 @@ const CashCassettes = ({ machine, config, refetchData }) => { denomination={getCashoutSettings(deviceId)?.top} currency={{ code: fiatCurrency }} notes={value} + threshold={fillingPercentageSettings.fillingPercentageCassette1} /> ), input: NumberInput, @@ -111,6 +113,7 @@ const CashCassettes = ({ machine, config, refetchData }) => { denomination={getCashoutSettings(deviceId)?.bottom} currency={{ code: fiatCurrency }} notes={value} + threshold={fillingPercentageSettings.fillingPercentageCassette2} /> ) }, From 17f39d8ea2ce973d11999e2ed266973f9a1e05af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1?= Date: Fri, 5 Nov 2021 13:06:41 +0000 Subject: [PATCH 5/5] fix: guard against falsy config --- .../Machines/MachineComponents/Cassettes/Cassettes.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js b/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js index c5458149..c0136e37 100644 --- a/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js +++ b/new-lamassu-admin/src/pages/Machines/MachineComponents/Cassettes/Cassettes.js @@ -59,9 +59,10 @@ const SET_CASSETTE_BILLS = gql` const CashCassettes = ({ machine, config, refetchData }) => { const classes = useStyles() - const cashout = fromNamespace('cashOut')(config) - const locale = fromNamespace('locale')(config) - const fillingPercentageSettings = fromNamespace('notifications', config) + const cashout = config && fromNamespace('cashOut')(config) + const locale = config && fromNamespace('locale')(config) + const fillingPercentageSettings = + config && fromNamespace('notifications', config) const fiatCurrency = locale?.fiatCurrency const getCashoutSettings = deviceId => fromNamespace(deviceId)(cashout)