Skip to content

Commit 7d83751

Browse files
committed
feat: add notification on task cancel; fix refresh logic on mobile
1 parent e4aa91e commit 7d83751

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

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

Lines changed: 22 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,33 @@ 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+
showNotification({
38+
message: 'Task cancelled. Press Refresh button to see the changes',
39+
type: TopNotificationType.SUCCESS,
40+
durationMs: 5000,
41+
});
42+
} catch (error) {
43+
showNotification({
44+
message: 'Something went wrong',
45+
type: TopNotificationType.WARNING,
46+
durationMs: 5000,
47+
});
48+
}
3449
};
3550

3651
const handleOpenReportAbuseModal = () => {
@@ -90,7 +105,7 @@ export function MoreButton({ job, isDisabled }: MoreButtonProps) {
90105
}}
91106
>
92107
<MenuList>
93-
<ListItemButton onClick={handleCancelTask}>
108+
<ListItemButton onClick={() => void handleCancelTask()}>
94109
{t('worker.reportAbuse.cancel')}
95110
</ListItemButton>
96111
<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) {

0 commit comments

Comments
 (0)