Skip to content

Commit

Permalink
[Job Launcher] job list api integration (#1106)
Browse files Browse the repository at this point in the history
* job list api integration

* fix all networks
  • Loading branch information
m00n620 authored Oct 26, 2023
1 parent 22553ce commit 48d3b61
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Link } from 'react-router-dom';
import * as authService from '../../services/auth';
import { useAppDispatch } from '../../state';
import { fetchUserBalanceAsync, signIn } from '../../state/auth/reducer';
import { fetchUserJobsAsync } from '../../state/jobs/reducer';
import { Password } from './Password';
import { LoginValidationSchema } from './schema';

Expand Down Expand Up @@ -35,7 +34,6 @@ export const SignInForm = ({ onError }) => {
});
dispatch(signIn(data));
dispatch(fetchUserBalanceAsync());
dispatch(fetchUserJobsAsync());
} catch (err) {
onError(err?.response?.data?.message ?? err.message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Box, Button, IconButton, Typography } from '@mui/material';
import { Link, useNavigate } from 'react-router-dom';
import { CopyLinkIcon } from '../../components/Icons/CopyLinkIcon';
import { Table } from '../../components/Table';
import { useJobs } from '../../state/jobs/hooks';
import { useJobs } from '../../hooks/useJobs';
import { JobStatus } from '../../types';

export const JobTable = ({
Expand Down
21 changes: 21 additions & 0 deletions packages/apps/job-launcher/client/src/hooks/useJobs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ChainId } from '@human-protocol/sdk';
import useSWR from 'swr';
import * as jobService from '../services/job';
import { JobStatus } from '../types';

export const useJobs = ({
chainId,
status,
}: {
chainId?: ChainId;
status?: JobStatus;
}) => {
return useSWR(`human-protocol-jobs-${chainId}-${status}`, async () => {
try {
const jobs = await jobService.getJobList({ chainId, status });
return jobs;
} catch (err) {
return [];
}
});
};
4 changes: 2 additions & 2 deletions packages/apps/job-launcher/client/src/layouts/AuthLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export default function AuthLayout() {
<ListItem>
<Link to="/jobs/pending">Pending</Link>
</ListItem>
{/* <ListItem>
<ListItem>
<Link to="/jobs/completed">Completed</Link>
</ListItem> */}
</ListItem>
<ListItem>
<Link to="/jobs/cancelled">Cancelled</Link>
</ListItem>
Expand Down
2 changes: 0 additions & 2 deletions packages/apps/job-launcher/client/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { LOCAL_STORAGE_KEYS } from './constants';
import reportWebVitals from './reportWebVitals';
import { store } from './state';
import { fetchUserBalanceAsync, signIn } from './state/auth/reducer';
import { fetchUserJobsAsync } from './state/jobs/reducer';
import theme from './theme';
// import { isJwtExpired } from './utils/jwt';

Expand Down Expand Up @@ -109,7 +108,6 @@ loadStripe(publishableKey).then((stripePromise) => {
})
);
store.dispatch(fetchUserBalanceAsync());
store.dispatch(fetchUserJobsAsync());
}

root.render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { JobStatus } from '../../../types';

const JOB_NAV_ITEMS = [
{ status: JobStatus.LAUNCHED, label: 'launched' },
{ status: JobStatus.COMPLETED, label: 'completed' },
{ status: JobStatus.PENDING, label: 'pending' },
{ status: JobStatus.CANCELED, label: 'cancelled' },
{ status: JobStatus.FAILED, label: 'failed' },
Expand Down
17 changes: 15 additions & 2 deletions packages/apps/job-launcher/client/src/services/job.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ChainId } from '@human-protocol/sdk';
import { SUPPORTED_CHAIN_IDS } from '../constants/chains';
import {
CreateFortuneJobRequest,
CreateCvatJobRequest,
Expand Down Expand Up @@ -41,8 +43,19 @@ export const createCvatJob = async (
await api.post('/job/cvat', body);
};

export const getJobList = async (status?: JobStatus) => {
const { data } = await api.get(`/job/list`, { params: { status } });
export const getJobList = async ({
chainId = ChainId.ALL,
status,
}: {
chainId?: ChainId;
status?: JobStatus;
}) => {
const { data } = await api.get(`/job/list`, {
params: {
networks: chainId === ChainId.ALL ? SUPPORTED_CHAIN_IDS : chainId,
status,
},
});
return data;
};

Expand Down
3 changes: 1 addition & 2 deletions packages/apps/job-launcher/client/src/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { useDispatch, useSelector, TypedUseSelectorHook } from 'react-redux';

import auth from './auth/reducer';
import dashboard from './dashboard/reducer';
import jobs from './jobs/reducer';

export const store = configureStore({
reducer: { auth, dashboard, jobs },
reducer: { auth, dashboard },
});

export type AppState = ReturnType<typeof store.getState>;
Expand Down
25 changes: 0 additions & 25 deletions packages/apps/job-launcher/client/src/state/jobs/hooks.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/apps/job-launcher/client/src/state/jobs/reducer.ts

This file was deleted.

15 changes: 0 additions & 15 deletions packages/apps/job-launcher/client/src/state/jobs/types.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/apps/job-launcher/client/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ export enum JobStatus {
PENDING = 'PENDING',
CANCELED = 'CANCELED',
FAILED = 'FAILED',
PAID = 'PAID',
TO_CANCEL = 'TO_CANCEL',
COMPLETED = 'COMPLETED',
}

export type JobDetailsResponse = {
Expand Down

1 comment on commit 48d3b61

@vercel
Copy link

@vercel vercel bot commented on 48d3b61 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

job-launcher-client – ./packages/apps/job-launcher/client

job-launcher-client-humanprotocol.vercel.app
job-launcher-client-git-develop-humanprotocol.vercel.app
job-launcher-client-nine.vercel.app

Please sign in to comment.