beherbergung/frontend/search/components/ngo/HostOfferLookupWrapper.tsx

43 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-03-09 15:39:15 +01:00
import React from 'react'
import { useGetOffersQuery, useGetRwQuery } from "../../codegen/generates"
import HostOfferLookupTable from "./HostOfferLookupTable"
import { Box } from "@mui/material"
import { useTranslation } from 'react-i18next'
import { Login, useAuthStore } from '../Login'
2022-03-09 15:39:15 +01:00
type HostLookupWrapperProps = Record<string, never>
const HostOfferLookupWrapper = ({}: HostLookupWrapperProps) => {
const { t } = useTranslation()
const auth = useAuthStore()
const staleTimeMinutes_ro = 5
const staleTimeMinutes_rw = 1
const queryResult_ro = useGetOffersQuery({auth}, {staleTime: staleTimeMinutes_ro * 60 * 1000})
const queryResult_rw = useGetRwQuery({auth}, {staleTime: staleTimeMinutes_rw * 60 * 1000})
2022-03-09 21:58:51 +01:00
2022-03-10 11:50:33 +01:00
return <>
2022-03-14 13:27:20 +01:00
<Box sx={{
display: 'flex',
alignItems: 'stretch',
flexDirection: 'column',
height: '100vh'}}>
<div>
{ (queryResult_ro.isFetching || queryResult_rw.isFetching) && t('loading…') }
{ (queryResult_ro.error || queryResult_rw.error) && t('An error occurred while trying to get data from the backend.') }
{ (queryResult_ro.data && !queryResult_ro.data.get_offers || queryResult_rw.data && !queryResult_rw.data.get_rw)
2022-03-14 13:27:20 +01:00
&& t('Seems like you have no permissions. Please try to login again.') }
</div>
<Login/>
2022-03-14 13:27:20 +01:00
{queryResult_ro.data && <div
2022-03-11 11:25:02 +01:00
style={{flex: '1 1', height: '100%'}}>
<HostOfferLookupTable data_ro={queryResult_ro.data}
2022-03-14 13:27:20 +01:00
data_rw={queryResult_rw.data}
refetch_rw={queryResult_rw.refetch}/>
2022-03-14 13:27:20 +01:00
</div>}
</Box>
2022-03-10 11:50:33 +01:00
</>
2022-03-09 15:39:15 +01:00
}
export default HostOfferLookupWrapper