connect users section api, fixed some ui, added some lang support to missed words

This commit is contained in:
Jelaletdin12
2026-08-18 21:41:13 +05:00
parent 0e75c85fe1
commit 7bb37f9b43
24 changed files with 1871 additions and 1543 deletions

View File

@@ -8,6 +8,7 @@ import { InfiniteSelect, type InfiniteSelectOption, type InfiniteSelectProps } f
import { Checkbox } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
import { FormActions } from "@/components/formActions";
import { AvatarUpload } from "@/components/avatarUpload";
import { BentoGrid, BentoCard } from "@/components/bento";
import { useCreateUser, useUpdateUser } from "../hooks/useAllUsers";
import { useInfiniteRoles } from "@/features/roles/hooks/useRoles";
@@ -59,7 +60,7 @@ export function UserForm({ mode, initialData }: UserFormProps) {
const roleSelect: Omit<InfiniteSelectProps, "label" | "required" | "placeholder"> = useMemo(() => {
const opts: InfiniteSelectOption[] = (roleQuery.data?.pages ?? [])
.flatMap((p) => p.roles)
.map((r) => ({ value: r.name, label: r.name }));
.map((r) => ({ value: r.code, label: r.name }));
// Ensure the currently-selected role is present (edit mode), even if it
// lives beyond the pages loaded so far.
@@ -150,123 +151,115 @@ export function UserForm({ mode, initialData }: UserFormProps) {
<h1 className="text-xl font-semibold text-foreground">
{mode === "create" ? t("users.createTitle", "Ulanyjy dörediň") : t("users.editTitle", "Ulanyjy üýtgetmek")}
</h1>
<BentoGrid cols={2}>
<BentoCard>
<FormInput
type="text"
label={t("users.fields.username", "Ulanyjy ady")}
value={form.username}
onChange={(v) => setField("username", v)}
placeholder={t("users.fields.username", "Ulanyjy ady")}
error={errors.username}
disabled={isPending}
required
/>
<p className="text-xs text-muted-foreground -mt-3">{t("users.fields.usernameHint", "Unikal login ady")}</p>
{/* ── Identity ── */}
<BentoCard title={t("users.sections.identity", "Şahsy maglumat")}>
<div className="grid grid-cols-2 gap-3">
<FormInput
type="text"
label={t("users.fields.username", "Ulanyjy ady")}
value={form.username}
onChange={(v) => setField("username", v)}
placeholder={t("users.fields.username", "Ulanyjy ady")}
error={errors.username}
disabled={isPending}
required
/>
<FormInput
type="text"
label={t("users.fields.name", "Ady")}
value={form.name}
onChange={(v) => setField("name", v)}
placeholder={t("users.fields.name", "Ady")}
error={errors.name}
disabled={isPending}
required
/>
<FormInput
type="text"
label={t("users.fields.firstName", "Ady (at)")}
value={form.firstName}
onChange={(v) => setField("firstName", v)}
placeholder={t("users.fields.firstName", "Ady (at)")}
error={errors.firstName}
disabled={isPending}
/>
<FormInput
type="text"
label={t("users.fields.lastName", "Familiýasy")}
value={form.lastName}
onChange={(v) => setField("lastName", v)}
placeholder={t("users.fields.lastName", "Familiýasy")}
error={errors.lastName}
disabled={isPending}
/>
</div>
<div className="grid grid-cols-2 gap-3">
<FormInput
type="phone"
label={t("users.fields.phone", "Telefon")}
value={form.phone}
onChange={(v) => setField("phone", v)}
placeholder="62-38-49-56"
error={errors.phone}
disabled={isPending}
required
/>
<FormInput
type="email"
label={t("users.fields.email", "E-poçta")}
value={form.email}
onChange={(v) => setField("email", v)}
placeholder={t("users.fields.email", "E-poçta")}
error={errors.email}
disabled={isPending}
/>
<InfiniteSelect
label={t("users.fields.role", "Roly")}
value={form.role}
onChange={(v) => setField("role", v)}
placeholder={t("users.fields.role", "Roly")}
error={errors.role}
disabled={isPending}
required
{...roleSelect}
/>
{mode === "create" && (
<FormInput
type="password"
label={t("users.fields.password", "Açar sözi")}
value={form.password}
onChange={(v) => setField("password", v)}
placeholder={t("users.fields.password", "Açar sözi")}
error={errors.password}
disabled={isPending}
required
/>
)}
<div className="flex items-center gap-2 pt-1">
<Checkbox id="active" checked={form.active} onCheckedChange={(v) => setField("active", !!v)} disabled={isPending} />
<Label htmlFor="active" className="text-sm text-muted-foreground cursor-pointer">
{form.active ? t("common.active", "Işjeň") : t("common.inactive", "Işjeň däl")}
</Label>
</div>
</div>
</BentoCard>
{/* ── Avatar ── */}
<BentoCard>
<FormInput
type="text"
label={t("users.fields.name", "Ady")}
value={form.name}
onChange={(v) => setField("name", v)}
placeholder={t("users.fields.name", "Ady")}
error={errors.name}
disabled={isPending}
required
/>
<p className="text-xs text-muted-foreground -mt-3">{t("users.fields.nameHint", "Doly ady we familiýasy")}</p>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label={t("users.fields.firstName", "Ady (at)")}
value={form.firstName}
onChange={(v) => setField("firstName", v)}
placeholder={t("users.fields.firstName", "Ady (at)")}
error={errors.firstName}
disabled={isPending}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label={t("users.fields.lastName", "Familiýasy")}
value={form.lastName}
onChange={(v) => setField("lastName", v)}
placeholder={t("users.fields.lastName", "Familiýasy")}
error={errors.lastName}
disabled={isPending}
/>
</BentoCard>
<BentoCard>
<FormInput
type="phone"
label={t("users.fields.phone", "Telefon")}
value={form.phone}
onChange={(v) => setField("phone", v)}
placeholder="62-38-49-56"
error={errors.phone}
disabled={isPending}
required
/>
<p className="text-xs text-muted-foreground -mt-3">{t("users.fields.phoneHint", "+993 bilen başlanýar")}</p>
</BentoCard>
<BentoCard>
<FormInput
type="email"
label={t("users.fields.email", "E-poçta")}
value={form.email}
onChange={(v) => setField("email", v)}
placeholder={t("users.fields.email", "E-poçta")}
error={errors.email}
disabled={isPending}
/>
<p className="text-xs text-muted-foreground -mt-3">{t("users.fields.emailHint", "Islege görä")}</p>
</BentoCard>
<BentoCard>
<InfiniteSelect
label={t("users.fields.role", "Roly")}
value={form.role}
onChange={(v) => setField("role", v)}
placeholder={t("users.fields.role", "Roly")}
error={errors.role}
disabled={isPending}
required
{...roleSelect}
/>
</BentoCard>
<BentoCard>
<FormInput
type="text"
label={t("users.fields.avatar", "Awatar URL")}
<AvatarUpload
label={t("users.fields.avatar", "Awatar")}
value={form.avatar}
onChange={(v) => setField("avatar", v)}
placeholder="https://..."
error={errors.avatar}
disabled={isPending}
/>
</BentoCard>
{mode === "create" && (
<BentoCard>
<FormInput
type="password"
label={t("users.fields.password", "Açar sözi")}
value={form.password}
onChange={(v) => setField("password", v)}
placeholder={t("users.fields.password", "Açar sözi")}
error={errors.password}
disabled={isPending}
required
/>
<p className="text-xs text-muted-foreground -mt-3">{t("users.fields.passwordHint", "Iň az 6 harp")}</p>
</BentoCard>
)}
<BentoCard>
<div className="space-y-1">
<p className="text-sm font-semibold text-muted-foreground">{t("users.fields.socialMedia", "Sosial media")}</p>
</div>
<div className="flex flex-col gap-3">
{/* ── Social media ── */}
<BentoCard title={t("users.fields.socialMedia", "Sosial media")} span="full">
<div className="grid grid-cols-3 gap-3">
<FormInput
type="text"
label={t("users.fields.facebook", "Facebook")}
@@ -296,30 +289,8 @@ export function UserForm({ mode, initialData }: UserFormProps) {
/>
</div>
</BentoCard>
<BentoCard>
<div className="space-y-1">
<p className="text-sm font-semibold text-muted-foreground">{t("users.fields.lightMode", "Light režimi")}</p>
</div>
<div className="flex items-center gap-2">
<Checkbox id="lightMode" checked={form.lightMode} onCheckedChange={(v) => setField("lightMode", !!v)} disabled={isPending} />
<Label htmlFor="lightMode" className="text-sm text-muted-foreground cursor-pointer">
{form.lightMode ? t("common.yes", "Hawa") : t("common.no", "Ýok")}
</Label>
</div>
</BentoCard>
<BentoCard>
<div className="space-y-1">
<p className="text-sm font-semibold text-muted-foreground">{t("users.fields.isActive", "Işjeň")}</p>
<p className="text-xs text-muted-foreground">{t("users.fields.isActiveHint", "Ulanyjynyň ulgama girip-bilmezligi")}</p>
</div>
<div className="flex items-center gap-2">
<Checkbox id="active" checked={form.active} onCheckedChange={(v) => setField("active", !!v)} disabled={isPending} />
<Label htmlFor="active" className="text-sm text-muted-foreground cursor-pointer">
{form.active ? t("common.active", "Işjeň") : t("common.inactive", "Işjeň däl")}
</Label>
</div>
</BentoCard>
</BentoGrid>
<FormActions
isPending={isPending}
onSubmit={handleSubmit}