Skip to content

Commit

Permalink
Merge pull request #3140 from ever-co/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
evereq authored Oct 9, 2024
2 parents 3b6457e + a73cb5f commit 9445061
Show file tree
Hide file tree
Showing 27 changed files with 641 additions and 214 deletions.
2 changes: 1 addition & 1 deletion apps/web/app/[locale]/settings/team/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Team = () => {
<>
<Link href={'/settings/personal'} className="w-full">
<button className="w-full lg:hidden hover:bg-white rounded-xl border border-dark text-dark p-4 mt-2">
Go to Personnal settings
{t("pages.settingsTeam.GO_TO_PERSONAL_SETTINGS")}
</button>
</Link>
{/* General Settings */}
Expand Down
36 changes: 33 additions & 3 deletions apps/web/app/helpers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export const formatIntegerToHour = (number: number) => {
return formattedHour;
};


export const isTestDateRange = (itemDate: Date, from?: Date, to?: Date) => {
if (from && to) {
return itemDate >= from && itemDate <= to;
Expand All @@ -162,9 +161,40 @@ export const isTestDateRange = (itemDate: Date, from?: Date, to?: Date) => {
} else {
return true; // or false, depending on your default logic
}
}

};

export function convertHourToSeconds(hours: number) {
return hours * 60 * 60;
}

/**
* A helper function to parse a time string
*
* @param timeString - The time string to be formated.
*
* @returns {string} The formated time string
*/
export function formatTimeString(timeString: string): string {
// Extract hours and minutes using regex
const matches = timeString.match(/(\d+)h\s*(\d+)m|\b(\d+)m\b|\b(\d+)h\b/);

let result = '';

if (matches) {
const hours = matches[1] || matches[4]; // Group 1 for hours when both exist, Group 4 for hours only
const minutes = matches[2] || matches[3]; // Group 2 for minutes when both exist, Group 3 for minutes only

if (parseInt(hours) > 0) {
result += `${hours}h`;
}

if (parseInt(minutes) > 0) {
if (result) {
result += ' '; // Add space if hours were included
}
result += `${minutes}m`;
}
}

return result.length ? result : '0h 00m';
}
45 changes: 34 additions & 11 deletions apps/web/app/hooks/features/useStartStopTimerHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TASKS_ESTIMATE_HOURS_MODAL_DATE,
DAILY_PLAN_ESTIMATE_HOURS_MODAL_DATE
} from '@app/constants';
import { estimatedTotalTime } from 'lib/features/task/daily-plan';

export function useStartStopTimerHandler() {
const {
Expand Down Expand Up @@ -60,6 +61,11 @@ export function useStartStopTimerHandler() {
[activeTeamTask?.id, hasPlan?.tasks]
);

const tasksEstimationTimes = useMemo(
() => (hasPlan && hasPlan.tasks ? estimatedTotalTime(hasPlan.tasks).timesEstimated / 3600 : 0),
[hasPlan]
);

const enforceTaskSoftCloseModal = () => {
_enforceTaskSoftCloseModal();
openAddTasksEstimationHoursModal();
Expand All @@ -82,13 +88,13 @@ export function useStartStopTimerHandler() {
if (tasksEstimateHoursModalDate != currentDate) {
openAddTasksEstimationHoursModal();
} else {
startTimer();
handleWarnings();
}
} else {
openEnforcePlannedTaskSoftModal();
}
} else {
startTimer();
handleWarnings();
}
};

Expand All @@ -100,10 +106,10 @@ export function useStartStopTimerHandler() {
if (!hasWorkedHours) {
openAddDailyPlanWorkHoursModal();
} else {
startTimer();
handleWarnings();
}
} else {
startTimer();
handleWarnings();
}
};

Expand All @@ -118,15 +124,32 @@ export function useStartStopTimerHandler() {
if (dailyPlanEstimateHoursModalDate != currentDate) {
handleMissingDailyPlanWorkHour();
} else {
startTimer();
handleWarnings();
}
} else {
if (tasksEstimateHoursModalDate != currentDate) {
openAddTasksEstimationHoursModal();
} else {
startTimer();
handleWarnings();
}
}
} else {
handleWarnings();
}
};

/**
* Check if there is warning for 'enforce' mode. If not,
* start tracking
*/
const handleWarnings = () => {
if (
requirePlan &&
(!areAllTasksEstimated ||
!hasWorkedHours ||
Math.abs(Number(hasPlan?.workTimePlanned) - tasksEstimationTimes) > 1)
) {
openAddTasksEstimationHoursModal();
} else {
startTimer();
}
Expand All @@ -147,7 +170,7 @@ export function useStartStopTimerHandler() {
tasksEstimateHoursModalDate == currentDate &&
dailyPlanEstimateHoursModalDate == currentDate
) {
startTimer();
handleWarnings();
} else {
if (dailyPlanSuggestionModalDate != currentDate) {
if (!hasPlan) {
Expand All @@ -162,14 +185,13 @@ export function useStartStopTimerHandler() {
if (areAllTasksEstimated) {
handleMissingDailyPlanWorkHour();
} else {
startTimer();
handleWarnings();
}
} else {
startTimer();
handleWarnings();
}
} else {
// Default action to start the timer
startTimer();
handleWarnings();
}
}
}
Expand All @@ -187,6 +209,7 @@ export function useStartStopTimerHandler() {
requirePlan,
startTimer,
stopTimer,
tasksEstimationTimes,
timerStatus?.running,
timerStatusFetching
]);
Expand Down
Loading

0 comments on commit 9445061

Please sign in to comment.