All files / client/src/views/all-program-items allProgramItemsThunks.ts

70% Statements 14/20
75% Branches 9/12
83.33% Functions 5/6
70% Lines 14/20

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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                      356x         426x 426x   425x       425x   425x 1749x     425x       270x     425x   1749x             425x       270x         356x                          
import { isDeepEqual } from "remeda";
import {
  getProgramItems,
  postUpdateProgramItems,
} from "client/services/programItemsServices";
import { AppThunk } from "client/types/reduxTypes";
import {
  submitGetDirectSignupsAsync,
  submitGetProgramItemsAsync,
} from "client/views/all-program-items/allProgramItemsSlice";
 
export const submitGetProgramItems = ({
  forceUpdate,
}: {
  forceUpdate: boolean;
}): AppThunk => {
  return async (dispatch, getState): Promise<void> => {
    const getProgramItemsResponse = await getProgramItems();
 
    Iif (getProgramItemsResponse.status === "error") {
      return;
    }
 
    const state = getState();
 
    const programItems = getProgramItemsResponse.programItems.map(
      (programItemWithAttendees) => programItemWithAttendees.programItem,
    );
 
    if (
      forceUpdate ||
      !isDeepEqual(state.allProgramItems.programItems, programItems)
    ) {
      dispatch(submitGetProgramItemsAsync(programItems));
    }
 
    const directSignups = getProgramItemsResponse.programItems.map(
      (programItemWithAttendees) => {
        return {
          users: programItemWithAttendees.users,
          programItemId: programItemWithAttendees.programItem.programItemId,
        };
      },
    );
 
    if (
      forceUpdate ||
      !isDeepEqual(state.allProgramItems.directSignups, directSignups)
    ) {
      dispatch(submitGetDirectSignupsAsync(directSignups));
    }
  };
};
 
export const submitUpdateProgramItems = (): AppThunk<
  Promise<string | undefined>
> => {
  return async (dispatch): Promise<string | undefined> => {
    const programItemsUpdateResponse = await postUpdateProgramItems();
 
    if (programItemsUpdateResponse.status === "error") {
      return programItemsUpdateResponse.message;
    }
 
    await dispatch(submitGetProgramItems({ forceUpdate: false }));
  };
};