17 lines
535 B
TypeScript

import { createAction, createAsyncThunk } from '@reduxjs/toolkit';
import { addLeadApi } from '@api';
import { AddLeadPayload, AddLeadResponse } from '@interfaces';
export const resetAddLeadState = createAction('addLead/resetState');
export const addLead = createAsyncThunk<AddLeadResponse, AddLeadPayload>(
'addLead/addLead',
async (payload, { rejectWithValue }) => {
try {
return await addLeadApi(payload);
} catch (error: any) {
return rejectWithValue(error.message || 'Failed to add lead');
}
},
);