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
+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) => {