Skip to content

Commit

Permalink
fix: server
Browse files Browse the repository at this point in the history
  • Loading branch information
SSameer20 committed Nov 1, 2024
1 parent ec64278 commit 0c41f3d
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 7 deletions.
1 change: 1 addition & 0 deletions landing_page/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
91 changes: 91 additions & 0 deletions landing_page/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 landing_page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.7",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sweetalert": "^2.1.2"
Expand Down
34 changes: 30 additions & 4 deletions landing_page/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import swal from "sweetalert";
import axios from "axios";
interface ScreenSize {
width: number;
height: number;
Expand All @@ -13,6 +14,26 @@ export default function App() {
height: window.innerHeight,
});

const SubscribeUser = async (email: string): Promise<boolean> => {
try {
const response = await axios.post(
"http://localhost:8080/api/v0/launch/register",
{
email: email,
}
);
if (response.status === 201) {
swal("Subscribed", "Subscribed to SKIN AI", "success");
return true;
}
swal("Error While Subscribing", "Error While Subscribing", "error");
return false;
} catch (error) {
swal("Error While Subscribing", "Error While Subscribing", "error");
return false;
}
};

function isEmailValid(email: string): boolean {
const emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
return emailRegex.test(email);
Expand All @@ -30,14 +51,19 @@ export default function App() {
return () => window.removeEventListener("resize", screenSetup);
}, [screen]);

const handleEmail = () => {
const handleEmail = async () => {
if (isEmailValid(email)) {
setFlag(true);
setEmail("");
swal("Thanks for Joining", "You have registered", "success");
const response = await SubscribeUser(email);

if (response) {
setFlag(true);
return swal("Thanks for Joining", "You have registered", "success");
}
return swal("unable to register", "Error While Registering", "warning");
} else {
setEmail("");
swal("Email Error", "Provide Correct Email", "warning");
swal("Email Error", "Provide Correct Email", "error");
}
};
return (
Expand Down
11 changes: 10 additions & 1 deletion server/controller/SubscriberController.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,13 @@ const SubscriberRegister = async (req, res) => {
}
};

module.exports = { SubscriberRegister };
const AllSubscribers = async (req, res) => {
try {
const users = await Subscriber.find();
return res.status(200).send({ subscribers: users });
} catch (error) {
return res.status(500).send({ message: error });
}
};

module.exports = { SubscriberRegister, AllSubscribers };
2 changes: 1 addition & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ app.use(cors());
app.use(bodyParser.json());

/** User Routes */
app.use("/api/v0/launch", SubscriberRouter);
app.use("/api/v1/launch", SubscriberRouter);
app.use("/api/v1/user", UserRouter);

app.get("/", (req, res) => {
Expand Down
6 changes: 5 additions & 1 deletion server/routes/SubscriberRoutes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const express = require("express");
const { Router } = express;
const { SubscriberRegister } = require("../controller/SubscriberController");
const {
SubscriberRegister,
AllSubscribers,
} = require("../controller/SubscriberController");

const SubscriberRouter = Router();

SubscriberRouter.post("/register", SubscriberRegister);
SubscriberRouter.get("/subscribers", AllSubscribers);

module.exports = SubscriberRouter;

0 comments on commit 0c41f3d

Please sign in to comment.