Skip to content

Commit 73895c5

Browse files
committed
created eventHandler.ts for ApplicationCard.tsx, the file itself hold so many functions
1 parent bdf3b1c commit 73895c5

3 files changed

Lines changed: 43 additions & 16 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { useContext } from 'react';
2+
import { useNavigate } from 'react-router-dom';
3+
import { DashboardContext } from "../../context/DashboardContext";
4+
import { ApplicationContext } from "../../context/ApplicationContext";
5+
6+
type ClickEvent = React.MouseEvent<HTMLElement>;
7+
8+
interface EventHandlersProps {
9+
application: any[];
10+
setModal: (modalState: { isOpen: boolean; type: string }) => void;
11+
}
12+
13+
export const useEventHandlers = ({ application, setModal }: EventHandlersProps) => {
14+
const { deleteApp, user } = useContext(DashboardContext);
15+
const { setAppIndex, setApp, setServicesData, app, example, connectToDB, setChart } = useContext(ApplicationContext);
16+
const navigate = useNavigate();
17+
18+
const handleClick = (selectedApp: string, selectedService: string, i: number) => {
19+
const services = ['auth', 'client', 'event-bus', 'items', 'inventory', 'orders'];
20+
setAppIndex(i);
21+
setApp(selectedApp);
22+
if (['AWS', 'AWS/EC2', 'AWS/ECS', 'AWS/EKS'].includes(selectedService)) {
23+
navigate(`/aws/:${app}`, { state: { typeOfService: selectedService } });
24+
} else if (example) {
25+
setServicesData([]);
26+
setChart('communications');
27+
connectToDB(user, i, app, application[2], application[1]);
28+
navigate(`/applications/example/${services.join(' ')}`);
29+
} else {
30+
setServicesData([]);
31+
setModal({ isOpen: true, type: 'serviceModal' });
32+
}
33+
};
34+
35+
const confirmDelete = (event: ClickEvent, i: number) => {
36+
event.stopPropagation();
37+
const message = `The application '${app}' will be permanently deleted. Continue?`;
38+
if (confirm(message)) deleteApp(i, "");
39+
};
40+
41+
return { handleClick, confirmDelete };
42+
};

examples/microservices/client/src/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path');
22
const express = require('express');
33

4-
const PORT = 5000;
4+
const PORT = 5001;
55

66
const chronosConfig = require('./chronos-config');
77
const Chronos = require('@chronosmicro/tracker');

examples/microservices/sample.env

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)