feat: add toast

This commit is contained in:
Kailasdevdas
2026-05-11 10:51:34 +05:30
parent 1717507555
commit 2c6da93dfb
6 changed files with 150 additions and 18 deletions
+41 -3
View File
@@ -1,11 +1,49 @@
import apiClient from "@/api/client";
import toast from "react-hot-toast";
export const getCareersApi = async () => {
const res = await apiClient.get("/careers/getAll?admin=true");
return res.data;
};
export const deleteCareerApi = async (id: number) => {
const res = await apiClient.delete(`/careers/${id}`);
return res.data;
export const createCareerApi = async (data: any) => {
try {
const res = await apiClient.post("/careers", data);
toast.success("Career created successfully");
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || "Failed to create career");
throw error;
}
};
export const updateCareerApi = async (id: number, data: any) => {
try {
const res = await apiClient.patch(`/careers/${id}`, data);
toast.success("Career updated successfully");
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || "Failed to update career");
throw error;
}
};
export const deleteCareerApi = async (id: number) => {
try {
const res = await apiClient.delete(`/careers/${id}`);
toast.success("Career deleted successfully");
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || "Failed to delete career");
throw error;
}
};
+42 -6
View File
@@ -1,4 +1,5 @@
import apiClient from "@/api/client";
import toast from "react-hot-toast";
export interface Department {
departmentId: string;
@@ -9,6 +10,8 @@ export interface Department {
para3: string;
facilities: string;
services: string;
isActive?: boolean;
sortOrder?: number;
}
export const getDepartmentsApi = async () => {
@@ -25,8 +28,19 @@ export const createDepartmentApi = async (data: {
facilities?: string;
services?: string;
}) => {
const res = await apiClient.post("/departments", data);
return res.data;
try {
const res = await apiClient.post("/departments", data);
toast.success("Department created successfully");
return res.data;
} catch (error: any) {
toast.error(
error?.response?.data?.message || "Failed to create department",
);
throw error;
}
};
export const updateDepartmentApi = async (
@@ -40,11 +54,33 @@ export const updateDepartmentApi = async (
services?: string;
},
) => {
const res = await apiClient.put(`/departments/${departmentId}`, data);
return res.data;
try {
const res = await apiClient.put(`/departments/${departmentId}`, data);
toast.success("Department updated successfully");
return res.data;
} catch (error: any) {
toast.error(
error?.response?.data?.message || "Failed to update department",
);
throw error;
}
};
export const deleteDepartmentApi = async (departmentId: string) => {
const res = await apiClient.delete(`/departments/${departmentId}`);
return res.data;
try {
const res = await apiClient.delete(`/departments/${departmentId}`);
toast.success("Department deleted successfully");
return res.data;
} catch (error: any) {
toast.error(
error?.response?.data?.message || "Failed to delete department",
);
throw error;
}
};
+34 -6
View File
@@ -1,4 +1,5 @@
import apiClient from "@/api/client";
import toast from "react-hot-toast";
export interface Doctor {
doctorId: string;
@@ -34,21 +35,48 @@ export const getDoctorByIdApi = async (doctorId: string) => {
};
export const createDoctorApi = async (data: Doctor) => {
const res = await apiClient.post("/doctors", data);
return res.data;
try {
const res = await apiClient.post("/doctors", data);
toast.success("Doctor created successfully");
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || "Failed to create doctor");
throw error;
}
};
export const updateDoctorApi = async (
doctorId: string,
data: Partial<Doctor>,
) => {
const res = await apiClient.patch(`/doctors/${doctorId}`, data);
return res.data;
try {
const res = await apiClient.patch(`/doctors/${doctorId}`, data);
toast.success("Doctor updated successfully");
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || "Failed to update doctor");
throw error;
}
};
export const deleteDoctorApi = async (doctorId: string) => {
const res = await apiClient.delete(`/doctors/${doctorId}`);
return res.data;
try {
const res = await apiClient.delete(`/doctors/${doctorId}`);
toast.success("Doctor deleted successfully");
return res.data;
} catch (error: any) {
toast.error(error?.response?.data?.message || "Failed to delete doctor");
throw error;
}
};
export const getDoctorTimingApi = async (doctorId: string) => {