Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/backend/src/db/frontend/CellTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 21 additions & 1 deletion apps/backend/src/db/frontend/RowSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()]);
Expand All @@ -29,6 +35,19 @@ export const CommentSchema = z.object({

export type CommentSchema = z.infer<typeof CommentSchema>;

export const ReportSchema = z.object({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also have a UUID field in the report schema as well - it's an easy way to have a unique identifier for each comment/report. Otherwise, looks good!

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<typeof ReportSchema>;

export const RowType = z.enum([CellType.Regular, CellType.PTO]);
export type RowType = z.infer<typeof RowType>;

Expand All @@ -41,6 +60,7 @@ export const RowSchema = z.object({
Admin: TimeRowEntry,
Comment: z.union([z.undefined(), z.array(CommentSchema)]),
});

export type RowSchema = z.infer<typeof RowSchema>;

export const ScheduledRowSchema = z.object({
Expand Down
1 change: 0 additions & 1 deletion apps/backend/src/db/timesheets/ItemsOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 0 additions & 1 deletion apps/backend/src/db/timesheets/UploadTimesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class UploadTimesheet {
selectedTimesheet[0],
frontendEntryConversions.updateConversion(request.Payload)
);

break;
default:
throw new Error(`Invalid operation: ${request.Operation}`);
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/test/UploadTimesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
21 changes: 10 additions & 11 deletions apps/frontend/src/aws-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion apps/frontend/src/components/Auth/UserUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ export const getCurrentUser = async function (): Promise<UserSchema> {
console.log(cognitoCurrentUser);
const currUser = CognitoUser.parse(cognitoCurrentUser);

return await apiClient.getUser(currUser.attributes.sub)
return await apiClient.getUser(currUser.attributes.sub);
};
52 changes: 20 additions & 32 deletions apps/frontend/src/components/Auth/apiClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -18,11 +18,7 @@ interface ApiClientOptions {
skipAuth?: boolean;
}




export class ApiClient {

export class ApiClient {
private axiosInstance: AxiosInstance;

constructor(
Expand Down Expand Up @@ -93,60 +89,52 @@ export class ApiClient {
return this.get("/auth/timesheet") as Promise<string>;
}


// a function that returns list of multiple users based on list of userIds passed in
public async getUsers(userIds: String[]): Promise<UserSchema[]> {
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<UserSchema> {
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
userConverted = {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be careful using ',' as a delimiter here, since it wouldn't surprise me for the Explanation to include commas. Could you use something less frequently use to join and split the content, even just a semi-colon?

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);
Expand All @@ -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}`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason why we need to try and turn reports into comments? Can we just fully separate out the reports and comments in the fields?

State: report.State,
})) as CommentSchema[];

updateComments("Comment", currentComments.concat(reportsToComments));
};

return (
<Stack direction="row">
<ShowCommentModal
Expand All @@ -42,7 +71,7 @@ export function CommentCell({ comments, date, timesheetID }: CommentProps) {
/>
<ShowReportModal
date={date}
setReports={setReports}
setReports={updateReports}
reports={reports}
isEditable={isEditable}
timesheetID={timesheetID}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,10 @@ export default function ShowReportModal({
onClose: onCloseAdd,
} = useDisclosure();
const user = useContext(UserContext);
let color = Color.Red;

const doReportsExist = reports.length > 0;

// no reports so gray it out
if (doReportsExist === false) {
color = Color.Gray;
}
const color = doReportsExist ? Color.Red : Color.Gray;

const DisplayReportsModal = () => {
return (
Expand Down
5 changes: 0 additions & 5 deletions apps/frontend/src/components/TimeCardPage/TimeSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/src/components/TimeCardPage/TimeTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function Row(props: RowProps) {
date={fields.Date}
comments={fields.Comment}
timesheetID={props.TimesheetID}
updateComments={updateField}
/>
),
};
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/components/TimeCardPage/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ export const createNewReport = (
Notified: notified,
Explanation: explanation,
State: CellStatus.Active,
time: moment().unix(),
Timestamp: moment().unix(),
};
};