-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from Code-Hammers/CHE-167/Dev-Branch-Pull
Pull dev branch changes into CHE-167 Story branch
- Loading branch information
Showing
24 changed files
with
1,413 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM postgres:16.3 | ||
|
||
COPY ./scripts/sql_db_init.sql /docker-entrypoint-initdb.d/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
client/src/components/ApplicationDashBoard/ApplicationDashBoard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import axios from 'axios'; | ||
import { useAppSelector } from '../../app/hooks'; | ||
|
||
interface IStatusCount { | ||
status: string; | ||
count: number; | ||
} | ||
|
||
const ApplicationDashboard = (): JSX.Element => { | ||
const [totalApplications, setTotalApplications] = useState(0); | ||
const [applicationsByStatus, setApplicationsByStatus] = useState<IStatusCount[]>([]); | ||
const [loading, setLoading] = useState(false); | ||
const [error, setError] = useState<string | null>(null); | ||
const user = useAppSelector((state) => state.user.userData); | ||
|
||
useEffect(() => { | ||
async function fetchAggregatedData() { | ||
setLoading(true); | ||
try { | ||
const response = await axios.get(`/api/applications/aggregated-user-stats/${user?._id}`); | ||
const { totalApplications = 0, applicationsByStatus = [] } = response.data || {}; | ||
setTotalApplications(totalApplications); | ||
setApplicationsByStatus(applicationsByStatus); | ||
setLoading(false); | ||
} catch (err) { | ||
const error = err as Error; | ||
console.error('Error fetching aggregated data:', error); | ||
setError(error.message); | ||
setLoading(false); | ||
} | ||
} | ||
|
||
fetchAggregatedData(); | ||
}, [user?._id]); | ||
|
||
if (loading) return <div>Loading...</div>; | ||
if (error) return <div>Error: {error}</div>; | ||
|
||
return ( | ||
<div className="bg-gray-800 p-4 rounded-lg shadow-lg mb-4 w-full max-w-4xl"> | ||
<h2 className="font-extrabold text-2xl mb-2">Dashboard</h2> | ||
<table className="min-w-full divide-y divide-gray-700"> | ||
<thead> | ||
<tr> | ||
<th className="px-6 py-3 text-center text-xs font-medium text-gray-400 uppercase tracking-wider"> | ||
Total Applications | ||
</th> | ||
{applicationsByStatus.map((status) => ( | ||
<th | ||
key={status.status} | ||
className="px-6 py-3 text-center text-xs font-medium text-gray-400 uppercase tracking-wider" | ||
> | ||
{status.status} | ||
</th> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody className="divide-y divide-gray-700"> | ||
<tr> | ||
<td className="px-6 py-4 whitespace-nowrap text-sm text-center text-white"> | ||
{totalApplications} | ||
</td> | ||
{applicationsByStatus.map((status) => ( | ||
<td | ||
key={status.status} | ||
className="px-6 py-4 whitespace-nowrap text-sm text-center text-white" | ||
> | ||
{status.count} | ||
</td> | ||
))} | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ApplicationDashboard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'; | ||
import axios from 'axios'; | ||
import { IApplicationFormData, IApplication } from '../../../types/applications'; | ||
|
||
interface ApplicationState { | ||
application: IApplication | null; | ||
status: 'idle' | 'loading' | 'failed' | 'creating' | 'updating' | 'deleting'; | ||
error: string | null; | ||
} | ||
|
||
const initialState: ApplicationState = { | ||
application: null, | ||
status: 'idle', | ||
error: null, | ||
}; | ||
|
||
export const createApplication = createAsyncThunk( | ||
'application/createApplication', | ||
async (applicationData: IApplicationFormData, thunkAPI) => { | ||
try { | ||
const response = await axios.post('/api/applications', applicationData); | ||
return response.data; | ||
} catch (error) { | ||
let errorMessage = 'An error occurred during application creation'; | ||
if (axios.isAxiosError(error)) { | ||
errorMessage = error.response?.data || errorMessage; | ||
} | ||
return thunkAPI.rejectWithValue(errorMessage); | ||
} | ||
}, | ||
); | ||
|
||
export const updateApplication = createAsyncThunk( | ||
'applications/updateApplication', | ||
async ({ id, ...formData }: Partial<IApplicationFormData> & { id: number }, thunkAPI) => { | ||
try { | ||
const response = await axios.put(`/api/applications/${id}`, formData); | ||
return response.data; | ||
} catch (error) { | ||
let errorMessage = 'An error occurred during application update'; | ||
if (axios.isAxiosError(error)) { | ||
errorMessage = error.response?.data || errorMessage; | ||
} | ||
return thunkAPI.rejectWithValue(errorMessage); | ||
} | ||
}, | ||
); | ||
|
||
//TODO Build out delete thunks | ||
|
||
const applicationSlice = createSlice({ | ||
name: 'application', | ||
initialState, | ||
reducers: { | ||
resetApplicationState(state) { | ||
state.application = null; | ||
state.status = 'idle'; | ||
state.error = null; | ||
}, | ||
}, | ||
extraReducers: (builder) => { | ||
builder | ||
.addCase(createApplication.pending, (state) => { | ||
state.status = 'creating'; | ||
}) | ||
.addCase(createApplication.fulfilled, (state, action) => { | ||
state.application = action.payload; | ||
state.status = 'idle'; | ||
}) | ||
.addCase(createApplication.rejected, (state, action) => { | ||
state.status = 'failed'; | ||
state.error = action.payload as string; | ||
}) | ||
.addCase(updateApplication.pending, (state) => { | ||
state.status = 'updating'; | ||
}) | ||
.addCase(updateApplication.fulfilled, (state, action) => { | ||
state.application = action.payload; | ||
state.status = 'idle'; | ||
}) | ||
.addCase(updateApplication.rejected, (state, action) => { | ||
state.status = 'failed'; | ||
state.error = action.payload as string; | ||
}); | ||
}, | ||
}); | ||
|
||
export const { resetApplicationState } = applicationSlice.actions; | ||
export default applicationSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'; | ||
import axios from 'axios'; | ||
import { IApplication } from '../../../types/applications'; | ||
|
||
interface ApplicationsState { | ||
applications: IApplication[]; | ||
status: 'idle' | 'loading' | 'failed'; | ||
error: string | null; | ||
} | ||
|
||
const initialState: ApplicationsState = { | ||
applications: [], | ||
status: 'idle', | ||
error: null, | ||
}; | ||
|
||
export const fetchApplications = createAsyncThunk( | ||
'applications/fetchApplications', | ||
async (_, thunkAPI) => { | ||
try { | ||
const response = await axios.get('/api/applications'); | ||
return response.data; | ||
} catch (error) { | ||
let errorMessage = 'An error occurred during fetching applications'; | ||
if (axios.isAxiosError(error)) { | ||
errorMessage = error.response?.data || errorMessage; | ||
} | ||
return thunkAPI.rejectWithValue(errorMessage); | ||
} | ||
}, | ||
); | ||
|
||
const applicationsSlice = createSlice({ | ||
name: 'applications', | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder | ||
.addCase(fetchApplications.pending, (state) => { | ||
state.status = 'loading'; | ||
}) | ||
.addCase(fetchApplications.fulfilled, (state, action) => { | ||
state.applications = action.payload; | ||
state.status = 'idle'; | ||
}) | ||
.addCase(fetchApplications.rejected, (state, action) => { | ||
state.status = 'failed'; | ||
state.error = action.payload as string; | ||
}); | ||
}, | ||
}); | ||
|
||
export default applicationsSlice.reducer; |
Oops, something went wrong.