fix: loading usage

This commit is contained in:
Sérgio Salgado 2021-12-13 19:56:53 +00:00
parent c641d6d3fa
commit dfa82e54ae
9 changed files with 71 additions and 62 deletions

View file

@ -114,7 +114,7 @@ const Accounting = () => {
const { data: configResponse, loading: configLoading } = useQuery(GET_DATA) const { data: configResponse, loading: configLoading } = useQuery(GET_DATA)
const timezone = R.path(['config', 'locale_timezone'], configResponse) const timezone = R.path(['config', 'locale_timezone'], configResponse)
const loading = operatorLoading && configLoading const loading = operatorLoading || configLoading
const operatorData = R.path(['operatorByUsername'], opData) const operatorData = R.path(['operatorByUsername'], opData)
@ -170,19 +170,16 @@ const Accounting = () => {
] ]
return ( return (
!loading && (
<> <>
<TitleSection title="Accounting" /> <TitleSection title="Accounting" />
<Assets <Assets
balance={ balance={operatorData.fiatBalances[operatorData.preferredFiatCurrency]}
operatorData.fiatBalances[operatorData.preferredFiatCurrency]
}
hedgingReserve={operatorData.hedgingReserve ?? 0} hedgingReserve={operatorData.hedgingReserve ?? 0}
currency={operatorData.preferredFiatCurrency} currency={operatorData.preferredFiatCurrency}
/> />
<H4 className={classes.tableTitle}>Fiat balance history</H4> <H4 className={classes.tableTitle}>Fiat balance history</H4>
<DataTable <DataTable
loading={false} loading={loading}
emptyText="No transactions so far" emptyText="No transactions so far"
elements={elements} elements={elements}
data={operatorData.fundings ?? []} data={operatorData.fundings ?? []}
@ -190,7 +187,6 @@ const Accounting = () => {
/> />
</> </>
) )
)
} }
export default Accounting export default Accounting

View file

@ -381,7 +381,7 @@ const CustomerProfile = memo(() => {
const photosData = formatPhotosData(R.append(frontCameraData, txPhotosData)) const photosData = formatPhotosData(R.append(frontCameraData, txPhotosData))
const loading = customerLoading && configLoading const loading = customerLoading || configLoading
const timezone = R.path(['config', 'locale_timezone'], configResponse) const timezone = R.path(['config', 'locale_timezone'], configResponse)

View file

@ -64,7 +64,9 @@ const IndividualDiscounts = () => {
const [showModal, setShowModal] = useState(false) const [showModal, setShowModal] = useState(false)
const toggleModal = () => setShowModal(!showModal) const toggleModal = () => setShowModal(!showModal)
const { data: discountResponse, loading } = useQuery(GET_INDIVIDUAL_DISCOUNTS) const { data: discountResponse, loading: discountLoading } = useQuery(
GET_INDIVIDUAL_DISCOUNTS
)
const { data: customerData, loading: customerLoading } = useQuery( const { data: customerData, loading: customerLoading } = useQuery(
GET_CUSTOMERS GET_CUSTOMERS
) )
@ -160,11 +162,11 @@ const IndividualDiscounts = () => {
} }
] ]
const isLoading = loading || customerLoading const loading = discountLoading || customerLoading
return ( return (
<> <>
{!isLoading && !R.isEmpty(discountResponse.individualDiscounts) && ( {!loading && !R.isEmpty(discountResponse.individualDiscounts) && (
<Box <Box
marginBottom={4} marginBottom={4}
marginTop={-7} marginTop={-7}
@ -176,7 +178,7 @@ const IndividualDiscounts = () => {
</Link> </Link>
</Box> </Box>
)} )}
{!isLoading && !R.isEmpty(discountResponse.individualDiscounts) && ( {!loading && !R.isEmpty(discountResponse.individualDiscounts) && (
<> <>
<DataTable <DataTable
elements={elements} elements={elements}
@ -196,7 +198,7 @@ const IndividualDiscounts = () => {
/> />
</> </>
)} )}
{!isLoading && R.isEmpty(discountResponse.individualDiscounts) && ( {!loading && R.isEmpty(discountResponse.individualDiscounts) && (
<Box display="flex" alignItems="left" flexDirection="column"> <Box display="flex" alignItems="left" flexDirection="column">
<Label3> <Label3>
It seems there are no active individual customer discounts on your It seems there are no active individual customer discounts on your

View file

@ -81,16 +81,21 @@ const Logs = () => {
const deviceId = selected?.deviceId const deviceId = selected?.deviceId
const { data: machineResponse } = useQuery(GET_MACHINES) const { data: machineResponse, loading: machinesLoading } = useQuery(
GET_MACHINES
)
const { data: configResponse } = useQuery(GET_DATA) const { data: configResponse, loading: configLoading } = useQuery(GET_DATA)
const timezone = R.path(['config', 'locale_timezone'], configResponse) const timezone = R.path(['config', 'locale_timezone'], configResponse)
const { data: logsResponse, loading } = useQuery(GET_MACHINE_LOGS, { const { data: logsResponse, loading: logsLoading } = useQuery(
GET_MACHINE_LOGS,
{
variables: { deviceId, limit: NUM_LOG_RESULTS }, variables: { deviceId, limit: NUM_LOG_RESULTS },
skip: !selected, skip: !selected,
onCompleted: () => setSaveMessage('') onCompleted: () => setSaveMessage('')
}) }
)
if (machineResponse?.machines?.length && !selected) { if (machineResponse?.machines?.length && !selected) {
setSelected(machineResponse?.machines[0]) setSelected(machineResponse?.machines[0])
@ -100,6 +105,8 @@ const Logs = () => {
return R.path(['deviceId'])(selected) === it.deviceId return R.path(['deviceId'])(selected) === it.deviceId
} }
const loading = machinesLoading || configLoading || logsLoading
return ( return (
<> <>
<div className={classes.titleWrapper}> <div className={classes.titleWrapper}>

View file

@ -82,7 +82,7 @@ const Transactions = ({ id }) => {
const { data: configData, loading: configLoading } = useQuery(GET_DATA) const { data: configData, loading: configLoading } = useQuery(GET_DATA)
const timezone = R.path(['config', 'locale_timezone'], configData) const timezone = R.path(['config', 'locale_timezone'], configData)
const loading = txLoading && configLoading const loading = txLoading || configLoading
if (!loading && txResponse) { if (!loading && txResponse) {
txResponse.transactions = txResponse.transactions.splice(0, 5) txResponse.transactions = txResponse.transactions.splice(0, 5)

View file

@ -85,7 +85,7 @@ const CashboxHistory = ({ machines, currency }) => {
const { data: configData, loading: configLoading } = useQuery(GET_DATA) const { data: configData, loading: configLoading } = useQuery(GET_DATA)
const timezone = R.path(['config', 'locale_timezone'], configData) const timezone = R.path(['config', 'locale_timezone'], configData)
const loading = batchesLoading && configLoading const loading = batchesLoading || configLoading
const batches = R.path(['cashboxBatches'])(batchesData) const batches = R.path(['cashboxBatches'])(batchesData)
@ -248,16 +248,13 @@ const CashboxHistory = ({ machines, currency }) => {
] ]
return ( return (
<>
{!loading && (
<DataTable <DataTable
loading={loading}
name="cashboxHistory" name="cashboxHistory"
elements={elements} elements={elements}
data={batches} data={batches}
emptyText="No cashbox batches so far" emptyText="No cashbox batches so far"
/> />
)}
</>
) )
} }

View file

@ -54,7 +54,11 @@ const MachineStatus = () => {
const history = useHistory() const history = useHistory()
const { state } = useLocation() const { state } = useLocation()
const addedMachineId = state?.id const addedMachineId = state?.id
const { data: machinesResponse, refetch, loading } = useQuery(GET_MACHINES) const {
data: machinesResponse,
refetch,
loading: machinesLoading
} = useQuery(GET_MACHINES)
const { data: configResponse, configLoading } = useQuery(GET_DATA) const { data: configResponse, configLoading } = useQuery(GET_DATA)
const timezone = R.path(['config', 'locale_timezone'], configResponse) const timezone = R.path(['config', 'locale_timezone'], configResponse)
@ -114,6 +118,8 @@ const MachineStatus = () => {
<MachineDetailsRow it={it} onActionSuccess={refetch} timezone={timezone} /> <MachineDetailsRow it={it} onActionSuccess={refetch} timezone={timezone} />
) )
const loading = machinesLoading || configLoading
return ( return (
<> <>
<div className={classes.titleWrapper}> <div className={classes.titleWrapper}>
@ -132,7 +138,7 @@ const MachineStatus = () => {
</div> </div>
</div> </div>
<DataTable <DataTable
loading={loading && configLoading} loading={loading}
elements={elements} elements={elements}
data={machines} data={machines}
Details={InnerMachineDetailsRow} Details={InnerMachineDetailsRow}

View file

@ -98,13 +98,13 @@ const Logs = () => {
const [saveMessage, setSaveMessage] = useState(null) const [saveMessage, setSaveMessage] = useState(null)
const [logLevel, setLogLevel] = useState(SHOW_ALL) const [logLevel, setLogLevel] = useState(SHOW_ALL)
const { data, loading } = useQuery(GET_SERVER_DATA, { const { data, loading: dataLoading } = useQuery(GET_SERVER_DATA, {
onCompleted: () => setSaveMessage(''), onCompleted: () => setSaveMessage(''),
variables: { variables: {
limit: NUM_LOG_RESULTS limit: NUM_LOG_RESULTS
} }
}) })
const { data: configResponse, configLoading } = useQuery(GET_DATA) const { data: configResponse, loading: configLoading } = useQuery(GET_DATA)
const timezone = R.path(['config', 'locale_timezone'], configResponse) const timezone = R.path(['config', 'locale_timezone'], configResponse)
const defaultLogLevels = [ const defaultLogLevels = [
@ -132,6 +132,8 @@ const Logs = () => {
setLogLevel(logLevel) setLogLevel(logLevel)
} }
const loading = dataLoading || configLoading
return ( return (
<> <>
<div className={classes.titleWrapper}> <div className={classes.titleWrapper}>
@ -206,8 +208,8 @@ const Logs = () => {
))} ))}
</TableBody> </TableBody>
</Table> </Table>
{loading && configLoading && <H4>{'Loading...'}</H4>} {loading && <H4>{'Loading...'}</H4>}
{!loading && !configLoading && !data?.serverLogs?.length && ( {!loading && !data?.serverLogs?.length && (
<H4>{'No activity so far'}</H4> <H4>{'No activity so far'}</H4>
)} )}
</div> </div>

View file

@ -48,7 +48,7 @@ const SessionManagement = () => {
const { data: configResponse, loading: configLoading } = useQuery(GET_DATA) const { data: configResponse, loading: configLoading } = useQuery(GET_DATA)
const timezone = R.path(['config', 'locale_timezone'], configResponse) const timezone = R.path(['config', 'locale_timezone'], configResponse)
const loading = sessionsLoading && configLoading const loading = sessionsLoading || configLoading
const elements = [ const elements = [
{ {
@ -107,16 +107,15 @@ const SessionManagement = () => {
] ]
return ( return (
!loading && (
<> <>
<TitleSection title="Session Management" /> <TitleSection title="Session Management" />
<DataTable <DataTable
loading={loading}
elements={elements} elements={elements}
data={R.path(['sessions'])(tknResponse)} data={R.path(['sessions'])(tknResponse)}
/> />
</> </>
) )
)
} }
export default SessionManagement export default SessionManagement