Skip to content

Commit

Permalink
Merge pull request #547 from SCCapstone/SilentFail
Browse files Browse the repository at this point in the history
Fixed silent errors and added email checking
  • Loading branch information
epadams authored Apr 21, 2024
2 parents 3d730cf + 2de5442 commit 7c6fe9c
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 52 deletions.
11 changes: 10 additions & 1 deletion FU.SPA/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion FU.SPA/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"react-dom": "^18.2.0",
"react-notifications-component": "^4.0.1",
"react-router": "^6.18.0",
"selenium-side-runner": "^4.0.0-alpha.66"
"selenium-side-runner": "^4.0.0-alpha.66",
"validator": "^13.11.0"
},
"devDependencies": {
"@types/react": "^18.2.15",
Expand Down
59 changes: 39 additions & 20 deletions FU.SPA/src/components/PostForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import TagService from '../services/tagService';
import GameService from '../services/gameService';
import UserContext from '../context/userContext';
import dayjs from 'dayjs';
import { Store } from 'react-notifications-component';

const PostForm = ({ onSubmit, submitButtonText, initialValue }) => {
const { user } = useContext(UserContext);
Expand Down Expand Up @@ -137,28 +138,46 @@ const PostForm = ({ onSubmit, submitButtonText, initialValue }) => {
const handleSubmit = async (e) => {
e.preventDefault();

let tagIds = [];

// Gets tags from API or creates them
for (const tag of tags) {
const newTag = await TagService.findOrCreateTagByName(tag.name);
tagIds.push(newTag.id);
}
try {
let tagIds = [];

// Gets game from API or creates it
var findGame = await GameService.findOrCreateGameByTitle(game.name);

// Form payload
const post = {
title: title,
description: description,
startTime: startTime !== null ? startTime.toISOString() : null,
endTime: endTime !== null ? endTime.toISOString() : null,
tagIds: tagIds,
gameId: findGame.id,
};
// Gets tags from API or creates them
for (const tag of tags) {
const newTag = await TagService.findOrCreateTagByName(tag.name);
tagIds.push(newTag.id);
}

onSubmit(post);
// Gets game from API or creates it
var findGame = await GameService.findOrCreateGameByTitle(game.name);

// Form payload
const post = {
title: title,
description: description,
startTime: startTime !== null ? startTime.toISOString() : null,
endTime: endTime !== null ? endTime.toISOString() : null,
tagIds: tagIds,
gameId: findGame.id,
};

onSubmit(post);
} catch (e) {
// Error notification
Store.addNotification({
title: 'Error has occured',
message: 'An error has occured.\n' + e,
type: 'danger',
insert: 'bottom',
container: 'bottom-right',
animationIn: ['animate__animated', 'animate__fadeIn'],
animationOut: ['animate__animated', 'animate__fadeOut'],
dismiss: {
duration: 8000,
onScreen: true,
},
});
console.error('Error in post form: ', e);
}
};

const getPreviewTags = () => {
Expand Down
43 changes: 43 additions & 0 deletions FU.SPA/src/components/pages/PostPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import { Store } from 'react-notifications-component';

const PostPage = () => {
const { postId } = useParams();
Expand All @@ -29,6 +30,20 @@ const PostPage = () => {
await PostService.joinPost(post.id);
update();
} catch (error) {
// Error notification
Store.addNotification({
title: 'Error joining post',
message: 'An error has occured. Please try again.',
type: 'danger',
insert: 'bottom',
container: 'bottom-right',
animationIn: ['animate__animated', 'animate__fadeIn'],
animationOut: ['animate__animated', 'animate__fadeOut'],
dismiss: {
duration: 8000,
onScreen: true,
},
});
console.error('Error joining post:', error);
}
};
Expand All @@ -38,6 +53,20 @@ const PostPage = () => {
await PostService.leavePost(post.id);
navigate(-1);
} catch (error) {
// Error notification
Store.addNotification({
title: 'Error leaving post',
message: 'An error has occured. Please try again.',
type: 'danger',
insert: 'bottom',
container: 'bottom-right',
animationIn: ['animate__animated', 'animate__fadeIn'],
animationOut: ['animate__animated', 'animate__fadeOut'],
dismiss: {
duration: 8000,
onScreen: true,
},
});
console.error('Error leaving post:', error);
}
};
Expand All @@ -48,6 +77,20 @@ const PostPage = () => {
const data = await PostService.getPostDetails(postId);
setPost(data);
} catch (error) {
// Error notification
Store.addNotification({
title: 'Error getting details',
message: 'An error has occured.\n' + error,
type: 'danger',
insert: 'bottom',
container: 'bottom-right',
animationIn: ['animate__animated', 'animate__fadeIn'],
animationOut: ['animate__animated', 'animate__fadeOut'],
dismiss: {
duration: 8000,
onScreen: true,
},
});
console.error('Error fetching post details:', error);
}
setLoading(false);
Expand Down
4 changes: 4 additions & 0 deletions FU.SPA/src/components/pages/SignUp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { useNavigate, useSearchParams } from 'react-router-dom';
import { useState } from 'react';
import { Store } from 'react-notifications-component';
import Theme from '../../Theme';
import validator from 'validator';

export default function SignUp() {
const navigate = useNavigate();
Expand Down Expand Up @@ -112,6 +113,9 @@ export default function SignUp() {
} else if (errorResponse?.status === 409) {
// Duplicate email
setEmailError(errorResponse.detail);
} else if (!validator.isEmail(email)) {
// Invalid email format
setEmailError('Invalid Email');
} else if (errorResponse?.status === 400) {
// bad password
setPasswordError(errorResponse.detail);
Expand Down
80 changes: 50 additions & 30 deletions FU.SPA/src/components/pages/UserProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import RelationService from '../../services/relationService';
import Button from '@mui/material/Button';
import UserCard from '../UserCard';
import ProfileSettings from './ProfileSettings';
import { Store } from 'react-notifications-component';

const UserProfile = () => {
const { userId } = useParams();
Expand Down Expand Up @@ -99,36 +100,55 @@ const SocialRelationActionButton = ({ requesteeId }) => {
// don't render if viewing your own profile
if (requesteeId === currentUser.id) return;

if (relationStatus === RelationService.STATUS.NONE) {
buttonText = 'Send Friend Request';
handleClick = async () => {
await RelationService.postRelation(
requesteeId,
RelationService.ACTIONS.FRIEND,
);
UpdateStatus();
};
} else if (relationStatus === RelationService.STATUS.REQUESTED) {
buttonText = 'Cancel Friend Request';
handleClick = async () => {
await RelationService.removeRelation(requesteeId);
UpdateStatus();
};
} else if (relationStatus === RelationService.STATUS.PENDING) {
buttonText = 'Accept Friend Request';
handleClick = async () => {
await RelationService.postRelation(
requesteeId,
RelationService.ACTIONS.FRIEND,
);
UpdateStatus();
};
} else if (relationStatus === RelationService.STATUS.FRIENDS) {
buttonText = 'Unfriend';
handleClick = async () => {
await RelationService.removeRelation(requesteeId);
UpdateStatus();
};
// Render friend button options and try to handle requests
try {
if (relationStatus === RelationService.STATUS.NONE) {
buttonText = 'Send Friend Request';
handleClick = async () => {
await RelationService.postRelation(
requesteeId,
RelationService.ACTIONS.FRIEND,
);
UpdateStatus();
};
} else if (relationStatus === RelationService.STATUS.REQUESTED) {
buttonText = 'Cancel Friend Request';
handleClick = async () => {
await RelationService.removeRelation(requesteeId);
UpdateStatus();
};
} else if (relationStatus === RelationService.STATUS.PENDING) {
buttonText = 'Accept Friend Request';
handleClick = async () => {
await RelationService.postRelation(
requesteeId,
RelationService.ACTIONS.FRIEND,
);
UpdateStatus();
};
} else if (relationStatus === RelationService.STATUS.FRIENDS) {
buttonText = 'Unfriend';
handleClick = async () => {
await RelationService.removeRelation(requesteeId);
UpdateStatus();
};
}
} catch (e) {
// Error notification
Store.addNotification({
title: 'Error has occured',
message: 'An error has occured.\n' + e,
type: 'danger',
insert: 'bottom',
container: 'bottom-right',
animationIn: ['animate__animated', 'animate__fadeIn'],
animationOut: ['animate__animated', 'animate__fadeOut'],
dismiss: {
duration: 8000,
onScreen: true,
},
});
console.error('Error in UserProfile: ', e);
}

return (
Expand Down

0 comments on commit 7c6fe9c

Please sign in to comment.