Merge pull request #1364 from siiky/feat/lam-609/cashbox-notifications
Add cash-in notifications settings
This commit is contained in:
commit
78f798fd4a
4 changed files with 126 additions and 56 deletions
|
|
@ -71,7 +71,9 @@ const fiatBalancesNotify = (fiatWarnings) => {
|
|||
const { cassette, deviceId } = o.detail
|
||||
return cassette === balance.cassette && deviceId === balance.deviceId
|
||||
}, notInvalidated)) return
|
||||
const message = `Cash-out cassette ${balance.cassette} low or empty!`
|
||||
const message = balance.code === 'LOW_CASH_OUT' ?
|
||||
`Cash-out cassette ${balance.cassette} low or empty!` :
|
||||
`Cash box full or almost full!`
|
||||
const detailB = utils.buildDetail({ deviceId: balance.deviceId, cassette: balance.cassette })
|
||||
return queries.addNotification(FIAT_BALANCE, message, detailB)
|
||||
})
|
||||
|
|
@ -111,11 +113,18 @@ const cryptoBalancesNotify = (cryptoWarnings) => {
|
|||
}
|
||||
|
||||
const balancesNotify = (balances) => {
|
||||
const cryptoFilter = o => o.code === 'HIGH_CRYPTO_BALANCE' || o.code === 'LOW_CRYPTO_BALANCE'
|
||||
const fiatFilter = o => o.code === 'LOW_CASH_OUT'
|
||||
const cryptoWarnings = _.filter(cryptoFilter, balances)
|
||||
const fiatWarnings = _.filter(fiatFilter, balances)
|
||||
return Promise.all([cryptoBalancesNotify(cryptoWarnings), fiatBalancesNotify(fiatWarnings)])
|
||||
const isCryptoCode = c => _.includes(c, ['HIGH_CRYPTO_BALANCE', 'LOW_CRYPTO_BALANCE'])
|
||||
const isFiatCode = c => _.includes(c, ['LOW_CASH_OUT', 'CASH_BOX_FULL'])
|
||||
const by = o =>
|
||||
isCryptoCode(o) ? 'crypto' :
|
||||
isFiatCode(o) ? 'fiat' :
|
||||
undefined
|
||||
const warnings = _.flow(
|
||||
_.groupBy(_.flow(_.get(['code']), by)),
|
||||
_.update('crypto', _.defaultTo([])),
|
||||
_.update('fiat', _.defaultTo([])),
|
||||
)(balances)
|
||||
return Promise.all([cryptoBalancesNotify(warnings.crypto), fiatBalancesNotify(warnings.fiat)])
|
||||
}
|
||||
|
||||
const clearOldErrorNotifications = alerts => {
|
||||
|
|
|
|||
|
|
@ -74,11 +74,11 @@ const MachineRoute = () => {
|
|||
setLoading(false)
|
||||
},
|
||||
variables: {
|
||||
deviceId: id
|
||||
},
|
||||
billFilters: {
|
||||
deviceId: id,
|
||||
batch: 'none'
|
||||
billFilters: {
|
||||
deviceId: id,
|
||||
batch: 'none'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,11 @@ import styles from './FiatBalanceAlerts.styles.js'
|
|||
|
||||
const useStyles = makeStyles(styles)
|
||||
|
||||
const NAME = 'fiatBalanceAlerts'
|
||||
const CASH_IN_KEY = 'fiatBalanceAlertsCashIn'
|
||||
const CASH_OUT_KEY = 'fiatBalanceAlertsCashOut'
|
||||
const DEFAULT_NUMBER_OF_CASSETTES = 2
|
||||
const notesMin = 0
|
||||
const notesMax = 9999999
|
||||
|
||||
const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
|
||||
const {
|
||||
|
|
@ -36,9 +39,13 @@ const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
|
|||
DEFAULT_NUMBER_OF_CASSETTES
|
||||
)
|
||||
|
||||
const editing = isEditing(NAME)
|
||||
|
||||
const schema = Yup.object().shape({
|
||||
cashInAlertThreshold: Yup.number()
|
||||
.transform(transformNumber)
|
||||
.integer()
|
||||
.min(notesMin)
|
||||
.max(notesMax)
|
||||
.nullable(),
|
||||
fillingPercentageCassette1: Yup.number()
|
||||
.transform(transformNumber)
|
||||
.integer()
|
||||
|
|
@ -71,6 +78,7 @@ const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
|
|||
validateOnChange={false}
|
||||
enableReinitialize
|
||||
initialValues={{
|
||||
cashInAlertThreshold: data?.cashInAlertThreshold ?? '',
|
||||
fillingPercentageCassette1: data?.fillingPercentageCassette1 ?? '',
|
||||
fillingPercentageCassette2: data?.fillingPercentageCassette2 ?? '',
|
||||
fillingPercentageCassette3: data?.fillingPercentageCassette3 ?? '',
|
||||
|
|
@ -79,52 +87,80 @@ const FiatBalance = ({ section, min = 0, max = 100, fieldWidth = 80 }) => {
|
|||
validationSchema={schema}
|
||||
onSubmit={it => save(section, schema.cast(it))}
|
||||
onReset={() => {
|
||||
setEditing(NAME, false)
|
||||
setEditing(CASH_IN_KEY, false)
|
||||
setEditing(CASH_OUT_KEY, false)
|
||||
}}>
|
||||
{({ values }) => (
|
||||
<Form className={classes.form}>
|
||||
<PromptWhenDirty />
|
||||
<Header
|
||||
title="Cash out (Empty)"
|
||||
editing={editing}
|
||||
disabled={isDisabled(NAME)}
|
||||
setEditing={it => setEditing(NAME, it)}
|
||||
/>
|
||||
<div className={classes.wrapper}>
|
||||
{R.map(
|
||||
it => (
|
||||
<>
|
||||
<div className={classes.row}>
|
||||
<Cashbox
|
||||
labelClassName={classes.cashboxLabel}
|
||||
emptyPartClassName={classes.cashboxEmptyPart}
|
||||
percent={
|
||||
values[`fillingPercentageCassette${it + 1}`] ??
|
||||
data[`cassette${it + 1}`]
|
||||
}
|
||||
applyColorVariant
|
||||
applyFiatBalanceAlertsStyling
|
||||
omitInnerPercentage
|
||||
cashOut
|
||||
<>
|
||||
<Form className={classes.form}>
|
||||
<PromptWhenDirty />
|
||||
<Header
|
||||
title="Cash box"
|
||||
editing={isEditing(CASH_IN_KEY)}
|
||||
disabled={isDisabled(CASH_IN_KEY)}
|
||||
setEditing={it => setEditing(CASH_IN_KEY, it)}
|
||||
/>
|
||||
<div className={classes.wrapper}>
|
||||
<div className={classes.first}>
|
||||
<div className={classes.row}>
|
||||
<div className={classes.col2}>
|
||||
<EditableNumber
|
||||
label="Alert me over"
|
||||
name="cashInAlertThreshold"
|
||||
editing={isEditing(CASH_IN_KEY)}
|
||||
displayValue={x => (x === '' ? '-' : x)}
|
||||
decoration="notes"
|
||||
width={fieldWidth}
|
||||
/>
|
||||
<div className={classes.col2}>
|
||||
<TL2 className={classes.title}>Cassette {it + 1}</TL2>
|
||||
<EditableNumber
|
||||
label="Alert me under"
|
||||
name={`fillingPercentageCassette${it + 1}`}
|
||||
editing={editing}
|
||||
displayValue={x => (x === '' ? '-' : x)}
|
||||
decoration="%"
|
||||
width={fieldWidth}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
),
|
||||
R.times(R.identity, maxNumberOfCassettes)
|
||||
)}
|
||||
</div>
|
||||
</Form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
<Form className={classes.form}>
|
||||
<PromptWhenDirty />
|
||||
<Header
|
||||
title="Cash out (Empty)"
|
||||
editing={isEditing(CASH_OUT_KEY)}
|
||||
disabled={isDisabled(CASH_OUT_KEY)}
|
||||
setEditing={it => setEditing(CASH_OUT_KEY, it)}
|
||||
/>
|
||||
<div className={classes.wrapper}>
|
||||
{R.map(
|
||||
it => (
|
||||
<>
|
||||
<div className={classes.row}>
|
||||
<Cashbox
|
||||
labelClassName={classes.cashboxLabel}
|
||||
emptyPartClassName={classes.cashboxEmptyPart}
|
||||
percent={
|
||||
values[`fillingPercentageCassette${it + 1}`] ??
|
||||
data[`cassette${it + 1}`]
|
||||
}
|
||||
applyColorVariant
|
||||
applyFiatBalanceAlertsStyling
|
||||
omitInnerPercentage
|
||||
cashOut
|
||||
/>
|
||||
<div className={classes.col2}>
|
||||
<TL2 className={classes.title}>Cassette {it + 1}</TL2>
|
||||
<EditableNumber
|
||||
label="Alert me under"
|
||||
name={`fillingPercentageCassette${it + 1}`}
|
||||
editing={isEditing(CASH_OUT_KEY)}
|
||||
displayValue={x => (x === '' ? '-' : x)}
|
||||
decoration="%"
|
||||
width={fieldWidth}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
),
|
||||
R.times(R.identity, maxNumberOfCassettes)
|
||||
)}
|
||||
</div>
|
||||
</Form>
|
||||
</>
|
||||
)}
|
||||
</Formik>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,12 +10,14 @@ import { transformNumber } from 'src/utils/number'
|
|||
|
||||
import NotificationsCtx from '../NotificationsContext'
|
||||
|
||||
const CASHBOX_KEY = 'cashbox'
|
||||
const CASSETTE_1_KEY = 'fillingPercentageCassette1'
|
||||
const CASSETTE_2_KEY = 'fillingPercentageCassette2'
|
||||
const CASSETTE_3_KEY = 'fillingPercentageCassette3'
|
||||
const CASSETTE_4_KEY = 'fillingPercentageCassette4'
|
||||
const MACHINE_KEY = 'machine'
|
||||
const NAME = 'fiatBalanceOverrides'
|
||||
const DEFAULT_NUMBER_OF_CASSETTES = 2
|
||||
|
||||
const CASSETTE_LIST = [
|
||||
CASSETTE_1_KEY,
|
||||
|
|
@ -60,15 +62,19 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
|||
|
||||
const initialValues = {
|
||||
[MACHINE_KEY]: null,
|
||||
[CASHBOX_KEY]: '',
|
||||
[CASSETTE_1_KEY]: '',
|
||||
[CASSETTE_2_KEY]: '',
|
||||
[CASSETTE_3_KEY]: '',
|
||||
[CASSETTE_4_KEY]: ''
|
||||
}
|
||||
|
||||
const notesMin = 0
|
||||
const notesMax = 9999999
|
||||
|
||||
const maxNumberOfCassettes = Math.max(
|
||||
...R.map(it => it.numberOfCassettes, machines),
|
||||
2
|
||||
DEFAULT_NUMBER_OF_CASSETTES
|
||||
)
|
||||
|
||||
const percentMin = 0
|
||||
|
|
@ -79,6 +85,13 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
|||
.label('Machine')
|
||||
.nullable()
|
||||
.required(),
|
||||
[CASHBOX_KEY]: Yup.number()
|
||||
.label('Cash box')
|
||||
.transform(transformNumber)
|
||||
.integer()
|
||||
.min(notesMin)
|
||||
.max(notesMax)
|
||||
.nullable(),
|
||||
[CASSETTE_1_KEY]: Yup.number()
|
||||
.label('Cassette 1')
|
||||
.transform(transformNumber)
|
||||
|
|
@ -134,6 +147,18 @@ const FiatBalanceOverrides = ({ config, section }) => {
|
|||
valueProp: 'deviceId',
|
||||
labelProp: 'name'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: CASHBOX_KEY,
|
||||
display: 'Cashbox',
|
||||
width: 155,
|
||||
textAlign: 'right',
|
||||
bold: true,
|
||||
input: NumberInput,
|
||||
suffix: 'notes',
|
||||
inputProps: {
|
||||
decimalPlaces: 0
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue