Skip to content

Commit e4c8173

Browse files
feat(pages/org/search): remove auth restrictions (#278)
1 parent 58371b8 commit e4c8173

File tree

1 file changed

+2
-35
lines changed

1 file changed

+2
-35
lines changed

pages/[org]/search.tsx

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { dequal } from 'dequal/lite';
77
import to from 'await-to-js';
88
import useTranslation from 'next-translate/useTranslation';
99

10-
import AuthDialog from 'components/auth-dialog';
1110
import FilterHeader from 'components/filter-header';
1211
import Page from 'components/page';
1312
import Search from 'components/search';
@@ -26,7 +25,6 @@ import useAnalytics from 'lib/hooks/analytics';
2625
import usePage from 'lib/hooks/page';
2726
import useTrack from 'lib/hooks/track';
2827
import useURLParamSync from 'lib/hooks/url-param-sync';
29-
import { useUser } from 'lib/context/user';
3028
import { withI18n } from 'lib/intl';
3129

3230
import 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

Comments
 (0)