Skip to content

Commit 95f42e5

Browse files
authored
Merge pull request #76 from uwblueprint/michael_qian_toast_invalid_email
Removed defualt toast and added email verification/error toast message
2 parents 10ca318 + 09a07a3 commit 95f42e5

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

frontend/src/components/common/NavBarVolunteer.tsx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { GoHome } from "react-icons/go";
3030
import { LuNavigation } from "react-icons/lu";
3131
import { FiPhone } from "react-icons/fi";
3232
import abtc_logo from '../../images/abtc_logo.png';
33+
import CreateShiftMain from '../pages/CreateShift/CreateShiftMain';
3334

3435
interface NavBarVolunteerProps {
3536
firstName: string;
@@ -41,21 +42,10 @@ const NavBarVolunteer: React.FC<NavBarVolunteerProps> = ({firstName, lastName, r
4142
const location = useLocation();
4243
const toast = useToast();
4344

44-
const showToast = () => {
45-
toast({
46-
title: "Toast Title",
47-
description: "This is a test toast message.",
48-
status: "success",
49-
position: 'top-right',
50-
duration: 5000,
51-
isClosable: true,
52-
});
53-
}
54-
5545
return (
5646
<Flex bg="white" p={4} alignItems="center">
5747
<Box ml={4}>
58-
<Image src={abtc_logo} alt="ABTC Logo" maxWidth="180px" height="auto"/>
48+
<Image src={abtc_logo} alt="ABTC Logo" maxWidth="180px" height="auto"/>
5949
</Box >
6050
<ChakraLink
6151
as={ReactRouterLink}
@@ -112,9 +102,9 @@ const NavBarVolunteer: React.FC<NavBarVolunteerProps> = ({firstName, lastName, r
112102
Contact Us
113103
</Flex>
114104
</ChakraLink>
115-
<button type="button" className="btn btn-primary" onClick={showToast}>
105+
{/* <button type="button" className="btn btn-primary" onClick={() => showToast("test@example.com")}>
116106
Test Toast
117-
</button>
107+
</button> */}
118108
<Spacer />
119109
{/* TODO: add logic behind notification button */}
120110
<ChakraLink

frontend/src/components/pages/CreateShift/CreateShiftMain.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import React from 'react';
22
import moment from "moment";
33

4-
import { Button, ModalBody, ModalFooter, Box, FormControl, FormLabel, Input, Flex, Select, NumberDecrementStepper, NumberIncrementStepper, NumberInput, NumberInputField, NumberInputStepper, InputRightElement, InputGroup, FormHelperText, Tag, TagLabel, TagCloseButton, Wrap, WrapItem} from "@chakra-ui/react";
4+
import { Button, ModalBody, ModalFooter, Box, FormControl, FormLabel, Input, Flex, Select, NumberDecrementStepper, NumberIncrementStepper, NumberInput, NumberInputField, NumberInputStepper, InputRightElement, InputGroup, FormHelperText, Tag, TagLabel, TagCloseButton, Wrap, WrapItem, useToast} from "@chakra-ui/react";
55
import { CreateShiftFormStepComponentType, CreateShiftFormStepProps, Frequency, ServiceRequestType } from '../../../types/ServiceRequestTypes';
66
import { titleCase } from '../../../utils/FormatUtils';
77
import EARLIEST_SHIFT_TIME from '../../../constants/ServiceRequestConstants';
8+
import { validateEmail } from '../../../utils/ValidationUtils'
89

910
const CreateShiftMain: CreateShiftFormStepComponentType = ({ onSubmit, updateFields, updateErrorFields, data, errors }: CreateShiftFormStepProps): React.ReactElement => {
1011
const { requestName, shiftTime, shiftEndTime, frequency, currentEmail, inviteEmails, requestType } = data;
1112
const { shiftTimeError, shiftEndTimeError } = errors;
13+
const toast = useToast();
1214

1315

1416
const formatDate = (date: Date) => {
@@ -84,11 +86,23 @@ const CreateShiftMain: CreateShiftFormStepComponentType = ({ onSubmit, updateFie
8486
updateShiftTimeErrorFields(new Date(shiftTime), endTime);
8587
}
8688
};
87-
const handleAddEmail = ()=> {
89+
90+
const handleAddEmail = () => {
8891
if (currentEmail && currentEmail.trim()) {
92+
const emailError = validateEmail(currentEmail);
93+
if (emailError) {
94+
toast({
95+
title: "Invalid Email",
96+
description: "Please enter a valid email address.",
97+
status: "error",
98+
position: 'top-right',
99+
duration: 5000,
100+
isClosable: true,
101+
});
102+
return; // Stop execution if email is invalid
103+
}
89104
const updatedEmails = [...(inviteEmails || []), currentEmail.trim()];
90-
updateFields({ inviteEmails: updatedEmails, currentEmail: ""});
91-
console.log(updatedEmails)
105+
updateFields({ inviteEmails: updatedEmails, currentEmail: "" });
92106
}
93107
};
94108

@@ -97,8 +111,6 @@ const CreateShiftMain: CreateShiftFormStepComponentType = ({ onSubmit, updateFie
97111
updateFields({ inviteEmails: updatedEmails });
98112
};
99113

100-
101-
102114
const isButtonDisabled =
103115
!requestName ||
104116
!shiftTime ||

0 commit comments

Comments
 (0)