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

Implemented helpful toast messages #156

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"configurations": [
{
"type": "java",
"name": "Spring Boot-BackendApplication<backend>",
"request": "launch",
"cwd": "${workspaceFolder}",
"mainClass": "com.uga.backend.BackendApplication",
"projectName": "backend",
"args": "",
"envFile": "${workspaceFolder}/.env"
}
]
}
6 changes: 6 additions & 0 deletions backend/node_modules/.package-lock.json

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

6 changes: 6 additions & 0 deletions backend/package-lock.json

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

1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
34 changes: 34 additions & 0 deletions my-app/package-lock.json

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

4 changes: 2 additions & 2 deletions my-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4",
"firebase": "^9.17.2"
"react-toastify": "^9.1.2",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
247 changes: 150 additions & 97 deletions my-app/src/components/ParkingPassSwap/ParkingPassMain.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useState } from 'react';
import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import { Container, Row, Col, Button, Select, Form } from 'react-bootstrap';

import ParkingPass from './ParkingPass';
import AddParkingPassModal from './AddParkingPassModal.jsx';
import './ParkingPassMain.css';
Expand All @@ -13,6 +14,7 @@ const ParkingPassMain = () => {
maxPrice: 999,
lot: 'Any',
});
const [myPromise, setPromise] = useState();

const getPasses = async () => {
const response = await fetch('http://localhost:8080/api/parking/getAll');
Expand Down Expand Up @@ -50,114 +52,165 @@ const ParkingPassMain = () => {
setFilterState(originalState);
};

// Another way to call the toast message
function notifySuccess(text) {
toast.success(text, {
position: 'top-center',
autoClose: 3000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: 'colored',
});
}

useEffect(() => {
getPasses();
console.log('useEffect running');
// showToastMessage(); // reusable toast message
setPromise(getPasses());
}, []);

useEffect(() => {
setPassesToShow(filterPasses(filterState));
}, [passes]);
if (passes.length == 0 && myPromise) {
// For some reason, the toast message is called twice. I found out that it's b/c of React.Strictmode for the index.js file
// Removing the wrapper component fixes the problem
toast.promise(
myPromise,
{
pending: 'Retrieving Data',
success: 'Data Successfully Displayed',
error: 'Error when fetching data. Turn on Backend',
},
{
style: {
minWidth: '380px',
},
success: {
duration: 5000,
},
}
);
}
}, [passes, myPromise]);

const handleAddPass = newPass => {
setPasses([...passes, newPass]);
notifySuccess('The Parking Pass was added successfully!');
};

return (
<Container fluid>
<Row>
<Col
className="side-tab-container"
xs={2}
style={{ marginTop: '150px' }}>
<Button
onClick={() => setShowAddModal(true)}
style={{
width: '100%',
}}>
Add Parking Pass
</Button>
<Form.Label
style={{
marginTop: '10%',
color: 'white',
}}>
Lot
</Form.Label>
<Form.Select
onChange={handleChange}
value={filterState.lot}
style={{}}
name="lot">
<option>Any</option>
<option>North Deck</option>
<option>South Deck</option>
<option>East Deck</option>
<option>STEM Deck</option>
</Form.Select>
<Form.Label
style={{
color: 'white',
marginTop: '10%',
}}>
Max Price ($)
</Form.Label>
<Form.Control
type="number"
name="maxPrice"
onChange={handleChange}
value={filterState.maxPrice}
/>
<Row
style={{
width: '100%',
alignContent: 'center',
alignItems: 'center',
justifyContent: 'space-evenly',
marginTop: '10%',
}}>
<Col>
<Button
style={{
marginTop: '10%',
width: '100%',
}}
onClick={onFilterClick}>
Filter
</Button>
</Col>
<Col>
<Button
style={{
width: '100%',
marginTop: '10%',
}}
onClick={onClearClick}>
Clear
</Button>
</Col>
</Row>
</Col>
<Col
className="parking-pass-list-container"
xs={10}
style={{ marginTop: '150px' }}>
<Row
className="parking-pass-list"
style={{
justifyContent: 'space-around',
}}>
{passesToShow.map(pass => {
return <ParkingPass {...pass} key={pass.id} />;
})}
</Row>
</Col>
</Row>
<AddParkingPassModal
show={showAddModal}
onHide={() => setShowAddModal(false)}
onSubmit={handleAddPass}
<>
<Container fluid>
<Row>
<Col
className="side-tab-container"
xs={2}
style={{ marginTop: '150px' }}>
<Button
onClick={() => setShowAddModal(true)}
style={{
width: '100%',
}}>
Add Parking Pass
</Button>
<Form.Label
style={{
marginTop: '10%',
color: 'white',
}}>
Lot
</Form.Label>
<Form.Select
onChange={handleChange}
value={filterState.lot}
style={{}}
name="lot">
<option>Any</option>
<option>North Deck</option>
<option>South Deck</option>
<option>East Deck</option>
<option>STEM Deck</option>
</Form.Select>
<Form.Label
style={{
color: 'white',
marginTop: '10%',
}}>
Max Price ($)
</Form.Label>
<Form.Control
type="number"
name="maxPrice"
onChange={handleChange}
value={filterState.maxPrice}
/>
<Row
style={{
width: '100%',
alignContent: 'center',
alignItems: 'center',
justifyContent: 'space-evenly',
marginTop: '10%',
}}>
<Col>
<Button
style={{
marginTop: '10%',
width: '100%',
}}
onClick={onFilterClick}>
Filter
</Button>
</Col>
<Col>
<Button
style={{
width: '100%',
marginTop: '10%',
}}
onClick={onClearClick}>
Clear
</Button>
</Col>
</Row>
</Col>
<Col
className="parking-pass-list-container"
xs={10}
style={{ marginTop: '150px' }}>
<Row
className="parking-pass-list"
style={{
justifyContent: 'space-around',
}}>
{passesToShow.map(pass => {
return <ParkingPass {...pass} key={pass.id} />;
})}
</Row>
</Col>
</Row>
<AddParkingPassModal
show={showAddModal}
onHide={() => setShowAddModal(false)}
onSubmit={handleAddPass}
/>
</Container>
<ToastContainer
position="top-center"
autoClose={5000}
hideProgressBar={false}
newestOnTop={false}
closeOnClick
rtl={false}
pauseOnFocusLoss
draggable
pauseOnHover
theme="colored"
/>
</Container>
</>
);
};

Expand Down
Loading