started connect with api

This commit is contained in:
Jelaletdin12 committed 2026-08-11 22:48:25 +05:00
1 parent 0ca218505d
commit 6da59f42d9
112 files changed
+7091 -6989

No files matched your search

@@ -5,12 +5,12 @@ import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { FormActions } from "@/components/formActions";
import { BentoGrid, BentoCard } from "@/components/bento";
import { MultiLangInput } from "@/components/multiLangInput";
import { useCreatePermission, useUpdatePermission } from "../hooks/usePermissions";
import { createPermissionFormSchema, DEFAULT_FORM_VALUES, buildPayload } from "../schemas/permission.schema";
import type { PermissionFormData } from "../schemas/permission.schema";
import type { Permission } from "../api/permissionsApi";
import { FormInput } from "@/components/formInput";
// ─── Types ────────────────────────────────────────────────────────────────────
interface PermissionFormProps {
@@ -18,12 +18,6 @@ interface PermissionFormProps {
initialData?: Permission;
}
const GUARD_OPTIONS = [
{ value: "web", label: "web" },
{ value: "api", label: "api" },
{ value: "sanctum", label: "sanctum" },
];
type FlatErrors = Partial<Record<keyof PermissionFormData, string>>;
function flattenErrors(errors: Record<string, { message?: string } | undefined>): FlatErrors {
@@ -65,10 +59,8 @@ export function PermissionForm({ mode, initialData }: PermissionFormProps) {
? {
...DEFAULT_FORM_VALUES,
code: initialData.code,
nameTk: initialData.name.tk,
nameRu: initialData.name.ru,
nameEn: initialData.name.en,
guard_name: initialData.guard_name,
name: initialData.name,
guardName: initialData.guardName,
}
: DEFAULT_FORM_VALUES,
});
@@ -84,33 +76,6 @@ export function PermissionForm({ mode, initialData }: PermissionFormProps) {
[setValue, clearErrors],
);
const nameFields = {
tk: {
value: form.nameTk,
onChange: (v: string) => {
setValue("nameTk", v);
clearErrors("nameTk");
},
error: errors.nameTk,
},
ru: {
value: form.nameRu,
onChange: (v: string) => {
setValue("nameRu", v);
clearErrors("nameRu");
},
error: errors.nameRu,
},
en: {
value: form.nameEn,
onChange: (v: string) => {
setValue("nameEn", v);
clearErrors("nameEn");
},
error: errors.nameEn,
},
};
// ── Re-validate on language change ──
useEffect(() => {
if (Object.keys(rhfErrors).length > 0) trigger();
@@ -159,22 +124,27 @@ export function PermissionForm({ mode, initialData }: PermissionFormProps) {
</BentoCard>
<BentoCard>
<FormInput
type="select"
type="text"
label={t("permissions.fields.guardName", "Guard name")}
value={form.guard_name}
onChange={setField("guard_name")}
options={GUARD_OPTIONS}
error={errors.guard_name}
value={form.guardName}
onChange={setField("guardName")}
placeholder="operator"
error={errors.guardName}
disabled={isPending}
required
/>
</BentoCard>
<BentoCard span="full">
<p className="text-sm font-semibold text-muted-foreground mb-1">
{t("permissions.fields.name", "Ady")}
<span className="text-destructive ml-0.5">*</span>
</p>
<MultiLangInput fields={nameFields} placeholder={t("permissions.fields.name", "Ady")} disabled={isPending} />
<FormInput
type="text"
label={t("permissions.fields.name", "Ady")}
value={form.name}
onChange={setField("name")}
placeholder={t("permissions.fields.name", "Ady")}
error={errors.name}
disabled={isPending}
required
/>
</BentoCard>
</BentoGrid>
<FormActions