17 lines
583 B
TypeScript

import { createAction, createAsyncThunk } from '@reduxjs/toolkit';
import { addCustomerApi } from '@api';
import { AddCustomerPayload, AddCustomerResponse } from '@interfaces';
export const resetAddCustomerState = createAction('addCustomer/resetState');
export const addCustomer = createAsyncThunk<AddCustomerResponse, AddCustomerPayload>(
'addCustomer/addCustomer',
async (payload, { rejectWithValue }) => {
try {
return await addCustomerApi(payload);
} catch (error: any) {
return rejectWithValue(error.message || 'Failed to add customer');
}
},
);