Skip to content

Commit 1522416

Browse files
authored
[Human App] Improve the task cancellation UI (#3675)
1 parent bb7a5a7 commit 1522416

File tree

9 files changed

+27
-13
lines changed

9 files changed

+27
-13
lines changed

packages/apps/human-app/frontend/serve.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"key": "Content-Security-Policy",
21-
"value": "frame-ancestors: 'none';"
21+
"value": "frame-ancestors 'none';"
2222
},
2323
{
2424
"key": "Strict-Transport-Security",

packages/apps/human-app/frontend/src/modules/worker/jobs/components/more-button.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useParams } from 'react-router-dom';
66
import { useTranslation } from 'react-i18next';
77
import { useModal } from '@/shared/contexts/modal-context';
88
import { useIsMobile } from '@/shared/hooks/use-is-mobile';
9+
import { TopNotificationType, useNotification } from '@/shared/hooks';
910
import { useResignJobMutation } from '../my-jobs/hooks';
1011
import { type MyJob } from '../schemas';
1112
import { ReportAbuseModal } from './report-abuse-modal';
@@ -18,19 +19,28 @@ interface MoreButtonProps {
1819
export function MoreButton({ job, isDisabled }: MoreButtonProps) {
1920
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
2021
const { address: oracleAddress } = useParams<{ address: string }>();
21-
const { mutate: rejectTaskMutation } = useResignJobMutation();
22+
const { mutateAsync: rejectTaskMutation } = useResignJobMutation();
2223
const { openModal, closeModal } = useModal();
2324
const isMobile = useIsMobile();
2425
const { t } = useTranslation();
26+
const { showNotification } = useNotification();
2527

2628
const isOpen = Boolean(anchorEl);
2729

28-
const handleCancelTask = () => {
30+
const handleCancelTask = async () => {
2931
setAnchorEl(null);
30-
rejectTaskMutation({
31-
oracle_address: oracleAddress ?? '',
32-
assignment_id: job.assignment_id,
33-
});
32+
try {
33+
await rejectTaskMutation({
34+
oracle_address: oracleAddress ?? '',
35+
assignment_id: job.assignment_id,
36+
});
37+
} catch (error) {
38+
showNotification({
39+
message: 'Something went wrong',
40+
type: TopNotificationType.WARNING,
41+
durationMs: 5000,
42+
});
43+
}
3444
};
3545

3646
const handleOpenReportAbuseModal = () => {
@@ -90,7 +100,7 @@ export function MoreButton({ job, isDisabled }: MoreButtonProps) {
90100
}}
91101
>
92102
<MenuList>
93-
<ListItemButton onClick={handleCancelTask}>
103+
<ListItemButton onClick={() => void handleCancelTask()}>
94104
{t('worker.reportAbuse.cancel')}
95105
</ListItemButton>
96106
<ListItemButton onClick={handleOpenReportAbuseModal}>

packages/apps/human-app/frontend/src/modules/worker/jobs/my-jobs/hooks/use-refresh-jobs.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function useRefreshJobsMutation(callbacks?: {
1818
void callbacks.onSuccess();
1919
}
2020
await queryClient.invalidateQueries({ queryKey: ['fetchMyJobs'] });
21+
await queryClient.invalidateQueries({ queryKey: ['myJobsInfinite'] });
2122
},
2223
onError: (error) => {
2324
if (callbacks?.onError) {

packages/apps/human-app/frontend/src/modules/worker/jobs/my-jobs/hooks/use-resign-job.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function useResignJobMutation(callbacks?: {
1818
void callbacks.onSuccess();
1919
}
2020
await queryClient.invalidateQueries({ queryKey: ['fetchMyJobs'] });
21+
await queryClient.invalidateQueries({ queryKey: ['myJobsInfinite'] });
2122
},
2223
onError: (error) => {
2324
if (callbacks?.onError) {

packages/apps/human-app/server/src/modules/job-assignment/job-assignment.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class JobAssignmentService {
6969
);
7070
assignmentsParamsCommand.token = command.token;
7171

72-
void this.updateAssignmentsCache(assignmentsParamsCommand);
72+
await this.updateAssignmentsCache(assignmentsParamsCommand);
7373

7474
return response;
7575
}
@@ -82,7 +82,7 @@ export class JobAssignmentService {
8282
assignmentsParamsCommand.oracleAddress = command.oracleAddress;
8383
assignmentsParamsCommand.token = command.token;
8484

85-
void this.updateAssignmentsCache(assignmentsParamsCommand);
85+
await this.updateAssignmentsCache(assignmentsParamsCommand);
8686

8787
return response;
8888
}

packages/apps/job-launcher/client/serve.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"key": "Content-Security-Policy",
21-
"value": "frame-ancestors: 'none';"
21+
"value": "frame-ancestors 'none';"
2222
},
2323
{
2424
"key": "Strict-Transport-Security",

packages/apps/staking/serve.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"key": "Content-Security-Policy",
21-
"value": "frame-ancestors: 'none';"
21+
"value": "frame-ancestors 'none';"
2222
},
2323
{
2424
"key": "Strict-Transport-Security",

packages/sdk/typescript/human-protocol-sdk/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"vitest": "^3.0.9"
5252
},
5353
"devDependencies": {
54+
"@types/validator": "^13.15.4",
5455
"eslint": "^8.55.0",
5556
"prettier": "^3.4.2",
5657
"ts-node": "^10.9.2",

yarn.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4981,6 +4981,7 @@ __metadata:
49814981
resolution: "@human-protocol/sdk@workspace:packages/sdk/typescript/human-protocol-sdk"
49824982
dependencies:
49834983
"@human-protocol/core": "workspace:*"
4984+
"@types/validator": "npm:^13.15.4"
49844985
axios: "npm:^1.4.0"
49854986
eslint: "npm:^8.55.0"
49864987
ethers: "npm:~6.15.0"
@@ -11703,7 +11704,7 @@ __metadata:
1170311704
languageName: node
1170411705
linkType: hard
1170511706

11706-
"@types/validator@npm:^13.11.8":
11707+
"@types/validator@npm:^13.11.8, @types/validator@npm:^13.15.4":
1170711708
version: 13.15.4
1170811709
resolution: "@types/validator@npm:13.15.4"
1170911710
checksum: 10c0/fca230ddae859f5a66d74b466608ed16c0bfd34700558972fcab789d50d4beb7b14a6419ee2d0aab9c288e82d1706029d1c5519225c4b8dacb20f72bc05d7722

0 commit comments

Comments
 (0)