Skip to content

Commit

Permalink
feat(front): add modal when the employee is not added + add employees…
Browse files Browse the repository at this point in the history
… list
  • Loading branch information
mathhetru committed Oct 3, 2024
1 parent 1b119eb commit d5c5c5e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 87 deletions.
9 changes: 7 additions & 2 deletions HRNet-project/src/pages/CreateEmployeeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLButtonElement>) => {
e.preventDefault();
Expand All @@ -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,
Expand All @@ -55,6 +59,7 @@ function CreateEmployeeView() {
zipCode,
});
addEmployee(employeeToAdd);
setSentenceForModal("✅ The employee has been added successfully.");
setIsOpen(!isOpen);
}
};
Expand Down Expand Up @@ -217,7 +222,7 @@ function CreateEmployeeView() {
<Modal
isOpen={isOpen}
closable={true}
mainContent="The employee has been added successfully."
mainContent={sentenceForModal}
hasFooter={true}
buttonFooter="Close"
modalSize="medium"
Expand Down
2 changes: 1 addition & 1 deletion HRNet-project/src/pages/EmployeeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function HomeView() {
onInput={handleSearchInput}
/>
</div>

<DataTable
size={"small"}
value={filteredEmployeesList}
Expand Down
168 changes: 84 additions & 84 deletions HRNet-project/src/store/employees.store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,90 +18,90 @@ export const useStore = create<EmployeesStore>()(
// @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) => {
Expand Down

0 comments on commit d5c5c5e

Please sign in to comment.