2023-07-25 20:27:29 +03:00
|
|
|
import { useEffect } from 'react';
|
2023-07-16 20:25:55 +03:00
|
|
|
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'
|
2023-07-16 20:25:55 +03:00
|
|
|
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() {
|
2023-07-16 20:25:55 +03:00
|
|
|
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 };
|
2023-07-16 20:25:55 +03:00
|
|
|
if (type === FilterType.PERSONAL) {
|
|
|
|
filter.data = user?.id;
|
|
|
|
}
|
2023-07-25 20:27:29 +03:00
|
|
|
loadList(filter).catch(console.error);
|
2023-07-16 20:25:55 +03:00
|
|
|
}, [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;
|