ConceptPortal-public/rsconcept/frontend/src/pages/RSFormsPage/index.tsx

33 lines
1.1 KiB
TypeScript
Raw Normal View History

import { useLocation } from 'react-router-dom';
2023-07-15 17:46:19 +03:00
import BackendError from '../../components/BackendError'
import { Loader } from '../../components/Common/Loader'
import { FilterType, RSFormsFilter, useRSForms } from '../../hooks/useRSForms'
2023-07-15 17:46:19 +03:00
import RSFormsTable from './RSFormsTable';
import { useEffect } from 'react';
import { useAuth } from '../../context/AuthContext';
2023-07-15 17:46:19 +03:00
function RSFormsPage() {
const search = useLocation().search;
const { user } = useAuth();
const { rsforms, error, loading, loadList } = useRSForms();
useEffect(() => {
const filterQuery = new URLSearchParams(search).get('filter');
const type = (!user || !filterQuery ? FilterType.COMMON : filterQuery as FilterType);
let filter: RSFormsFilter = {type: type};
if (type === FilterType.PERSONAL) {
filter.data = user?.id;
}
loadList(filter);
}, [search, user, loadList]);
2023-07-15 17:46:19 +03:00
return (
<div className='container'>
{ loading && <Loader /> }
{ error && <BackendError error={error} />}
{ !loading && rsforms && <RSFormsTable schemas={rsforms} /> }
</div>
);
}
export default RSFormsPage;