diff --git a/apps/backend/src/db/frontend/CellTypes.ts b/apps/backend/src/db/frontend/CellTypes.ts index 3585628..0d8ab11 100644 --- a/apps/backend/src/db/frontend/CellTypes.ts +++ b/apps/backend/src/db/frontend/CellTypes.ts @@ -12,6 +12,12 @@ export enum CellStatus { Deleted = "Deleted", } +export enum ReportOptions { + Late = "Late Arrival", + LeftEarly = "Early Departure", + Absent = "No Show", +} + export enum CommentType { Comment = "Comment", Report = "Report", diff --git a/apps/backend/src/db/frontend/RowSchema.ts b/apps/backend/src/db/frontend/RowSchema.ts index f36502e..a2eea6e 100644 --- a/apps/backend/src/db/frontend/RowSchema.ts +++ b/apps/backend/src/db/frontend/RowSchema.ts @@ -3,7 +3,13 @@ ////////////////////////////////////////////////////////////////////////// import { z } from "zod"; -import { CellType, CommentType, Review_Stages, CellStatus } from "./CellTypes"; +import { + CellType, + CommentType, + ReportOptions, + Review_Stages, + CellStatus, +} from "./CellTypes"; const optionalNumber = z.union([z.undefined(), z.number()]); const optionalString = z.union([z.undefined(), z.string()]); @@ -29,6 +35,19 @@ export const CommentSchema = z.object({ export type CommentSchema = z.infer; +export const ReportSchema = z.object({ + AuthorID: z.string(), + Timestamp: z.number(), + Type: z.nativeEnum(CommentType), + CorrectTime: z.number(), + Content: z.nativeEnum(ReportOptions), + Notified: z.string(), + Explanation: z.string(), + State: z.nativeEnum(CellStatus), +}); + +export type ReportSchema = z.infer; + export const RowType = z.enum([CellType.Regular, CellType.PTO]); export type RowType = z.infer; @@ -41,6 +60,7 @@ export const RowSchema = z.object({ Admin: TimeRowEntry, Comment: z.union([z.undefined(), z.array(CommentSchema)]), }); + export type RowSchema = z.infer; export const ScheduledRowSchema = z.object({ diff --git a/apps/backend/src/db/timesheets/ItemsOperations.ts b/apps/backend/src/db/timesheets/ItemsOperations.ts index dc4e272..602527e 100644 --- a/apps/backend/src/db/timesheets/ItemsOperations.ts +++ b/apps/backend/src/db/timesheets/ItemsOperations.ts @@ -240,7 +240,6 @@ export class NotesOperations implements ItemsOperations { public Update(timesheet: TimeSheetSchema, body: UpdateRequest) { //TODO - Add in functionality to trigger insert instead of update if ID does not yet exist - return { ...timesheet, WeekNotes: timesheet.WeekNotes.map((note) => { diff --git a/apps/backend/src/db/timesheets/UploadTimesheet.ts b/apps/backend/src/db/timesheets/UploadTimesheet.ts index 5277067..ca5ccd9 100644 --- a/apps/backend/src/db/timesheets/UploadTimesheet.ts +++ b/apps/backend/src/db/timesheets/UploadTimesheet.ts @@ -68,7 +68,6 @@ export class UploadTimesheet { selectedTimesheet[0], frontendEntryConversions.updateConversion(request.Payload) ); - break; default: throw new Error(`Invalid operation: ${request.Operation}`); diff --git a/apps/backend/test/UploadTimesheet.ts b/apps/backend/test/UploadTimesheet.ts index f053c85..8a836b7 100644 --- a/apps/backend/test/UploadTimesheet.ts +++ b/apps/backend/test/UploadTimesheet.ts @@ -13,8 +13,8 @@ const moment = require("moment-timezone"); Utils file used in testing to upload entire timesheets */ -const TIMEZONE = "America/New_York"; -const UUID = "f4e43e22-2be3-4945-83f0-c961655e90e8" +const TIMEZONE = "America/New_York"; +const UUID = "f4e43e22-2be3-4945-83f0-c961655e90e8"; function createTimeEntry(start, end) { return TimeEntrySchema.parse({ diff --git a/apps/frontend/src/aws-exports.js b/apps/frontend/src/aws-exports.js index 499c33a..ad0bc65 100644 --- a/apps/frontend/src/aws-exports.js +++ b/apps/frontend/src/aws-exports.js @@ -10,17 +10,16 @@ const awsmobile = { // aws_user_pools_id: 'us-east-2_zG2SfHpXC', aws_user_pools_id: "us-east-1_BO2rSGqTd", - - aws_user_pools_web_client_id: '3cekddbq7ail1s50qt2thfle7u', - oauth: {}, - aws_cognito_login_mechanism: [], - aws_cognito_signup_attributes: ['EMAIL'], - aws_cognito_mfa_configuration: 'OFF', - aws_cognito_mfa_types: ['SMS'], - aws_cognito_password_protection_settings: { - passwordPolicyMinLength: 8, - passwordPolicyCharacters: [], - }, + aws_user_pools_web_client_id: "3cekddbq7ail1s50qt2thfle7u", + oauth: {}, + aws_cognito_login_mechanism: [], + aws_cognito_signup_attributes: ["EMAIL"], + aws_cognito_mfa_configuration: "OFF", + aws_cognito_mfa_types: ["SMS"], + aws_cognito_password_protection_settings: { + passwordPolicyMinLength: 8, + passwordPolicyCharacters: [], + }, }; export default awsmobile; diff --git a/apps/frontend/src/components/Auth/UserUtils.tsx b/apps/frontend/src/components/Auth/UserUtils.tsx index 54a3053..f62eb5c 100644 --- a/apps/frontend/src/components/Auth/UserUtils.tsx +++ b/apps/frontend/src/components/Auth/UserUtils.tsx @@ -47,5 +47,5 @@ export const getCurrentUser = async function (): Promise { console.log(cognitoCurrentUser); const currUser = CognitoUser.parse(cognitoCurrentUser); - return await apiClient.getUser(currUser.attributes.sub) + return await apiClient.getUser(currUser.attributes.sub); }; diff --git a/apps/frontend/src/components/Auth/apiClient.tsx b/apps/frontend/src/components/Auth/apiClient.tsx index c33b8f4..4dfbd18 100644 --- a/apps/frontend/src/components/Auth/apiClient.tsx +++ b/apps/frontend/src/components/Auth/apiClient.tsx @@ -3,7 +3,7 @@ import axios, { AxiosInstance } from "axios"; import { TimeSheetSchema } from "../../schemas/TimesheetSchema"; import { UserSchema } from "../../schemas/UserSchema"; import { ReportOptions, UserTypes } from "../TimeCardPage/types"; -import React, { useState } from 'react'; +import React, { useState } from "react"; import { getCurrentUser } from "../Auth/UserUtils"; const defaultBaseUrl = @@ -18,11 +18,7 @@ interface ApiClientOptions { skipAuth?: boolean; } - - - -export class ApiClient { - +export class ApiClient { private axiosInstance: AxiosInstance; constructor( @@ -93,40 +89,37 @@ export class ApiClient { return this.get("/auth/timesheet") as Promise; } - // a function that returns list of multiple users based on list of userIds passed in public async getUsers(userIds: String[]): Promise { var allUsers; try { - allUsers = await Promise.all(userIds.map(userId => this.getUser(userId))); - } - catch (e) { - console.log(e) + allUsers = await Promise.all( + userIds.map((userId) => this.getUser(userId)) + ); + } catch (e) { + console.log(e); } - return allUsers + return allUsers; } - // TODO: setup endpoint for getting user information // all roles -> return UserSchema for the current user that is logged in public async getUser(UserID: String): Promise { - const userId = UserID + const userId = UserID; - var userConverted = {} + var userConverted = {}; try { await this.get(`/user/usersById?userIds[]=${userId}`).then((userList) => { - - var userType = {} + var userType = {}; // set current user's type - if (userList[0].Type === 'breaktime-associate') { - userType = UserTypes.Associate - } - else { - userType = UserTypes.Supervisor + if (userList[0].Type === "breaktime-associate") { + userType = UserTypes.Associate; + } else { + userType = UserTypes.Supervisor; } // create current user @@ -134,19 +127,14 @@ export class ApiClient { UserID: userList[0].userID, FirstName: userList[0].firstName, LastName: userList[0].lastName, - Type: userType + Type: userType, }; - - }) - } - - catch (e) { - console.log(e) + }); + } catch (e) { + console.log(e); } - - return userConverted - + return userConverted; } //TODO: hook up to backend, izzys pr has it just not merged yet diff --git a/apps/frontend/src/components/TimeCardPage/CellTypes/CommentCell.tsx b/apps/frontend/src/components/TimeCardPage/CellTypes/CommentCell.tsx index 1755182..a60462d 100644 --- a/apps/frontend/src/components/TimeCardPage/CellTypes/CommentCell.tsx +++ b/apps/frontend/src/components/TimeCardPage/CellTypes/CommentCell.tsx @@ -12,15 +12,29 @@ import ShowReportModal from "./CommentModals/ShowReportModal"; interface CommentProps { comments: CommentSchema[] | undefined; date: number; + updateComments: Function; timesheetID: number; } -export function CommentCell({ comments, date, timesheetID }: CommentProps) { +export function CommentCell({ + comments, + date, + updateComments, + timesheetID, +}: CommentProps) { const [currentComments, setCurrentComments] = useState( getAllActiveCommentsOfType(CommentType.Comment, comments) ); const [reports, setReports] = useState( - getAllActiveCommentsOfType(CommentType.Report, comments) as ReportSchema[] + getAllActiveCommentsOfType(CommentType.Report, comments).map((comment) => ({ + AuthorID: comment.AuthorID, + Type: comment.Type, + Content: comment.Content.split(",")[0], + Notified: comment.Content.split(",")[1], + Explanation: comment.Content.split(",")[2], + State: comment.State, + Timestamp: comment.Timestamp, + })) as ReportSchema[] ); const [isEditable, setisEditable] = useState(false); const user = useContext(UserContext); @@ -32,6 +46,21 @@ export function CommentCell({ comments, date, timesheetID }: CommentProps) { } }, [user?.Type]); + const updateReports = (updatedReports: ReportSchema[]) => { + setReports(updatedReports); + + const reportsToComments = updatedReports.map((report) => ({ + UUID: report.AuthorID, + AuthorID: report.AuthorID, + Type: report.Type, + Timestamp: report.Timestamp, + Content: `${report.Content},${report.Notified},${report.Explanation}`, + State: report.State, + })) as CommentSchema[]; + + updateComments("Comment", currentComments.concat(reportsToComments)); + }; + return ( 0; - // no reports so gray it out - if (doReportsExist === false) { - color = Color.Gray; - } + const color = doReportsExist ? Color.Red : Color.Gray; const DisplayReportsModal = () => { return ( diff --git a/apps/frontend/src/components/TimeCardPage/TimeSheet.tsx b/apps/frontend/src/components/TimeCardPage/TimeSheet.tsx index 74ae644..aa63ed2 100644 --- a/apps/frontend/src/components/TimeCardPage/TimeSheet.tsx +++ b/apps/frontend/src/components/TimeCardPage/TimeSheet.tsx @@ -241,16 +241,11 @@ export default function Page() { setSelectedUser(userInfo); }); - }); - // if employee setSelectedUSer to be userinfo // if supervisor/admin get all users // set selected user - - - }, []); const getUpdatedTimesheet = (userId) => { diff --git a/apps/frontend/src/components/TimeCardPage/TimeTableRow.tsx b/apps/frontend/src/components/TimeCardPage/TimeTableRow.tsx index 0308975..c7ebce5 100644 --- a/apps/frontend/src/components/TimeCardPage/TimeTableRow.tsx +++ b/apps/frontend/src/components/TimeCardPage/TimeTableRow.tsx @@ -72,6 +72,7 @@ function Row(props: RowProps) { date={fields.Date} comments={fields.Comment} timesheetID={props.TimesheetID} + updateComments={updateField} /> ), }; diff --git a/apps/frontend/src/components/TimeCardPage/utils.tsx b/apps/frontend/src/components/TimeCardPage/utils.tsx index 92b66a9..2c38469 100644 --- a/apps/frontend/src/components/TimeCardPage/utils.tsx +++ b/apps/frontend/src/components/TimeCardPage/utils.tsx @@ -57,6 +57,6 @@ export const createNewReport = ( Notified: notified, Explanation: explanation, State: CellStatus.Active, - time: moment().unix(), + Timestamp: moment().unix(), }; };