started connect with api

This commit is contained in:
Jelaletdin12
2026-08-11 22:48:25 +05:00
parent 0ca218505d
commit 6da59f42d9
112 changed files with 7091 additions and 6989 deletions

View File

@@ -19,7 +19,8 @@ export interface ColumnMeta {
export interface FilterField {
id: string;
label: string;
options: { value: string; label: string }[];
type?: "select" | "text";
options?: { value: string; label: string }[];
}
export interface ActiveFilter {
@@ -246,37 +247,65 @@ function FilterDropdown({
<label className="block text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">{field.label}</label>
<div className="flex items-center gap-1">
<Select value={current || "__all__"} onValueChange={(val) => onFilterChange(field.id, val === "__all__" ? "" : val)}>
<SelectTrigger
className={cn(
"h-8 flex-1 text-sm gap-1.5 transition-colors",
isFieldActive ? "border-primary text-primary [&>svg:last-child]:text-primary" : "text-muted-foreground",
{field.type === "text" ? (
<>
<input
type="text"
value={current}
onChange={(e) => onFilterChange(field.id, e.target.value)}
placeholder="—"
className={cn(
"h-8 flex-1 rounded-md border border-input bg-background px-2.5 text-sm text-foreground",
"placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-ring",
"transition-colors",
isFieldActive && "border-primary",
)}
/>
{isFieldActive && (
<button
type="button"
onClick={() => onFilterChange(field.id, "")}
className="h-6 w-6 rounded flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors shrink-0"
>
<X size={11} />
</button>
)}
>
<span className="flex-1 text-left truncate">
{isFieldActive ? field.options.find((o) => o.value === current)?.label : "—"}
</span>
</SelectTrigger>
<SelectContent position="popper" sideOffset={4} className="p-1">
<SelectItem value="__all__">
<span className="text-muted-foreground">— Ählisi</span>
</SelectItem>
{field.options.map((opt) => (
<SelectItem key={opt.value} value={opt.value}>
{opt.label}
</SelectItem>
))}
</SelectContent>
</Select>
</>
) : (
<>
<Select value={current || "__all__"} onValueChange={(val) => onFilterChange(field.id, val === "__all__" ? "" : val)}>
<SelectTrigger
className={cn(
"h-8 flex-1 text-sm gap-1.5 transition-colors",
isFieldActive ? "border-primary text-primary [&>svg:last-child]:text-primary" : "text-muted-foreground",
)}
>
<span className="flex-1 text-left truncate">
{isFieldActive ? (field.options ?? []).find((o) => o.value === current)?.label : "—"}
</span>
</SelectTrigger>
<SelectContent position="popper" sideOffset={4} className="p-1">
<SelectItem value="__all__">
<span className="text-muted-foreground">— Ählisi</span>
</SelectItem>
{(field.options ?? []).map((opt) => (
<SelectItem key={opt.value} value={opt.value}>
{opt.label}
</SelectItem>
))}
</SelectContent>
</Select>
{isFieldActive && (
<button
type="button"
onClick={() => onFilterChange(field.id, "")}
className="h-6 w-6 rounded flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors shrink-0"
>
<X size={11} />
</button>
{isFieldActive && (
<button
type="button"
onClick={() => onFilterChange(field.id, "")}
className="h-6 w-6 rounded flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors shrink-0"
>
<X size={11} />
</button>
)}
</>
)}
</div>
</div>

View File

@@ -2,7 +2,7 @@ import { useState, useRef, useEffect } from "react";
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
import { Check, ChevronsUpDown, Search, X, Eye, EyeOff, Upload, Hash } from "lucide-react";
import { cn } from "@/lib/utils";
import { cn, cleanPhoneNumber, formatFromApiDate } from "@/lib/utils";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
@@ -175,6 +175,9 @@ function PhoneInput({
className,
phonePrefix = "+993",
}: FormInputProps) {
// Gelen veride ülke kodu (+993) veya boşluklar olsa bile temiz 8 haneyi elde et
const cleanedDigits = cleanPhoneNumber(value);
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const digits = e.target.value.replace(/\D/g, "").slice(0, 8);
@@ -185,6 +188,8 @@ function PhoneInput({
}
};
const formattedDisplayValue = cleanedDigits.length <= 2 ? cleanedDigits : `${cleanedDigits.slice(0, 2)} ${cleanedDigits.slice(2)}`;
return (
<div className={className}>
<FieldLabel label={label} required={required} />
@@ -203,7 +208,7 @@ function PhoneInput({
</div>
<input
type="tel"
value={value}
value={formattedDisplayValue}
onChange={handleChange}
placeholder={placeholder}
disabled={disabled}
@@ -221,8 +226,9 @@ function PhoneInput({
function DateInput({ value = "", onChange, error, disabled, required, label, className, placeholder = "Sene saýlaň" }: FormInputProps) {
const [open, setOpen] = useState(false);
// value is stored as 'yyyy-MM-dd' string
const parsed = value ? parse(value, "yyyy-MM-dd", new Date()) : undefined;
// value backend'den 'yyyy-MM-dd' veya 'yyyy-MM-ddTHH:mm:ssZ' gelebilir
const dateStr = formatFromApiDate(value);
const parsed = dateStr ? parse(dateStr, "yyyy-MM-dd", new Date()) : undefined;
const selected = parsed && isValid(parsed) ? parsed : undefined;
const handleSelect = (day: Date | undefined) => {

View File

@@ -0,0 +1,225 @@
import { useEffect, useRef, useState } from "react";
import * as CollapsiblePrimitive from "@radix-ui/react-collapsible";
import { Check, ChevronsUpDown, Search, X, Loader2 } from "lucide-react";
import { cn } from "@/lib/utils";
// ─── Types ────────────────────────────────────────────────────────────────────
export interface InfiniteSelectOption {
value: string;
label: string;
}
export interface InfiniteSelectProps {
value?: string;
onChange?: (value: string) => void;
options?: InfiniteSelectOption[];
placeholder?: string;
searchPlaceholder?: string;
label?: string;
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.
*
* The consumer owns the data fetching (e.g. TanStack Query `useInfiniteQuery`):
* it passes the flattened options, and `hasNextPage`/`onLoadMore` drive loading
* additional pages when the list bottom is reached.
*/
export function InfiniteSelect({
value = "",
onChange,
options = [],
placeholder = "Saýlamak üçin basyň",
searchPlaceholder = "Gözle...",
label,
required,
error,
disabled,
loading = false,
isLoadingMore = false,
hasNextPage = false,
onLoadMore,
searchValue,
onSearchChange,
}: InfiniteSelectProps) {
const [open, setOpen] = useState(false);
const sentinelRef = useRef<HTMLDivElement>(null);
const selected = options.find((o) => o.value === value);
const handleSelect = (val: string) => {
onChange?.(val);
setOpen(false);
};
const handleClear = (e: React.MouseEvent) => {
e.preventDefault();
e.stopPropagation();
onChange?.("");
};
// ── Infinite scroll: load more when the sentinel becomes visible ──
useEffect(() => {
if (!open || !sentinelRef.current || !hasNextPage || isLoadingMore) return;
const el = sentinelRef.current;
const observer = new IntersectionObserver(
(entries) => {
if (entries[0]?.isIntersecting && hasNextPage && !isLoadingMore) {
onLoadMore?.();
}
},
{ rootMargin: "120px" },
);
observer.observe(el);
return () => observer.disconnect();
}, [open, hasNextPage, isLoadingMore, onLoadMore]);
return (
<div className="relative">
{label && (
<label className="block text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-1.5 select-none">
{label}
{required && <span className="text-destructive ml-0.5">*</span>}
</label>
)}
<Collapsible
open={open}
onOpenChange={(next) => {
if (!disabled) setOpen(next);
}}
>
<CollapsibleTrigger 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",
"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",
open && !error && "ring-2 ring-ring ring-offset-0 border-transparent",
)}
>
<span className={cn("truncate text-left", !selected && "text-muted-foreground/60")}>
{selected ? selected.label : placeholder}
</span>
<div className="flex items-center gap-1 shrink-0 ml-2">
{selected && !disabled && (
<span
role="button"
tabIndex={-1}
onMouseDown={handleClear}
className="p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors"
>
<X size={12} />
</span>
)}
<ChevronsUpDown
size={14}
className={cn("text-muted-foreground transition-transform duration-200 shrink-0", open && "text-foreground")}
/>
</div>
</button>
</CollapsibleTrigger>
<CollapsibleContent className="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 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>
</CollapsibleContent>
</Collapsible>
{error && (
<p className="mt-1.5 text-xs text-destructive font-medium flex items-center gap-1.5">
<span className="inline-block w-1 h-1 rounded-full bg-destructive shrink-0" />
{error}
</p>
)}
</div>
);
}

View File

@@ -91,14 +91,14 @@ export function InfoRow({ label, value, children, isLink, href }: InfoRowProps)
export interface MultiLangRowProps {
label: string;
value?: { tk?: string; ru?: string; en?: string } | null;
value?: { tm?: string; tk?: string; ru?: string; en?: string } | null;
}
export function MultiLangRow({ label, value }: MultiLangRowProps) {
if (!value) return <InfoRow label={label} value="—" />;
const langs = [
{ code: "TK", val: value.tk },
{ code: "TK", val: value.tm ?? value.tk },
{ code: "RU", val: value.ru },
{ code: "EN", val: value.en },
];