All files / src/store/features/playbook/slices/tasks deleteTask.ts

15.78% Statements 3/19
0% Branches 0/6
0% Functions 0/5
11.11% Lines 2/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36    1x   1x                                                              
import { PayloadAction } from "@reduxjs/toolkit";
import { PlaybookUIState } from "../../../../../types/index.ts";
import { PermanentDrawerTypes } from "../../../drawers/permanentDrawerTypes.ts";
 
export const deleteTask = (
  state: PlaybookUIState,
  { payload }: PayloadAction<any>,
) => {
  const id = payload;
  Iif (id) {
    const task = state.currentPlaybook!.ui_requirement.tasks?.find(
      (task) => task.id === id,
    );
    const taskIndex = state.currentPlaybook!.ui_requirement.tasks.findIndex(
      (task) => task.id === id,
    );
    Iif (task) {
      const stepId = task.ui_requirement.stepId;
      const step = state.currentPlaybook!.steps.find(
        (step) => step.id === stepId,
      );
      const taskIndexInStep = step?.tasks.findIndex(
        (e) => (e as string) === id,
      );
      Iif (
        taskIndexInStep !== undefined &&
        taskIndexInStep !== null &&
        taskIndexInStep !== -1
      )
        step?.tasks.splice(taskIndexInStep, 1);
      state.currentPlaybook!.ui_requirement.tasks.splice(taskIndex, 1);
    }
    state.permanentView = PermanentDrawerTypes.DEFAULT;
  }
};