Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repo cleanup #110

Merged
merged 38 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3865e17
Update _app.tsx
farisashai Jan 2, 2024
99c2e13
Update leaderboard.tsx
farisashai Jan 2, 2024
eb66a2a
Merge branch 'main' into faris/misc-fixes
farisashai Jan 2, 2024
bad83be
Rename permission
farisashai Jan 2, 2024
6c2348e
Merge branch 'faris/misc-fixes' of https://github.com/acmucsd/members…
farisashai Jan 2, 2024
1cf17fd
Remove user specific store 404 details
farisashai Jan 2, 2024
a992ae5
remove magic var and type children correctly
farisashai Jan 2, 2024
b310de3
Refactor community logos to support future changes
farisashai Jan 2, 2024
2e605f1
Update index.tsx
farisashai Jan 2, 2024
434f89e
Merge branch 'main' into faris/misc-fixes
farisashai Jan 7, 2024
b195d8f
Fix package
farisashai Jan 7, 2024
cdfeb1e
fix build
farisashai Jan 7, 2024
839f552
Update style.module.scss
farisashai Jan 7, 2024
8a3e77a
test pwa
farisashai Jan 7, 2024
eb810ce
Upgrade node from 18 to 21
farisashai Jan 7, 2024
3b0ea7e
Update yarn.lock
farisashai Jan 7, 2024
e7b4fbe
Change to LTS
farisashai Jan 7, 2024
6761d5b
Change to LTS
farisashai Jan 7, 2024
42a49ae
Revert "Change to LTS"
farisashai Jan 7, 2024
7548be7
Merge branch 'faris/misc-fixes' of https://github.com/acmucsd/members…
farisashai Jan 7, 2024
20d4847
Revert
farisashai Jan 7, 2024
cfd0f78
undo undo undo
farisashai Jan 7, 2024
8d57315
Update yarn.lock
farisashai Jan 7, 2024
368e5d3
Update .nvmrc
farisashai Jan 7, 2024
f6eecee
Update package.json
farisashai Jan 7, 2024
e937c2c
Update yarn.lock
farisashai Jan 7, 2024
567a050
Update yarn.lock
farisashai Jan 7, 2024
820764f
Configure PWA
farisashai Jan 7, 2024
fffc6e6
Disable lint in service worker
farisashai Jan 7, 2024
7de251b
fix navbar border
farisashai Jan 7, 2024
7631a04
Merge branch 'main' into faris/misc-fixes
farisashai Jan 10, 2024
f2a60c1
Update style.module.scss
farisashai Jan 10, 2024
fe54e3e
Merge branch 'faris/misc-fixes' of https://github.com/acmucsd/members…
farisashai Jan 10, 2024
9796bd4
date selection
farisashai Jan 10, 2024
4d8ec54
center page
farisashai Jan 10, 2024
f7eed9b
center grid items better
farisashai Jan 10, 2024
e930248
Merge branch 'main' into faris/misc-fixes
farisashai Jan 19, 2024
0fc9bac
fixes
farisashai Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/components/common/Carousel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type { ReactNode } from 'react';
import type { PropsWithChildren } from 'react';
import styles from './style.module.scss';

interface CarouselProps {
children: ReactNode[];
}

const Carousel = ({ children }: CarouselProps) => {
const Carousel = ({ children }: PropsWithChildren) => {
return <div className={styles.slider}>{children}</div>;
};

Expand Down
29 changes: 11 additions & 18 deletions src/components/common/CommunityLogo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import { communityLogos } from '@/lib/constants/communityLogos';
import { Community } from '@/lib/types/enums';
import { capitalize } from '@/lib/utils';
import Image from 'next/image';

import AILogo from '@/public/assets/acm-logos/communities/ai.png';
import CyberLogo from '@/public/assets/acm-logos/communities/cyber.png';
import DesignLogo from '@/public/assets/acm-logos/communities/design.png';
import HackLogo from '@/public/assets/acm-logos/communities/hack.png';
import ACMLogo from '@/public/assets/acm-logos/general/light-mode.png';

interface CommunityLogoProps {
community: string;
size: number;
}

const CommunityLogo = ({ community, size }: CommunityLogoProps) => {
switch (community.toLowerCase()) {
case 'hack':
return <Image src={HackLogo} width={size} alt="ACM Hack Logo" />;
case 'ai':
return <Image src={AILogo} width={size} alt="ACM AI Logo" />;
case 'cyber':
return <Image src={CyberLogo} width={size} alt="ACM Cyber Logo" />;
case 'design':
return <Image src={DesignLogo} width={size} alt="ACM Design Logo" />;
default:
return <Image src={ACMLogo} width={size} alt="ACM General Logo" />;
}
const formattedName = capitalize(community) as Community;

if (!Object.values(Community).includes(formattedName))
return <Image src={communityLogos.General} width={size} alt="ACM General Logo" />;

return (
<Image src={communityLogos[formattedName]} width={size} alt={`ACM ${formattedName} Logo`} />
);
};

export default CommunityLogo;
8 changes: 5 additions & 3 deletions src/components/common/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ interface Option {
label: string;
}

export const DIVIDER = '----';

interface DropdownProps {
name: string;
ariaLabel: string;
options: (Option | '---')[];
options: (Option | typeof DIVIDER)[];
value: string;
// Justification for disabling rules: This seems to be a false positive.
// https://stackoverflow.com/q/63767199/
Expand All @@ -33,7 +35,7 @@ const Dropdown = ({ name, ariaLabel, options, value, onChange }: DropdownProps)
const optionButtons: ReactNode[] = [];
let dividers = 0;
options.forEach(option => {
if (option === '---') {
if (option === DIVIDER) {
optionButtons.push(<hr key={dividers} />);
dividers += 1;
} else {
Expand Down Expand Up @@ -81,7 +83,7 @@ const Dropdown = ({ name, ariaLabel, options, value, onChange }: DropdownProps)
aria-label={ariaLabel}
>
{options.map(option =>
option !== '---' ? (
option !== DIVIDER ? (
<option value={option.value} key={option.value}>
{option.label}
</option>
Expand Down
10 changes: 5 additions & 5 deletions src/components/layout/Navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ThemeToggle from '@/components/common/ThemeToggle';
import { config } from '@/lib';
import { useWindowSize } from '@/lib/hooks/useWindowSize';
import { PermissionService } from '@/lib/services';
import type { PrivateProfile } from '@/lib/types/apiResponses';
import { UserAccessType } from '@/lib/types/enums';
import LightModeLogo from '@/public/assets/acm-logos/general/light-mode.png';
import ACMIcon from '@/public/assets/icons/acm-icon.svg';
import CalendarIcon from '@/public/assets/icons/calendar-icon.svg';
Expand All @@ -17,9 +17,9 @@ import { memo, useCallback, useEffect, useRef, useState } from 'react';
import styles from './style.module.scss';

interface NavbarProps {
user?: PrivateProfile;
accessType?: UserAccessType;
}
const Navbar = ({ user }: NavbarProps) => {
const Navbar = ({ accessType }: NavbarProps) => {
const size = useWindowSize();
const headerRef = useRef<HTMLHeadElement>(null);

Expand Down Expand Up @@ -48,7 +48,7 @@ const Navbar = ({ user }: NavbarProps) => {
if (!isMobile) setMenuOpen(false);
}, [isMobile]);

if (!user) {
if (!accessType) {
return (
<header className={styles.header}>
<div className={styles.content}>
Expand All @@ -63,7 +63,7 @@ const Navbar = ({ user }: NavbarProps) => {
);
}

const isAdmin = PermissionService.canViewAdminPage().includes(user.accessType);
const isAdmin = PermissionService.canViewAdminPage().includes(accessType);

return (
<header className={styles.header} ref={headerRef}>
Expand Down
8 changes: 4 additions & 4 deletions src/components/layout/PageLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Navbar from '@/components/layout/Navbar';
import type { PrivateProfile } from '@/lib/types/apiResponses';
import { UserAccessType } from '@/lib/types/enums';
import { PropsWithChildren } from 'react';
import styles from './style.module.scss';

interface LayoutProps {
user?: PrivateProfile;
accessType?: UserAccessType;
}

const PageLayout = ({ user, children }: PropsWithChildren<LayoutProps>) => (
const PageLayout = ({ accessType, children }: PropsWithChildren<LayoutProps>) => (
<>
<Navbar user={user} />
<Navbar accessType={accessType} />
<main className={styles.content}>{children}</main>
</>
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/store/HelpModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import Step4 from '@/public/assets/graphics/store/step4.svg';
import ArrowLeftIcon from '@/public/assets/icons/arrow-left.svg';
import ArrowRightIcon from '@/public/assets/icons/arrow-right.svg';
import CloseIcon from '@/public/assets/icons/close-icon.svg';
import { ReactNode, useEffect, useRef } from 'react';
import { useEffect, useRef, type PropsWithChildren } from 'react';
import styles from './style.module.scss';

interface StepProps {
step: number;
children?: ReactNode;
}
const Step = ({ step, children }: StepProps) => {

const Step = ({ step, children }: PropsWithChildren<StepProps>) => {
const Left = step > 1 ? 'a' : 'span';
const Right = step < 4 ? 'a' : 'span';
return (
Expand Down
16 changes: 16 additions & 0 deletions src/lib/constants/communityLogos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* eslint-disable import/prefer-default-export */
import { Community } from '@/lib/types/enums';
import AILogo from '@/public/assets/acm-logos/communities/ai.png';
import CyberLogo from '@/public/assets/acm-logos/communities/cyber.png';
import DesignLogo from '@/public/assets/acm-logos/communities/design.png';
import HackLogo from '@/public/assets/acm-logos/communities/hack.png';
import ACMLogo from '@/public/assets/acm-logos/general/light-mode.png';
import type { StaticImageData } from 'next/image';

export const communityLogos: Record<Community, StaticImageData> = {
AI: AILogo,
Cyber: CyberLogo,
Design: DesignLogo,
Hack: HackLogo,
General: ACMLogo,
};
9 changes: 9 additions & 0 deletions src/lib/services/CookieService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CookieType } from '@/lib/types/enums';
import { deleteCookie, getCookie, setCookie } from 'cookies-next';
import type { OptionsType } from 'cookies-next/lib/types';

Expand Down Expand Up @@ -33,3 +34,11 @@ export const deleteClientCookie = (key: string): void => {
export const deleteServerCookie = (key: string, options: OptionsType): void => {
deleteCookie(key, options);
};

export const clearClientCookies = (): void => {
Object.keys(CookieType).forEach(key => deleteClientCookie(key));
};

export const clearServerCookies = (options: OptionsType): void => {
Object.keys(CookieType).forEach(key => deleteServerCookie(key, options));
};
15 changes: 7 additions & 8 deletions src/lib/services/PermissionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ export const canViewAdminPage = (): UserAccessType[] => {
];
};

/**
* @returns Array of all possible user access types
*/
export const allUserTypes = (): UserAccessType[] => {
const values = Object.values(UserAccessType) as UserAccessType[];
return values;
};

/**
* @param types to exclude from array
* @returns Array with all user access types except exclusions
Expand All @@ -36,3 +28,10 @@ export const allUserTypesExcept = (types: UserAccessType[]): UserAccessType[] =>
const values = Object.keys(UserAccessType) as UserAccessType[];
return values.filter(value => !types.includes(value));
};

/**
* @returns Valid logged in user types
*/
export const loggedInUser = (): UserAccessType[] => {
return allUserTypesExcept([UserAccessType.RESTRICTED]);
};
8 changes: 8 additions & 0 deletions src/lib/types/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ export enum CookieType {
ACCESS_TOKEN = 'ACCESS_TOKEN',
}

export enum Community {
HACK = 'Hack',
AI = 'AI',
CYBER = 'Cyber',
DESIGN = 'Design',
GENERAL = 'General',
}

export enum UserAccessType {
RESTRICTED = 'RESTRICTED',
STANDARD = 'STANDARD',
Expand Down
14 changes: 1 addition & 13 deletions src/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
import { SignInButton } from '@/components/auth';
import { VerticalForm } from '@/components/common';
import { Navbar } from '@/components/store';
import { config } from '@/lib';
import { PrivateProfile } from '@/lib/types/apiResponses';
import Cat404 from '@/public/assets/graphics/cat404.png';
import styles from '@/styles/pages/404.module.scss';
import Image from 'next/image';
import { useRouter } from 'next/router';

interface PageNotFoundProps {
user?: PrivateProfile;
}

const PageNotFound = ({ user }: PageNotFoundProps) => {
const router = useRouter();
const PageNotFound = () => {
return (
<div style={{ display: 'flex', flexDirection: 'column', height: 'calc(100vh - 8.25rem)' }}>
{user && router.asPath.startsWith(config.storeRoute) && (
<Navbar balance={user.credits} showBack />
)}
<VerticalForm style={{ alignItems: 'center', flex: 'auto', height: 'unset' }}>
<h1 className={styles.header}>Whoops, we ended up on the wrong page!</h1>
<Image src={Cat404} width={256} height={256} alt="Sad Cat" />
Expand Down
45 changes: 3 additions & 42 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,14 @@ import 'react-toastify/dist/ReactToastify.css';

import { SEO } from '@/components/common';
import { PageLayout } from '@/components/layout';
import { CookieService } from '@/lib/services';
import type { PrivateProfile } from '@/lib/types/apiResponses';
import { CookieType } from '@/lib/types/enums';
import { NextPageContext } from 'next';
import { ThemeProvider } from 'next-themes';
import type { AppProps } from 'next/app';
import { DM_Sans as DMSans } from 'next/font/google';
import { useEffect, useState } from 'react';
import { ToastContainer } from 'react-toastify';

interface InitialPropInterface {
user?: PrivateProfile;
}
const dmSans = DMSans({ subsets: ['latin'], weight: ['400', '500', '700'] });

export default function MyApp({ Component, pageProps }: AppProps<InitialPropInterface>) {
const [user, setUser] = useState(pageProps?.user);

// For 404 page: Try getting user from cookie on client side (because 404
// pages in Next.js must be a static page)
useEffect(() => {
if (pageProps?.user) {
setUser(pageProps?.user);
return;
}
const userCookie = CookieService.getClientCookie(CookieType.USER);
if (userCookie) {
setUser(JSON.parse(userCookie));
}
}, [pageProps?.user]);
farisashai marked this conversation as resolved.
Show resolved Hide resolved

export default function MyApp({ Component, pageProps }: AppProps) {
return (
<>
<style jsx global>{`
Expand All @@ -47,26 +24,10 @@ export default function MyApp({ Component, pageProps }: AppProps<InitialPropInte
<SEO />
<ThemeProvider>
<ToastContainer />
<PageLayout user={user}>
<Component user={user} {...pageProps} />
<PageLayout accessType={pageProps?.user?.accessType}>
<Component {...pageProps} />
</PageLayout>
</ThemeProvider>
</>
);
}

MyApp.getInitialProps = ({ req, res }: NextPageContext) => {
const userCookie = CookieService.getServerCookie(CookieType.USER, { req, res });

if (!userCookie) {
return {
user: null,
};
}

const user: PrivateProfile = JSON.parse(userCookie);

return {
user,
};
};
2 changes: 1 addition & 1 deletion src/pages/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ const getServerSidePropsFunc: GetServerSideProps = async () => ({

export const getServerSideProps = withAccessType(
getServerSidePropsFunc,
PermissionService.allUserTypes()
PermissionService.loggedInUser()
);
2 changes: 1 addition & 1 deletion src/pages/discord.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ const getServerSidePropsFunc: GetServerSideProps = async () => ({

export const getServerSideProps = withAccessType(
getServerSidePropsFunc,
PermissionService.allUserTypes()
PermissionService.loggedInUser()
);
11 changes: 7 additions & 4 deletions src/pages/events.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Dropdown, PaginationControls, Typography } from '@/components/common';
import { DIVIDER } from '@/components/common/Dropdown';
import { EventDisplay } from '@/components/events';
import { EventAPI } from '@/lib/api';
import withAccessType from '@/lib/hoc/withAccessType';
Expand Down Expand Up @@ -127,7 +128,7 @@ const EventsPage = ({ events, attendances }: EventsPageProps) => {
{ value: 'past-month', label: 'Past month' },
{ value: 'past-year', label: 'Past year' },
{ value: 'all-time', label: 'All time' },
'---',
DIVIDER,
...years,
]}
value={dateFilter}
Expand Down Expand Up @@ -172,13 +173,15 @@ export default EventsPage;

const getServerSidePropsFunc: GetServerSideProps = async ({ req, res }) => {
const authToken = CookieService.getServerCookie(CookieType.ACCESS_TOKEN, { req, res });
const events = await EventAPI.getAllEvents();
const attendances = await EventAPI.getAttendancesForUser(authToken);
const getEvents = EventAPI.getAllEvents();
const getAttendances = EventAPI.getAttendancesForUser(authToken);

const [events, attendances] = await Promise.all([getEvents, getAttendances]);

return { props: { events, attendances } };
};

export const getServerSideProps = withAccessType(
getServerSidePropsFunc,
PermissionService.allUserTypes()
PermissionService.loggedInUser()
);
Loading