diff --git a/frontend/src/pages/boss.tsx b/frontend/src/pages/boss.tsx index c26d604..59ca781 100644 --- a/frontend/src/pages/boss.tsx +++ b/frontend/src/pages/boss.tsx @@ -1,11 +1,19 @@ import { useNavigate } from "react-router-dom"; import { Role } from "./signUp"; -import { Card, Modal } from "antd"; +import { Button, Card, Form, Input, Modal } from "antd"; import Title from "antd/es/typography/Title"; -import { useState } from "react"; +import { useEffect, useState } from "react"; +import axios from "axios"; +import { + ROLE_LOCALSTORAGE_KEY, + SERVER_URL, + TOKEN_LOCALSTORAGE_KEY, +} from "../constants"; + +import { LogoutOutlined, PlusOutlined } from "@ant-design/icons"; export type User = { - id: number; + id: string; username: string; email: string; role: Role; @@ -21,23 +29,39 @@ export const Boss: React.FC = () => { const [selectedEmployee, setSelectedEmployee] = useState( null ); + const [isAddingEmployee, setIsAddingEmployee] = useState(false); + const [employees, setEmployees] = useState([]); + useEffect(() => { + axios + .get(`${SERVER_URL}/auth/boos/employee`, { + headers: { + Authorization: `Bearer ${localStorage.getItem( + TOKEN_LOCALSTORAGE_KEY + )}`, + }, + }) + .then((response) => { + setEmployees(response.data); + }); + }, []); + const EMPLOYEES: Employee[] = [ { - id: 1, + id: "1", username: "employee1", email: "employee1@gmail.com", role: Role.EMPLOYEE, bossId: "1", }, { - id: 2, + id: "2", username: "employee2", email: "employee2@gmail.com", role: Role.EMPLOYEE, bossId: "1", }, { - id: 3, + id: "3", username: "employee3", email: "employee3@gmail.com", role: Role.EMPLOYEE, @@ -45,44 +69,122 @@ export const Boss: React.FC = () => { }, ]; - const openModal = (employee: Employee) => { + const openAssignTaskModal = (employee: Employee) => { setSelectedEmployee(employee); }; - const closeModal = () => { + const closeAssignTaskModal = () => { setSelectedEmployee(null); }; + + const openAddEmployeeModal = () => { + setIsAddingEmployee(true); + }; + + const closeAddEmployeeModal = () => { + setIsAddingEmployee(false); + }; + + const handleAddEmployee = (employee: Employee) => { + const newEmployee: Employee = { + ...employee, + id: `${employee.username}-${employees.length + 1}`, + role: Role.EMPLOYEE, + bossId: "1", + }; + setEmployees([...employees, newEmployee]); + closeAddEmployeeModal(); + }; + + const logout = () => { + localStorage.removeItem(TOKEN_LOCALSTORAGE_KEY); + localStorage.removeItem(ROLE_LOCALSTORAGE_KEY); + navigate("/login"); + }; return ( <>
- {EMPLOYEES.map((employee) => ( - + Employees +
openModal(employee)} > - {employee.username} -

{employee.email}

- - ))} + + +
+ +
+ {employees.length > 0 ? ( + employees.map((employee) => ( + openAssignTaskModal(employee)} + > + {employee.username} +

{employee.email}

+
+ )) + ) : ( +
+ No employees found + +
+ )} +
{

Tasks:

+ +
+ + This will only hardcode employee, to test UI, you can create it with + signUp page + +

Form to add employee

+
+ + + + + name="email" + label="Email" + rules={[{ required: true, type: "email" }]} + > + + + + + + +
+
); };