From d5c5c5efc44e4b60568ef7f4a49d2e3d01c36b24 Mon Sep 17 00:00:00 2001 From: Mathilde Hetru <76809829+mathhetru@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:26:29 +0200 Subject: [PATCH] feat(front): add modal when the employee is not added + add employees list --- .../src/pages/CreateEmployeeView.tsx | 9 +- HRNet-project/src/pages/EmployeeList.tsx | 2 +- HRNet-project/src/store/employees.store.tsx | 168 +++++++++--------- 3 files changed, 92 insertions(+), 87 deletions(-) diff --git a/HRNet-project/src/pages/CreateEmployeeView.tsx b/HRNet-project/src/pages/CreateEmployeeView.tsx index 82ef59d..8d2a308 100644 --- a/HRNet-project/src/pages/CreateEmployeeView.tsx +++ b/HRNet-project/src/pages/CreateEmployeeView.tsx @@ -27,6 +27,7 @@ function CreateEmployeeView() { const [city, setCity] = useState(""); const [zipCode, setZipCode] = useState(""); const [isOpen, setIsOpen] = useState(false); + const [sentenceForModal, setSentenceForModal] = useState(""); const onSaveForm = (e: React.MouseEvent) => { e.preventDefault(); @@ -41,7 +42,10 @@ function CreateEmployeeView() { !city || !zipCode ) { - alert("Please, fill in all fields before saving."); + setSentenceForModal( + "❌ The employee has NOT been added. Please, fill in all fields before saving.", + ); + setIsOpen(!isOpen); } else { const employeeToAdd: Employee = formatEmployeeForm({ firstName, @@ -55,6 +59,7 @@ function CreateEmployeeView() { zipCode, }); addEmployee(employeeToAdd); + setSentenceForModal("✅ The employee has been added successfully."); setIsOpen(!isOpen); } }; @@ -217,7 +222,7 @@ function CreateEmployeeView() { - + ()( // @ts-expect-error immer error ts immer((set) => ({ employeesList: [ - // { - // id: 19684621, - // firstName: "Forrest", - // lastName: "Gump", - // startDate: "24/05/2024", - // department: "Sales", - // birthDate: "25/04/1940", - // street: "Mother's House", - // city: "Greenbow", - // state: "Alabama", - // zipCode: "555", - // }, - // { - // id: 19684622, - // firstName: "Indiana", - // lastName: "Jones", - // startDate: "18/05/1917", - // department: "Human Resources", - // birthDate: "01/07/1899", - // street: "38 Adler Avenue", - // city: "Fairfield", - // state: "New Jersey", - // zipCode: "2543", - // }, - // { - // id: 19684623, - // firstName: "Ellen", - // lastName: "Ripley", - // startDate: "24/05/2122", - // department: "Engineering", - // birthDate: "07/01/2092", - // street: "Nostromo", - // city: "Solomons", - // state: "Maryland", - // zipCode: "20688", - // }, - // { - // id: 19684624, - // firstName: "John", - // lastName: "McClane", - // startDate: "15/07/1988", - // department: "Engineering", - // birthDate: "12/05/1955", - // street: "Nakatomi Plaza", - // city: "Los Angeles", - // state: "California", - // zipCode: "90067", - // }, - // { - // id: 19684625, - // firstName: "Sarah", - // lastName: "Connor", - // startDate: "12/05/1984", - // department: "Human Resources", - // birthDate: "28/08/1959", - // street: "Terminator's House", - // city: "Los Angeles", - // state: "California", - // zipCode: "90067", - // }, - // { - // id: 19684626, - // firstName: "Marty", - // lastName: "McFly", - // startDate: "26/10/1985", - // department: "Marketing", - // birthDate: "04/07/1968", - // street: "9303 Lyon Drive", - // city: "Hill Valley", - // state: "California", - // zipCode: "95420", - // }, - // { - // id: 19684627, - // firstName: "Rick", - // lastName: "Deckard", - // startDate: "25/06/1982", - // department: "Legal", - // birthDate: "07/01/2016", - // street: "Los Angeles", - // city: "Los Angeles", - // state: "California", - // zipCode: "90067", - // }, + { + id: 19684621, + firstName: "Forrest", + lastName: "Gump", + startDate: "24/05/2024", + department: "Sales", + birthDate: "25/04/1940", + street: "Mother's House", + city: "Greenbow", + state: "Alabama", + zipCode: "555", + }, + { + id: 19684622, + firstName: "Indiana", + lastName: "Jones", + startDate: "18/05/1917", + department: "Human Resources", + birthDate: "01/07/1899", + street: "38 Adler Avenue", + city: "Fairfield", + state: "New Jersey", + zipCode: "2543", + }, + { + id: 19684623, + firstName: "Ellen", + lastName: "Ripley", + startDate: "24/05/2122", + department: "Engineering", + birthDate: "07/01/2092", + street: "Nostromo", + city: "Solomons", + state: "Maryland", + zipCode: "20688", + }, + { + id: 19684624, + firstName: "John", + lastName: "McClane", + startDate: "15/07/1988", + department: "Engineering", + birthDate: "12/05/1955", + street: "Nakatomi Plaza", + city: "Los Angeles", + state: "California", + zipCode: "90067", + }, + { + id: 19684625, + firstName: "Sarah", + lastName: "Connor", + startDate: "12/05/1984", + department: "Human Resources", + birthDate: "28/08/1959", + street: "Terminator's House", + city: "Los Angeles", + state: "California", + zipCode: "90067", + }, + { + id: 19684626, + firstName: "Marty", + lastName: "McFly", + startDate: "26/10/1985", + department: "Marketing", + birthDate: "04/07/1968", + street: "9303 Lyon Drive", + city: "Hill Valley", + state: "California", + zipCode: "95420", + }, + { + id: 19684627, + firstName: "Rick", + lastName: "Deckard", + startDate: "25/06/1982", + department: "Legal", + birthDate: "07/01/2016", + street: "Los Angeles", + city: "Los Angeles", + state: "California", + zipCode: "90067", + }, ], numberOfEmployees: (employeesList: Employee[]) => employeesList.length, addEmployee: (employee: Employee) => {