FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

25 rivejä
716 B

  1. "use client";
  2. import { NEXT_PUBLIC_API_URL } from "@/config/api";
  3. import { WarehouseResult } from "./index";
  4. export const fetchWarehouseListClient = async (): Promise<WarehouseResult[]> => {
  5. const token = localStorage.getItem("accessToken");
  6. const response = await fetch(`${NEXT_PUBLIC_API_URL}/warehouse`, {
  7. method: "GET",
  8. headers: {
  9. "Content-Type": "application/json",
  10. ...(token && { Authorization: `Bearer ${token}` }),
  11. },
  12. });
  13. if (!response.ok) {
  14. if (response.status === 401) {
  15. throw new Error("Unauthorized: Please log in again");
  16. }
  17. throw new Error(`Failed to fetch warehouses: ${response.status} ${response.statusText}`);
  18. }
  19. return response.json();
  20. };