import { notifications } from "@mantine/notifications"; export const fetchUserDetails = async () => { try { const token = localStorage.getItem("mandate_token"); const response = await fetch("/api/customer", { method: "GET", headers: { "Content-Type": "application/json", "X-Login-Type": "eMandate", Authorization: `Bearer ${token}`, }, }); if (!response.ok) throw new Error("Failed"); const data = await response.json(); if (Array.isArray(data) && data.length > 0) { const name = data[0].custname; const mobile = data[0].mobileno; localStorage.setItem("user_name", name); localStorage.setItem("userMobNo", mobile); return { name, mobile }; } } catch { notifications.show({ title: "Please try again later", message: "Unable to fetch user details", color: "red", }); } return null; };