Skip to content

Commit

Permalink
3022 improvement see plan the timer is running and user addsremove a …
Browse files Browse the repository at this point in the history
…task to the plan (#3059)

* feat: add 'unplan-active-task-modal'

* feat: add
'Add the Save changes'

* feat: The timer is running and user can add/remove a task to the plan

* feat: The timer is running and user can add/remove a task to the plan
  • Loading branch information
CREDO23 authored Sep 25, 2024
1 parent 29ca052 commit ada6c08
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 54 deletions.
36 changes: 22 additions & 14 deletions apps/web/app/hooks/features/useDailyPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ export function useDailyPlan() {
user?.tenantId || ''
);
//Check if there is an existing plan
const isPlanExist = profileDailyPlans.items.find((plan) =>
const isPlanExist = [...(profileDailyPlans.items ? profileDailyPlans.items : [])].find((plan) =>
plan.date?.toString()?.startsWith(new Date(data.date)?.toISOString().split('T')[0])
);
if (isPlanExist) {
const updatedPlans = profileDailyPlans.items.map((plan) => {
const updatedPlans = [...(profileDailyPlans.items ? profileDailyPlans.items : [])].map((plan) => {
if (plan.date?.toString()?.startsWith(new Date(data.date)?.toISOString().split('T')[0])) {
return res.data;
}
Expand All @@ -127,11 +127,11 @@ export function useDailyPlan() {
} else {
setProfileDailyPlans({
total: profileDailyPlans.total + 1,
items: [...profileDailyPlans.items, res.data]
items: [...(profileDailyPlans.items ? profileDailyPlans.items : []), res.data]
});
}

setEmployeePlans([...employeePlans, res.data]);
setEmployeePlans([...(employeePlans ? employeePlans : []), res.data]);
getMyDailyPlans();
return res;
}
Expand All @@ -151,8 +151,10 @@ export function useDailyPlan() {
const updateDailyPlan = useCallback(
async (data: IUpdateDailyPlan, planId: string) => {
const res = await updateQueryCall(data, planId);
const updated = profileDailyPlans.items.filter((plan) => plan.id != planId);
const updatedEmployee = employeePlans.filter((plan) => plan.id != planId);
const updated = [...(profileDailyPlans.items ? profileDailyPlans.items : [])].filter(
(plan) => plan.id != planId
);
const updatedEmployee = [...(employeePlans ? employeePlans : [])].filter((plan) => plan.id != planId);
setProfileDailyPlans({
total: profileDailyPlans.total,
items: [...updated, res.data]
Expand All @@ -178,8 +180,10 @@ export function useDailyPlan() {
const addTaskToPlan = useCallback(
async (data: IDailyPlanTasksUpdate, planId: string) => {
const res = await addTaskToPlanQueryCall(data, planId);
const updated = profileDailyPlans.items.filter((plan) => plan.id != planId);
const updatedEmployee = employeePlans.filter((plan) => plan.id != planId);
const updated = [...(profileDailyPlans.items ? profileDailyPlans.items : [])].filter(
(plan) => plan.id != planId
);
const updatedEmployee = [...(employeePlans ? employeePlans : [])].filter((plan) => plan.id != planId);
setProfileDailyPlans({
total: profileDailyPlans.total,
items: [...updated, res.data]
Expand All @@ -201,8 +205,10 @@ export function useDailyPlan() {
const removeTaskFromPlan = useCallback(
async (data: IDailyPlanTasksUpdate, planId: string) => {
const res = await removeTAskFromPlanQueryCall(data, planId);
const updated = profileDailyPlans.items.filter((plan) => plan.id != planId);
const updatedEmployee = employeePlans.filter((plan) => plan.id != planId);
const updated = [...(profileDailyPlans.items ? profileDailyPlans.items : [])].filter(
(plan) => plan.id != planId
);
const updatedEmployee = [...(employeePlans ? employeePlans : [])].filter((plan) => plan.id != planId);
setProfileDailyPlans({
total: profileDailyPlans.total,
items: [...updated, res.data]
Expand All @@ -224,14 +230,14 @@ export function useDailyPlan() {
const removeManyTaskPlans = useCallback(
async (data: IRemoveTaskFromManyPlans, taskId: string) => {
const res = await removeManyTaskPlanQueryCall({ taskId, data });
const updatedProfileDailyPlans = profileDailyPlans.items
const updatedProfileDailyPlans = [...(profileDailyPlans.items ? profileDailyPlans.items : [])]
.map((plan) => {
const updatedTasks = plan.tasks ? plan.tasks.filter((task) => task.id !== taskId) : [];
return { ...plan, tasks: updatedTasks };
})
.filter((plan) => plan.tasks && plan.tasks.length > 0);
// Delete plans without tasks
const updatedEmployeePlans = employeePlans
const updatedEmployeePlans = [...(employeePlans ? employeePlans : [])]
.map((plan) => {
const updatedTasks = plan.tasks ? plan.tasks.filter((task) => task.id !== taskId) : [];
return { ...plan, tasks: updatedTasks };
Expand Down Expand Up @@ -259,8 +265,10 @@ export function useDailyPlan() {
const deleteDailyPlan = useCallback(
async (planId: string) => {
const res = await deleteDailyPlanQueryCall(planId);
const updated = profileDailyPlans.items.filter((plan) => plan.id != planId);
const updatedEmployee = employeePlans.filter((plan) => plan.id != planId);
const updated = [...(profileDailyPlans.items ? profileDailyPlans.items : [])].filter(
(plan) => plan.id != planId
);
const updatedEmployee = [...(employeePlans ? employeePlans : [])].filter((plan) => plan.id != planId);
setProfileDailyPlans({ total: updated.length, items: [...updated] });
setEmployeePlans([...updatedEmployee]);

Expand Down
Loading

0 comments on commit ada6c08

Please sign in to comment.