fixed ui, connected role user, branch user permissions user api
This commit is contained in:
1 parent
d230b12d6a
commit
f00d2abcac
20 files changed
+906
-391
No files matched your search
+323
-128
@@ -1,18 +1,36 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useState, useMemo } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Pencil, CheckCircle2, UserRound, X } from "lucide-react";
|
||||
import * as VisuallyHidden from "@radix-ui/react-visually-hidden";
|
||||
import { Pencil, CheckCircle2, UserRound, X, Shield, KeyRound, Building2 } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { BentoGrid, BentoCard, InfoRow, CollapsibleSection, EmptyState, AuditLog } from "@/components/viewPageComponents";
|
||||
import { DataTableToolbar } from "@/components/dataTableToolbar";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
|
||||
import { FormInput } from "@/components/formInput";
|
||||
import { AvatarUpload } from "@/components/avatarUpload";
|
||||
import { FormActions } from "@/components/formActions";
|
||||
import { InfiniteSelect, type InfiniteSelectOption } from "@/components/infiniteSelect";
|
||||
import { useAuthStore } from "@/app/store/authStore";
|
||||
import { useProfile, useUpdateProfile } from "@/features/auth/hooks/useLogin";
|
||||
import { useInfiniteRoles } from "@/features/roles/hooks/useRoles";
|
||||
import { useInfinitePermissions } from "@/features/permissions/hooks/usePermissions";
|
||||
import { useInfiniteBranches } from "@/features/shared/hooks/useSharedBranchUsers";
|
||||
import { useInfiniteStaff } from "@/features/operators/hooks/useOperators";
|
||||
import { useAssignRoleToUser, useAssignPermissionToUser, useAssignBranchToUser } from "@/features/shared/hooks/useSharedUserAssignments";
|
||||
import type { LocalizedText } from "@/features/branches/api/branchesApi";
|
||||
|
||||
type AssignDialogKind = "role" | "permission" | "branch";
|
||||
|
||||
export default function ProfilePage() {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const { data: profileQueryData, isLoading } = useProfile();
|
||||
const authUser = useAuthStore((s) => s.user);
|
||||
const user = profileQueryData ?? authUser;
|
||||
@@ -20,10 +38,11 @@ export default function ProfilePage() {
|
||||
const updateProfileMutation = useUpdateProfile();
|
||||
|
||||
const [isEditing, setIsEditing] = useState(false);
|
||||
const [assignDialog, setAssignDialog] = useState<AssignDialogKind | null>(null);
|
||||
|
||||
const [roleSearch, setRoleSearch] = useState("");
|
||||
const [permSearch, setPermSearch] = useState("");
|
||||
const [branchSearch, setBranchSearch] = useState("");
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as keyof LocalizedText;
|
||||
|
||||
const branches = user?.branches ?? [];
|
||||
|
||||
// ── Form State for Editing ──
|
||||
const [formData, setFormData] = useState({
|
||||
@@ -36,17 +55,18 @@ export default function ProfilePage() {
|
||||
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
setFormData({
|
||||
name: user.name ?? "",
|
||||
firstName: user.firstName ?? "",
|
||||
lastName: user.lastName ?? "",
|
||||
phone: user.phone ?? "",
|
||||
avatar: user.avatar ?? "",
|
||||
});
|
||||
}
|
||||
}, [user, isEditing]);
|
||||
const startEditing = () => {
|
||||
if (!user) return;
|
||||
setFormData({
|
||||
name: user.name ?? "",
|
||||
firstName: user.firstName ?? "",
|
||||
lastName: user.lastName ?? "",
|
||||
phone: user.phone ?? "",
|
||||
avatar: user.avatar ?? "",
|
||||
});
|
||||
setErrors({});
|
||||
setIsEditing(true);
|
||||
};
|
||||
|
||||
const handleFieldChange = (field: keyof typeof formData, value: string) => {
|
||||
setFormData((prev) => ({ ...prev, [field]: value }));
|
||||
@@ -102,132 +122,138 @@ export default function ProfilePage() {
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* ── Title + actions ──────────────────────────────────────────────── */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-bold text-foreground leading-tight">
|
||||
{isEditing ? t("profile.editTitle", "Profili üýtgetmek") : `${t("profile.title", "Meniň profilim")}: ${user.name}`}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
{!isEditing ? (
|
||||
<Button variant="outline" size="sm" className="gap-2" onClick={() => setIsEditing(true)}>
|
||||
<Pencil size={15} />
|
||||
{t("common.edit", "Üýtgetmek")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="gap-2 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => setIsEditing(false)}
|
||||
disabled={updateProfileMutation.isPending}
|
||||
>
|
||||
<X size={15} />
|
||||
{t("common.cancel", "Yza")}
|
||||
</Button>
|
||||
)}
|
||||
{/* ── Profile hero ─────────────────────────────────────────────────── */}
|
||||
{!isEditing ? (
|
||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 bg-card border border-border rounded-xl p-5">
|
||||
<div className="flex items-center gap-4 min-w-0">
|
||||
{user.avatar ? (
|
||||
<img
|
||||
src={user.avatar}
|
||||
alt="avatar"
|
||||
className="w-16 h-16 rounded-full border border-border bg-muted/40 object-cover shrink-0 shadow-sm"
|
||||
/>
|
||||
) : (
|
||||
<div className="w-16 h-16 rounded-full border border-border bg-muted/40 flex items-center justify-center shrink-0 shadow-sm">
|
||||
<UserRound size={28} className="text-muted-foreground/60" />
|
||||
</div>
|
||||
)}
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<h1 className="text-lg font-bold text-foreground truncate">
|
||||
{[user.firstName, user.lastName].filter(Boolean).join(" ") || user.name}
|
||||
</h1>
|
||||
<span className="inline-flex items-center gap-1 text-xs font-medium text-emerald-600 bg-emerald-500/10 px-2 py-0.5 rounded-full shrink-0">
|
||||
<CheckCircle2 size={12} />
|
||||
{t("common.active", "Işjeň")}
|
||||
</span>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground mt-0.5 truncate">
|
||||
@{user.name}
|
||||
{user.phone ? ` · ${user.phone}` : ""}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" className="gap-2 shrink-0" onClick={startEditing}>
|
||||
<Pencil size={15} />
|
||||
{t("common.edit", "Üýtgetmek")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-bold text-foreground leading-tight">{t("profile.editTitle", "Profili üýtgetmek")}</h1>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="gap-2 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => setIsEditing(false)}
|
||||
disabled={updateProfileMutation.isPending}
|
||||
>
|
||||
<X size={15} />
|
||||
{t("common.cancel", "Yza")}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Main content ─────────────────────────────────────────────────── */}
|
||||
{!isEditing ? (
|
||||
<>
|
||||
<BentoGrid cols={1}>
|
||||
<BentoCard title={t("profile.sections.basic", "Esasy maglumatlar")}>
|
||||
<div className="flex flex-col items-center gap-4 px-4 pt-4 pb-2">
|
||||
{user.avatar ? (
|
||||
<img
|
||||
src={user.avatar}
|
||||
alt="avatar"
|
||||
className="w-20 h-20 rounded-full border border-border bg-muted/40 object-cover shrink-0 shadow-sm"
|
||||
/>
|
||||
) : (
|
||||
<div className="w-20 h-20 rounded-full border border-border bg-muted/40 flex items-center justify-center shrink-0 shadow-sm">
|
||||
<UserRound size={32} className="text-muted-foreground/60" />
|
||||
</div>
|
||||
)}
|
||||
<div className="min-w-0 text-center">
|
||||
<p className="text-base font-semibold text-foreground truncate">
|
||||
{[user.firstName, user.lastName].filter(Boolean).join(" ") || user.name}
|
||||
</p>
|
||||
{user.phone && <p className="text-xs text-muted-foreground mt-0.5">{user.phone}</p>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("profile.sections.account", "Hasap maglumatlary")}>
|
||||
<InfoRow label={t("common.id", "ID")} value={user.id} />
|
||||
<InfoRow label={t("users.fields.username", "Ulanyjy ady")} value={user.name} />
|
||||
<InfoRow label={t("users.fields.firstName", "At ady")} value={user.firstName ?? "—"} />
|
||||
<InfoRow label={t("users.fields.lastName", "Familiýasy")} value={user.lastName ?? "—"} />
|
||||
<InfoRow label={t("users.fields.phone", "Telefon belgisi")} value={user.phone ?? "—"} />
|
||||
{user.role && <InfoRow label={t("users.fields.role", "Roly")} value={user.role} />}
|
||||
{user.email && <InfoRow label={t("users.fields.email", "E-poçta")} value={user.email} />}
|
||||
<InfoRow
|
||||
label={t("users.fields.createdAt", "Döredilen wagty")}
|
||||
value={user.createdAt ? new Date(user.createdAt).toLocaleString() : "—"}
|
||||
/>
|
||||
<InfoRow label={t("users.fields.isActive", "Işjeň")}>
|
||||
<div className="flex items-center gap-1.5 text-emerald-500 font-medium text-sm">
|
||||
<CheckCircle2 size={16} />
|
||||
<span>{t("common.active", "Işjeň")}</span>
|
||||
</div>
|
||||
</InfoRow>
|
||||
{user.email && <InfoRow label={t("users.fields.email", "E-poçta")} value={user.email} />}
|
||||
</BentoCard>
|
||||
|
||||
<BentoCard title={t("profile.sections.contact", "Habarlaşmak maglumatlary")}>
|
||||
<InfoRow label={t("users.fields.firstName", "At ady")} value={user.firstName ?? "—"} />
|
||||
<InfoRow label={t("users.fields.lastName", "Familiýasy")} value={user.lastName ?? "—"} />
|
||||
<InfoRow label={t("users.fields.phone", "Telefon belgisi")} value={user.phone ?? "—"} />
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
|
||||
{/* ── Rollar ───────────────────────────────────────────────────────── */}
|
||||
<CollapsibleSection title={t("users.sections.roles", "Rollar")}>
|
||||
<DataTableToolbar
|
||||
searchValue={roleSearch}
|
||||
onSearchChange={setRoleSearch}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={[]}
|
||||
columnVisibility={{}}
|
||||
onColumnVisibilityChange={() => {}}
|
||||
columnOrder={[]}
|
||||
onColumnOrderChange={() => {}}
|
||||
actionLabel={t("users.actions.addRole", "Rol birikdiriň")}
|
||||
onAction={() => {}}
|
||||
/>
|
||||
<EmptyState label={t("users.empty.roles", "Berlen kriteriýalara Rol gabat gelmedi.")} />
|
||||
</CollapsibleSection>
|
||||
<BentoGrid cols={2}>
|
||||
<BentoCard title={t("profile.sections.org", "Guramaçylyk maglumatlary")}>
|
||||
<InfoRow label={t("users.fields.role", "Roly")}>
|
||||
{user.role ? (
|
||||
<Link
|
||||
to={`/settings/users/roles/${user.role.id}`}
|
||||
className="inline-flex items-center gap-1 text-xs border border-border rounded-md px-2 py-1 hover:bg-muted transition-colors"
|
||||
>
|
||||
<Shield size={12} />
|
||||
{user.role.name}
|
||||
</Link>
|
||||
) : (
|
||||
<span className="text-sm text-muted-foreground">—</span>
|
||||
)}
|
||||
</InfoRow>
|
||||
|
||||
{/* ── Rugsatlar ────────────────────────────────────────────────────── */}
|
||||
<CollapsibleSection title={t("users.sections.permissions", "Rugsatlar")}>
|
||||
<DataTableToolbar
|
||||
searchValue={permSearch}
|
||||
onSearchChange={setPermSearch}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={[]}
|
||||
columnVisibility={{}}
|
||||
onColumnVisibilityChange={() => {}}
|
||||
columnOrder={[]}
|
||||
onColumnOrderChange={() => {}}
|
||||
actionLabel={t("users.actions.addPermission", "Rugsat birikdiriň")}
|
||||
onAction={() => {}}
|
||||
/>
|
||||
<EmptyState label={t("users.empty.permissions", "Berlen kriteriýalara Rugsat gabat gelmedi.")} />
|
||||
</CollapsibleSection>
|
||||
<InfoRow label={t("users.sections.branches", "Şahamçalar")}>
|
||||
{branches.length > 0 ? (
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{branches.map((b) => (
|
||||
<Link
|
||||
key={b.id}
|
||||
to={`/settings/location/branches/${b.id}`}
|
||||
className="inline-flex items-center gap-1 text-xs border border-border rounded-md px-2 py-1 hover:bg-muted transition-colors"
|
||||
>
|
||||
<Building2 size={11} className="text-muted-foreground" />
|
||||
<span className="text-foreground font-medium">
|
||||
{b.name?.[lang] || b.name?.tm || b.name?.en || b.name?.ru || b.uniqueCode || b.id}
|
||||
</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-sm text-muted-foreground">—</span>
|
||||
)}
|
||||
</InfoRow>
|
||||
|
||||
{/* ── Şahamçalar ───────────────────────────────────────────────────── */}
|
||||
<CollapsibleSection title={t("users.sections.branches", "Şahamçalar")}>
|
||||
<DataTableToolbar
|
||||
searchValue={branchSearch}
|
||||
onSearchChange={setBranchSearch}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={[]}
|
||||
columnVisibility={{}}
|
||||
onColumnVisibilityChange={() => {}}
|
||||
columnOrder={[]}
|
||||
onColumnOrderChange={() => {}}
|
||||
actionLabel={t("users.actions.addBranch", "Şahamça birikdiriň")}
|
||||
onAction={() => {}}
|
||||
/>
|
||||
<EmptyState label={t("users.empty.branches", "Berlen kriteriýalara Şahamça gabat gelmedi.")} />
|
||||
</CollapsibleSection>
|
||||
<InfoRow label={t("users.sections.permissions", "Rugsatlar")}>
|
||||
<span className="text-sm text-muted-foreground">—</span>
|
||||
</InfoRow>
|
||||
</BentoCard>
|
||||
|
||||
{/* ── Ammallar ─────────────────────────────────────────────────────── */}
|
||||
<CollapsibleSection title={t("users.sections.audit", "Ammallar")}>
|
||||
<AuditLog logs={[]} currentPage={1} totalPages={1} totalCount={0} />
|
||||
</CollapsibleSection>
|
||||
<BentoCard title={t("profile.sections.actions", "Amallar")}>
|
||||
<div className="flex flex-wrap gap-2 px-4 py-3">
|
||||
<Button variant="outline" size="sm" className="gap-1.5" onClick={() => setAssignDialog("role")}>
|
||||
<Shield size={14} />
|
||||
{t("profile.actions.assignRole", "Rol birikdiriň")}
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="gap-1.5" onClick={() => setAssignDialog("permission")}>
|
||||
<KeyRound size={14} />
|
||||
{t("profile.actions.assignPermission", "Rugsat birikdiriň")}
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" className="gap-1.5" onClick={() => setAssignDialog("branch")}>
|
||||
<Building2 size={14} />
|
||||
{t("profile.actions.assignBranch", "Şahamça birikdiriň")}
|
||||
</Button>
|
||||
</div>
|
||||
</BentoCard>
|
||||
</BentoGrid>
|
||||
</>
|
||||
) : (
|
||||
<div className="w-full">
|
||||
@@ -288,6 +314,175 @@ export default function ProfilePage() {
|
||||
</BentoCard>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* ── Assign dialog (staff user + role/permission/branch) ─────────────── */}
|
||||
{assignDialog && <AssignDialog kind={assignDialog} onClose={() => setAssignDialog(null)} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Assign dialog ────────────────────────────────────────────────────────────
|
||||
|
||||
const ASSIGN_DIALOG_TITLES: Record<AssignDialogKind, string> = {
|
||||
role: "profile.actions.assignRole",
|
||||
permission: "profile.actions.assignPermission",
|
||||
branch: "profile.actions.assignBranch",
|
||||
};
|
||||
|
||||
const ASSIGN_DIALOG_FIELD_LABELS: Record<AssignDialogKind, string> = {
|
||||
role: "users.fields.role",
|
||||
permission: "users.sections.permissions",
|
||||
branch: "users.sections.branches",
|
||||
};
|
||||
|
||||
/**
|
||||
* Dialog for assigning a role / permission / branch to a staff user.
|
||||
* Two selects: target user (GET /users/staff) and the resource to assign.
|
||||
*/
|
||||
function AssignDialog({ kind, onClose }: { kind: AssignDialogKind; onClose: () => void }) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const lang = (i18n.language === "ru" ? "ru" : i18n.language === "en" ? "en" : "tm") as keyof LocalizedText;
|
||||
|
||||
const [userSearch, setUserSearch] = useState("");
|
||||
const [userValue, setUserValue] = useState("");
|
||||
const [resourceSearch, setResourceSearch] = useState("");
|
||||
const [resourceValue, setResourceValue] = useState("");
|
||||
const [error, setError] = useState<string | undefined>();
|
||||
|
||||
const staffQuery = useInfiniteStaff(userSearch);
|
||||
const rolesQuery = useInfiniteRoles(resourceSearch, kind === "role");
|
||||
const permissionsQuery = useInfinitePermissions(resourceSearch, kind === "permission");
|
||||
const branchesQuery = useInfiniteBranches(resourceSearch, kind === "branch");
|
||||
|
||||
const roleMutation = useAssignRoleToUser();
|
||||
const permissionMutation = useAssignPermissionToUser();
|
||||
const branchMutation = useAssignBranchToUser();
|
||||
const isPending = roleMutation.isPending || permissionMutation.isPending || branchMutation.isPending;
|
||||
|
||||
const staffOptions: InfiniteSelectOption[] = useMemo(
|
||||
() =>
|
||||
(staffQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p?.users ?? [])
|
||||
.map((u) => ({
|
||||
value: String(u.id),
|
||||
label: [u.firstName, u.lastName].filter(Boolean).join(" ") || u.name || u.username || String(u.id),
|
||||
})),
|
||||
[staffQuery.data],
|
||||
);
|
||||
|
||||
const resourceOptions: InfiniteSelectOption[] = useMemo(() => {
|
||||
if (kind === "role") {
|
||||
return (rolesQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p?.roles ?? [])
|
||||
.map((r) => ({ value: String(r.id), label: r.name || r.code || String(r.id) }));
|
||||
}
|
||||
if (kind === "permission") {
|
||||
return (permissionsQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p?.permissions ?? [])
|
||||
.map((perm) => ({ value: String(perm.id), label: perm.name || perm.code || String(perm.id) }));
|
||||
}
|
||||
return (branchesQuery.data?.pages ?? [])
|
||||
.flatMap((p) => p?.branches ?? [])
|
||||
.map((b) => ({
|
||||
value: String(b.id),
|
||||
label: b.name?.[lang] || b.name?.tm || b.name?.en || b.name?.ru || b.uniqueCode || String(b.id),
|
||||
}));
|
||||
}, [kind, rolesQuery.data, permissionsQuery.data, branchesQuery.data, lang]);
|
||||
|
||||
const resourceLoading =
|
||||
kind === "role" ? rolesQuery.isLoading : kind === "permission" ? permissionsQuery.isLoading : branchesQuery.isLoading;
|
||||
const resourceLoadingMore =
|
||||
kind === "role"
|
||||
? rolesQuery.isFetchingNextPage
|
||||
: kind === "permission"
|
||||
? permissionsQuery.isFetchingNextPage
|
||||
: branchesQuery.isFetchingNextPage;
|
||||
const resourceHasNextPage =
|
||||
kind === "role" ? !!rolesQuery.hasNextPage : kind === "permission" ? !!permissionsQuery.hasNextPage : !!branchesQuery.hasNextPage;
|
||||
const loadMoreResources = () => {
|
||||
if (kind === "role") rolesQuery.fetchNextPage();
|
||||
else if (kind === "permission") permissionsQuery.fetchNextPage();
|
||||
else branchesQuery.fetchNextPage();
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (!userValue || !resourceValue) {
|
||||
setError(t("common.errors.required", "Meýdança hökmany doldurylmaly"));
|
||||
return;
|
||||
}
|
||||
setError(undefined);
|
||||
|
||||
const userId = Number(userValue);
|
||||
const resourceId = Number(resourceValue);
|
||||
const onSuccess = () => {
|
||||
setUserValue("");
|
||||
setResourceValue("");
|
||||
onClose();
|
||||
};
|
||||
|
||||
if (kind === "role") roleMutation.mutate({ userId, roleId: resourceId }, { onSuccess });
|
||||
else if (kind === "permission") permissionMutation.mutate({ userId, permissionId: resourceId }, { onSuccess });
|
||||
else branchMutation.mutate({ userId, branchId: resourceId }, { onSuccess });
|
||||
};
|
||||
|
||||
return (
|
||||
<AlertDialog open onOpenChange={(open) => !open && onClose()}>
|
||||
<AlertDialogContent className="max-w-md sm:max-w-md">
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t(ASSIGN_DIALOG_TITLES[kind])}</AlertDialogTitle>
|
||||
<VisuallyHidden.Root>
|
||||
<AlertDialogDescription>{t(ASSIGN_DIALOG_TITLES[kind])}</AlertDialogDescription>
|
||||
</VisuallyHidden.Root>
|
||||
</AlertDialogHeader>
|
||||
|
||||
<div className="space-y-3">
|
||||
<InfiniteSelect
|
||||
required
|
||||
label={t("profile.assign.userLabel", "Ulanyjy (staff)")}
|
||||
value={userValue}
|
||||
onChange={(v) => {
|
||||
setUserValue(v);
|
||||
if (error) setError(undefined);
|
||||
}}
|
||||
options={staffOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
loading={staffQuery.isLoading}
|
||||
isLoadingMore={staffQuery.isFetchingNextPage}
|
||||
hasNextPage={!!staffQuery.hasNextPage}
|
||||
onLoadMore={() => staffQuery.fetchNextPage()}
|
||||
searchValue={userSearch}
|
||||
onSearchChange={setUserSearch}
|
||||
/>
|
||||
|
||||
<InfiniteSelect
|
||||
required
|
||||
label={t(ASSIGN_DIALOG_FIELD_LABELS[kind])}
|
||||
value={resourceValue}
|
||||
onChange={(v) => {
|
||||
setResourceValue(v);
|
||||
if (error) setError(undefined);
|
||||
}}
|
||||
error={error}
|
||||
options={resourceOptions}
|
||||
placeholder={t("loanOrderForm.placeholders.searchableSelect") || "Saýlamak üçin basyň"}
|
||||
loading={resourceLoading}
|
||||
isLoadingMore={resourceLoadingMore}
|
||||
hasNextPage={resourceHasNextPage}
|
||||
onLoadMore={loadMoreResources}
|
||||
searchValue={resourceSearch}
|
||||
onSearchChange={setResourceSearch}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<AlertDialogFooter>
|
||||
<Button variant="ghost" size="sm" onClick={onClose} disabled={isPending}>
|
||||
{t("common.cancel", "Yza")}
|
||||
</Button>
|
||||
<Button size="sm" onClick={handleSubmit} disabled={!userValue || !resourceValue || isPending}>
|
||||
{t("common.save", "Ýatda sakla")}
|
||||
</Button>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user