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

Make events not require sign-in #228

Merged
merged 14 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
2 changes: 1 addition & 1 deletion src/components/admin/store/DetailsForm/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@
}

:export {
#{defaultThemeColorHex}: vars.$light-primary-2;
#{defaultThemeColorHex}: vars.$blue-5;
}
113 changes: 113 additions & 0 deletions src/components/common/Login/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { SignInButton, SignInFormItem, SignInTitle } from '@/components/auth';
import VerticalForm from '@/components/common/VerticalForm';
import { config, showToast } from '@/lib';
import { resendEmailVerification } from '@/lib/api/AuthAPI';
import { AuthManager } from '@/lib/managers';
import { CookieService, ValidationService } from '@/lib/services';
import { URL } from '@/lib/types';
import { LoginRequest } from '@/lib/types/apiRequests';
import { PrivateProfile } from '@/lib/types/apiResponses';
import { UserState } from '@/lib/types/enums';
import { reportError } from '@/lib/utils';
import { useRouter } from 'next/router';
import { SubmitHandler, useForm } from 'react-hook-form';
import { AiOutlineMail } from 'react-icons/ai';
import { VscLock } from 'react-icons/vsc';

interface LoginProps {
destination: URL;
full?: boolean;
}

const Login = ({ destination, full }: LoginProps) => {
const router = useRouter();

const {
register,
handleSubmit,
formState: { errors },
} = useForm<LoginRequest>();

const onSubmit: SubmitHandler<LoginRequest> = ({ email, password }) => {
AuthManager.login({
email,
password,
onSuccessCallback: (user: PrivateProfile) => {
if (user.state === UserState.PENDING) {
showToast('Account Not Verified', 'Click to resend a verification email', [
{
text: 'Send Email',
onClick: async () => {
await resendEmailVerification(user.email);
showToast(`Verification email sent to ${user.email}!`);
},
},
]);

CookieService.clearClientCookies();

return;
}
if (user.state === UserState.BLOCKED) {
showToast('This account has been disabled', 'Email [email protected] if you have questions.');

CookieService.clearClientCookies();
return;
}

router.push(destination);
},
onFailCallback: error => {
reportError('Unable to login', error);
},
});
};

return (
<VerticalForm onEnterPress={handleSubmit(onSubmit)} style={{ height: full ? '' : 'auto' }}>
{full ? <SignInTitle text="Welcome to ACM!" /> : null}
<SignInFormItem
icon={<AiOutlineMail />}
element="input"
name="email"
type="email"
placeholder="Email ([email protected])"
formRegister={register('email', {
validate: email => {
const validation = ValidationService.isValidEmail(email);
return validation.valid || validation.error;
},
})}
error={errors.email}
/>
<SignInFormItem
icon={<VscLock />}
name="password"
element="input"
type="password"
placeholder="Password"
formRegister={register('password', {
required: 'Required',
})}
error={errors.password}
/>
<SignInButton
type="link"
display="link"
text="Forgot your password?"
href="/forgot-password"
/>
SheepTester marked this conversation as resolved.
Show resolved Hide resolved
<SignInButton
type="button"
display="button1"
text="Sign In"
onClick={handleSubmit(onSubmit)}
/>
{full ? (
<SignInButton type="link" href={config.registerRoute} text="Sign Up" display="button2" />
) : null}
</VerticalForm>
);
};

export default Login;
40 changes: 40 additions & 0 deletions src/components/common/LoginAppeal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Login from '@/components/common/Login';
import Typography from '@/components/common/Typography';
import { config } from '@/lib';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { ReactNode } from 'react';
import styles from './style.module.scss';

interface LoginAppealProps {
children: ReactNode;
}

const LoginAppeal = ({ children }: LoginAppealProps) => {
const router = useRouter();

return (
<div className={styles.wrapper}>
<div className={styles.aside}>
<Typography variant="h1/bold" component="h2">
Join ACM
</Typography>
<Typography variant="body/medium" component="p" style={{ lineHeight: '1.5' }}>
{children}
</Typography>
</div>
<div className={styles.line} />
<div className={styles.login}>
<Login destination={router.asPath} />
<p>
Don&lsquo;t have an account?{' '}
<Link href={config.registerRoute} className={styles.signUp}>
Sign up
</Link>
</p>
</div>
</div>
);
};

export default LoginAppeal;
56 changes: 56 additions & 0 deletions src/components/common/LoginAppeal/style.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@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: 2rem;
padding: 2rem;

@media (max-width: vars.$breakpoint-md) {
flex-direction: column;
text-align: center;
}

.aside {
display: flex;
flex-basis: 30rem;
flex-direction: column;
gap: 1rem;
justify-content: center;
margin-right: auto;

@media (max-width: vars.$breakpoint-md) {
flex-basis: auto;
margin: 0 auto;
max-width: 30rem;
}
}

.line {
border-left: 1px solid var(--theme-elevated-stroke);
@media (max-width: vars.$breakpoint-md) {
border-top: 1px solid var(--theme-elevated-stroke);
margin: 0 auto;
width: 10rem;
}
}

.login {
display: flex;
flex-direction: column;
gap: 2rem;
margin: 0 auto;
max-width: 300px;
width: 100%;

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

&:hover {
text-decoration: underline;
}
}
}
}
13 changes: 13 additions & 0 deletions src/components/common/LoginAppeal/style.module.scss.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export type Styles = {
aside: string;
line: string;
login: string;
signUp: string;
wrapper: string;
};

export type ClassNames = keyof Styles;

declare const styles: Styles;

export default styles;
23 changes: 16 additions & 7 deletions src/components/common/SEO/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Logo from '@/public/assets/acm-logos/general/light-mode.png';
import Head from 'next/head';
import style from './style.module.scss';

const TITLE = 'ACM UCSD Membership Portal';
const DESC =
Expand All @@ -8,16 +9,21 @@ const DESC =
interface SEOProps {
title?: string;
description?: string;
previewImage?: string;
bigPreviewImage?: boolean;
}

const SEO = ({ title, description = DESC }: SEOProps) => {
const fullTitle = title ? `${title} | ${TITLE}` : TITLE;

const SEO = ({
title,
description = DESC,
previewImage = Logo.src,
bigPreviewImage = false,
}: SEOProps) => {
return (
<Head>
{/* google indexing data */}

<title>{fullTitle}</title>
<title>{title ? `${title} | ${TITLE}` : TITLE}</title>
<meta name="description" content={description} />
<link rel="shortcut icon" href="/favicon.ico" />

Expand All @@ -28,13 +34,16 @@ const SEO = ({ title, description = DESC }: SEOProps) => {
{/* type of content */}
<meta property="og:type" content="website" />
{/* actual website title */}
<meta property="og:site_name" content="ACM at UCSD" />
<meta property="og:site_name" content="ACM at UC San Diego" />
{/* title to display for the specific link being shared */}
<meta property="og:title" content={fullTitle} />
<meta property="og:title" content={title ?? TITLE} />
{/* preview image */}
<meta property="og:image" content={Logo.src} />
<meta property="og:image" content={previewImage} />
{/* make preview image large on Discord and other sites */}
{bigPreviewImage ? <meta name="twitter:card" content="summary_large_image" /> : null}
{/* preview description text */}
<meta property="og:description" content={description} />
<meta name="theme-color" content={style.defaultThemeColorHex} />
</Head>
);
};
Expand Down
5 changes: 5 additions & 0 deletions src/components/common/SEO/style.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@use 'src/styles/vars.scss' as vars;

:export {
#{defaultThemeColorHex}: vars.$blue-5;
}
9 changes: 9 additions & 0 deletions src/components/common/SEO/style.module.scss.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export type Styles = {
defaultThemeColorHex: string;
};

export type ClassNames = keyof Styles;

declare const styles: Styles;

export default styles;
3 changes: 2 additions & 1 deletion src/components/common/VerticalForm/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
height: calc(vars.$min-content-height - 4rem);
justify-content: center;
margin: 0 auto;
width: 300px;
max-width: 300px;
width: 100%;
}
1 change: 1 addition & 0 deletions src/components/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export { default as Dropdown } from './Dropdown';
export { default as EditButton } from './EditButton';
export { default as GifSafeImage } from './GifSafeImage';
export { default as LinkButton } from './LinkButton';
export { default as LoginAppeal } from './LoginAppeal';
export { default as Modal } from './Modal';
export { default as PaginationControls } from './PaginationControls';
export { default as SEO } from './SEO';
Expand Down
5 changes: 3 additions & 2 deletions src/lib/api/EventAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import axios from 'axios';
/**
* Get a single event by UUID
* @param uuid Search query uuid
* @param token Bearer token
* @param token Bearer token. Optional, but should be provided if you need to
* see attendance codes.
* @returns Event info
*/
export const getEvent = async (uuid: UUID, token: string): Promise<PublicEvent> => {
export const getEvent = async (uuid: UUID, token?: string): Promise<PublicEvent> => {
SheepTester marked this conversation as resolved.
Show resolved Hide resolved
const requestUrl = `${config.api.baseUrl}${config.api.endpoints.event.event}/${uuid}`;

const response = await axios.get<GetOneEventResponse>(requestUrl, {
Expand Down
1 change: 1 addition & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const config = {
},
homeRoute: '/',
eventsRoute: '/events',
registerRoute: '/register',
loginRoute: '/login',
logoutRoute: '/logout',
leaderboardRoute: '/leaderboard',
Expand Down
Loading
Loading