Skip to content

Commit 8e53e8d

Browse files
authored
[offers][feat] add admin page to navbar (#553)
* [offers][feat] add admin page to navbar * [offers][chore] remove comments
1 parent 75d7132 commit 8e53e8d

File tree

8 files changed

+47
-33
lines changed

8 files changed

+47
-33
lines changed

apps/portal/src/components/global/AppShell.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@ import { Button } from '@tih/ui';
1111
import GlobalNavigation from '~/components/global/GlobalNavigation';
1212
import HomeNavigation from '~/components/global/HomeNavigation';
1313
import OffersNavigation, {
14+
OffersNavigationAdmin,
1415
OffersNavigationAuthenticated,
1516
} from '~/components/offers/OffersNavigation';
1617
import QuestionsNavigation from '~/components/questions/QuestionsNavigation';
1718
import ResumesNavigation from '~/components/resumes/ResumesNavigation';
1819

20+
import { trpc } from '~/utils/trpc';
21+
1922
import GoogleAnalytics from './GoogleAnalytics';
2023
import MobileNavigation from './MobileNavigation';
2124
import type { ProductNavigationItems } from './ProductNavigation';
@@ -131,7 +134,12 @@ export default function AppShell({ children }: Props) {
131134
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
132135
const router = useRouter();
133136
const { data: session } = useSession();
134-
137+
const { isLoading: isOffersAdminResultsLoading, data: isOffersAdmin } =
138+
trpc.useQuery(['offers.admin.isAdmin'], {
139+
onError: () => {
140+
router.push('/offers');
141+
},
142+
});
135143
const currentProductNavigation: Readonly<{
136144
googleAnalyticsMeasurementID: string;
137145
logo?: React.ReactNode;
@@ -149,7 +157,9 @@ export default function AppShell({ children }: Props) {
149157
if (session == null) {
150158
return OffersNavigation;
151159
}
152-
return OffersNavigationAuthenticated;
160+
return !isOffersAdminResultsLoading && isOffersAdmin
161+
? OffersNavigationAdmin
162+
: OffersNavigationAuthenticated;
153163
}
154164

155165
if (path.startsWith('/questions')) {

apps/portal/src/components/offers/OffersNavigation.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ const navigationAuthenticated: ProductNavigationItems = [
1313
{ href: '/offers/about', name: 'About' },
1414
];
1515

16+
const navigationAdmin: ProductNavigationItems = [
17+
{ href: '/offers/submit', name: 'Analyze your offers' },
18+
{ href: '/offers/dashboard', name: 'My dashboard' },
19+
{ href: '/offers/features', name: 'Features' },
20+
{ href: '/offers/about', name: 'About' },
21+
{ href: '/offers/admin', name: 'Admin' },
22+
];
23+
1624
const config = {
1725
googleAnalyticsMeasurementID: 'G-34XRGLEVCF',
1826
logo: (
@@ -28,6 +36,11 @@ const config = {
2836
titleHref: '/offers',
2937
};
3038

39+
export const OffersNavigationAdmin = {
40+
...config,
41+
navigation: navigationAdmin,
42+
};
43+
3144
export const OffersNavigationAuthenticated = {
3245
...config,
3346
navigation: navigationAuthenticated,

apps/portal/src/components/offers/admin_temp/OffersHeader.tsx renamed to apps/portal/src/components/offers/admin/OffersHeader.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import clsx from 'clsx';
22

3-
import type { OfferTableSortType } from '~/components/offers/admin_temp/types';
3+
import type { OfferTableSortType } from '~/components/offers/admin/types';
44
import {
55
getOppositeSortOrder,
66
OFFER_TABLE_SORT_ORDER,
7-
} from '~/components/offers/admin_temp/types';
7+
} from '~/components/offers/admin/types';
88

99
export type OffersTableHeaderProps = Readonly<{
1010
header: string;

apps/portal/src/components/offers/admin_temp/OffersTable.tsx renamed to apps/portal/src/components/offers/admin/OffersTable.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ import { JobType } from '@prisma/client';
44
import { DropdownMenu, Spinner, useToast } from '@tih/ui';
55

66
import { useGoogleAnalytics } from '~/components/global/GoogleAnalytics';
7-
import OffersRow from '~/components/offers/admin_temp//OffersRow';
8-
import OffersHeader from '~/components/offers/admin_temp/OffersHeader';
9-
import OffersTablePagination from '~/components/offers/admin_temp/OffersTablePagination';
7+
import OffersHeader from '~/components/offers/admin/OffersHeader';
8+
import OffersRow from '~/components/offers/admin/OffersRow';
9+
import OffersTablePagination from '~/components/offers/admin/OffersTablePagination';
1010
import type {
1111
OfferTableColumn,
1212
OfferTableSortType,
13-
} from '~/components/offers/admin_temp/types';
13+
} from '~/components/offers/admin/types';
1414
import {
1515
FullTimeOfferTableColumns,
1616
InternOfferTableColumns,
1717
OFFER_TABLE_SORT_ORDER,
1818
OfferTableYoeOptions,
1919
YOE_CATEGORY_PARAM,
20-
} from '~/components/offers/admin_temp/types';
20+
} from '~/components/offers/admin/types';
2121

2222
import { getCurrencyForCountry } from '~/utils/offers/currency/CurrencyEnum';
2323
import CurrencySelector from '~/utils/offers/currency/CurrencySelector';
@@ -294,12 +294,11 @@ export default function OffersTable({
294294
<Spinner display="block" size="lg" />
295295
</div>
296296
)}
297-
{(!isLoading && !offers) ||
298-
(offers.length === 0 && (
299-
<div className="py-16 text-lg">
300-
<div className="flex justify-center">No data yet 🥺</div>
301-
</div>
302-
))}
297+
{!isLoading && (!offers || offers.length === 0) && (
298+
<div className="py-16 text-lg">
299+
<div className="flex justify-center">No data yet 🥺</div>
300+
</div>
301+
)}
303302
</div>
304303
<OffersTablePagination
305304
endNumber={

apps/portal/src/pages/offers/admin_temp.tsx renamed to apps/portal/src/pages/offers/admin.tsx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import crypto from 'crypto';
21
import type { GetServerSideProps, InferGetServerSidePropsType } from 'next';
32
import Head from 'next/head';
43
import Link from 'next/link';
54
import { useRouter } from 'next/router';
6-
import { useSession } from 'next-auth/react';
75
import { useState } from 'react';
86
import { MapPinIcon } from '@heroicons/react/24/outline';
97
import { Banner } from '@tih/ui';
108

119
import { useGoogleAnalytics } from '~/components/global/GoogleAnalytics';
12-
import OffersTable from '~/components/offers/admin_temp/OffersTable';
10+
import OffersTable from '~/components/offers/admin/OffersTable';
1311
import CompaniesTypeahead from '~/components/shared/CompaniesTypeahead';
1412
import Container from '~/components/shared/Container';
1513
import CountriesTypeahead from '~/components/shared/CountriesTypeahead';
@@ -18,6 +16,7 @@ import { getLabelForJobTitleType } from '~/components/shared/JobTitles';
1816
import JobTitlesTypeahead from '~/components/shared/JobTitlesTypeahead';
1917

2018
import { useSearchParamSingle } from '~/utils/offers/useSearchParam';
19+
import { trpc } from '~/utils/trpc';
2120

2221
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
2322
return {
@@ -41,23 +40,16 @@ export default function OffersHomePage({
4140
const [selectedJobTitleId, setSelectedJobTitleId] =
4241
useSearchParamSingle<JobTitleType | null>('jobTitleId');
4342

44-
const { data: session, status } = useSession();
45-
46-
const authoizedPeople = [
47-
'8b4550989cb7fe9ea7649b5538178b8d19aba0f3e5944dbff0b8d0e2ffe3911f',
48-
'0544d5d2be7815b5347dd2233c4d08a52120e52ac529f21b1a5c2005db3c42ab',
49-
'9934698c65bc72876018350a02910acdb27b7974dc757a320057588b67c5422b',
50-
'5cd57c9d1cc00d1010c3548ea3941941c04d18f7cf50766cdec30b12630e69ac',
51-
];
52-
53-
const isAuthorized = authoizedPeople.includes(
54-
crypto
55-
.createHash('sha256')
56-
.update(session?.user?.email ?? '')
57-
.digest('hex'),
43+
const { isLoading, data: isAuthorized } = trpc.useQuery(
44+
['offers.admin.isAdmin'],
45+
{
46+
onError: () => {
47+
router.push('/offers');
48+
},
49+
},
5850
);
5951

60-
if (!isAuthorized && status !== 'loading') {
52+
if (!isLoading && !isAuthorized) {
6153
router.push('/offers');
6254
}
6355
return (

0 commit comments

Comments
 (0)