Skip to content

Commit

Permalink
Merge branch 'dev' into account-page-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheryl Chen authored and Cheryl Chen committed May 4, 2024
2 parents 3918993 + 2366a1a commit d69c003
Show file tree
Hide file tree
Showing 32 changed files with 514 additions and 348 deletions.
7 changes: 7 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import Logout from './components/Authentication/Logout';
import SignUp from './components/Authentication/SignUp';
import ForgotPassword from './components/Authentication/ForgotPassword';
import EmailAction from './components/Authentication/EmailAction';
import AccountPendingApproval from './components/Authentication/EmailAction';
import AwaitConfirmation from './components/Authentication/AwaitConfirmation';
import ForgotPasswordConfirmation from './components/Authentication/ForgotPasswordConfirmation';
import CreateNewPasswordConfirmation from './components/Authentication/CreateNewPasswordConfirmation';
import AUTH_ROLES from './utils/auth_config';
import ProtectedRoute from './utils/ProtectedRoute';
import Catalog from './pages/Catalog/Catalog';
Expand Down Expand Up @@ -53,8 +56,12 @@ const App = () => {
<Route exact path="/logout" element={<Logout />} />
<Route exact path="/forgotpassword" element={<ForgotPassword />} />
<Route exact path="/signUp" element={<SignUp />} />
<Route exact path="/signUpConfirmation" element={<AccountPendingApproval redirectPath="/" />} />
<Route exact path="/emailAction" element={<EmailAction redirectPath="/" />} />
<Route exact path="/awaitConfirmation" element={<AwaitConfirmation redirectPath="/" />} />
<Route exact path="/forgotPasswordConfirmation" element={<ForgotPasswordConfirmation redirectPath="/" />} />
<Route exact path="/createNewPasswordConfirmation" element={<CreateNewPasswordConfirmation redirectPath="/" />} />

<Route
exact
path="/catalog"
Expand Down
1 change: 0 additions & 1 deletion src/common/AuthContext.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/jsx-no-constructed-context-values */
import { createContext, useState, useContext } from 'react';
import PropTypes from 'prop-types';

Expand Down
1 change: 0 additions & 1 deletion src/components/AddDayForm/AddDayForm.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/jsx-props-no-spreading */
import {
Box,
FormLabel,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/jsx-props-no-spreading */
import {
Box,
FormLabel,
Expand Down Expand Up @@ -89,14 +88,10 @@ const AddEventToPublishedScheduleForm = ({ closeForm }) => {
setValue('startTime', eventData.startTime);
setValue('endTime', eventData.endTime);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [eventData]);

useEffect(() => {
if (formData.startTime && formData.endTime && formData.startTime < formData.endTime && formData.startTime >= "07:00" && formData.endTime <= "23:00") {
// if (isEdit) {
// // setPlannedEvents([...plannedEvents.filter(e => e.id != -1 && e.id != eventData.id)]);
// }
const newPlannedEvent = new PlannedEvent(
-1,
formData.title,
Expand All @@ -109,7 +104,6 @@ const AddEventToPublishedScheduleForm = ({ closeForm }) => {
} else {
setPlannedEvents(plannedEvents.filter(e => e.id != -1));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [formData])

const toast = useToast();
Expand All @@ -125,8 +119,6 @@ const AddEventToPublishedScheduleForm = ({ closeForm }) => {

const handleCancel = () => {
if (isEdit) {
// let reAddedEvent = plannedEvents.filter(e => e.id == -1)[0];
// reAddedEvent.id = eventData.id;
const reAddedEvent = new PlannedEvent(
eventData.id,
eventData.title,
Expand Down Expand Up @@ -169,7 +161,8 @@ const AddEventToPublishedScheduleForm = ({ closeForm }) => {
variant: 'subtle',
position: 'top-right',
containerStyle: {
mt: '6rem',
mt: '3rem',
mr: '2rem'
},
duration: 3000,
isClosable: true,
Expand All @@ -178,16 +171,12 @@ const AddEventToPublishedScheduleForm = ({ closeForm }) => {

const submitData = async (data) => {
try {
// eslint-disable-next-line no-unused-vars
const { title, host, description, tentative, startTime, endTime } = data;
const { title, host, description, startTime, endTime } = data;
const season = filterValues.season;
const eventType = filterValues.eventType;
const year = filterValues.year;
const subject = filterValues.subject;
console.log('submmitted data', data, season, eventType, year, subject);

toast.closeAll();

const catalogDataChanged = currentCatalogDataHasChanged(eventData, {
title,
host,
Expand Down Expand Up @@ -372,7 +361,7 @@ const AddEventToPublishedScheduleForm = ({ closeForm }) => {
{/* SUBJECT */}
<Box mb="1rem">
<FormControl>
<FormLabel fontWeight="bold" color="gray.600">Topic</FormLabel>
<FormLabel fontWeight="bold" color="gray.600">Subject</FormLabel>
<Dropdown
options={subjectOptions}
filter={subjectFilter}
Expand Down
33 changes: 33 additions & 0 deletions src/components/Authentication/AccountPendingApproval.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Box, Heading, Button, Center, Link} from '@chakra-ui/react';

const AccountPendingApproval = () => {

return (
<Center h="90vh">
<Box pt={4}>
<Heading as='h1' size='lg'>Account Pending Approval</Heading>
<Center>
<Link href="/login">
<Button
style={{
borderRadius: '30px',
marginTop: '30px',
paddingLeft: '80px',
paddingRight: '80px',
width: '140px',
height: '38px',
}}
backgroundColor={'#243268'}
color={'#ffffff'}
_hover={{backgroundColor: '#1A2559'}}
>
Return to login
</Button>
</Link>
</Center>
</Box>
</Center>
)
};

export default AccountPendingApproval;
145 changes: 145 additions & 0 deletions src/components/Authentication/CreateNewPassword.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { useState } from 'react';
import PropTypes from 'prop-types';
import { confirmNewPassword } from '../../utils/auth_utils';
import { FormControl, Input, Button, Center, Link, Box, Heading, Text, Alert, AlertDescription} from '@chakra-ui/react';

const CreateNewPassword = ({ code }) => {
const [password, setPassword] = useState('');
const [checkPassword, setCheckPassword] = useState('');
const [hasError, setHasError] = useState(false);
const [errorMessage, setErrorMessage] = useState();

const handleResetPassword = async e => {
try {
e.preventDefault();
setHasError(false);
if (password !== checkPassword) {
throw new Error("Passwords do not match.");
}
await confirmNewPassword(code, password);
setErrorMessage('');
setPassword('');
window.location.replace("/createNewPasswordConfirmation");
} catch (err) {
setHasError(true);
console.log(err.message);
if (err.code === "auth/weak-password"){
setErrorMessage("Password must be at least 6 characters.");
} else if (err.code === "auth/invalid-action-code"){
setErrorMessage("Link has expired.");
} else {
setErrorMessage(err.message);
}
}
};
return (
<Box>
<Box>
{ hasError &&
<Alert
status='warning'
alignItems='center'
justifyContent='center'
height='80px'
position='absolute'
backgroundColor="#F69052"
color="black"
>
<AlertDescription>{ errorMessage }</AlertDescription>
</Alert>
}
</Box>

<Center h="90vh">
<Box
style={{
margin: 'auto',
textAlign: 'center',
width: '598px',
minWidth: '300px',
}}
>
<Heading as='h1' size='lg'>Enter New Password</Heading>
<Text as='h2' size='md' mt={2}>Please enter a new password.</Text>
<form onSubmit={handleResetPassword}>
<FormControl>
<Box>
<Input
style={{ width: '360px', height: '48px', marginTop: '40px' }}
id={"password"}
isRequired={true}
onChange={({ target }) => setPassword(target.value)}
placeholder="Enter new password"
borderColor={"#CBD5E0"}
borderRadius= '3px'
type="password"
/>
<Input
style={{ width: '360px', height: '48px', margin: '20px' }}
id={"checkPassword"}
isRequired={true}
onChange={({ target }) => setCheckPassword(target.value)}
placeholder="Re-enter password"
borderColor={"#CBD5E0"}
borderRadius= '3px'
type="password"
/>
</Box>
<Box
style={{
marginTop: '25px',
marginBottom: '25px',
}}
>
<Link href='/login'>
<Button
style={{
borderRadius: '30px',
borderColor: '#155696',
borderWidth: '1.5px',
marginRight: '16px',
paddingLeft: '80px',
paddingRight: '80px',
width: '140px',
height: '38px',
}}
backgroundColor={'#FFFFFF'}
color={'#155696'}
variant='outline'
_hover={{backgroundColor: '#E0E0E0'}}
>
Cancel
</Button>
</Link>

<Button
type="submit"
style={{
borderRadius: '30px',
marginLeft: '16px',
paddingLeft: '80px',
paddingRight: '80px',
width: '140px',
height: '38px',
}}
backgroundColor={'#243268'}
color={'#ffffff'}
_hover={{backgroundColor: '#1A2559'}}
>
Reset Password
</Button>

</Box>
</FormControl>
</form>
</Box>
</Center>
</Box>
);
};

CreateNewPassword.propTypes = {
code: PropTypes.string.isRequired,
};

export default CreateNewPassword;
33 changes: 33 additions & 0 deletions src/components/Authentication/CreateNewPasswordConfirmation.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Box, Heading, Button, Center, Link} from '@chakra-ui/react';

const CreateNewPasswordConfirmation = () => {

return (
<Center h="90vh">
<Box pt={4}>
<Heading as='h1' size='lg'>Password Successfully Reset</Heading>
<Center>
<Link href="/login">
<Button
style={{
borderRadius: '30px',
marginTop: '30px',
paddingLeft: '80px',
paddingRight: '80px',
width: '140px',
height: '38px',
}}
backgroundColor={'#243268'}
color={'#ffffff'}
_hover={{backgroundColor: '#1A2559'}}
>
Return to login
</Button>
</Link>
</Center>
</Box>
</Center>
)
};

export default CreateNewPasswordConfirmation;
6 changes: 3 additions & 3 deletions src/components/Authentication/EmailAction.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// import React from 'react';
import { useLocation, Navigate } from 'react-router-dom';
import PropTypes from 'prop-types';
import ResetPassword from './ResetPassword';
import CreateNewPassword from './CreateNewPassword';
import VerifyEmail from './VerifyEmail';

const EmailAction = ({ redirectPath }) => {
Expand All @@ -12,7 +11,8 @@ const EmailAction = ({ redirectPath }) => {
if (code === null) {
return <Navigate to={redirectPath} />;
}
return mode === 'resetPassword' ? <ResetPassword code={code} /> : <VerifyEmail code={code} />;

return mode === 'resetPassword' ? <CreateNewPassword code={code} /> : <VerifyEmail code={code} />;
};

EmailAction.propTypes = {
Expand Down
Loading

0 comments on commit d69c003

Please sign in to comment.