Skip to content

Commit

Permalink
fix: fix form
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneMoroz committed Sep 20, 2024
1 parent c707932 commit f1d5aee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CacheTag } from "@/utils/cacheTag";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import routePaths from "@/utils/routePaths";
import { Forms } from "@/utils/form/formsEnums";
import { Forms, UserRole } from "@/utils/form/formsEnums";
import { type Question, type TeamMemberForCheckbox } from "@/utils/form/types";
import { getSprintCheckinIsStatus } from "@/utils/getFormStatus";
import { getCurrentSprint } from "@/utils/getCurrentSprint";
Expand Down Expand Up @@ -77,6 +77,8 @@ export default async function WeeklyCheckInWrapper({

let hasProductOwner = false;
let hasScrumMaster = false;
let isScrumMaster = false;
let isProductOwner = false;

const [user, error] = await getUser();

Expand Down Expand Up @@ -144,15 +146,25 @@ export default async function WeeklyCheckInWrapper({
}).voyageTeamMemberId;
}

// Check if a team has a product owner or a scrum muster
// Check if a team has a product owner or a scrum muster and if a user is a team has a product owner or a scrum muster
hasScrumMaster = !!res.voyageTeamMembers.find(
(member) => member.voyageRole.name === "Scrum Master",
(member) =>
member.voyageRole.name === UserRole.scrumMaster.toString(),
);

hasProductOwner = !!res.voyageTeamMembers.find(
(member) => member.voyageRole.name === "Product Owner",
(member) =>
member.voyageRole.name === UserRole.productOwner.toString(),
);

const currentUserRole = res.voyageTeamMembers.find(
(member) => member.id === voyageTeamMemberId,
)?.voyageRole.name;

isScrumMaster = currentUserRole === UserRole.scrumMaster.toString();

isProductOwner = currentUserRole === UserRole.productOwner.toString();

// Get all teamMembers except for the current user
if (voyageTeamMemberId) {
teamMembers = res.voyageTeamMembers
Expand Down Expand Up @@ -193,7 +205,7 @@ export default async function WeeklyCheckInWrapper({
if (formRes && formRes?.questions) questions = formRes.questions;

// Fetch PO checkin questions (form)
if (hasProductOwner) {
if (hasProductOwner && !isProductOwner) {
const [POformRes, POformError] = await fetchFormQuestions({
formId: Forms.checkinPO,
});
Expand All @@ -212,7 +224,7 @@ export default async function WeeklyCheckInWrapper({
}

// Fetch SM checkin questions (form)
if (hasScrumMaster) {
if (hasScrumMaster && !isScrumMaster) {
const [SMformRes, SMformError] = await fetchFormQuestions({
formId: Forms.checkinSM,
});
Expand Down
6 changes: 6 additions & 0 deletions src/utils/form/formsEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ export enum ReviewQuestions {
what_to_improve = 2,
what_to_change = 1,
}

export enum UserRole {
developer = "Developer",
productOwner = "Product Owner",
scrumMaster = "Scrum Master",
}
2 changes: 1 addition & 1 deletion src/utils/getCurrentSprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type Sprint } from "@/store/features/sprint/sprintSlice";

export const currentDate =
process.env.NODE_ENV === "development"
? new Date(2024, 5, 10, 12)
? new Date(2024, 5, 1, 12)
: new Date();

export function getCurrentSprint(sprints: Sprint[]) {
Expand Down

0 comments on commit f1d5aee

Please sign in to comment.