fixed some ui, upgrade functionalitym added permission to operator
This commit is contained in:
1 parent
25c104ad8c
commit
5ed4c9a8ec
46 files changed
+1058
-1401
No files matched your search
@@ -1,6 +1,6 @@
|
||||
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 { Check, ChevronsUpDown, Search, X, Eye, EyeOff, Upload, Hash, CreditCard } from "lucide-react";
|
||||
|
||||
import { cn, cleanPhoneNumber } from "@/lib/utils";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -29,7 +29,11 @@ export type FormInputType =
|
||||
| "select"
|
||||
| "searchable-select"
|
||||
| "file"
|
||||
| "textarea";
|
||||
| "textarea"
|
||||
| "card-number"
|
||||
| "card-name"
|
||||
| "passport-id"
|
||||
| "digits";
|
||||
|
||||
export interface SelectOption {
|
||||
value: string;
|
||||
@@ -54,6 +58,7 @@ export interface FormInputProps {
|
||||
rows?: number;
|
||||
name?: string;
|
||||
readOnly?: boolean;
|
||||
maxLength?: number;
|
||||
}
|
||||
|
||||
// ─── FieldLabel ───────────────────────────────────────────────────────────────
|
||||
@@ -277,6 +282,189 @@ function PhoneInput({
|
||||
);
|
||||
}
|
||||
|
||||
// ─── formatCardNumber helper ──────────────────────────────────────────────────
|
||||
|
||||
export function formatCardNumber(value?: string | null): string {
|
||||
if (!value) return "";
|
||||
const digits = value.replace(/\D/g, "").slice(0, 16);
|
||||
return digits.replace(/(\d{4})(?=\d)/g, "$1 ");
|
||||
}
|
||||
|
||||
// ─── CardNumberInput ──────────────────────────────────────────────────────────
|
||||
|
||||
export function CardNumberInput({
|
||||
value = "",
|
||||
onChange,
|
||||
placeholder = "9999 9999 9999 9999",
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
name,
|
||||
readOnly,
|
||||
}: FormInputProps) {
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const formatted = formatCardNumber(e.target.value);
|
||||
onChange?.(formatted);
|
||||
};
|
||||
|
||||
const display = formatCardNumber(value);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
<div className="relative">
|
||||
<Input
|
||||
name={name}
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
value={display}
|
||||
onChange={handleChange}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
maxLength={19}
|
||||
className={cn("pr-10 font-mono tracking-wider", withError(error))}
|
||||
/>
|
||||
<CreditCard size={15} className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none" />
|
||||
</div>
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── CardNameInput ────────────────────────────────────────────────────────────
|
||||
|
||||
export function CardNameInput({
|
||||
value = "",
|
||||
onChange,
|
||||
placeholder,
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
name,
|
||||
readOnly,
|
||||
}: FormInputProps) {
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
// Only characters (letters in any alphabet) and spaces
|
||||
const sanitized = e.target.value.replace(/[^\p{L}\s]/gu, "");
|
||||
onChange?.(sanitized);
|
||||
};
|
||||
|
||||
const display = (value || "").replace(/[^\p{L}\s]/gu, "");
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
<div className="relative">
|
||||
<Input
|
||||
name={name}
|
||||
type="text"
|
||||
value={display}
|
||||
onChange={handleChange}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
className={cn(withError(error))}
|
||||
/>
|
||||
</div>
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── PassportIdInput ──────────────────────────────────────────────────────────
|
||||
|
||||
export function PassportIdInput({
|
||||
value = "",
|
||||
onChange,
|
||||
placeholder = "999999",
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
name,
|
||||
readOnly,
|
||||
}: FormInputProps) {
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const digits = e.target.value.replace(/\D/g, "").slice(0, 6);
|
||||
onChange?.(digits);
|
||||
};
|
||||
|
||||
const display = (value || "").replace(/\D/g, "").slice(0, 6);
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
<div className="relative">
|
||||
<Input
|
||||
name={name}
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
value={display}
|
||||
onChange={handleChange}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
maxLength={6}
|
||||
className={cn("font-mono tracking-wider", withError(error))}
|
||||
/>
|
||||
</div>
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── DigitsInput ──────────────────────────────────────────────────────────────
|
||||
|
||||
export function DigitsInput({
|
||||
value = "",
|
||||
onChange,
|
||||
placeholder,
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
name,
|
||||
readOnly,
|
||||
maxLength,
|
||||
}: FormInputProps) {
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const raw = e.target.value.replace(/\D/g, "");
|
||||
const digits = maxLength ? raw.slice(0, maxLength) : raw;
|
||||
onChange?.(digits);
|
||||
};
|
||||
|
||||
const rawDisplay = (value || "").replace(/\D/g, "");
|
||||
const display = maxLength ? rawDisplay.slice(0, maxLength) : rawDisplay;
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
<div className="relative">
|
||||
<Input
|
||||
name={name}
|
||||
type="text"
|
||||
inputMode="numeric"
|
||||
value={display}
|
||||
onChange={handleChange}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
maxLength={maxLength}
|
||||
className={cn(withError(error))}
|
||||
/>
|
||||
</div>
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── DateInput (shadcn Popover + Calendar) ───────────────────────────────────
|
||||
|
||||
function DateInput({ value = "", onChange, error, disabled, required, label, className, placeholder = "Sene saýlaň" }: FormInputProps) {
|
||||
@@ -726,6 +914,10 @@ export function FormInput(props: FormInputProps) {
|
||||
|
||||
if (type === "number") return <NumberInput {...props} />;
|
||||
if (type === "phone") return <PhoneInput {...props} />;
|
||||
if (type === "card-number") return <CardNumberInput {...props} />;
|
||||
if (type === "card-name") return <CardNameInput {...props} />;
|
||||
if (type === "passport-id") return <PassportIdInput {...props} />;
|
||||
if (type === "digits") return <DigitsInput {...props} />;
|
||||
if (type === "date") return <DateInput {...props} />;
|
||||
if (type === "select") return <SelectInput {...props} />;
|
||||
if (type === "searchable-select") return <SearchableSelect {...props} />;
|
||||
|
||||
Reference in new issue
Block a user