Skip to content

Commit

Permalink
latest and last changes
Browse files Browse the repository at this point in the history
  • Loading branch information
inesmrad committed May 9, 2024
1 parent eb8416b commit d4bdc4f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/app/api/connection.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ app.get('/application', async (req, res) => {
const application = await getApp();
res.json(application);
});

app.get('/application/summary', async (req, res) => {
const application = await getApplication();
res.json(application);
Expand Down
22 changes: 19 additions & 3 deletions src/app/api/db.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,25 @@ export async function updateUser(userName,fname,lname,age, email, phone, city, l
// return result;
// }
export async function getApp() {
const [rows] = await pool.query("SELECT * FROM application");
return rows;
}
const query = `
SELECT
app.applicationID,
users.fname AS user_fname,
job.title AS job_title,
app.status,
app.created_at
FROM
application AS app
INNER JOIN
users ON app.userid = users.userid
INNER JOIN
joblisting AS job ON app.jobid = job.jobid
`;

const [rows] = await pool.query(query);
return rows;
}

export async function getApplication() {
try {
const [rows] = await pool.query("SELECT userid, GROUP_CONCAT(jobid) AS job_application_id FROM application GROUP BY userid");
Expand Down
2 changes: 1 addition & 1 deletion src/app/tables/table-1/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Table1Page = () => {

<DefaultLayout>
<TableOne />
<TableEight />

</DefaultLayout>
</>
);
Expand Down
36 changes: 17 additions & 19 deletions src/components/Tables/TableOne.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import dynamic from 'next/dynamic';

interface Location {
applicationID:number;
userid: number;
jobid: number;
user_fname: string;
job_title: number;
status: string;

}
Expand All @@ -18,8 +18,8 @@ const TableOne = () => {

// New states for pop-up
const [isAddUserPopupOpen, setAddUserPopupOpen] = useState(false);
const [newUserUserid, setNewUserUserid] = useState("");
const [newUserJobid, setNewUserJobid] = useState("");
const [newUseruser_fname, setNewUseruser_fname] = useState("");
const [newUserjob_title, setNewUserjob_title] = useState("");
const [newUserStatus, setNewUserStatus] = useState("");


Expand Down Expand Up @@ -86,8 +86,8 @@ const handleOpenPopup = () => {
const handleClosePopup = () => {
setAddUserPopupOpen(false);
// Reset input fields when closing the pop-up
setNewUserUserid("");
setNewUserJobid("");
setNewUseruser_fname("");
setNewUserjob_title("");
setNewUserStatus("");
};

Expand All @@ -96,8 +96,8 @@ const handleAddUser = async () => {
try {
// Make a POST request to add a new user to the server
await axios.post("http://localhost:8000/application", {
userid: newUserUserid,
jobid: newUserJobid,
user_fname: newUseruser_fname,
job_title: newUserjob_title,
status: newUserStatus
});

Expand All @@ -118,9 +118,7 @@ const handleAddUser = async () => {
<h4 className="text-xl font-semibold text-black dark:text-white">
Application's Summury List
</h4>
<button onClick={handleOpenPopup} className="bg-primary text-white px-4 py-2 rounded">
Add New Application
</button>

</div>
<table className="w-full table-auto">
<thead>
Expand All @@ -129,10 +127,10 @@ const handleAddUser = async () => {
Application ID
</th>
<th className="min-w-[150px] px-4 py-4 font-medium text-black dark:text-white">
User ID
User First Name
</th>
<th className="min-w-[120px] px-4 py-4 font-medium text-black dark:text-white">
Job ID
Job title
</th>
<th className="min-w-[120px] px-4 py-4 font-medium text-black dark:text-white">
Status
Expand All @@ -153,13 +151,13 @@ const handleAddUser = async () => {
</td>
<td className="border-b border-[#eee] px-4 py-5 pl-9 dark:border-strokedark xl:pl-11">
<h5 className="font-medium text-black dark:text-white">
{item.userid}
{item.user_fname}
</h5>

</td>
<td className="border-b border-[#eee] px-4 py-5 pl-9 dark:border-strokedark xl:pl-11">
<h5 className="font-medium text-black dark:text-white">
{item.jobid}
{item.job_title}
</h5>

</td>
Expand Down Expand Up @@ -197,17 +195,17 @@ const handleAddUser = async () => {
<label className="block text-sm font-medium text-gray-700">User ID</label>
<input
type="text"
value={newUserUserid}
onChange={(e) => setNewUserUserid(e.target.value)}
value={newUseruser_fname}
onChange={(e) => setNewUseruser_fname(e.target.value)}
className="border p-2 w-full"
/>
</div>
<div className="mb-4">
<label className="block text-sm font-medium text-gray-700">Job ID</label>
<input
type="text"
value={newUserJobid}
onChange={(e) => setNewUserJobid(e.target.value)}
value={newUserjob_title}
onChange={(e) => setNewUserjob_title(e.target.value)}
className="border p-2 w-full"
/>
</div>
Expand Down

0 comments on commit d4bdc4f

Please sign in to comment.