@@ -7,7 +7,6 @@ import { dequal } from 'dequal/lite';
77import to from 'await-to-js' ;
88import useTranslation from 'next-translate/useTranslation' ;
99
10- import AuthDialog from 'components/auth-dialog' ;
1110import FilterHeader from 'components/filter-header' ;
1211import Page from 'components/page' ;
1312import Search from 'components/search' ;
@@ -26,7 +25,6 @@ import useAnalytics from 'lib/hooks/analytics';
2625import usePage from 'lib/hooks/page' ;
2726import useTrack from 'lib/hooks/track' ;
2827import useURLParamSync from 'lib/hooks/url-param-sync' ;
29- import { useUser } from 'lib/context/user' ;
3028import { withI18n } from 'lib/intl' ;
3129
3230import common from 'locales/en/common.json' ;
@@ -42,44 +40,14 @@ function SearchPage({ org, ...props }: SearchPageProps): JSX.Element {
4240 usePage ( 'Org Search' ) ;
4341
4442 const { t } = useTranslation ( ) ;
45- const { user : currentUser , orgs, loggedIn } = useUser ( ) ;
4643
4744 const [ query , setQuery ] = useState < UsersQuery > ( new UsersQuery ( ) ) ;
4845 const [ hits , setHits ] = useState < number > ( query . hitsPerPage ) ;
49- const [ auth , setAuth ] = useState < boolean > ( false ) ;
50- const [ canSearch , setCanSearch ] = useState < boolean > ( false ) ;
5146 const [ searching , setSearching ] = useState < boolean > ( true ) ;
5247
5348 useURLParamSync ( query , setQuery , UsersQuery , [ 'o' , 'av' ] ) ;
5449
55- const { data, isValidating } = useSWR < ListUsersRes > (
56- canSearch ? query . endpoint : null
57- ) ;
58-
59- /**
60- * If the user isn't a part of this org, attempt to add them using the
61- * `/api/users` endpoint. If that endpoint errors, show an undismissable
62- * dialog explaining the error (includes an org-configurable prompt too).
63- * @todo Add this validation to the back-end as well.
64- * @see {@link https://github.com/tutorbookapp/tutorbook/issues/115 }
65- */
66- useEffect ( ( ) => {
67- if ( ! org || loggedIn === undefined ) {
68- setAuth ( false ) ;
69- setCanSearch ( false ) ;
70- } else if (
71- currentUser . orgs . includes ( org . id ) ||
72- ! org . domains . length ||
73- org . domains . some ( ( d : string ) => currentUser . email . endsWith ( `@${ d } ` ) ) ||
74- orgs . some ( ( { id } ) => id === org . id )
75- ) {
76- setAuth ( false ) ;
77- setCanSearch ( true ) ;
78- } else {
79- setAuth ( true ) ;
80- setCanSearch ( false ) ;
81- }
82- } , [ loggedIn , currentUser , org , orgs ] ) ;
50+ const { data, isValidating } = useSWR < ListUsersRes > ( query . endpoint ) ;
8351
8452 // Save the number of hits from the last successful request.
8553 useEffect ( ( ) => setHits ( ( prev ) => data ?. hits || prev ) , [ data ?. hits ] ) ;
@@ -176,13 +144,12 @@ function SearchPage({ org, ...props }: SearchPageProps): JSX.Element {
176144 } ) }
177145 { ...props }
178146 >
179- { auth && < AuthDialog /> }
180147 < FilterHeader query = { query } onChange = { setQuery } />
181148 < Search
182149 hits = { hits }
183150 query = { query }
184151 results = { results }
185- searching = { searching || ! canSearch }
152+ searching = { searching }
186153 onChange = { onQueryChange }
187154 />
188155 </ Page >
0 commit comments