Skip to content

Commit

Permalink
Admin view resumes page
Browse files Browse the repository at this point in the history
  • Loading branch information
SheepTester committed May 4, 2024
1 parent ac77e3b commit 9581468
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 4 deletions.
46 changes: 46 additions & 0 deletions src/components/admin/Resume/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { GifSafeImage, Typography } from '@/components/common';
import { config } from '@/lib';
import { PublicResume } from '@/lib/types/apiResponses';
import { getProfilePicture } from '@/lib/utils';
import Link from 'next/link';
import { BsDownload } from 'react-icons/bs';
import styles from './style.module.scss';

interface ResumeProps {
resume: PublicResume;
}

const Resume = ({ resume }: ResumeProps) => {
const fileName = decodeURIComponent(resume.url.split('/').at(-1) ?? 'resume.pdf');

return (
<div className={styles.wrapper}>
{resume.user ? (
<Link href={`${config.userProfileRoute}${resume.user.handle}`} className={styles.user}>
<GifSafeImage
src={getProfilePicture(resume.user)}
width={48}
height={48}
alt={`Profile picture for ${resume.user.firstName} ${resume.user.lastName}`}
className={styles.image}
/>
<Typography variant="label/large" className={styles.name}>
{resume.user.firstName} {resume.user.lastName}
</Typography>
<p className={styles.info}>
{resume.user.graduationYear} {resume.user.major}
</p>
</Link>
) : null}
<Link href={resume.url} className={styles.resume}>
<BsDownload className={styles.image} />
<p className={styles.name}>{fileName}</p>
<p className={styles.info}>
Uploaded {new Date(resume.lastUpdated).toLocaleDateString('en-US', { dateStyle: 'full' })}
</p>
</Link>
</div>
);
};

export default Resume;
73 changes: 73 additions & 0 deletions src/components/admin/Resume/style.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
@use 'src/styles/vars.scss' as vars;

.wrapper {
background-color: var(--theme-elevated-background);
border: 1px solid var(--theme-elevated-stroke);
border-radius: 0.5rem;
display: flex;
gap: 1rem;
padding: 1rem;
word-break: break-word;

@media (max-width: vars.$breakpoint-md) {
flex-direction: column;
gap: 2rem;
}

.user,
.resume {
align-items: center;
display: grid;
gap: 0.5rem 1rem;
grid-template-areas:
'image name'
'image info';
grid-template-columns: auto 1fr;

.image {
grid-area: image;
}

.name {
grid-area: name;
}

&:hover .name {
text-decoration: underline;
}

.info {
grid-area: info;
}
}

.user {
flex: 1 0 0;

.image {
border-radius: 5rem;
object-fit: contain;
}
}

.resume {
flex: 1.5 0 0;

.image {
height: 1.5rem;
width: 1.5rem;

@media (max-width: vars.$breakpoint-md) {
width: 3rem;
}
}

.name {
color: var(--theme-blue-text-button);
}

.info {
color: var(--theme-text-on-background-2);
}
}
}
14 changes: 14 additions & 0 deletions src/components/admin/Resume/style.module.scss.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type Styles = {
image: string;
info: string;
name: string;
resume: string;
user: string;
wrapper: string;
};

export type ClassNames = keyof Styles;

declare const styles: Styles;

export default styles;
26 changes: 22 additions & 4 deletions src/lib/api/ResumeAPI.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { config } from '@/lib';
import type { UUID } from '@/lib/types';
import { PatchResumeRequest } from '@/lib/types/apiRequests';
import type {
PatchResumeResponse,
PublicResume,
UpdateResumeResponse,
import {
GetVisibleResumesResponse,
type PatchResumeResponse,
type PublicResume,
type UpdateResumeResponse,
} from '@/lib/types/apiResponses';
import axios from 'axios';

Expand Down Expand Up @@ -76,3 +77,20 @@ export const deleteResume = async (token: string, uuid: UUID): Promise<void> =>
},
});
};

/**
* Get all visible resumes
* @param token Authorization bearer token. User needs to be admin or
* sponsorship manager
*/
export const getResumes = async (token: string): Promise<PublicResume[]> => {
const requestUrl = `${config.api.baseUrl}${config.api.endpoints.resume}`;

const response = await axios.get<GetVisibleResumesResponse>(requestUrl, {
headers: {
Authorization: `Bearer ${token}`,
},
});

return response.data.resumes;
};
40 changes: 40 additions & 0 deletions src/pages/admin/resumes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Resume from '@/components/admin/Resume';
import { Typography } from '@/components/common';
import { config } from '@/lib';
import { ResumeAPI } from '@/lib/api';
import withAccessType, { GetServerSidePropsWithAuth } from '@/lib/hoc/withAccessType';
import { PermissionService } from '@/lib/services';
import type { PublicResume } from '@/lib/types/apiResponses';
import styles from '@/styles/pages/resumes.module.scss';

interface AdminResumePageProps {
resumes: PublicResume[];
}

const AdminResumePage = ({ resumes }: AdminResumePageProps) => {
return (
<div className={styles.page}>
<Typography variant="title/large" component="h1">
Resumes
</Typography>
{resumes.map(resume => (
<Resume key={resume.uuid} resume={resume} />
))}
</div>
);
};

export default AdminResumePage;

const getServerSidePropsFunc: GetServerSidePropsWithAuth<AdminResumePageProps> = async ({
authToken,
}) => {
const resumes = await ResumeAPI.getResumes(authToken);
return { props: { title: 'View Resumes', resumes } };
};

export const getServerSideProps = withAccessType(
getServerSidePropsFunc,
PermissionService.canViewResumes,
{ redirectTo: config.homeRoute }
);
7 changes: 7 additions & 0 deletions src/styles/pages/resumes.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.page {
display: flex;
flex-direction: column;
gap: 1rem;
margin: 0 auto;
max-width: 60rem;
}
9 changes: 9 additions & 0 deletions src/styles/pages/resumes.module.scss.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type Styles = {
page: string;
};

export type ClassNames = keyof Styles;

declare const styles: Styles;

export default styles;

0 comments on commit 9581468

Please sign in to comment.