fix: lint, stubs, StatusBadge, uptime %, closure remarks UX

This commit is contained in:
Atharv1705
2026-11-12 17:32:14 +05:30
parent 22fad38280
commit 5027c0766e
24 changed files with 243 additions and 123 deletions
+9 -3
View File
@@ -83,8 +83,14 @@ export function AssetFormModal({
});
const departments = deptsQuery.data?.items ?? [];
const allLocations = locsQuery.data?.items ?? [];
const categories = catsQuery.data?.items ?? [];
const allLocations = useMemo(
() => locsQuery.data?.items ?? [],
[locsQuery.data?.items]
);
const categories = useMemo(
() => catsQuery.data?.items ?? [],
[catsQuery.data?.items]
);
const vendors = vendorsQuery.data?.items ?? [];
const defaultDeptId = editing?.department_id ?? departments[0]?.id ?? 0;
@@ -161,7 +167,7 @@ export function AssetFormModal({
remarks: "",
});
}
}, [open, editing, categories.length, defaultDeptId, defaultLocId, reset]);
}, [open, editing, categories, defaultDeptId, defaultLocId, reset]);
const watchedDeptId = Number(watch("department_id"));
const filteredLocations = useMemo(
+1 -18
View File
@@ -16,26 +16,9 @@ import {
} from "@/api/attachments";
import { ApiError } from "@/api/client";
import { formatDateTime } from "@/lib/format";
import { validateAttachmentFile } from "@/lib/validation";
import { Button } from "@/components/ui/button";
const MAX_SIZE_BYTES = 10 * 1024 * 1024; // 10 MB
const ALLOWED_EXTENSIONS = [".jpg", ".jpeg", ".png", ".pdf"];
const ALLOWED_MIME_TYPES = ["image/jpeg", "image/png", "application/pdf"];
export function validateAttachmentFile(file: File): string | null {
const nameLower = file.name.toLowerCase();
const hasAllowedExt = ALLOWED_EXTENSIONS.some((ext) => nameLower.endsWith(ext));
const hasAllowedMime = !file.type || ALLOWED_MIME_TYPES.includes(file.type);
if (!hasAllowedExt || !hasAllowedMime) {
return "Invalid file type. Only JPG, PNG, and PDF files are allowed.";
}
if (file.size > MAX_SIZE_BYTES) {
return "File is too large. Maximum allowed size is 10 MB.";
}
return null;
}
function formatBytes(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
@@ -12,7 +12,7 @@ import { assetsApi, type BulkImportResult } from "@/api/assets";
import { ApiError } from "@/api/client";
import { Modal } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { toast } from "@/components/ToastProvider";
import { toast } from "@/lib/toast";
import { cn } from "@/lib/utils";
interface BulkAssetImportModalProps {
@@ -3,7 +3,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
import { AlertCircle, Paperclip, X } from "lucide-react";
import { Modal } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { validateAttachmentFile } from "@/components/Attachments";
import { validateAttachmentFile } from "@/lib/validation";
import { ApiError } from "@/api/client";
import { assetsApi } from "@/api/assets";
import { vendorsApi } from "@/api/masters";
@@ -7,7 +7,7 @@ import { useAuthStore } from "@/hooks/useAuth";
import { formatDate } from "@/lib/format";
import { Modal } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { toast } from "@/components/ToastProvider";
import { toast } from "@/lib/toast";
export function CalibrationReminderModal() {
const navigate = useNavigate();
@@ -8,7 +8,7 @@ import { AlertCircle, Clock, Paperclip, X } from "lucide-react";
import { Modal } from "@/components/ui/dialog";
import { Button } from "@/components/ui/button";
import { AssetPicker } from "@/components/AssetPicker";
import { validateAttachmentFile } from "@/components/Attachments";
import { validateAttachmentFile } from "@/lib/validation";
import { ApiError } from "@/api/client";
import { assetsApi, type AssetLookupItem, type AssetCriticality } from "@/api/assets";
import { complaintsApi, type ComplaintItem } from "@/api/complaints";
+1 -40
View File
@@ -1,44 +1,5 @@
import { create } from "zustand";
import { CheckCircle2, Info, AlertTriangle, AlertCircle, X } from "lucide-react";
export type ToastVariant = "success" | "info" | "warning" | "error";
export interface ToastEntry {
id: string;
title: string;
description?: string;
variant: ToastVariant;
}
interface ToastState {
toasts: ToastEntry[];
push: (t: Omit<ToastEntry, "id">) => void;
dismiss: (id: string) => void;
}
export const useToastStore = create<ToastState>((set) => ({
toasts: [],
push: (entry) => {
const id = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
set((s) => ({ toasts: [...s.toasts.slice(-4), { ...entry, id }] }));
setTimeout(() => {
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) }));
}, 5000);
},
dismiss: (id) =>
set((s) => ({ toasts: s.toasts.filter((t) => t.id !== id) })),
}));
export const toast = {
success: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "success" }),
info: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "info" }),
warning: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "warning" }),
error: (title: string, description?: string) =>
useToastStore.getState().push({ title, description, variant: "error" }),
};
import { useToastStore, type ToastVariant } from "@/lib/toast";
const VARIANT_CLS: Record<ToastVariant, string> = {
success: "bg-emerald-50 border-emerald-300 text-emerald-900",
+6 -3
View File
@@ -1,4 +1,4 @@
import { useState, useEffect, useRef } from "react";
import { useState, useEffect, useRef, useMemo } from "react";
import { useNavigate } from "react-router-dom";
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
import {
@@ -28,7 +28,7 @@ import { notificationsApi, type NotificationItem } from "@/api/notifications";
import { searchApi } from "@/api/search";
import { Badge } from "@/components/ui/badge";
import { AssetStatusBadge, CallStatusBadge } from "@/components/StatusBadge";
import { toast } from "@/components/ToastProvider";
import { toast } from "@/lib/toast";
interface TopBarProps {
title?: string;
@@ -121,7 +121,10 @@ export function TopBar({ title, onMenuClick }: TopBarProps) {
refetchInterval: 60_000,
});
const bellItems = bellQuery.data?.items ?? [];
const bellItems = useMemo(
() => bellQuery.data?.items ?? [],
[bellQuery.data?.items]
);
const unreadCount = bellQuery.data?.unread_count ?? 0;
// Detect newly arrived unread notifications while app is open