fixed some ui, upgrade functionalitym added permission to operator

This commit is contained in:
Jelaletdin12
2026-09-03 20:31:34 +05:00
parent 25c104ad8c
commit 5ed4c9a8ec
46 changed files with 1058 additions and 1401 deletions

View File

@@ -1,23 +1,29 @@
import type { ReactNode } from 'react'
import { useTranslation } from 'react-i18next'
import { Loader2 } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { cn } from '@/lib/utils'
import type { ReactNode } from "react";
import { useTranslation } from "react-i18next";
import { Loader2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
interface FormActionsProps {
isPending?: boolean
onSubmit?: () => void
onCancel?: () => void
submitLabel?: ReactNode
cancelLabel?: ReactNode
loadingLabel?: ReactNode
cancelVariant?: 'outline' | 'ghost'
className?: string
onNext?: () => void
onPrev?: () => void
nextLabel?: ReactNode
prevLabel?: ReactNode
showSubmit?: boolean
isPending?: boolean;
onSubmit?: () => void;
onCancel?: () => void;
submitLabel?: ReactNode;
cancelLabel?: ReactNode;
loadingLabel?: ReactNode;
cancelVariant?: "outline" | "ghost";
className?: string;
onNext?: () => void;
onPrev?: () => void;
nextLabel?: ReactNode;
prevLabel?: ReactNode;
showSubmit?: boolean;
/**
* When true and not on the last step, render an extra "Save" button so an
* edit can be persisted without navigating through every step. Suppressed
* on the last step to avoid a duplicate submit button.
*/
saveOnEveryStep?: boolean;
}
export function FormActions({
@@ -27,23 +33,24 @@ export function FormActions({
submitLabel,
cancelLabel,
loadingLabel,
cancelVariant = 'outline',
cancelVariant = "outline",
className,
onNext,
onPrev,
nextLabel,
prevLabel,
showSubmit = true,
saveOnEveryStep = false,
}: FormActionsProps) {
const { t } = useTranslation()
const { t } = useTranslation();
const cancelText = cancelLabel ?? t('common.cancel', 'Ýatyr')
const loadingText = loadingLabel ?? t('common.saving', 'Saklanýar...')
const prevText = prevLabel ?? t('common.prev', 'Yza')
const nextText = nextLabel ?? t('common.next', 'Indiki')
const cancelText = cancelLabel ?? t("common.cancel", "Ýatyr");
const loadingText = loadingLabel ?? t("common.saving", "Saklanýar...");
const prevText = prevLabel ?? t("common.prev", "Yza");
const nextText = nextLabel ?? t("common.next", "Indiki");
return (
<div className={cn('flex items-center justify-end gap-3', className)}>
<div className={cn("flex items-center justify-end gap-3", className)}>
{onCancel && (
<Button type="button" variant={cancelVariant} onClick={onCancel} disabled={isPending}>
{cancelText}
@@ -59,6 +66,18 @@ export function FormActions({
{nextText}
</Button>
)}
{saveOnEveryStep && onSubmit && !showSubmit && (
<Button type="button" onClick={onSubmit} disabled={isPending}>
{isPending ? (
<span className="flex items-center gap-2">
<Loader2 size={14} className="animate-spin" />
{loadingText}
</span>
) : (
submitLabel
)}
</Button>
)}
{showSubmit && onSubmit && (
<Button type="button" onClick={onSubmit} disabled={isPending}>
{isPending ? (
@@ -72,5 +91,5 @@ export function FormActions({
</Button>
)}
</div>
)
);
}

View File

@@ -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} />;

View File

@@ -1,7 +1,18 @@
import { useMemo, useState } from "react";
import { Download, Eye, ChevronDown, Inbox } from "lucide-react";
import { Download, Eye, ChevronDown, Inbox, Pencil, Trash2 } from "lucide-react";
import { useTranslation } from "react-i18next";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { DataTable, type ColumnDef } from "@/components/dataTable";
import { Link } from "react-router-dom";
@@ -320,6 +331,87 @@ export function EmptyState({ label }: EmptyStateProps) {
);
}
// ─── ViewActions ──────────────────────────────────────────────────────────────
// Standard edit (→ `/edit` route) + delete (with confirmation AlertDialog)
// action buttons rendered in a view page header. Delete validation and the
// destructive mutation itself live in the caller's `onDelete`; this component
// only handles the dialog flow (open → confirm → close).
export interface ViewActionsProps {
editTo?: string;
onDelete?: () => void | Promise<void>;
deleteTitle?: string;
deleteDescription?: string;
deleting?: boolean;
deleteConfirmLabel?: string;
editDisabled?: boolean;
deleteDisabled?: boolean;
}
export function ViewActions({
editTo,
onDelete,
deleteTitle,
deleteDescription,
deleting,
deleteConfirmLabel,
editDisabled,
deleteDisabled,
}: ViewActionsProps) {
const { t } = useTranslation();
const [deleteOpen, setDeleteOpen] = useState(false);
const handleConfirm = async () => {
await onDelete?.();
setDeleteOpen(false);
};
return (
<div className="flex items-center gap-2">
{editTo && (
<Button variant="outline" size="sm" asChild disabled={editDisabled}>
<Link to={editTo}>
<Pencil size={14} />
</Link>
</Button>
)}
{onDelete && (
<Button
variant="outline"
size="sm"
disabled={deleteDisabled}
className="text-destructive border-destructive/30 hover:bg-destructive/10"
onClick={() => setDeleteOpen(true)}
>
<Trash2 size={14} />
</Button>
)}
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{deleteTitle ?? t("Are you sure?", "Eminsiňizmi?")}</AlertDialogTitle>
<AlertDialogDescription>
{deleteDescription ?? t("This action cannot be undone.", "Bu amal yzyna gaýtarylmaz.")}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t("Cancel", "Ýatyr")}</AlertDialogCancel>
<AlertDialogAction
onClick={handleConfirm}
disabled={deleting}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{deleting ? t("Deleting...", "Öçürilýär...") : (deleteConfirmLabel ?? t("Delete", "Öçür"))}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
);
}
// ─── AuditLog ─────────────────────────────────────────────────────────────────
export function AuditLog({ logs, currentPage, totalPages, totalCount, onPageChange, isLoading, onView }: AuditLogProps) {