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

35 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-07-25 20:27:29 +03:00
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
2023-07-25 20:27:29 +03:00
2023-07-15 17:46:19 +03:00
import BackendError from '../../components/BackendError'
import { Loader } from '../../components/Common/Loader'
import { useAuth } from '../../context/AuthContext';
2023-07-25 20:27:29 +03:00
import { FilterType, type RSFormsFilter, useRSForms } from '../../hooks/useRSForms'
import RSFormsTable from './RSFormsTable';
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);
2023-07-25 20:27:29 +03:00
const filter: RSFormsFilter = { type };
if (type === FilterType.PERSONAL) {
filter.data = user?.id;
}
2023-07-25 20:27:29 +03:00
loadList(filter).catch(console.error);
}, [search, user, loadList]);
2023-07-25 20:27:29 +03:00
2023-07-15 17:46:19 +03:00
return (
2023-07-20 17:11:03 +03:00
<div className='w-full'>
2023-07-15 17:46:19 +03:00
{ loading && <Loader /> }
{ error && <BackendError error={error} />}
{ !loading && rsforms && <RSFormsTable schemas={rsforms} /> }
</div>
);
}
2023-07-25 20:27:29 +03:00
export default RSFormsPage;