33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { createAction, createAsyncThunk } from '@reduxjs/toolkit';
|
|
import { updateProfileApi, getStaffDetailsApi } from '@api';
|
|
import { UpdateProfilePayload, UpdateProfileResponse, UserData } from '@interfaces';
|
|
|
|
export const resetEditProfileState = createAction('editProfile/resetState');
|
|
|
|
export const updateProfile = createAsyncThunk<UpdateProfileResponse, UpdateProfilePayload>(
|
|
'editProfile/updateProfile',
|
|
async (payload, { rejectWithValue }) => {
|
|
console.log('payload', payload)
|
|
try {
|
|
return await updateProfileApi(payload);
|
|
} catch (error: any) {
|
|
const serverMessage =
|
|
error?.response?.data?.message ||
|
|
error.message ||
|
|
'Failed to update profile';
|
|
return rejectWithValue(serverMessage);
|
|
}
|
|
},
|
|
);
|
|
|
|
export const getStaffDetails = createAsyncThunk<UserData, string | number>(
|
|
'editProfile/getStaffDetails',
|
|
async (id, { rejectWithValue }) => {
|
|
try {
|
|
return await getStaffDetailsApi(id);
|
|
} catch (error: any) {
|
|
return rejectWithValue(error.message || 'Failed to fetch staff details');
|
|
}
|
|
},
|
|
);
|