Skip to content

Commit

Permalink
Added function documention
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwain-Anderson committed Dec 5, 2024
1 parent f7d5c21 commit 826b330
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions frontend/src/components/EmployeeModal/EmployeeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ const EmployeeModal = ({
refresh();
}

/**
* [createEmployee id employeeData endpoint refresh table iteration] creates a new employee
* using the provided data and endpoint. Optionally uploads a photo if [iteration] is 0 and
* [imageBase64] is non-empty.
* Requires: [id] to be a valid string or empty, [employeeData] to be a valid object,
* [endpoint] to be a valid API endpoint string, [refresh] to be a function, and [iteration]
* to be a non-negative integer.
* Returns: the created employee data.
*/
async function createEmployee(
id: string,
employeeData: AdminData | DriverData,
Expand All @@ -146,6 +155,17 @@ const EmployeeModal = ({
return createdEmployee;
}

/**
* [updateEmployee id employeeData endpoint refresh table iteration] updates an existing
* employee's data using the specified endpoint. Optionally uploads a photo if [iteration]
* is 0 and [imageBase64] is non-empty.
* Requires: [id] to be a valid string, [employeeData] to be a valid object, [endpoint] to
* be a valid API endpoint string, [refresh] to be a function, and [iteration] to be a
* non-negative integer.
* Returns: a promise that resolves after successfully updating the employee and refreshing
* the data.
*/

async function updateEmployee(
id: string,
employeeData: AdminData | DriverData,
Expand All @@ -162,10 +182,26 @@ const EmployeeModal = ({
refresh();
}

/**
* [deleteEmployee id emptype] removes an employee with the specified [id] from the backend,
* using the employee type [emptype] ('drivers' or 'admins') to determine the endpoint.
* Requires: [id] to be a valid string, [emptype] to be either 'drivers' or 'admins'.
* Returns: a promise that resolves after successfully deleting the employee.
*/

async function deleteEmployee(id: string, emptype: 'drivers' | 'admins') {
await axios.delete(`/api/${emptype}/${id}`);
}

/**
* [processRoles selectedRole existingEmployee admin driver] processes and assigns roles
* ('driver', 'admin') for the given employee, creating, updating, or deleting their
* information as necessary.
* Requires: [selectedRole] to be a valid array of roles, [existingEmployee] to be an object
* or null, and [admin] and [driver] to be valid employee data objects.
* Returns: a promise that resolves after processing all roles.
*/

async function processRoles(
selectedRole: any,
existingEmployee: any,
Expand Down Expand Up @@ -276,6 +312,14 @@ const EmployeeModal = ({
}
}

/**
* [onSubmit data] handles form submission, processes employee data, and invokes role
* processing.
* Requires: [data] to be an object containing valid employee form fields, including
* [firstName], [lastName], [netid], [phoneNumber], [startDate], and [availability].
* Returns: a promise that resolves after successfully processing the form data.
*/

async function onSubmit(data: ObjectType) {
const { firstName, lastName, netid, phoneNumber, startDate, availability } =
data;
Expand Down Expand Up @@ -309,6 +353,12 @@ const EmployeeModal = ({
}
}

/**
* [updateBase64 e] updates the [imageBase64] state by converting the selected file from the
* input event [e] into a base64-encoded string.
* Requires: [e] to be a valid React change event containing file input data.
* Returns: a promise that resolves after successfully updating the [imageBase64] state.
*/
async function updateBase64(e: React.ChangeEvent<HTMLInputElement>) {
e.preventDefault();

Expand Down

0 comments on commit 826b330

Please sign in to comment.