"use client"; import LocationDialog from "@/components/locations/location-dialog"; import IUser from "@/interfaces/IUser"; import hasPermissions from "@/lib/hasPermissions"; import { useState } from "react"; import { Location } from "@/types/types"; import request from "@/lib/request"; import { useApi } from "@/hooks/use-api"; import { LocationCard } from "@/components/locations/location-card"; export default function LocationsPage({ user }: { user: IUser }) { const { locations: locationsPerm } = hasPermissions(user.roles, { locations: ["update", "insert", "delete"], } as const); const locations = useApi("/locations/all"); const onUpdate = async (l: Location) => { try { const res = await request("/locations", { method: "PATCH", body: l, requiresAuth: true, }); if (res.status === "Success") { locations.mutate(); } else { } } catch (e) { console.error(e); } }; const onDelete = async (l: Location) => { try { const res = await request("/locations", { method: "DELETE", body: l, requiresAuth: true, }); if (res.status === "Success") locations.mutate(); else { } } catch (e) { console.error(e); } }; return (
{locationsPerm.insert && (
{ try { const res = await request("/locations/new", { body: l, method: "POST", requiresAuth: true, csrfToken: false, }); if (res.status === "Success") { locations.mutate(); } else { } } catch (e) {} }} />
)}
{locations.data?.map((l) => { return ( ); })}
); }