fixed some params and ui
This commit is contained in:
@@ -8,6 +8,7 @@ import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { InfiniteSelect } from "@/components/infiniteSelect";
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -19,8 +20,18 @@ export interface ColumnMeta {
|
||||
export interface FilterField {
|
||||
id: string;
|
||||
label: string;
|
||||
type?: "select" | "text";
|
||||
type?: "select" | "text" | "infinite-select";
|
||||
options?: { value: string; label: string }[];
|
||||
|
||||
// Infinite Select props
|
||||
loading?: boolean;
|
||||
isLoadingMore?: boolean;
|
||||
hasNextPage?: boolean;
|
||||
onLoadMore?: () => void;
|
||||
searchValue?: string;
|
||||
onSearchChange?: (value: string) => void;
|
||||
searchPlaceholder?: string;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export interface ActiveFilter {
|
||||
@@ -271,6 +282,23 @@ function FilterDropdown({
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
) : field.type === "infinite-select" ? (
|
||||
<div className="flex-1 min-w-0">
|
||||
<InfiniteSelect
|
||||
value={current}
|
||||
onChange={(val) => onFilterChange(field.id, val)}
|
||||
options={field.options}
|
||||
placeholder="—"
|
||||
searchPlaceholder={field.searchPlaceholder || t("common.search", "Gözle...")}
|
||||
disabled={field.disabled}
|
||||
loading={field.loading}
|
||||
isLoadingMore={field.isLoadingMore}
|
||||
hasNextPage={field.hasNextPage}
|
||||
onLoadMore={field.onLoadMore}
|
||||
searchValue={field.searchValue}
|
||||
onSearchChange={field.onSearchChange}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Select value={current || "__all__"} onValueChange={(val) => onFilterChange(field.id, val === "__all__" ? "" : val)}>
|
||||
|
||||
@@ -86,6 +86,73 @@ const withError = (error?: string) => (error ? "border-destructive focus-visible
|
||||
|
||||
// ─── TextInput ────────────────────────────────────────────────────────────────
|
||||
|
||||
// ─── formatNumber helpers ─────────────────────────────────────────────────────
|
||||
|
||||
/** "1000000.50" → "1 000 000.50" (integer part only gets spaces) */
|
||||
function formatNumberDisplay(raw: string): string {
|
||||
if (!raw) return "";
|
||||
const [intPart, decPart] = raw.split(".");
|
||||
const formatted = intPart.replace(/\B(?=(\d{3})+(?!\d))/g, " ");
|
||||
return decPart !== undefined ? `${formatted}.${decPart}` : formatted;
|
||||
}
|
||||
|
||||
/** "1 000 000.50" → "1000000.50" */
|
||||
function stripNumberFormat(display: string): string {
|
||||
return display.replace(/ /g, "");
|
||||
}
|
||||
|
||||
// ─── NumberInput ──────────────────────────────────────────────────────────────
|
||||
|
||||
function NumberInput({ value = "", onChange, placeholder, error, disabled, required, label, className, name, readOnly }: FormInputProps) {
|
||||
// Display state — formatted for the user to see
|
||||
const [display, setDisplay] = useState(() => formatNumberDisplay(value));
|
||||
|
||||
// Sync display when value changes externally (e.g. form reset)
|
||||
useEffect(() => {
|
||||
const current = stripNumberFormat(display);
|
||||
if (current !== value) {
|
||||
setDisplay(formatNumberDisplay(value));
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [value]);
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const raw = e.target.value;
|
||||
// Allow only digits, dots, and spaces (we manage spaces ourselves)
|
||||
const stripped = raw.replace(/ /g, "");
|
||||
if (stripped !== "" && !/^\d*\.?\d*$/.test(stripped)) return;
|
||||
if (stripped !== "" && Number(stripped) < 0) return;
|
||||
|
||||
setDisplay(formatNumberDisplay(stripped));
|
||||
onChange?.(stripped);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
|
||||
<div className="relative">
|
||||
<Input
|
||||
name={name}
|
||||
type="text"
|
||||
inputMode="decimal"
|
||||
value={display}
|
||||
onChange={handleChange}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
className={cn("pr-10", withError(error))}
|
||||
/>
|
||||
<Hash size={14} className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none" />
|
||||
</div>
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── TextInput ────────────────────────────────────────────────────────────────
|
||||
|
||||
function TextInput({
|
||||
type = "text",
|
||||
value = "",
|
||||
@@ -104,7 +171,6 @@ function TextInput({
|
||||
|
||||
const isPassword = type === "password";
|
||||
const isTextarea = type === "textarea";
|
||||
const isNumber = type === "number";
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
@@ -125,21 +191,13 @@ function TextInput({
|
||||
) : (
|
||||
<Input
|
||||
name={name}
|
||||
type={isPassword ? (showPass ? "text" : "password") : isNumber ? "number" : type === "email" ? "email" : "text"}
|
||||
min={isNumber ? 0 : undefined}
|
||||
type={isPassword ? (showPass ? "text" : "password") : type === "email" ? "email" : "text"}
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
if (isNumber) {
|
||||
const num = e.target.value;
|
||||
if (num === "" || Number(num) >= 0) onChange?.(num);
|
||||
} else {
|
||||
onChange?.(e.target.value);
|
||||
}
|
||||
}}
|
||||
onChange={(e) => onChange?.(e.target.value)}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
className={cn(isPassword && "pr-10", isNumber && "pr-10", withError(error))}
|
||||
className={cn(isPassword && "pr-10", withError(error))}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -153,8 +211,6 @@ function TextInput({
|
||||
{showPass ? <EyeOff size={15} /> : <Eye size={15} />}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{isNumber && <Hash size={14} className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none" />}
|
||||
</div>
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
@@ -667,6 +723,7 @@ function FileInput({
|
||||
export function FormInput(props: FormInputProps) {
|
||||
const { type = "text" } = props;
|
||||
|
||||
if (type === "number") return <NumberInput {...props} />;
|
||||
if (type === "phone") return <PhoneInput {...props} />;
|
||||
if (type === "date") return <DateInput {...props} />;
|
||||
if (type === "select") return <SelectInput {...props} />;
|
||||
|
||||
@@ -79,13 +79,23 @@ export function InfiniteSelect({
|
||||
onChange?.("");
|
||||
};
|
||||
|
||||
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;
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
if (entries[0]?.isIntersecting && hasNextPage && !isLoadingMore) {
|
||||
if (entries[0]?.isIntersecting && hasNextPage && !isLoadingMore && !loadingRef.current) {
|
||||
loadingRef.current = true;
|
||||
onLoadMore?.();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -175,11 +175,10 @@ export function PassportImage({ label, src, url }: PassportImageProps) {
|
||||
const imageSrc = src ?? url ?? null;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col sm:grid sm:grid-cols-[minmax(0,42%)_minmax(0,58%)] items-start py-3 px-4 border-b border-border last:border-0 gap-1 sm:gap-0">
|
||||
<span className="text-xs sm:text-sm text-muted-foreground">{label}</span>
|
||||
<div className="flex flex-col items-start py-3 px-4 border-b border-border last:border-0 gap-1 sm:gap-0">
|
||||
<div className="flex flex-col gap-2">
|
||||
{imageSrc ? (
|
||||
<img src={imageSrc} alt={label} className="w-28 h-20 object-cover rounded-md border border-border" />
|
||||
<img src={imageSrc} alt={label} className="w-full h-46 object-contain rounded-md border border-border" />
|
||||
) : (
|
||||
<div className="w-28 h-20 bg-muted rounded-md border border-border flex items-center justify-center">
|
||||
<span className="text-xs text-muted-foreground">—</span>
|
||||
|
||||
Reference in New Issue
Block a user