fixed some statuses and filters

This commit is contained in:
Jelaletdin12
2026-09-10 15:59:05 +05:00
parent 34e8fef9b6
commit edf503e329
20 changed files with 355 additions and 214 deletions

View File

@@ -241,14 +241,14 @@ function FilterDropdown({
</button>
</PopoverTrigger>
<PopoverContent align="end" sideOffset={4} className="w-64 p-0">
<PopoverContent align="end" sideOffset={4} className="w-64 p-0 max-h-(--radix-popover-content-available-height) flex flex-col">
{/* Header */}
<div className="flex items-center justify-between px-3 py-2 border-b border-border">
<p className="text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">{t("table.filters", "Filters")}</p>
</div>
{/* Fields */}
<div className="px-3 py-3 space-y-3">
<div className="px-3 py-3 space-y-3 overflow-y-auto">
{filterFields.map((field) => {
const current = getActiveValue(field.id);
const isFieldActive = current !== "";

View File

@@ -1,4 +1,4 @@
import { useState, useRef, useEffect } from "react";
import { useState, useRef, useEffect, useMemo } from "react";
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
import { Check, ChevronsUpDown, Search, X, Eye, EyeOff, Upload, Hash, CreditCard } from "lucide-react";
@@ -257,7 +257,7 @@ function PhoneInput({
<div
className={cn(
"flex h-8 w-full rounded-md border bg-background overflow-hidden",
"flex h-8 w-full rounded-md border border-input bg-transparent dark:bg-input/30 overflow-hidden",
"ring-offset-background transition-colors duration-150",
"focus-within:outline-none focus-within:ring-1 focus-within:ring-ring focus-within:ring-offset-0",
error ? "border-destructive focus-within:ring-destructive/30" : "border-input",
@@ -273,7 +273,7 @@ function PhoneInput({
onChange={handleChange}
placeholder={placeholder}
disabled={disabled}
className="flex-1 h-full px-3 bg-transparent text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none disabled:cursor-not-allowed"
className="flex-1 h-full px-3 bg-transparent text-sm text-foreground placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed"
/>
</div>
@@ -491,12 +491,12 @@ function DateInput({ value = "", onChange, error, disabled, required, label, cla
type="button"
disabled={disabled}
className={cn(
"flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2",
"flex h-8 w-full items-center justify-between rounded-md border border-input bg-transparent dark:bg-input/30 px-3 py-2",
"text-sm ring-offset-background transition-colors duration-150",
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",
"disabled:cursor-not-allowed disabled:opacity-50",
error ? "border-destructive" : "border-input",
!selected && "text-muted-foreground/60",
!selected && "text-muted-foreground",
)}
>
<span>{selected ? format(selected, "dd.MM.yyyy") : placeholder}</span>
@@ -539,7 +539,16 @@ function SelectInput({
}: FormInputProps) {
const [open, setOpen] = useState(false);
const selected = options.find((o) => o.value === value);
const uniqueOptions = useMemo(() => {
const seen = new Set<string>();
return options.filter((opt) => {
if (seen.has(opt.value)) return false;
seen.add(opt.value);
return true;
});
}, [options]);
const selected = uniqueOptions.find((o) => o.value === value);
const handleSelect = (val: string) => {
onChange?.(val);
@@ -561,7 +570,7 @@ function SelectInput({
type="button"
disabled={disabled}
className={cn(
"flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2",
"flex h-8 w-full items-center justify-between rounded-md border border-input bg-transparent dark:bg-input/30 px-3 py-2",
"text-sm ring-offset-background transition-colors duration-150",
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",
"disabled:cursor-not-allowed disabled:opacity-50",
@@ -569,7 +578,7 @@ function SelectInput({
open && !error && "ring-2 ring-ring ring-offset-0 border-transparent",
)}
>
<span className={cn("truncate text-left", !selected && "text-muted-foreground/60")}>
<span className={cn("truncate text-left", !selected && "text-muted-foreground")}>
{selected ? selected.label : placeholder}
</span>
<ChevronsUpDown
@@ -583,7 +592,7 @@ function SelectInput({
className={cn("absolute z-50 top-full left-0 right-0 mt-1", "rounded-md border border-border bg-card shadow-lg overflow-hidden")}
>
<div className="max-h-52 overflow-y-auto scrollbar-thin py-1">
{options.map((opt) => {
{uniqueOptions.map((opt) => {
const isSelected = opt.value === value;
return (
<button
@@ -633,8 +642,17 @@ function SearchableSelect({
const [query, setQuery] = useState("");
const searchRef = useRef<HTMLInputElement>(null);
const selected = options.find((o) => o.value === value);
const filtered = query.trim() ? options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase())) : options;
const uniqueOptions = useMemo(() => {
const seen = new Set<string>();
return options.filter((opt) => {
if (seen.has(opt.value)) return false;
seen.add(opt.value);
return true;
});
}, [options]);
const selected = uniqueOptions.find((o) => o.value === value);
const filtered = query.trim() ? uniqueOptions.filter((o) => o.label.toLowerCase().includes(query.toLowerCase())) : uniqueOptions;
const openDropdown = () => {
setOpen(true);
@@ -680,7 +698,7 @@ function SearchableSelect({
type="button"
disabled={disabled}
className={cn(
"flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2",
"flex h-8 w-full items-center justify-between rounded-md border border-input bg-transparent dark:bg-input/30 px-3 py-2",
"text-sm ring-offset-background transition-colors duration-150",
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",
"disabled:cursor-not-allowed disabled:opacity-50",
@@ -688,7 +706,7 @@ function SearchableSelect({
open && !error && "ring-2 ring-ring ring-offset-0 border-transparent",
)}
>
<span className={cn("truncate text-left", !selected && "text-muted-foreground/60")}>
<span className={cn("truncate text-left", !selected && "text-muted-foreground")}>
{selected ? selected.label : placeholder}
</span>

View File

@@ -1,5 +1,5 @@
import { useEffect, useRef, useState } from "react";
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
import * as PopoverPrimitive from "@radix-ui/react-popover";
import { Check, ChevronsUpDown, Search, X, Loader2 } from "lucide-react";
import { cn } from "@/lib/utils";
@@ -20,25 +20,14 @@ export interface InfiniteSelectProps {
required?: boolean;
error?: string;
disabled?: boolean;
/** True while the first page is being fetched. */
loading?: boolean;
/** True while the next page is being fetched. */
isLoadingMore?: boolean;
/** Whether more pages are available to load. */
hasNextPage?: boolean;
/** Called when the user scrolls to the bottom of the list. */
onLoadMore?: () => void;
/** Controlled search text; drives server-side search + page reset. */
searchValue?: string;
onSearchChange?: (value: string) => void;
}
// ─── Collapsible aliases ──────────────────────────────────────────────────────
const Collapsible = CollapsiblePrimitive.Root;
const CollapsibleTrigger = CollapsiblePrimitive.Trigger;
const CollapsibleContent = CollapsiblePrimitive.Content;
/**
* Searchable select with infinite scroll.
*
@@ -81,14 +70,12 @@ export function InfiniteSelect({
const loadingRef = useRef(false);
// Reset loading ref when the query transitions out of loading state
useEffect(() => {
if (!isLoadingMore) {
loadingRef.current = false;
}
}, [isLoadingMore]);
// ── Infinite scroll: load more when the sentinel becomes visible ──
useEffect(() => {
if (!open || !sentinelRef.current || !hasNextPage || isLoadingMore) return;
const el = sentinelRef.current;
@@ -114,18 +101,18 @@ export function InfiniteSelect({
</label>
)}
<Collapsible
<PopoverPrimitive.Root
open={open}
onOpenChange={(next) => {
if (!disabled) setOpen(next);
}}
>
<CollapsibleTrigger asChild>
<PopoverPrimitive.Trigger asChild>
<button
type="button"
disabled={disabled}
className={cn(
"flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2",
"flex h-8 w-full items-center justify-between rounded-md border border-input bg-transparent dark:bg-input/30 px-3 py-2",
"text-sm ring-offset-background transition-colors duration-150",
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0",
"disabled:cursor-not-allowed disabled:opacity-50",
@@ -133,7 +120,7 @@ export function InfiniteSelect({
open && !error && "ring-2 ring-ring ring-offset-0 border-transparent",
)}
>
<span className={cn("truncate text-left", !selected && "text-muted-foreground/60")}>
<span className={cn("truncate text-left", !selected && "text-muted-foreground")}>
{selected ? selected.label : placeholder}
</span>
@@ -154,75 +141,85 @@ export function InfiniteSelect({
/>
</div>
</button>
</CollapsibleTrigger>
</PopoverPrimitive.Trigger>
<CollapsibleContent className="absolute z-50 top-full left-0 right-0 mt-1 rounded-md border border-border bg-card shadow-lg overflow-hidden">
{onSearchChange && (
<div className="flex items-center gap-2 px-3 py-2 border-b border-border bg-muted/20">
<Search size={13} className="text-muted-foreground shrink-0" />
<input
type="text"
value={searchValue ?? ""}
onChange={(e) => onSearchChange(e.target.value)}
placeholder={searchPlaceholder}
className="flex-1 bg-transparent text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none"
/>
{searchValue && (
<button
type="button"
tabIndex={-1}
onMouseDown={() => onSearchChange?.("")}
className="text-muted-foreground hover:text-foreground transition-colors"
>
<X size={12} />
</button>
)}
</div>
)}
<div className="max-h-60 overflow-y-auto scrollbar-thin py-1">
{loading && options.length === 0 ? (
<p className="px-3 py-4 text-sm text-muted-foreground text-center flex items-center justify-center gap-2">
<Loader2 size={14} className="animate-spin" /> Loading...
</p>
) : options.length === 0 ? (
<p className="px-3 py-4 text-sm text-muted-foreground text-center">Netije tapylmady</p>
) : (
options.map((opt) => {
const isSelected = opt.value === value;
return (
<PopoverPrimitive.Portal>
<PopoverPrimitive.Content
align="start"
side="bottom"
sideOffset={4}
collisionPadding={16}
avoidCollisions
style={{ width: "var(--radix-popover-trigger-width)" }}
className="z-50 rounded-md border border-border bg-card shadow-lg overflow-hidden max-h-[var(--radix-popover-content-available-height)] flex flex-col"
>
{onSearchChange && (
<div className="flex items-center gap-2 px-3 py-2 border-b border-border bg-muted/20 shrink-0">
<Search size={13} className="text-muted-foreground shrink-0" />
<input
type="text"
value={searchValue ?? ""}
onChange={(e) => onSearchChange(e.target.value)}
placeholder={searchPlaceholder}
className="flex-1 bg-transparent text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none"
/>
{searchValue && (
<button
key={opt.value}
type="button"
onMouseDown={(e) => {
e.preventDefault();
handleSelect(opt.value);
}}
className={cn(
"flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors",
"hover:bg-accent hover:text-accent-foreground",
isSelected && "text-primary font-medium bg-primary/10",
)}
tabIndex={-1}
onMouseDown={() => onSearchChange?.("")}
className="text-muted-foreground hover:text-foreground transition-colors"
>
<span>{opt.label}</span>
{isSelected && <Check size={13} className="text-primary shrink-0" />}
<X size={12} />
</button>
);
})
)}
{hasNextPage && (
<div ref={sentinelRef} className="px-3 py-2 text-xs text-muted-foreground text-center">
{isLoadingMore && (
<span className="inline-flex items-center gap-1.5">
<Loader2 size={12} className="animate-spin" /> Loading...
</span>
)}
</div>
)}
</div>
</CollapsibleContent>
</Collapsible>
<div className="max-h-60 overflow-y-auto scrollbar-thin py-1">
{loading && options.length === 0 ? (
<p className="px-3 py-4 text-sm text-muted-foreground text-center flex items-center justify-center gap-2">
<Loader2 size={14} className="animate-spin" /> Loading...
</p>
) : options.length === 0 ? (
<p className="px-3 py-4 text-sm text-muted-foreground text-center">Netije tapylmady</p>
) : (
options.map((opt) => {
const isSelected = opt.value === value;
return (
<button
key={opt.value}
type="button"
onMouseDown={(e) => {
e.preventDefault();
handleSelect(opt.value);
}}
className={cn(
"flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors",
"hover:bg-accent hover:text-accent-foreground",
isSelected && "text-primary font-medium bg-primary/10",
)}
>
<span>{opt.label}</span>
{isSelected && <Check size={13} className="text-primary shrink-0" />}
</button>
);
})
)}
{hasNextPage && (
<div ref={sentinelRef} className="px-3 py-2 text-xs text-muted-foreground text-center">
{isLoadingMore && (
<span className="inline-flex items-center gap-1.5">
<Loader2 size={12} className="animate-spin" /> Loading...
</span>
)}
</div>
)}
</div>
</PopoverPrimitive.Content>
</PopoverPrimitive.Portal>
</PopoverPrimitive.Root>
{error && (
<p className="mt-1.5 text-xs text-destructive font-medium flex items-center gap-1.5">