59 lines
1.7 KiB
TypeScript

import { createAsyncThunk } from '@reduxjs/toolkit';
import { Job } from '@app-types/index';
import * as jobApi from '../../../api/jobApi';
export const acceptJobThunk = createAsyncThunk<Job, string>(
'job/acceptJob',
async (jobId, { rejectWithValue }) => {
try {
return await jobApi.acceptJob(jobId);
} catch (error: any) {
return rejectWithValue(error.message || 'Failed to accept job');
}
}
);
export const rejectJobThunk = createAsyncThunk<void, string>(
'job/rejectJob',
async (jobId, { rejectWithValue }) => {
try {
return await jobApi.rejectJob(jobId);
} catch (error: any) {
return rejectWithValue(error.message || 'Failed to reject job');
}
}
);
export const confirmPickupThunk = createAsyncThunk<void, string>(
'job/confirmPickup',
async (jobId, { rejectWithValue }) => {
try {
return await jobApi.confirmPickup(jobId);
} catch (error: any) {
return rejectWithValue(error.message || 'Failed to confirm pickup');
}
}
);
export const confirmDeliveryThunk = createAsyncThunk<{ earnings: number }, { jobId: string; rating: number }>(
'job/confirmDelivery',
async ({ jobId, rating }, { rejectWithValue }) => {
try {
return await jobApi.confirmDelivery(jobId, rating);
} catch (error: any) {
return rejectWithValue(error.message || 'Failed to confirm delivery');
}
}
);
export const reportIssueThunk = createAsyncThunk<void, { jobId: string; reason: string }>(
'job/reportIssue',
async ({ jobId, reason }, { rejectWithValue }) => {
try {
return await jobApi.reportIssue(jobId, reason);
} catch (error: any) {
return rejectWithValue(error.message || 'Failed to report issue');
}
}
);