1d78b2b65d
This commit introduces the functionality for super admins to change the status of other admin users to either 'Active' or 'Inactive'. This provides better control over admin account access. Key changes include: - A 'Status' column with a visual badge has been added to the admins table. - A new 'Change Status' action button, using a new `UserSettingIcon`, opens a modal for status updates. - The backend service and frontend mutation for updating an admin's status are implemented. - The `IUser` type and a new `AdminStatus` enum have been added to support this feature. Additionally, the confirmation modal implementation has been simplified across the admin and customer tables by removing the `modalConfig` state.
108 lines
2.9 KiB
TypeScript
108 lines
2.9 KiB
TypeScript
import api from "../axios";
|
|
import { API_ENDPOINTS } from "../endpoints";
|
|
import {
|
|
ApiResponse,
|
|
IAdminListResponse,
|
|
ICreateAdminCredentials,
|
|
ILoginCredentials,
|
|
ILoginResponse,
|
|
ILogoutResponse,
|
|
LoginResponseSchema,
|
|
LogoutResponseSchema,
|
|
TChangeAdminStatusCredentials,
|
|
} from "../types";
|
|
|
|
export const userService = {
|
|
login: async (
|
|
credentials: ILoginCredentials,
|
|
): Promise<ApiResponse<ILoginResponse>> => {
|
|
try {
|
|
const response = await api.post(API_ENDPOINTS.USER.LOGIN, credentials);
|
|
|
|
return LoginResponseSchema.parse(response.data);
|
|
} catch (error) {
|
|
console.error("ERROR caught in User Service Login:", error);
|
|
throw error;
|
|
}
|
|
},
|
|
logout: async (): Promise<ApiResponse<ILogoutResponse>> => {
|
|
try {
|
|
const response = await api.delete(API_ENDPOINTS.USER.LOGOUT);
|
|
return LogoutResponseSchema.parse(response.data);
|
|
} catch (error) {
|
|
console.error("ERROR caught in User Service Logout", error);
|
|
throw error;
|
|
}
|
|
},
|
|
adminsList: async (
|
|
params?: Record<string, any>,
|
|
): Promise<ApiResponse<IAdminListResponse>> => {
|
|
try {
|
|
const response = await api.get(API_ENDPOINTS.USER.ADMINS, { params });
|
|
return response.data;
|
|
} catch (error) {
|
|
console.error("ERROR caught in User Service User List", error);
|
|
throw error;
|
|
}
|
|
},
|
|
createAdmin: async (credentials: ICreateAdminCredentials) => {
|
|
try {
|
|
return (await api.post(API_ENDPOINTS.USER.ADMINS, credentials)).data
|
|
.message;
|
|
} catch (error) {
|
|
console.error("ERROR caught in User Service Create Admin", error);
|
|
throw error;
|
|
}
|
|
},
|
|
updateAdmin: async ({
|
|
id,
|
|
credentials,
|
|
}: {
|
|
id: string;
|
|
credentials: ICreateAdminCredentials;
|
|
}) => {
|
|
try {
|
|
return (await api.put(API_ENDPOINTS.USER.ADMIN_DETAILS(id), credentials))
|
|
.data.message;
|
|
} catch (error) {
|
|
console.error("ERROR caught in User Service Update Admin", error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
adminDetails: async (id: string) => {
|
|
try {
|
|
return (await api.get(API_ENDPOINTS.USER.ADMIN_DETAILS(id))).data;
|
|
} catch (error) {
|
|
console.error("ERROR caught in User Service Admin Details", error);
|
|
throw error;
|
|
}
|
|
},
|
|
deleteAdmin: async (
|
|
id: string,
|
|
): Promise<ApiResponse<{ message: string }>> => {
|
|
try {
|
|
return await api.delete(`${API_ENDPOINTS.USER.ADMINS}/${id}`);
|
|
} catch (error) {
|
|
console.error("ERROR caught in User Service Delete Admin", error);
|
|
throw error;
|
|
}
|
|
},
|
|
changeAdminStatus: async ({
|
|
id,
|
|
credentials,
|
|
}: {
|
|
id: string;
|
|
credentials: TChangeAdminStatusCredentials;
|
|
}) => {
|
|
try {
|
|
return (
|
|
await api.put(API_ENDPOINTS.USER.CHANGE_ADMIN_STATUS(id), credentials)
|
|
).data;
|
|
} catch (error) {
|
|
console.error("ERROR Caught in user service => change status", error);
|
|
throw error;
|
|
}
|
|
},
|
|
};
|