Skip to content

Commit 0d8a69e

Browse files
committed
added popup for when connection to user provided database is invalid or times out.
1 parent a455254 commit 0d8a69e

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

app/components/SignUp.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { ipcRenderer } = window.require('electron');
99
const SignUp:React.FC = React.memo(() => {
1010
const navigate = useNavigate();
1111
const { setUser } = useContext(DashboardContext);
12-
const [failedSignUp, setFailedSignUp] = useState<JSX.Element>(<>hey</>);
12+
const [failedSignUp, setFailedSignUp] = useState<JSX.Element>(<></>);
1313
const [username, setUsername] = useState('');
1414
const [email, setEmail] = useState('');
1515
const [password, setPassword] = useState('');

app/context/ApplicationContext.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const ApplicationContext = React.createContext<any>(null);
2020
const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props => {
2121
const children = props.children;
2222
const [servicesData, setServicesData] = useState([]);
23+
const [serviceConnected, setServiceConnected] = useState<boolean>(false);
2324
// v10 note: there is not function for setApp so app is never updated.
2425
const [app, setApp] = useState<string>('');
2526
const [savedMetrics, setSavedMetrics] = useState({});
@@ -74,6 +75,7 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
7475
console.log('Leaving fetchedServicesNames function.');
7576
ipcRenderer.removeAllListeners('servicesResponse');
7677
});
78+
7779
}, []);
7880

7981
/**
@@ -88,7 +90,11 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
8890
ipcRenderer.removeAllListeners('databaseConnected');
8991
ipcRenderer.send('connect', username, index, URI, databaseType);
9092
ipcRenderer.on('databaseConnected', (event: Electron.Event, data: any) => {
91-
fetchServicesNames(application);
93+
if(data === true) {
94+
fetchServicesNames(application);
95+
} else {
96+
alert('Database connection is not valid.');
97+
}
9298
});
9399
}, []);
94100

electron/routes/data.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ ipcMain.on('connect', async (message: Electron.IpcMainEvent, username: string, i
8080
mongoose.connect(URI, { useNewUrlParser: true, useUnifiedTopology: true })
8181
.then(() => {
8282
console.log('Connected to user provided mongo database!');
83-
message.sender.send('databaseConnected', 'connected!');
83+
message.sender.send('databaseConnected', true);
8484
})
8585
.catch(error => {
86+
message.sender.send('databaseConnected', false);
8687
console.log('Error connecting to MongoDB inside data.ts connection:', error);
8788
});
8889
} else if (currentDatabaseType === 'SQL'){
@@ -91,10 +92,12 @@ ipcMain.on('connect', async (message: Electron.IpcMainEvent, username: string, i
9192
message.sender.send('databaseConnected', 'connected!');
9293
}
9394
} catch(err){
95+
message.sender.send('databaseConnected', false);
9496
console.log('Error connecting to databse: ', err);
9597
}
9698
});
9799

100+
98101
/**
99102
* @event serviceRequest/serviceResponse
100103
* @desc Query to services table for all microservices of a specific app

0 commit comments

Comments
 (0)