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

Less intrusive anon modal #495

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
Binary file added client/src/assets/img/you-got-this-emoji.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 0 additions & 83 deletions client/src/modules/Course/Components/AnonymousWarning.tsx

This file was deleted.

49 changes: 49 additions & 0 deletions client/src/modules/Course/Components/LoginModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';

import styles from '../Styles/LoginModal.module.css';

import Emoji from '../../../assets/img/you-got-this-emoji.png';
import { useAuthOptionalLogin } from '../../../auth/auth_utils';

type Props = {
open: boolean;
};

const LoginModal = ({ open }: Props) => {
const { signIn } = useAuthOptionalLogin();
if (!open) {
return <></>;
}

/**
* Should only render when the user is not signed in
*/
return (
<div className={styles.warningContainer}>
<div className={styles.emoji}>
mjaydenkim marked this conversation as resolved.
Show resolved Hide resolved
<img
src={Emoji}
className="emoji"
alt="CUReviews Bear -- 'You got this!' emoji"
/>
</div>
<div className={styles.message}>
<span className="line1">
Login to submit - your review will upload once you login!
mjaydenkim marked this conversation as resolved.
Show resolved Hide resolved
<br />
</span>{' '}
</div>
<button
className={`${styles.button}`}
onClick={() => signIn('profile')}
>
Login
</button>
<div className={styles.pastReviewsMessage}>
You will be redirected to your past reviews page
</div>
</div>
);
};

export default LoginModal;
38 changes: 11 additions & 27 deletions client/src/modules/Course/Components/ReviewModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useState } from 'react';
import axios from 'axios';

import MultiSelect from './MultiSelect';
import SingleSelect from './SingleSelect';
Expand All @@ -11,7 +10,7 @@ import closeIcon from '../../../assets/icons/X.svg';

// Data
import majors from '../../Globals/majors';
import AnonymousWarning from './AnonymousWarning';
import LoginModal from './LoginModal';
import { useAuthOptionalLogin } from '../../../auth/auth_utils';

const ReviewModal = ({
Expand Down Expand Up @@ -58,10 +57,9 @@ const ReviewModal = ({
const [difficulty, setDifficulty] = useState<number>(3);
const [workload, setWorkload] = useState<number>(3);

const [anonymousOpen, setAnonymousOpen] = useState<boolean>(false);
const [noReviews, setNoReviews] = useState<boolean>(false);
const [loginModalOpen, setLoginModalOpen] = useState<boolean>(false);

const { isLoggedIn, netId, signIn } = useAuthOptionalLogin();
const { isLoggedIn, signIn } = useAuthOptionalLogin();

const [valid, setValid] = useState<Valid>({
professor: false,
Expand All @@ -79,25 +77,8 @@ const ReviewModal = ({

useEffect(() => {
setAllowSubmit(valid.professor && valid.major && valid.grade && valid.text);
if (isLoggedIn) {
getNoReviews();
}
}, [valid]);

/**
* Determines if the current user has no reviews, so they should receive
* the anonymous modal
*/
async function getNoReviews() {
const response = await axios.post('/api/profiles/count-reviews', {
netId
});
const res = response.data;
if (response.status === 200) {
setNoReviews(res.result === 0);
}
}

function onProfessorChange(newSelectedProfessors: string[]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be part of a codebase cleanup PR, but it'd be nicer if these functions were all arrow functions (i.e. const onProfessorChange = (newSelectedProfessors: string[]) => {...}).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only converted the four onXChange methods -- should I convert the other functions as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would be great!

setSelectedProfessors(newSelectedProfessors);
if (newSelectedProfessors.length > 0)
Expand Down Expand Up @@ -131,7 +112,7 @@ const ReviewModal = ({
return false;
}

// Called by onSubmitReview if the user should not see anonymous
// Called by onSubmitReview if the user should not see modal
function handleSubmitReview() {
if (validReview()) {
const newReview: NewReview = {
Expand All @@ -150,21 +131,21 @@ const ReviewModal = ({

// Handle click of submit button
function onSubmitReview() {
if (!noReviews && isLoggedIn) {
if (isLoggedIn) {
handleSubmitReview();
signIn('profile');
} else {
handleSubmitReview();
setAnonymousOpen(true);
setLoginModalOpen(true);
setReviewOpen(false);
}
}

if (!open && anonymousOpen) {
if (!open && loginModalOpen && !isLoggedIn) {
return (
<div className={styles.modalbg}>
<div className={styles.modal}>
<AnonymousWarning open={anonymousOpen} />
<LoginModal open={loginModalOpen} />
</div>
</div>
);
Expand Down Expand Up @@ -251,6 +232,9 @@ const ReviewModal = ({
id="review-content"
placeholder={placeholdertext}
></textarea>
<p className={styles.anonymouslabel}>
mjaydenkim marked this conversation as resolved.
Show resolved Hide resolved
Don't worry - all your reviews are anonymous!
</p>
<button
className={styles.submitbutton}
onClick={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
border-radius: 8px;
}

.anonymousLogo {
.emoji {
max-width: 25%;
max-height: 25%;
margin: auto;
Expand Down
25 changes: 10 additions & 15 deletions client/src/modules/Course/Styles/ReviewModal.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@
place-self: center;
}

.anonymouslabel {
display: flex;
font-size: 1em;
mjaydenkim marked this conversation as resolved.
Show resolved Hide resolved
font-weight: 500;
color: var(--clr-blue-300);
margin-top: -1em;
margin-bottom: -1em;
text-align: center;
}

.textinputbox {
width: 100%;
height: 100%;
Expand All @@ -140,21 +150,6 @@
color: #a8a8a8;
}

/* for future tags feature - placeholder */
.tags {
display: flex;
align-items: center;
justify-content: center;
border-radius: 10px;
width: 100%;
height: 100px;
font-size: 1em;
letter-spacing: 1ch;
font-weight: 500;
border: 2px solid var(--clr-blue-200);
color: var(--clr-blue-300);
}

.submitbutton {
width: 100%;
height: 39px;
Expand Down
Loading