Skip to content

Commit

Permalink
Fixed bug when sending emails
Browse files Browse the repository at this point in the history
  • Loading branch information
Josymar authored and Josymar committed Nov 2, 2021
1 parent 3bff06d commit 2ea9eef
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ REACT_APP_FIREBASE_AUTH_DOMAIN =
REACT_APP_FIREBASE_PROJECT_ID =
REACT_APP_FIREBASE_STORAGE_BUCKET =
REACT_APP_FIREBASE_MESSAGING_SENDER =
REACT_APP_FIREBASE_APP_ID =
REACT_APP_FIREBASE_APP_ID =
REACT_APP_MAIL_SERVER =
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ End user must be capable of:
- React Hooks
- Firebase (database and authentication)
- MaterialUI (User interface)
- Axios (to communicate with external server. I am using a small api that I created for another project to send emails)
- Axios (to communicate with email backend: https://github.com/jossydeleon/nodemailer-express-app)
- React-hook-form (Form Validation Api)

## Login credentials
Expand All @@ -48,7 +48,8 @@ In order to receive notifications when products hits zero:

### Note

You need to check Spam folder in your email in case notification is not received in inbox folder.
- Emails will take time to arrive since the backend is hosted in Heroku free version account.
- You need to check Spam folder in your email in case notification is not received in inbox folder.

## Run it locally

Expand All @@ -63,6 +64,7 @@ REACT_APP_FIREBASE_PROJECT_ID =
REACT_APP_FIREBASE_STORAGE_BUCKET =
REACT_APP_FIREBASE_MESSAGING_SENDER =
REACT_APP_FIREBASE_APP_ID =
REACT_APP_MAIL_SERVER =
```

3. Then, start the development server:
Expand Down
4 changes: 2 additions & 2 deletions Rest.http
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
### Post
POST https://fncapi.vercel.app/api/mailer HTTP/1.1
POST https://nodemailer-express-app.herokuapp.com/mail-tracker HTTP/1.1
content-type: application/json

{
"product": "Fruit",
"product": "Bananas",
"email": "[email protected]"
}
2 changes: 1 addition & 1 deletion src/pages/Debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const Debug: React.FC = () => {
},
data.email
);
toast.success(`Email has been set successfully`);
toast.success(`Email has been sent successfully`);
} catch (error) {
toast.error(`Something happend: ` + error);
console.log(error);
Expand Down
16 changes: 7 additions & 9 deletions src/pages/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import { RootStore } from "../state/Store";
import Products from "./Products";
import Shop from "./Shop";
import Settings from "./Settings";
import Debug from "./Debug";
import { actionSetProducts } from "../state/actions/DatabaseActions";
import {
FaBug,
FaDoorOpen,
FaList,
FaShoppingBag,
Expand Down Expand Up @@ -117,13 +115,13 @@ const Root: React.FC = () => {
icon: <FaTools size={"1.5em"} color="white" />,
component: Settings,
},
{
name: "Debug",
path: `${url}debug`,
exact: true,
icon: <FaBug size={"1.5em"} color="white" />,
component: Debug,
},
// {
// name: "Debug",
// path: `${url}debug`,
// exact: true,
// icon: <FaBug size={"1.5em"} color="white" />,
// component: Debug,
// },
];

/**
Expand Down
6 changes: 3 additions & 3 deletions src/util/Helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import axios from "axios";
import { IProduct } from "../types";

const API = process.env.REACT_APP_MAIL_SERVER;

/**
* Add 2 decimals to number
* @param value number
Expand All @@ -17,12 +19,10 @@ export function convertToCurrency(value: number) {
*/
export async function sendEmailReport(product: IProduct, email: string) {
try {
const result = await axios.post("https://fncapi.vercel.app/api/mailer", {
await axios.post(`${API}`, {
product: product.name,
email,
});

console.log(JSON.stringify(result));
} catch (error) {
throw error;
}
Expand Down

0 comments on commit 2ea9eef

Please sign in to comment.