Skip to content

Commit 761fc8b

Browse files
authored
feat: loading state for refresh tasks (#2797)
1 parent a819bb7 commit 761fc8b

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

packages/apps/human-app/frontend/src/pages/worker/jobs/components/my-jobs/desktop/my-jobs-table.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
useMaterialReactTable,
99
type MRT_ColumnDef,
1010
} from 'material-react-table';
11-
import { Box, Button, Typography } from '@mui/material';
11+
import { Box, Typography } from '@mui/material';
1212
import RefreshIcon from '@mui/icons-material/Refresh';
1313
import { TableHeaderCell } from '@/components/ui/table/table-header-cell';
1414
import {
@@ -18,6 +18,7 @@ import {
1818
import { useMyJobsFilterStore } from '@/hooks/use-my-jobs-filter-store';
1919
import { getNetworkName } from '@/smart-contracts/get-network-name';
2020
import { RewardAmount } from '@/pages/worker/jobs/components/reward-amount';
21+
import { Button } from '@/components/ui/button';
2122
import { Chip } from '@/components/ui/chip';
2223
import { formatDate } from '@/shared/helpers/format-date';
2324
import { EvmAddress } from '@/pages/worker/jobs/components/evm-address';
@@ -36,10 +37,15 @@ import type { JobType } from '@/smart-contracts/EthKVStore/config';
3637
import { EscrowAddressSearchForm } from '@/pages/worker/jobs/components/escrow-address-search-form';
3738
import { useRefreshTasksMutation } from '@/api/services/worker/refresh-tasks';
3839

39-
const getColumnsDefinition = (
40-
resignJob: (assignment_id: string) => void,
41-
refreshData: () => void
42-
): MRT_ColumnDef<MyJob>[] => [
40+
const getColumnsDefinition = ({
41+
resignJob,
42+
refreshData,
43+
isRefreshTasksPending,
44+
}: {
45+
resignJob: (assignment_id: string) => void;
46+
refreshData: () => void;
47+
isRefreshTasksPending: boolean;
48+
}): MRT_ColumnDef<MyJob>[] => [
4349
{
4450
accessorKey: 'escrow_address',
4551
header: t('worker.jobs.escrowAddress'),
@@ -226,6 +232,7 @@ const getColumnsDefinition = (
226232
paddingInline: '1rem',
227233
fontSize: '13px',
228234
}}
235+
loading={isRefreshTasksPending}
229236
type="button"
230237
variant="outlined"
231238
onClick={refreshData}
@@ -256,7 +263,8 @@ export function MyJobsTable() {
256263
);
257264

258265
const { mutate: rejectTaskMutation } = useRejectTaskMutation();
259-
const { mutate: refreshTasksMutation } = useRefreshTasksMutation();
266+
const { mutate: refreshTasksMutation, isPending: isRefreshTasksPending } =
267+
useRefreshTasksMutation();
260268
const { address: oracle_address } = useParams<{ address: string }>();
261269

262270
const [paginationState, setPaginationState] = useState({
@@ -294,10 +302,11 @@ export function MyJobsTable() {
294302
}, [resetFilterParams]);
295303

296304
const table = useMaterialReactTable({
297-
columns: getColumnsDefinition(
298-
rejectTask(oracle_address ?? ''),
299-
refreshTasks(oracle_address ?? '')
300-
),
305+
columns: getColumnsDefinition({
306+
resignJob: rejectTask(oracle_address ?? ''),
307+
refreshData: refreshTasks(oracle_address ?? ''),
308+
isRefreshTasksPending,
309+
}),
301310
data: memoizedTableDataResults,
302311
state: {
303312
isLoading: tableStatus === 'pending',

packages/apps/human-app/frontend/src/pages/worker/jobs/components/my-jobs/mobile/my-jobs-table-mobile.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ export function MyJobsTableMobile({
5050
} = useInfiniteGetMyJobsData();
5151

5252
const { mutate: rejectTaskMutation } = useRejectTaskMutation();
53-
const { mutate: refreshTasksMutation } = useRefreshTasksMutation();
53+
const { mutate: refreshTasksMutation, isPending: isRefreshTasksPending } =
54+
useRefreshTasksMutation();
5455
const { setSearchEscrowAddress } = useJobsFilterStore();
5556
const { address: oracle_address } = useParams<{ address: string }>();
5657

@@ -106,6 +107,7 @@ export function MyJobsTableMobile({
106107
}}
107108
type="button"
108109
variant="outlined"
110+
loading={isRefreshTasksPending}
109111
onClick={() => {
110112
refreshTasksMutation({
111113
oracle_address: oracle_address ?? '',

0 commit comments

Comments
 (0)