Skip to content

Add API toast service for ARO and MCC#599

Merged
batteryspecial merged 7 commits intomainfrom
manfromthefog/aro-mcc-toast-service
Nov 12, 2025
Merged

Add API toast service for ARO and MCC#599
batteryspecial merged 7 commits intomainfrom
manfromthefog/aro-mcc-toast-service

Conversation

@batteryspecial
Copy link
Contributor

Purpose

Closes #570.

New Changes

  • A standardized notification service which responds based on the success or failure of an API call. The service is very flexible and can be called in a variety of situations. A toast will emerge from the top-left, and will last for five seconds. If you hover over it, the toast will not dissapear.
  • Uses react-toastify, so be sure to install that.
  • In ARO's main.tsx, I added two buttons that you can play around with to see how the toasts appear. Please remove them for future updates.
  • Added .DS_Store to .gitignore.

How to Use the Service

Usage

Import the Service

import toastService from '../services/Toast.service.ts';

Call the Service

The service should be used within logic that handles asynchronous operations, such as in a try...catch...finally block after an API call.
On Success, call toastService.success() with a confirmation message.
On Error, call toastService.error() with an informative error message.

Example Implementation for a Form

Place a single at the application root and trigger toasts from the API service layer.

const handleFormSubmit = async (formData) => {
  try {
    await apiClient.saveData(formData);
    toastService.success("Data saved successfully!");
  } catch (err: any) {
    const message = err.response?.data?.message || "An unexpected error occurred.";
    toastService.error(`Failed to save: ${message}`);
  }
};

Example in App.tsx

Try running the following code added to App.tsx. The dots ... represents the rest of the code.

...
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import './styles/toasts.css';

import toastService from './services/Toast.service.ts'
...

function App() {
 ...
 const showSuccess = () => {
     toastService.success("This is a success message for testing!");
 };
 
 const showError = () => {
     toastService.error("This is an error message for testing.");
 };
 return (
  ...
  {/* --- TEST BUTTONS --- */}
   <div className="w-1/4 flex flex-row mt-[10%] ms-[34.5%]">
       <h3>Toast Test Controls</h3>
       <button onClick={showSuccess} className="bg-lime-400 w-1/2 cursor-pointer">Success</button>
       <button onClick={showError} className="bg-red-400 btn w-1/2 cursor-pointer">Error</button>
   </div>
   <ToastContainer />
  {/* --- END --- */}
  ...
 )
}

Clicking on the buttons should display the error messages respectively.

Testing

Explain tests that you ran to verify code functionality.

  • I have tested this PR by running the ARO website by adding buttons which call the toasts, and they worked as expected.
  • I have tested this PR by running the MCC website by adding buttons which call the toasts, and they worked as expected.
  • I have included a video of the tests performed below.
2025-10-14.mp4

Outstanding Changes

Because this is meant to be a standardized service, I tried making the service with generality in mind. You can use this for any API call, from backend to frontend responses (although it was designed for frontend).

@github-actions
Copy link

Pull reviewers stats

Stats of the last 120 days for UWOrbital:

User Total reviews Time to review Total comments
Adityya-K
🥇
49
▀▀▀▀▀
1d 2h 39m
167
▀▀▀▀
camspec
🥈
19
▀▀
23h 54m
130
▀▀▀
kepler452b123
🥉
16
▀▀
6d 5h 35m
▀▀
48
Yarik-Popov
5
1d 3h 12m
41
Navtajh04
2
7d 12h 7m
▀▀
25
sunray4
1
12d 21m
▀▀▀
9
proprogrammer504
1
8d 6h 19m
▀▀
5

⚡️ Pull request stats

@camspec camspec changed the title Added API toast service for ARO and MCC. #596 Add API toast service for ARO and MCC Oct 29, 2025
camspec
camspec previously approved these changes Oct 29, 2025
Copy link
Member

@camspec camspec left a comment

Choose a reason for hiding this comment

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

lgtm!

@batteryspecial batteryspecial requested review from kepler452b123 and removed request for joannalauu November 2, 2025 19:41
Copy link
Contributor

@kepler452b123 kepler452b123 left a comment

Choose a reason for hiding this comment

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

One qn, rest looks fine

Removed duplicate toast service in ARO
Copy link
Member

@camspec camspec left a comment

Choose a reason for hiding this comment

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

good to merge

@batteryspecial batteryspecial dismissed kepler452b123’s stale review November 12, 2025 01:45

The requested changes are complete.

@batteryspecial batteryspecial merged commit 8118fa3 into main Nov 12, 2025
49 checks passed
@batteryspecial batteryspecial deleted the manfromthefog/aro-mcc-toast-service branch November 12, 2025 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a toast service to ARO and MCC

3 participants