Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Job Launcher] job list api integration #1106

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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