Skip to content

Commit

Permalink
feat: map service url with service name
Browse files Browse the repository at this point in the history
  • Loading branch information
proffapt committed Jun 29, 2024
1 parent 061ce85 commit 7bbed78
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
8 changes: 4 additions & 4 deletions frontend/src/Services.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { servicesList } from "./constants";
import { ALLOWED_SERVICES } from "./constants";

const Services = () => {
return (
Expand All @@ -7,9 +7,9 @@ const Services = () => {
<div className="subtitle">
Click on any of the links below to visit
</div>
{servicesList.map((service) => (
<a className="service" key={service} href={service}>
{service}
{Object.entries(ALLOWED_SERVICES).map(([url, serviceName]) => (
<a className="service" key={url} href={url}>
{serviceName}
</a>
))}
</div>
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/Success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import { useEffect } from "react";
const Success = ({ email }: { email: string }) => {
const [searchParams] = useSearchParams();
const givenRedirectUrl = searchParams.get("redirect_url");
const redirectUrl = validRedirect(givenRedirectUrl);
const { serviceName, serviceLink } = validRedirect(givenRedirectUrl);
console.log(serviceName, serviceLink)
const navigate = useNavigate();

useEffect(() => {
const timer = setTimeout(() => {
if (redirectUrl === "/services") {
navigate(redirectUrl);
if (serviceLink === "/services") {
navigate(serviceLink);
} else {
window.open(redirectUrl, "_self");
window.open(serviceLink, "_self");
}
}, 3000);

return () => clearTimeout(timer)
}, [redirectUrl])
return () => clearTimeout(timer);
}, [serviceLink]);

return (
<div className="success-container">
Expand All @@ -28,8 +29,8 @@ const Success = ({ email }: { email: string }) => {
<br />
<span>{email}</span>
</div>
<Link to={redirectUrl}>
Redirecting to <span>{redirectUrl}</span> in a few seconds
<Link to={serviceLink}>
Redirecting to <span>{serviceName}</span> in a few seconds
</Link>
</div>
);
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ export const BACKEND_URL = import.meta.env.PROD
? "https://heimdall-api.metakgp.org"
: "http://localhost:3333";

export const servicesList = [
"https://chill.metakgp.org",
"https://naarad.metakgp.org",
"https://naarad.metakgp.org/signup",
];
export type AllowedServices = {
[key: string]: string;
};

export const ALLOWED_SERVICES: AllowedServices = {
"https://chill.metakgp.org": "Chillzone",
"https://naarad.metakgp.org": "Naarad",
};
14 changes: 7 additions & 7 deletions frontend/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { servicesList } from "./constants";
import { ALLOWED_SERVICES } from "./constants";

export const validateEmail = (email: string): boolean => {
return (
Expand All @@ -7,16 +7,16 @@ export const validateEmail = (email: string): boolean => {
);
};

export const validRedirect = (link: string | null): string => {
export const validRedirect = (link: string | null): { serviceName: string, serviceLink: string } => {
if (!link) {
return "/services";
return { serviceName: "Services Page", serviceLink: "/services" };
}

for (var service of servicesList) {
if (link.startsWith(service)) {
return link;
for (const serviceUrl in ALLOWED_SERVICES) {
if (link.startsWith(serviceUrl)) {
return { serviceName: ALLOWED_SERVICES[serviceUrl], serviceLink: link };
}
}

return "/services";
return { serviceName: "Services Page", serviceLink: "/services" };
};

0 comments on commit 7bbed78

Please sign in to comment.