Skip to content

Commit

Permalink
table now refetches and displays data
Browse files Browse the repository at this point in the history
  • Loading branch information
loganwc committed Jan 29, 2025
2 parents 70540fd + bb970df commit bc78def
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 28 deletions.
18 changes: 5 additions & 13 deletions src/components/Table/TableQueue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ const TableQueue = ({
setIsBulkAssignModalVisible(true);
};

const [tableData, setTableData] = useState([]);
const {
queueResult: {
totalCount = 0,
Expand All @@ -127,10 +126,8 @@ const TableQueue = ({
currentPage,
currentPageSize,
viewAsGBLOC: selectedGbloc,
onSuccess: (res) => {
if (tableData.length < 1) setTableData(res.queueMoves);
},
});
const tableData = useMemo(() => data, [data]);

// react-table setup below
const defaultColumn = useMemo(
Expand All @@ -140,14 +137,12 @@ const TableQueue = ({
}),
[],
);
// const cachedTableData = useMemo(() => data, [data]);

const { mutate: mutateBulkAssignment } = useMutation(saveBulkAssignmentData, {
onSuccess: () => {
// reload page to refetch queue
// window.location.reload();
refetch().then((res) => {
setTableData([...res.data.queueMoves]);
// refetch queue
refetch().then(() => {
setIsBulkAssignModalVisible(false);
});
},
});
Expand Down Expand Up @@ -332,10 +327,7 @@ const TableQueue = ({
};

const handleCloseBulkAssignModal = () => {
refetch().then((res) => {
setTableData([...res.data.queueMoves]);
setIsBulkAssignModalVisible(false);
});
setIsBulkAssignModalVisible(false);
};

const onSubmitBulk = (bulkAssignmentSavePayload) => {
Expand Down
19 changes: 13 additions & 6 deletions src/hooks/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,12 @@ export const useMovesQueueQueries = ({
currentPageSize = PAGINATION_PAGE_SIZE_DEFAULT,
viewAsGBLOC,
}) => {
const { data = {}, ...movesQueueQuery } = useQuery(
[MOVES_QUEUE, { sort, order, filters, currentPage, currentPageSize, viewAsGBLOC }],
({ queryKey }) => getMovesQueue(...queryKey),
const {
refetch,
data = {},
...movesQueueQuery
} = useQuery([MOVES_QUEUE, { sort, order, filters, currentPage, currentPageSize, viewAsGBLOC }], ({ queryKey }) =>
getMovesQueue(...queryKey),
);
const { isLoading, isError, isSuccess } = movesQueueQuery;
const { queueMoves, ...dataProps } = data;
Expand All @@ -583,6 +586,7 @@ export const useMovesQueueQueries = ({
isLoading,
isError,
isSuccess,
refetch,
};
};

Expand All @@ -594,7 +598,11 @@ export const useServicesCounselingQueuePPMQueries = ({
currentPageSize = PAGINATION_PAGE_SIZE_DEFAULT,
viewAsGBLOC,
}) => {
const { data = {}, ...servicesCounselingQueueQuery } = useQuery(
const {
refetch,
data = {},
...servicesCounselingQueueQuery
} = useQuery(
[
SERVICES_COUNSELING_QUEUE,
{ sort, order, filters, currentPage, currentPageSize, needsPPMCloseout: true, viewAsGBLOC },
Expand All @@ -609,6 +617,7 @@ export const useServicesCounselingQueuePPMQueries = ({
isLoading,
isError,
isSuccess,
refetch,
};
};

Expand All @@ -619,7 +628,6 @@ export const useServicesCounselingQueueQueries = ({
currentPage = PAGINATION_PAGE_DEFAULT,
currentPageSize = PAGINATION_PAGE_SIZE_DEFAULT,
viewAsGBLOC,
onSuccess,
}) => {
const {
refetch,
Expand All @@ -631,7 +639,6 @@ export const useServicesCounselingQueueQueries = ({
{ sort, order, filters, currentPage, currentPageSize, needsPPMCloseout: false, viewAsGBLOC },
],
({ queryKey }) => getServicesCounselingQueue(...queryKey),
{ onSuccess },
);

const { isLoading, isError, isSuccess } = servicesCounselingQueueQuery;
Expand Down
9 changes: 6 additions & 3 deletions src/pages/Office/MoveQueue/MoveQueue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import React, { useCallback, useEffect, useState } from 'react';
import { useNavigate, NavLink, useParams, Navigate, generatePath } from 'react-router-dom';
import { Dropdown } from '@trussworks/react-uswds';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { useMutation } from '@tanstack/react-query';

import styles from './MoveQueue.module.scss';

import { createHeader } from 'components/Table/utils';
import { useMovesQueueQueries, useUserQueries, useMoveSearchQueries } from 'hooks/queries';
import { getMovesQueue, saveBulkAssignmentData } from 'services/ghcApi';
import { getMovesQueue } from 'services/ghcApi';
import { formatDateFromIso, serviceMemberAgencyLabel } from 'utils/formatters';
import MultiSelectCheckBoxFilter from 'components/Table/Filters/MultiSelectCheckBoxFilter';
import SelectFilter from 'components/Table/Filters/SelectFilter';
Expand Down Expand Up @@ -168,7 +167,11 @@ export const columns = (moveLockFlag, isQueueManagementEnabled, showBranchFilter
>
<option value={null}>{DEFAULT_EMPTY_VALUE}</option>
{row.availableOfficeUsers?.map(({ lastName, firstName, officeUserId }) => (
<option value={officeUserId} key={`filterOption_${officeUserId}`}>
<option
value={officeUserId}
key={officeUserId}
selected={row.assignedTo?.officeUserId === officeUserId}
>
{`${lastName}, ${firstName}`}
</option>
))}
Expand Down
6 changes: 5 additions & 1 deletion src/pages/Office/PaymentRequestQueue/PaymentRequestQueue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ export const columns = (moveLockFlag, isQueueManagementEnabled, showBranchFilter
<option value={null}>{DEFAULT_EMPTY_VALUE}</option>
{row.availableOfficeUsers.map(({ lastName, firstName, officeUserId }) => {
return (
<option value={officeUserId} key={`filterOption_${officeUserId}`}>
<option
value={officeUserId}
key={officeUserId}
selected={row.assignedTo?.officeUserId === officeUserId}
>
{`${lastName}, ${firstName}`}
</option>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { generatePath, useNavigate, Navigate, useParams, NavLink } from 'react-r
import { connect } from 'react-redux';
import { Button, Dropdown } from '@trussworks/react-uswds';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { useMutation, useQueryClient } from '@tanstack/react-query';

import styles from './ServicesCounselingQueue.module.scss';

Expand Down Expand Up @@ -33,7 +32,6 @@ import {
getServicesCounselingOriginLocations,
getServicesCounselingPPMQueue,
getServicesCounselingQueue,
saveBulkAssignmentData,
} from 'services/ghcApi';
import { DATE_FORMAT_STRING, DEFAULT_EMPTY_VALUE, MOVE_STATUSES } from 'shared/constants';
import { formatDateFromIso, serviceMemberAgencyLabel } from 'utils/formatters';
Expand All @@ -55,7 +53,6 @@ import MultiSelectTypeAheadCheckBoxFilter from 'components/Table/Filters/MutliSe
import handleQueueAssignment from 'utils/queues';
import { selectLoggedInUser } from 'store/entities/selectors';
import SelectedGblocContext from 'components/Office/GblocSwitcher/SelectedGblocContext';
import { MOVES, MOVES_QUEUE, SERVICES_COUNSELING_PPM_QUEUE, SERVICES_COUNSELING_QUEUE } from 'constants/queryKeys';

export const counselingColumns = (moveLockFlag, originLocationList, supervisor, isQueueManagementEnabled) => {
const cols = [
Expand Down Expand Up @@ -214,7 +211,11 @@ export const counselingColumns = (moveLockFlag, originLocationList, supervisor,
>
<option value={null}>{DEFAULT_EMPTY_VALUE}</option>
{row.availableOfficeUsers.map(({ lastName, firstName, officeUserId }) => (
<option value={officeUserId} key={`filterOption_${officeUserId}`}>
<option
value={officeUserId}
key={officeUserId}
selected={row.assignedTo?.officeUserId === officeUserId}
>
{`${lastName}, ${firstName}`}
</option>
))}
Expand Down Expand Up @@ -411,7 +412,11 @@ export const closeoutColumns = (
>
<option value={null}>{DEFAULT_EMPTY_VALUE}</option>
{row.availableOfficeUsers.map(({ lastName, firstName, officeUserId }) => (
<option value={officeUserId} key={`filterOption_${officeUserId}`}>
<option
value={officeUserId}
key={officeUserId}
selected={row.assignedTo?.officeUserId === officeUserId}
>
{`${lastName}, ${firstName}`}
</option>
))}
Expand Down

0 comments on commit bc78def

Please sign in to comment.