diff --git a/src/api/api.ts b/src/api/api.ts index 162231cc..2a6181fb 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -1,8 +1,8 @@ -import ky, { type HTTPError, type KyInstance, type Options } from "ky"; +import ky, { type KyInstance, type Options } from "ky"; import { env } from "@/lib/env"; import { resolveApiPrefixUrl } from "@/lib/resolve-api-prefix-url"; import { API_PATHS } from "@/api/api-paths"; -import { createApiErrorFromResponse, mapHttpStatusToMessage } from "@/api/api-error"; +import { mapHttpStatusToMessage, normalizeApiRequestError } from "@/api/api-error"; import { queryKeys } from "@/infra/query-key/query-key"; import queryClient from "@/lib/query/query-client"; import { isAuthBypassEnabled } from "@/lib/auth/auth-bypass"; @@ -22,36 +22,23 @@ function isAuthLoginRequest(request: Request): boolean { } export const api: KyInstance = ky.create({ - prefixUrl: resolveApiPrefixUrl(env.apiUrl), + prefix: resolveApiPrefixUrl(env.apiUrl), headers: { Accept: "application/json", "Content-Type": "application/json", }, hooks: { beforeRequest: [ - (request) => { + ({ request }) => { const token = getAccessToken(); if (token) { request.headers.set("Authorization", token); } }, ], - beforeError: [ - async (error: HTTPError) => { - const { response } = error; - - if (!response) { - error.message = "No response from server. Please check your connection."; - return error; - } - - const apiError = await createApiErrorFromResponse(response); - error.message = apiError.message; - return error; - }, - ], + beforeError: [({ error }) => normalizeApiRequestError(error)], afterResponse: [ - async (request, _options, response) => { + ({ request, response }) => { if (response.status !== 401 || isAuthLoginRequest(request) || isAuthBypassEnabled()) { return response; } diff --git a/src/app/(protected)/_layout.tsx b/src/app/(protected)/_layout.tsx index 6d6655fa..c3281edf 100644 --- a/src/app/(protected)/_layout.tsx +++ b/src/app/(protected)/_layout.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import { Outlet } from "react-router-dom"; +import { Outlet } from "react-router"; import { Box } from "@mui/material"; import { ProtectedRoute } from "@/components/auth/protected-route"; diff --git a/src/app/(protected)/vendor-pos/[id].tsx b/src/app/(protected)/vendor-pos/[id].tsx index 1fd959b1..3fe4d7e1 100644 --- a/src/app/(protected)/vendor-pos/[id].tsx +++ b/src/app/(protected)/vendor-pos/[id].tsx @@ -1,5 +1,5 @@ import { useState, type ReactNode } from "react"; -import { useNavigate, useParams } from "react-router-dom"; +import { useNavigate, useParams } from "react-router"; import { Alert, Box, @@ -33,7 +33,7 @@ function formatMoney(value: number | null | undefined): string { function InfoRow({ label, children }: { label: string; children: ReactNode }) { return ( - + {label} @@ -107,7 +107,11 @@ export default function VendorPoViewPage() { return ( - + @@ -118,7 +122,7 @@ export default function VendorPoViewPage() { {dispatch.poNumber || "(no PO #)"} - + Dispatch {dispatch.dispatchNumber || "—"} @@ -256,7 +260,10 @@ export default function VendorPoViewPage() { {dispatch.upliftRequests.map((u) => ( - + {formatMoney(u.currentNTE)} → {formatMoney(u.requestedNTE)} {sorted.map((item) => ( - + {item.author} diff --git a/src/components/common/detail-field.tsx b/src/components/common/detail-field.tsx index 0b0f2fdf..6ab3a448 100644 --- a/src/components/common/detail-field.tsx +++ b/src/components/common/detail-field.tsx @@ -21,7 +21,7 @@ export function DetailField({ label, value, className, highlight }: DetailFieldP return ( - + {label} diff --git a/src/components/layout/app-topbar.tsx b/src/components/layout/app-topbar.tsx index cf679631..b2a5b417 100644 --- a/src/components/layout/app-topbar.tsx +++ b/src/components/layout/app-topbar.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import { useNavigate } from "react-router-dom"; +import { useNavigate } from "react-router"; import LogoutOutlinedIcon from "@mui/icons-material/LogoutOutlined"; import SettingsOutlinedIcon from "@mui/icons-material/SettingsOutlined"; import { @@ -199,7 +199,7 @@ export function AppTopbar({ onToggleNav }: AppTopbarProps) { {userInitials} - + {user?.fullname || "User"} diff --git a/src/components/ui/page-header.tsx b/src/components/ui/page-header.tsx index 885a4138..a43b99e3 100644 --- a/src/components/ui/page-header.tsx +++ b/src/components/ui/page-header.tsx @@ -24,13 +24,15 @@ export function PageHeader({ return ( {eyebrow && ( @@ -53,7 +55,7 @@ export function PageHeader({ )} {actions && ( - + {actions} )} diff --git a/src/components/ui/resource-list-table.tsx b/src/components/ui/resource-list-table.tsx index 56b5cce1..dee4dab4 100644 --- a/src/components/ui/resource-list-table.tsx +++ b/src/components/ui/resource-list-table.tsx @@ -9,7 +9,8 @@ import { TableRow, } from "@mui/material"; import { TableEmptyRow, TableLoadingRow } from "@/components/ui/table-state-rows"; -import type { SortDirection } from "@/domain/work-orders/types/work-order-list"; + +export type SortDirection = "asc" | "desc" | ""; export type ResourceListColumn = { id: string; diff --git a/src/components/ui/status-chip-filter.tsx b/src/components/ui/status-chip-filter.tsx index 8a3c0a07..04308315 100644 --- a/src/components/ui/status-chip-filter.tsx +++ b/src/components/ui/status-chip-filter.tsx @@ -16,7 +16,7 @@ export function StatusChipFilter({ return (
{label} - + ; export const queryKeys = { auth: {